| 49 | } |
| 50 | |
| 51 | void IntermediateResultCacheTransform::transform(DB::Chunk & chunk) |
| 52 | { |
| 53 | if (chunk.empty()) |
| 54 | return; |
| 55 | |
| 56 | const auto & owner_info = chunk.getOwnerInfo(); |
| 57 | CacheValuePtr value; |
| 58 | if (!owner_info.empty()) |
| 59 | { |
| 60 | CacheKey key{cache_param.digest, cache_param.cached_table.getFullTableName(), owner_info}; |
| 61 | if (!cache_holder->write_cache.contains(key)) |
| 62 | return; |
| 63 | |
| 64 | auto it = uncompleted_cache.find(key); |
| 65 | if (it != uncompleted_cache.end()) |
| 66 | value = it->second; |
| 67 | else |
| 68 | { |
| 69 | value = cache->tryGetUncompletedCache(key); |
| 70 | uncompleted_cache.emplace(key, value); |
| 71 | } |
| 72 | |
| 73 | if (!value) |
| 74 | return; |
| 75 | |
| 76 | if ((cache_max_bytes < value->getBytes() + chunk.bytes()) || (cache_max_rows < value->getRows() + chunk.getNumRows())) |
| 77 | { |
| 78 | cache->modifyKeyStateToRefused(key); |
| 79 | uncompleted_cache.emplace(key, nullptr); |
| 80 | LOG_INFO( |
| 81 | log, |
| 82 | "Key:{} was refused because it was too large. (bytes,rows)->({},{})", |
| 83 | key.toString(), |
| 84 | value->getBytes() + chunk.bytes(), |
| 85 | value->getRows() + chunk.getNumRows()); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | auto cache_chunk = chunk.clone(); |
| 90 | size_t num_columns = cache_chunk.getNumColumns(); |
| 91 | size_t num_rows = cache_chunk.getNumRows(); |
| 92 | auto output_columns = cache_chunk.detachColumns(); |
| 93 | Columns cache_columns(num_columns); |
| 94 | for (size_t i = 0; i < num_columns; ++i) |
| 95 | cache_columns[cache_param.output_pos_to_cache_pos[i]] = std::move(output_columns[i]); |
| 96 | cache_chunk.setColumns(std::move(cache_columns), num_rows); |
| 97 | |
| 98 | if (value) |
| 99 | value->addChunk(cache_chunk); |
| 100 | else |
| 101 | { |
| 102 | CacheKey key{cache_param.digest, cache_param.cached_table.getFullTableName()}; |
| 103 | cache->emplaceCacheForEmptyResult(key, cache_chunk); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | } |
nothing calls this directly
no test coverage detected