| 72 | } |
| 73 | |
| 74 | void StatisticsCollector::writeToCatalog() |
| 75 | { |
| 76 | if (!catalog) |
| 77 | { |
| 78 | throw Exception("catalog is NULL", ErrorCodes::LOGICAL_ERROR); |
| 79 | } |
| 80 | StatsData data; |
| 81 | data.table_stats = table_stats.writeToCollection(); |
| 82 | std::vector<String> columns; |
| 83 | for (auto & [name, stats] : columns_stats) |
| 84 | { |
| 85 | columns.emplace_back(name); |
| 86 | data.column_stats[name] = stats.writeToCollection(); |
| 87 | } |
| 88 | auto proxy = createCachedStatsProxy(catalog, settings.cache_policy); |
| 89 | auto cols_desc = catalog->filterCollectableColumns(table_info, columns); |
| 90 | // drop old columns to ensure other data is deleted |
| 91 | // especially when collecting statistics_collect_histogram=0 |
| 92 | proxy->dropColumns(table_info, cols_desc); |
| 93 | proxy->put(table_info, std::move(data)); |
| 94 | catalog->invalidateClusterStatsCache(table_info); |
| 95 | // clear udi whenever it is to create/drop stats |
| 96 | // since after manual drop stats, users just don't want statistics, |
| 97 | // so we needn't care about udi for auto stats until next insertion |
| 98 | catalog->removeUdiCount(table_info); |
| 99 | } |
| 100 | |
| 101 | void StatisticsCollector::readAllFromCatalog() |
| 102 | { |
no test coverage detected