Repository navigation
Enable merge filters optimization. - #71539
Conversation
|
This is an automated comment for commit de41100 with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
| /// but contains values other than 0 and 1 (e.g. if it is (number%5) it contains 2,3,4) | ||
| /// 2. CAST the result to the exact type of the PREWHERE column from the original DAG | ||
| const auto & last_step_result_node_info = node_remap[steps.back().column_name]; | ||
| //const auto & last_step_result_node_info = node_remap[steps.back().column_name]; |
| /// If PREWHERE has multiple conditions combined with AND, execute them in separate read/filtering steps. | ||
| bool enable_multiple_prewhere_read_steps = false; | ||
| /// In case of multiple prewhere steps, execute filtering earlier to support short-circuit properly. | ||
| bool force_shirt_circuit_execution = false; |
|
@KochetovNicolai "shirt" still appears in some of the function param names, worth doing a grep |
|
Some bugs found by SQLancer. Disabling the setting by default again, but leaving the changes -> #71890 |
Issue 1 BuildQueryPipelineSettings is created manually instead of calling BuildQueryPipelineSettings::fromContext(); so even ClickHouse/ClickHouse#71890 disable 'query_plan_merge_filters', UTs are still failed. To fix this issue, we need set correct default parameters in CHUtil.cpp Issue 2 If we set query_plan_merge_filters to true, then ClickHouse/ClickHouse#71539 will try to split the left most AND atom to a separate DAG and hence create FilterTransformer for each And atom, which cause collecting metrics failed. I am not sure the benefits of setting it to true, let's keep it to false.
|
|
||
| std::vector<ActionsAndName> and_atoms; | ||
| if (!actions_dag.hasStatefulFunctions()) | ||
| and_atoms = splitAndChainIntoMultipleFilters(cloned_dag, filter_column_name); |
There was a problem hiding this comment.
Calling describeActions after building pipeline will failed at splitAndChainIntoMultipleFilters, due to action_dag is moved.
// ....
auto expression = std::make_shared<ExpressionActions>(std::move(actions_dag), settings.getActionsSettings());
// ....There was a problem hiding this comment.
This is true for most other steps as well.
Afiak we really call explain after pipeline is build.
I was planning to make explain destructive as well; but it is not convenient while debugging.
Issue 1 BuildQueryPipelineSettings is created manually instead of calling BuildQueryPipelineSettings::fromContext(); so even ClickHouse/ClickHouse#71890 disable 'query_plan_merge_filters', UTs are still failed. To fix this issue, we need set correct default parameters in CHUtil.cpp Issue 2 If we set query_plan_merge_filters to true, then ClickHouse/ClickHouse#71539 will try to split the left most AND atom to a separate DAG and hence create FilterTransformer for each And atom, which cause collecting metrics failed. I am not sure the benefits of setting it to true, let's keep it to false.
* Fix issues due to ClickHouse/ClickHouse#71539. Issue 1 BuildQueryPipelineSettings is created manually instead of calling BuildQueryPipelineSettings::fromContext(); so even ClickHouse/ClickHouse#71890 disable 'query_plan_merge_filters', UTs are still failed. To fix this issue, we need set correct default parameters in CHUtil.cpp Issue 2 If we set query_plan_merge_filters to true, then ClickHouse/ClickHouse#71539 will try to split the left most AND atom to a separate DAG and hence create FilterTransformer for each And atom, which cause collecting metrics failed. I am not sure the benefits of setting it to true, let's keep it to false. * Calling `QueryPlan::explainPlan` after building pipeline is not correct, due to `action_dag` is [moved](https://github.com/ClickHouse/ClickHouse/blob/22d2c856a70dfb8b6e4c506fcb22ac03d59df9be/src/Processors/QueryPlan/FilterStep.cpp#L161).
| OriginalToNewNodeMap & node_remap) | ||
| const DataTypePtr & to_type) | ||
| { | ||
| if (!node_to_cast.result_type->equals(*to_type)) |
There was a problem hiding this comment.
Should be if (node_to_cast.result_type->equals(*to_type)) (without negation) to fix test 03271_sqllancer_having_issue.sql? Didn't try, just a hunch.
…ers-optimization Enable merge filters optimization.
…ge_filters_optimization 24.8 Backport of ClickHouse#71539 - Enable merge filters optimization.
…g later uses it ClickHouse#71539 (8c2e541) replaced the by-name removal of intermediate filter columns with a check on `Step::original_node`, but never assigned it. So every step but the last kept its condition result until the end of the read, and each later step filtered it again. Assign `original_node` for a single-condition step; the existing `node_to_step` / `all_outputs` check then decides whether a later step or an output of the PREWHERE still uses it. The AND of several conditions of one step is a node the steps create, nothing else references it, so it is always removed. A condition that is a stored column stays: a later step may read it as the parent of a subcolumn missing in the part. Removing it too returned `f.null = 1` for `SELECT f.null ... PREWHERE f AND x = 1` while `MODIFY COLUMN f Nullable(UInt8)` is pending (0 with this change, as on master and with WHERE). This also drops the condition columns of the split PREWHERE on `Memory` (ClickHouse#124498). Tests: the pending-MODIFY query in `04628_multistep_prewhere_default_column`, and a step whose condition a later step reuses in `02559_multiple_read_steps_in_prewhere_reuse_computation`. Both queries pass on master as well; they fail if the stored-column or the later-use guard is dropped. Found and analysed by @ snelheidai in ClickHouse#128432. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ated on more rows With `query_plan_merge_filters = 1` (the default since ClickHouse#71539) every PREWHERE read step of a MergeTree read applied its filter to the whole block, to keep short-circuit evaluation of merged filters. So a step that keeps almost all rows still copied every column through its filter. The forced filter is now skipped when the next step's conditions (and, before the last step, the outputs computed in the last step) pass `canBeMovedToTheFrontOfAndChain`, the reader neither converts nor fills a PREWHERE column (`canReadPrewhereColumnsAhead`), and the last step filters. The step filters are then combined and applied together by `ReadResult::optimize`. `groups_requiring_filtered_input` is unchanged. `system.predicate_statistics_log` now counts the rows that passed all steps so far after `optimize`, so `passed_rows` and `total_passed_rows` stay the rows surviving a step when an earlier filter was combined but not applied (also with `query_plan_merge_filters = 0`). Found, analysed and measured by @ snelheidai in ClickHouse#128442. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Improve
query_plan_merge_filtersoptimization. Fixes #71408Documentation entry for user-facing changes
CI Settings (Only check the boxes if you know what you are doing):