| 35 | } |
| 36 | |
| 37 | BlockIO InterpreterDropStatsQuery::execute() |
| 38 | { |
| 39 | auto context = getContext(); |
| 40 | auto query = query_ptr->as<const ASTDropStatsQuery>(); |
| 41 | auto catalog = Statistics::createCatalogAdaptor(context); |
| 42 | |
| 43 | auto cache_policy = query->cache_policy; |
| 44 | |
| 45 | if (cache_policy == StatisticsCachePolicy::Default) |
| 46 | { |
| 47 | // use context settings |
| 48 | cache_policy = context->getSettingsRef().statistics_cache_policy; |
| 49 | } |
| 50 | |
| 51 | // when enable_memory_catalog is true, we won't use cache |
| 52 | if (catalog->getSettingsRef().enable_memory_catalog) |
| 53 | { |
| 54 | if (cache_policy != StatisticsCachePolicy::Default) |
| 55 | throw Exception("memory catalog don't support cache policy", ErrorCodes::BAD_ARGUMENTS); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | if (query->table == "__reset") |
| 60 | { |
| 61 | if (cache_policy != StatisticsCachePolicy::Cache) |
| 62 | throw Exception("__reset is only valid at cache mode", ErrorCodes::NOT_IMPLEMENTED); |
| 63 | |
| 64 | // dummy means all |
| 65 | StatsTableIdentifier dummy(StorageID("", "__reset", UUID{})); |
| 66 | catalog->invalidateClusterStatsCache(dummy); |
| 67 | |
| 68 | return {}; |
| 69 | } |
| 70 | |
| 71 | catalog->checkHealth(/*is_write=*/true); |
| 72 | |
| 73 | auto proxy = Statistics::createCachedStatsProxy(catalog, cache_policy); |
| 74 | auto db = context->resolveDatabase(query->database); |
| 75 | |
| 76 | if (!DatabaseCatalog::instance().isDatabaseExist(db, context)) |
| 77 | { |
| 78 | auto msg = fmt::format(FMT_STRING("Unknown database ({})"), db); |
| 79 | throw Exception(msg, ErrorCodes::UNKNOWN_DATABASE); |
| 80 | } |
| 81 | |
| 82 | auto tables = getTablesFromAST(context, query); |
| 83 | |
| 84 | |
| 85 | if (tables.size() == 1 && !query->columns.empty()) |
| 86 | { |
| 87 | auto table = tables[0]; |
| 88 | dropStatsColumns(context, table, query->columns, cache_policy, true); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | for (auto table : tables) |
| 93 | { |
| 94 | dropStatsTable(context, table, cache_policy, true); |
nothing calls this directly
no test coverage detected