diff --git a/dbms/src/Databases/DatabaseOnDisk.h b/dbms/src/Databases/DatabaseOnDisk.h index 08a4319affb..761d55bd90b 100644 --- a/dbms/src/Databases/DatabaseOnDisk.h +++ b/dbms/src/Databases/DatabaseOnDisk.h @@ -18,7 +18,7 @@ namespace detail ASTPtr getCreateQueryFromMetadata(const String & metadata_path, const String & database, bool throw_on_error); } -/* Class to provide basic operations with tables stored on disk. +/* Class to provide basic operations with tables when metadata is stored on disk in .sql files. */ class DatabaseOnDisk { diff --git a/dbms/src/Storages/System/StorageSystemColumns.cpp b/dbms/src/Storages/System/StorageSystemColumns.cpp index 46ad7634a8f..c1d5c827f30 100644 --- a/dbms/src/Storages/System/StorageSystemColumns.cpp +++ b/dbms/src/Storages/System/StorageSystemColumns.cpp @@ -264,7 +264,11 @@ BlockInputStreams StorageSystemColumns::read( MutableColumnPtr database_column_mut = ColumnString::create(); for (const auto & database : databases) { - if (context.hasDatabaseAccessRights(database.first) && database.second->getEngineName() != "Lazy") + /// We are skipping "Lazy" database because we cannot afford initialization of all its tables. + /// This should be documented. + + if (context.hasDatabaseAccessRights(database.first) + && database.second->getEngineName() != "Lazy") database_column_mut->insert(database.first); } diff --git a/dbms/src/Storages/System/StorageSystemTables.cpp b/dbms/src/Storages/System/StorageSystemTables.cpp index 268cea76bec..27861fcb909 100644 --- a/dbms/src/Storages/System/StorageSystemTables.cpp +++ b/dbms/src/Storages/System/StorageSystemTables.cpp @@ -61,13 +61,15 @@ static ColumnPtr getFilteredDatabases(const ASTPtr & query, const Context & cont return block.getByPosition(0).column; } -static bool needLockStructure(const DatabasePtr& database, const Block& header) +/// Avoid heavy operation on tables if we only queried columns that we can get without table object. +/// Otherwise it will require table initialization for Lazy database. +static bool needLockStructure(const DatabasePtr & database, const Block & header) { if (database->getEngineName() != "Lazy") return true; static const std::set columns_without_lock = { "database", "name", "metadata_modification_time" }; - for (const auto& column : header.getColumnsWithTypeAndName()) + for (const auto & column : header.getColumnsWithTypeAndName()) { if (columns_without_lock.find(column.name) == columns_without_lock.end()) return true;