Fix some tests, add debug logging for test 00693_max_block_size_system_tables_columns, use global context + current database in getDependenciesFromCreateQuery

This commit is contained in:
avogar 2024-06-19 19:25:16 +00:00
parent 20abea8f64
commit ede8630205
13 changed files with 17 additions and 16 deletions

View File

@ -438,7 +438,7 @@ void RestorerFromBackup::findTableInBackupImpl(const QualifiedTableName & table_
String create_table_query_str = serializeAST(*create_table_query); String create_table_query_str = serializeAST(*create_table_query);
bool is_predefined_table = DatabaseCatalog::instance().isPredefinedTable(StorageID{table_name.database, table_name.table}); bool is_predefined_table = DatabaseCatalog::instance().isPredefinedTable(StorageID{table_name.database, table_name.table});
auto table_dependencies = getDependenciesFromCreateQuery(context, table_name, create_table_query); auto table_dependencies = getDependenciesFromCreateQuery(context, table_name, create_table_query, context->getCurrentDatabase());
bool table_has_data = backup->hasFiles(data_path_in_backup); bool table_has_data = backup->hasFiles(data_path_in_backup);
std::lock_guard lock{mutex}; std::lock_guard lock{mutex};

View File

@ -30,8 +30,8 @@ namespace
{ {
friend void tryVisitNestedSelect(const String & query, DDLDependencyVisitorData & data); friend void tryVisitNestedSelect(const String & query, DDLDependencyVisitorData & data);
public: public:
DDLDependencyVisitorData(const ContextPtr & context_, const QualifiedTableName & table_name_, const ASTPtr & ast_) DDLDependencyVisitorData(const ContextPtr & context_, const QualifiedTableName & table_name_, const ASTPtr & ast_, const String & current_database_)
: create_query(ast_), table_name(table_name_), current_database(context_->getCurrentDatabase()), context(context_) : create_query(ast_), table_name(table_name_), current_database(current_database_), context(context_)
{ {
} }
@ -464,9 +464,9 @@ namespace
} }
TableNamesSet getDependenciesFromCreateQuery(const ContextPtr & context, const QualifiedTableName & table_name, const ASTPtr & ast) TableNamesSet getDependenciesFromCreateQuery(const ContextPtr & global_context, const QualifiedTableName & table_name, const ASTPtr & ast, const String & current_database)
{ {
DDLDependencyVisitor::Data data{context, table_name, ast}; DDLDependencyVisitor::Data data{global_context, table_name, ast, current_database};
DDLDependencyVisitor::Visitor visitor{data}; DDLDependencyVisitor::Visitor visitor{data};
visitor.visit(ast); visitor.visit(ast);
return std::move(data).getDependencies(); return std::move(data).getDependencies();

View File

@ -13,6 +13,6 @@ using TableNamesSet = std::unordered_set<QualifiedTableName>;
/// Returns a list of all tables explicitly referenced in the create query of a specified table. /// Returns a list of all tables explicitly referenced in the create query of a specified table.
/// For example, a column default expression can use dictGet() and thus reference a dictionary. /// For example, a column default expression can use dictGet() and thus reference a dictionary.
/// Does not validate AST, works a best-effort way. /// Does not validate AST, works a best-effort way.
TableNamesSet getDependenciesFromCreateQuery(const ContextPtr & context, const QualifiedTableName & table_name, const ASTPtr & ast); TableNamesSet getDependenciesFromCreateQuery(const ContextPtr & global_context, const QualifiedTableName & table_name, const ASTPtr & ast, const String & current_database);
} }

View File

@ -122,7 +122,7 @@ void DDLLoadingDependencyVisitor::visit(const ASTStorage & storage, Data & data)
{ {
if (storage.ttl_table) if (storage.ttl_table)
{ {
auto ttl_dependensies = getDependenciesFromCreateQuery(data.global_context, data.table_name, storage.ttl_table->ptr()); auto ttl_dependensies = getDependenciesFromCreateQuery(data.global_context, data.table_name, storage.ttl_table->ptr(), data.default_database);
data.dependencies.merge(ttl_dependensies); data.dependencies.merge(ttl_dependensies);
} }

View File

@ -154,7 +154,7 @@ void DatabaseMemory::alterTable(ContextPtr local_context, const StorageID & tabl
applyMetadataChangesToCreateQuery(it->second, metadata); applyMetadataChangesToCreateQuery(it->second, metadata);
/// The create query of the table has been just changed, we need to update dependencies too. /// The create query of the table has been just changed, we need to update dependencies too.
auto ref_dependencies = getDependenciesFromCreateQuery(local_context, table_id.getQualifiedName(), it->second); auto ref_dependencies = getDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), it->second, local_context->getCurrentDatabase());
auto loading_dependencies = getLoadingDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), it->second, local_context->getCurrentDatabase()); auto loading_dependencies = getLoadingDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), it->second, local_context->getCurrentDatabase());
DatabaseCatalog::instance().updateDependencies(table_id, ref_dependencies, loading_dependencies); DatabaseCatalog::instance().updateDependencies(table_id, ref_dependencies, loading_dependencies);
} }

View File

@ -539,7 +539,7 @@ void DatabaseOrdinary::alterTable(ContextPtr local_context, const StorageID & ta
} }
/// The create query of the table has been just changed, we need to update dependencies too. /// The create query of the table has been just changed, we need to update dependencies too.
auto ref_dependencies = getDependenciesFromCreateQuery(local_context, table_id.getQualifiedName(), ast); auto ref_dependencies = getDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), ast, local_context->getCurrentDatabase());
auto loading_dependencies = getLoadingDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), ast, local_context->getCurrentDatabase()); auto loading_dependencies = getLoadingDependenciesFromCreateQuery(local_context->getGlobalContext(), table_id.getQualifiedName(), ast, local_context->getCurrentDatabase());
DatabaseCatalog::instance().updateDependencies(table_id, ref_dependencies, loading_dependencies); DatabaseCatalog::instance().updateDependencies(table_id, ref_dependencies, loading_dependencies);

View File

@ -1146,7 +1146,7 @@ void DatabaseReplicated::recoverLostReplica(const ZooKeeperPtr & current_zookeep
/// And QualifiedTableName::parseFromString doesn't handle this. /// And QualifiedTableName::parseFromString doesn't handle this.
auto qualified_name = QualifiedTableName{.database = getDatabaseName(), .table = table_name}; auto qualified_name = QualifiedTableName{.database = getDatabaseName(), .table = table_name};
auto query_ast = parseQueryFromMetadataInZooKeeper(table_name, create_table_query); auto query_ast = parseQueryFromMetadataInZooKeeper(table_name, create_table_query);
tables_dependencies.addDependencies(qualified_name, getDependenciesFromCreateQuery(getContext(), qualified_name, query_ast)); tables_dependencies.addDependencies(qualified_name, getDependenciesFromCreateQuery(getContext(), qualified_name, query_ast, getContext()->getCurrentDatabase()));
} }
tables_dependencies.checkNoCyclicDependencies(); tables_dependencies.checkNoCyclicDependencies();

View File

@ -137,7 +137,7 @@ void TablesLoader::buildDependencyGraph()
{ {
for (const auto & [table_name, table_metadata] : metadata.parsed_tables) for (const auto & [table_name, table_metadata] : metadata.parsed_tables)
{ {
auto new_ref_dependencies = getDependenciesFromCreateQuery(global_context, table_name, table_metadata.ast); auto new_ref_dependencies = getDependenciesFromCreateQuery(global_context, table_name, table_metadata.ast, global_context->getCurrentDatabase());
auto new_loading_dependencies = getLoadingDependenciesFromCreateQuery(global_context, table_name, table_metadata.ast, global_context->getCurrentDatabase()); auto new_loading_dependencies = getLoadingDependenciesFromCreateQuery(global_context, table_name, table_metadata.ast, global_context->getCurrentDatabase());
if (!new_ref_dependencies.empty()) if (!new_ref_dependencies.empty())

View File

@ -1083,7 +1083,7 @@ namespace
void addTableDependencies(const ASTCreateQuery & create, const ASTPtr & query_ptr, const ContextPtr & context) void addTableDependencies(const ASTCreateQuery & create, const ASTPtr & query_ptr, const ContextPtr & context)
{ {
QualifiedTableName qualified_name{create.getDatabase(), create.getTable()}; QualifiedTableName qualified_name{create.getDatabase(), create.getTable()};
auto ref_dependencies = getDependenciesFromCreateQuery(context, qualified_name, query_ptr); auto ref_dependencies = getDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase());
auto loading_dependencies = getLoadingDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase()); auto loading_dependencies = getLoadingDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase());
DatabaseCatalog::instance().addDependencies(qualified_name, ref_dependencies, loading_dependencies); DatabaseCatalog::instance().addDependencies(qualified_name, ref_dependencies, loading_dependencies);
} }
@ -1091,7 +1091,7 @@ void addTableDependencies(const ASTCreateQuery & create, const ASTPtr & query_pt
void checkTableCanBeAddedWithNoCyclicDependencies(const ASTCreateQuery & create, const ASTPtr & query_ptr, const ContextPtr & context) void checkTableCanBeAddedWithNoCyclicDependencies(const ASTCreateQuery & create, const ASTPtr & query_ptr, const ContextPtr & context)
{ {
QualifiedTableName qualified_name{create.getDatabase(), create.getTable()}; QualifiedTableName qualified_name{create.getDatabase(), create.getTable()};
auto ref_dependencies = getDependenciesFromCreateQuery(context, qualified_name, query_ptr); auto ref_dependencies = getDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase());
auto loading_dependencies = getLoadingDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase()); auto loading_dependencies = getLoadingDependenciesFromCreateQuery(context->getGlobalContext(), qualified_name, query_ptr, context->getCurrentDatabase());
DatabaseCatalog::instance().checkTableCanBeAddedWithNoCyclicDependencies(qualified_name, ref_dependencies, loading_dependencies); DatabaseCatalog::instance().checkTableCanBeAddedWithNoCyclicDependencies(qualified_name, ref_dependencies, loading_dependencies);
} }

View File

@ -134,6 +134,7 @@ protected:
cols_required_for_sorting_key = metadata_snapshot->getColumnsRequiredForSortingKey(); cols_required_for_sorting_key = metadata_snapshot->getColumnsRequiredForSortingKey();
cols_required_for_primary_key = metadata_snapshot->getColumnsRequiredForPrimaryKey(); cols_required_for_primary_key = metadata_snapshot->getColumnsRequiredForPrimaryKey();
cols_required_for_sampling = metadata_snapshot->getColumnsRequiredForSampling(); cols_required_for_sampling = metadata_snapshot->getColumnsRequiredForSampling();
LOG_DEBUG(getLogger("StorageSystemColumns"), "Get column sizes for table {}.{}", database_name, table_name);
column_sizes = storage->getColumnSizes(); column_sizes = storage->getColumnSizes();
} }

View File

@ -88,6 +88,7 @@ SELECT sum(n) from rich_syntax;
SYSTEM DROP DNS CACHE; SYSTEM DROP DNS CACHE;
DROP TABLE file; DROP TABLE file;
DROP DICTIONARY dict;
DROP TABLE url; DROP TABLE url;
DROP TABLE view; DROP TABLE view;
DROP TABLE buffer; DROP TABLE buffer;
@ -96,4 +97,3 @@ DROP TABLE merge_tf;
DROP TABLE distributed; DROP TABLE distributed;
DROP TABLE distributed_tf; DROP TABLE distributed_tf;
DROP TABLE rich_syntax; DROP TABLE rich_syntax;
DROP DICTIONARY dict;

View File

@ -310,6 +310,6 @@ SELECT name, found_rate FROM system.dictionaries WHERE database = currentDatabas
SELECT tuple(x, y) as key, dictGet('polygon_dictionary_01862', 'name', key) FROM points_01862 FORMAT Null; SELECT tuple(x, y) as key, dictGet('polygon_dictionary_01862', 'name', key) FROM points_01862 FORMAT Null;
SELECT name, found_rate FROM system.dictionaries WHERE database = currentDatabase() AND name = 'polygon_dictionary_01862'; SELECT name, found_rate FROM system.dictionaries WHERE database = currentDatabase() AND name = 'polygon_dictionary_01862';
DROP DICTIONARY polygon_dictionary_01862;
DROP TABLE polygons_01862; DROP TABLE polygons_01862;
DROP TABLE points_01862; DROP TABLE points_01862;
DROP DICTIONARY polygon_dictionary_01862;

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Tags: no-tsan, no-cpu-aarch64, no-parallel, no-debug # Tags: no-tsan, no-cpu-aarch64, no-parallel
# TSan does not supports tracing. # TSan does not supports tracing.
# trace_log doesn't work on aarch64 # trace_log doesn't work on aarch64