Merge pull request #62398 from Avogar/fix-analyzer-merge-push-down

Fix filter pushdown from additional_table_filters in Merge engine in analyzer
This commit is contained in:
Kruglov Pavel 2024-04-09 10:54:06 +00:00 committed by GitHub
commit 057efdb447
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 1 deletions

View File

@ -814,7 +814,8 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(QueryTreeNodePtr table_expres
bool optimize_move_to_prewhere
= settings.optimize_move_to_prewhere && (!is_final || settings.optimize_move_to_prewhere_if_final);
if (storage->supportsPrewhere() && optimize_move_to_prewhere)
auto supported_prewhere_columns = storage->supportedPrewhereColumns();
if (storage->canMoveConditionsToPrewhere() && optimize_move_to_prewhere && (!supported_prewhere_columns || supported_prewhere_columns->contains(filter_info.column_name)))
{
if (!prewhere_info)
prewhere_info = std::make_shared<PrewhereInfo>();

View File

@ -19,6 +19,12 @@ public:
bool supportsSampling() const override { return true; }
bool supportsFinal() const override { return true; }
bool supportsPrewhere() const override { return true; }
std::optional<NameSet> supportedPrewhereColumns() const override
{
return original_storage_snapshot ? original_storage_snapshot->storage.supportedPrewhereColumns() : std::nullopt;
}
bool supportsSubcolumns() const override { return true; }
bool supportsDynamicSubcolumns() const override { return true; }
bool canMoveConditionsToPrewhere() const override

View File

@ -0,0 +1,3 @@
UInt32 1
UInt32 2
UInt32 3

View File

@ -0,0 +1,8 @@
set allow_suspicious_low_cardinality_types=1;
drop table if exists test;
create table test (`x` LowCardinality(Nullable(UInt32)), `y` String) engine = MergeTree order by tuple();
insert into test values (1, 'a'), (2, 'bb'), (3, 'ccc'), (4, 'dddd');
create table m_table (x UInt32, y String) engine = Merge(currentDatabase(), 'test*');
select toTypeName(x), x FROM m_table SETTINGS additional_table_filters = {'m_table':'x != 4'}, optimize_move_to_prewhere=1, allow_experimental_analyzer=1;
drop table test;