Repository navigation
Check what if I remove materialize from StorageView::read - #105846
Conversation
|
Workflow [PR], commit [58820ba] Summary: ✅
AI ReviewSummaryThis PR removes analyzer-side materialization after Tests
Final VerdictStatus: Minimum required action: add the focused regression test described above. |
| /// Because method 'getSampleBlockForColumns' is used to obtain a structure of result in InterpreterSelectQuery. | ||
| ActionsDAG materializing_actions(query_plan.getCurrentHeader()->getColumnsWithTypeAndName()); | ||
| materializing_actions.addMaterializingOutputActions(/*materialize_sparse=*/ true); | ||
| /// It's expected that the columns read from storage are not constant. |
There was a problem hiding this comment.
This change drops materialize for the analyzer path, but the PR does not add a focused regression test proving the contract it is trying to fix (issue #78166): constant aliases from a VIEW should still allow filter simplification / key-condition pushdown, and VIEW reads should remain stable when constant columns flow through this branch.
Please add a stateless test with enable_analyzer=1 that validates both query result and EXPLAIN indexes for a VIEW producing constant or derived columns.
…EW subquery` The previous commit drops the `materialize` step that `StorageView::read` used to insert after the view subquery. All five tests below only embed the `EXPLAIN` plan in their output, so the changes are purely cosmetic: - `Materialize constants after VIEW subquery` no longer appears in the merged `Expression`/`Filter` step descriptions. - For `03302_analyzer_distributed_filter_push_down` the merged filter DAG no longer wraps `n` with `materialize(...)`. Without that wrapper, the (Change column names → ... → Project names) rename cycles the analyzer inserts at every scope boundary collapse into a chain of pure `ALIAS n ↔ __table1.n` round-trips. These aliases never did anything semantically - `materialize` was just keeping them wired up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Pass duplicate_const_columns = false when building expression-analysis
chain DAGs: buildActionsDAGFromExpressionNode (WHERE/HAVING/QUALIFY,
projection, LIMIT BY) and the before_window, before_sort, interpolate
and project-names DAGs. A constant observed in the source header (e.g.
a VIEW subquery returning constants after the materialization step was
removed) no longer gets a free-standing COLUMN twin in chain DAGs, so
the INPUT stays reachable and the column keeps flowing through the
stream like an ordinary column. Stream structure then stays identical
to the structure computed during analysis (where such columns are not
constant), which distributed processing relies on when comparing
independently computed headers.
Fixes THERE_IS_NO_COLUMN / NOT_FOUND_COLUMN_IN_BLOCK in
`01244_optimize_distributed_group_by_sharding_key` and
`01952_optimize_distributed_group_by_sharding_key` for queries like
`select distinct on (k1) k2 from remote('127.{1,2}', view(select 1 k1, 2 k2, 3 v), cityHash64(k1, k2))`.
Update the `01952` reference: shard-local plans now get an anonymous
converting Expression step that materializes observed constants to
match the initiator's expected header.
Known follow-ups:
- The non-duplicating ActionsDAG constructor strips constant values
from INPUT nodes (addInput(name, type) instead of addInput(column)),
which makes addConstantIfNecessary treat them as materialized inputs
and re-bind window-function arguments to fresh constants. This breaks
`03916_window_functions_group_by_use_nulls` and
`04068_window_function_type_mismatch_with_rollup_and_group_by_use_nulls`
with group_by_use_nulls = 1 (a ROLLUP key argument binds to the
constant instead of the nullable key column). The fix is to keep the
value on the INPUT, which in turn requires disabling the
constant-folding rewrite in ActionsChainStep finalize so folded
ALIAS/FUNCTION nodes do not orphan value-carrying inputs.
- Several EXPLAIN-based tests still need reference updates / triage for
plan-shape-only diffs (extra anonymous converting Expression steps).
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105846&sha=91d9fefa0080113957d05e135b94cc134f76535d&name_0=PR&name_1=Fast+test
PR: #105846
Co-Authored-By: Claude Fable 5 <[email protected]>
After removing the `Materialize constants after VIEW subquery` step, a
constant column returned by `Storage::read` (e.g. a view subquery
`select 1 k1, 2 k2`) could be folded into a free-standing `COLUMN` node
and dropped from the stream at a distributed stage boundary, while the
initiator computes the expected per-shard header from the query tree
where the column is ordinary. The mismatch surfaced as
`THERE_IS_NO_COLUMN` / `NOT_FOUND_COLUMN_IN_BLOCK`, e.g. for
`select distinct on (k1) k2 from remote('127.{1,2}', view(select 1 k1, 2 k2, 3 v), cityHash64(k1, k2))`.
Collect the constants the storage actually returns into
`JoinTreeQueryPlan::source_constants` (in `buildQueryPlanForTableExpression`,
merged across joins) and keep those `INPUT` nodes from being orphaned by
constant folding while the expression chain is finalized: `ActionsDAG::project`
and `ActionsChainStep::finalizeInputAndOutputColumns` forward them as
`used_inputs` to `removeUnusedActions`, so the column keeps propagating as a
required input and stays in the stream to match the initiator's expectation.
`ALIAS` columns are excluded from `source_constants`: a constant `ALIAS`
(e.g. `y Array(String) ALIAS ['qwqw']`) is declared on the table but not
stored, so it is re-creatable from the expression that is propagated to the
shard via the query AST (`ReplaseAliasColumnsVisitor`) and may be dropped.
Query-tree literals (e.g. the `1` in `HAVING cnt = 1`) are likewise not in
`source_constants` and stay foldable; keeping them would add inputs absent
from the actual stream block. This keeps `03371_constant_alias_columns`
working while fixing the view-constant case.
Fixes `01244_optimize_distributed_group_by_sharding_key` and
`01952_optimize_distributed_group_by_sharding_key`.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105846&sha=91d9fefa0080113957d05e135b94cc134f76535d&name_0=PR&name_1=Fast+test
PR: #105846
Co-Authored-By: Claude Fable 5 <[email protected]>
Shorten the explanatory comments added for `source_constants` keeping to 2-3 lines each. No code changes. Co-Authored-By: Claude Fable 5 <[email protected]>
`source_constants` is empty for the common case (no constant columns returned by the storage), so skip iterating the DAG inputs entirely. Co-Authored-By: Claude Fable 5 <[email protected]>
…e-materialize-in-view # Conflicts: # tests/queries/0_stateless/03302_analyzer_distributed_filter_push_down.reference
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 99/100 (99.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 4 line(s) · Uncovered code |
Changelog category (leave one):
Remove the
Materialize constants after VIEW subquerystep inStorageView::readImpl. Now, constants are kept in plan and could be used by optimizations without checking formaterialize.Version info
26.6.1.1034