diff --git a/src/Interpreters/ExpressionAnalyzer.cpp b/src/Interpreters/ExpressionAnalyzer.cpp index de82a9b9645761d058fb95c8f5d0b388cc7270bd..4146f0c3391b9ee67985e89b76ce6d2dd1b1eee2 100644 --- a/src/Interpreters/ExpressionAnalyzer.cpp +++ b/src/Interpreters/ExpressionAnalyzer.cpp @@ -139,11 +139,6 @@ ExpressionAnalyzer::ExpressionAnalyzer( analyzeAggregation(); } -bool ExpressionAnalyzer::isRemoteStorage() const -{ - return storage() && storage()->isRemote(); -} - void ExpressionAnalyzer::analyzeAggregation() { diff --git a/src/Interpreters/ExpressionAnalyzer.h b/src/Interpreters/ExpressionAnalyzer.h index a50fe4de2662f81e8c58464052678a1bb1e63148..14fd601732ecb423c0f93429f45beaa69bed94d1 100644 --- a/src/Interpreters/ExpressionAnalyzer.h +++ b/src/Interpreters/ExpressionAnalyzer.h @@ -164,7 +164,7 @@ protected: const ASTSelectQuery * getSelectQuery() const; - bool isRemoteStorage() const; + bool isRemoteStorage() const { return syntax->is_remote_storage; } }; class SelectQueryExpressionAnalyzer; diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index b2dbd02719145e827305fae2bdef406ab83fee0a..fb3495ca873fa92ca81464249e2a5a7e03531629 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -387,6 +387,19 @@ std::vector getAggregates(ASTPtr & query, const ASTSelectQu } +TreeRewriterResult::TreeRewriterResult( + const NamesAndTypesList & source_columns_, + ConstStoragePtr storage_, + const StorageMetadataPtr & metadata_snapshot_, + bool add_special) + : storage(storage_) + , metadata_snapshot(metadata_snapshot_) + , source_columns(source_columns_) +{ + collectSourceColumns(add_special); + is_remote_storage = storage && storage->isRemote(); +} + /// Add columns from storage to source_columns list. Deduplicate resulted list. /// Special columns are non physical columns, for example ALIAS void TreeRewriterResult::collectSourceColumns(bool add_special) diff --git a/src/Interpreters/TreeRewriter.h b/src/Interpreters/TreeRewriter.h index 83cfabe2ec41d251c41f18258e254ad5565576e3..4075be4326deb2ce5643b43b71b378d5523aaf8c 100644 --- a/src/Interpreters/TreeRewriter.h +++ b/src/Interpreters/TreeRewriter.h @@ -53,6 +53,9 @@ struct TreeRewriterResult bool optimize_trivial_count = false; + /// Cache isRemote() call for storage, because it may be too heavy. + bool is_remote_storage = false; + /// Results of scalar sub queries Scalars scalars; @@ -60,13 +63,7 @@ struct TreeRewriterResult const NamesAndTypesList & source_columns_, ConstStoragePtr storage_ = {}, const StorageMetadataPtr & metadata_snapshot_ = {}, - bool add_special = true) - : storage(storage_) - , metadata_snapshot(metadata_snapshot_) - , source_columns(source_columns_) - { - collectSourceColumns(add_special); - } + bool add_special = true); void collectSourceColumns(bool add_special); void collectUsedColumns(const ASTPtr & query, bool is_select);