diff --git a/src/Core/Field.h b/src/Core/Field.h index a139316e3fd..45abb10f3b9 100644 --- a/src/Core/Field.h +++ b/src/Core/Field.h @@ -297,10 +297,6 @@ public: Map = 26, UUID = 27, Object = 28, - - // Special types for index analysis - NegativeInfinity = 254, - PositiveInfinity = 255, }; static const char * toString(Which which) diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 11b52a8bd27..28185a44512 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -4515,7 +4515,37 @@ bool MergeTreeData::getQueryProcessingStageWithAggregateProjection( } // Let's select the best projection to execute the query. - if (!candidates.empty() && !selected_candidate)src/Storages/StorageS3.cpp + if (!candidates.empty() && !selected_candidate) + { + std::shared_ptr max_added_blocks; + if (settings.select_sequential_consistency) + { + if (const StorageReplicatedMergeTree * replicated = dynamic_cast(this)) + max_added_blocks = std::make_shared(replicated->getMaxAddedBlocks()); + } + + auto parts = getDataPartsVector(); + MergeTreeDataSelectExecutor reader(*this); + query_info.merge_tree_select_result_ptr = reader.estimateNumMarksToRead( + parts, + analysis_result.required_columns, + metadata_snapshot, + metadata_snapshot, + query_info, + query_context, + settings.max_threads, + max_added_blocks); + + if (!query_info.merge_tree_select_result_ptr->error()) + { + // Add 1 to base sum_marks so that we prefer projections even when they have equal number of marks to read. + // NOTE: It is not clear if we need it. E.g. projections do not support skip index for now. + min_sum_marks = query_info.merge_tree_select_result_ptr->marks() + 1; + } + + /// Favor aggregate projections + for (auto & candidate : candidates) + { if (candidate.desc->type == ProjectionDescription::Type::Aggregate) { selectBestProjection( diff --git a/src/Storages/StorageExecutable.cpp b/src/Storages/StorageExecutable.cpp index 4b0aaf6caea..86479f8242a 100644 --- a/src/Storages/StorageExecutable.cpp +++ b/src/Storages/StorageExecutable.cpp @@ -77,7 +77,7 @@ StorageExecutable::StorageExecutable( Pipe StorageExecutable::read( const Names & /*column_names*/, - const StorageMetadataPtr & metadata_snapshot, + const StorageSnapshotPtr & storage_snapshot, SelectQueryInfo & /*query_info*/, ContextPtr context, QueryProcessingStage::Enum /*processed_stage*/, @@ -172,7 +172,7 @@ Pipe StorageExecutable::read( tasks.emplace_back(std::move(task)); } - auto sample_block = metadata_snapshot->getSampleBlock(); + auto sample_block = storage_snapshot->metadata->getSampleBlock(); ShellCommandSourceConfiguration configuration; configuration.max_block_size = max_block_size; diff --git a/src/Storages/StorageExecutable.h b/src/Storages/StorageExecutable.h index dd986ee3956..4974f845c14 100644 --- a/src/Storages/StorageExecutable.h +++ b/src/Storages/StorageExecutable.h @@ -31,7 +31,7 @@ public: Pipe read( const Names & column_names, - const StorageMetadataPtr & /*metadata_snapshot*/, + const StorageSnapshotPtr & /*storage_snapshot*/, SelectQueryInfo & query_info, ContextPtr context, QueryProcessingStage::Enum processed_stage,