Repository navigation
Cherry pick #124553 to 26.3: Group PREWHERE read steps by exact columns and rewrite m['key'] to a key subcolumn only for bucketed Map - #129571
Conversation
…n its subcolumn Since #107988, tryBuildPrewhereSteps groups adjacent PREWHERE conditions by the storage column they read, so that the keys of one Map, each of which reads the whole Map, share one read step (#107912). The resolution was type-blind: `j.kind` and `j`, two JSON paths, a Tuple element and the whole Tuple, `m.size0` and `m.key_k1`, and keys of two Maps nested in one Tuple all resolved to one storage column. A cheap subcolumn condition was then merged with an expensive condition on the rest of the column, which read the whole column for every row. On master a may-throw `toString(j)` gets its own step (#111954), but its read-ahead, keyed on the same comparison, reads `j` in step 0 anyway. Key each input by the storage column and the substreams cache key of its subcolumn path instead. A Map key subcolumn drops its trailing MapKeyValue, so it keys as the Map that owns it (`(m, "")` at the top level, as before; `(c, "%2Eleft")` for a Map inside a Tuple, so two sibling Maps no longer share a step). The pair is used rather than a concatenated string because the path rendering escapes tuple dots. MergeTreeWhereOptimizer keeps grouping by storage column: that keeps a guard ahead of a throwing condition on the same column. So with the expensive condition written first the order is still kept. Closes #124535 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the clause narrating how the new grouping identity splits steps from the resolveStorageColumnName comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The performance test runner expands every `{name}` in a query template
with `str.format`, so the JSON literal in the fill query was read as a
`{"kind"}` placeholder and the test failed with `KeyError: '"kind"'`
before running any query. Double the braces, as other JSON perf tests do.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…zation With `basic` serialization, reading the key subcolumn `m.key_<key>` of a `Map` reads the whole column, so the rewrite gave nothing there, and #107988 had to group PREWHERE conditions by the storage column to keep several keys of one `Map` in one read step. That grouping also merged a cheap subcolumn condition with an expensive condition on the rest of the same column (#124535). The first version of this pull request worked around it with a `Map` key special case in `tryBuildPrewhereSteps`, which put generic PREWHERE code in charge of `Map` serialization details and was wrong for `with_buckets`. Gate the rewrite on the new `IStorage::hasBucketedMapSerialization`, true for a `MergeTree` table if either `map_serialization_version` setting is `with_buckets`, and forwarded by the storages that pass the analyzed query to other tables (`Merge` requires all of them). The check is in `storageAllowsTransformer`, so both passes of `FunctionToSubcolumnsPass` agree. Explicit key subcolumns still work for any serialization. With that, `MergeTreeWhereOptimizer` and `tryBuildPrewhereSteps` group conditions by their exact column set again, and `tryBuildPrewhereSteps` no longer needs `ColumnsDescription`. The `may_throw` split and the read-ahead of a split run stay. Tests that assert the rewrite now pin both map serialization settings, which clickhouse-test randomizes. The new `05340` covers the gate, and `05339` gets the `with_buckets` case from the CI review. Closes: #124535 Related: #124553 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…re-subcolumn-read-steps Keep the query condition cache attribution boundary from master in the PREWHERE step grouping, comparing exact column sets. Drop the `ColumnsDescription` argument from the new seal-gated `MergeTreeSelectProcessor` call site. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The test compares the `arrayElement` and key subcolumn forms of `m['key']`, and the key subcolumn rewrite now applies only to bucketed Maps. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The new `SubcolumnSupportAnswers::bucketed_map_serialization` field was missing from the aggregate initialization, which fails the build with `-Wmissing-field-initializers`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124553&sha=6a84ce82278446b934bb316be58af106c2f4f53b&name_0=PR&name_1=Fast%20test PR: #124553 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
In 04631 the interleaved Map conditions read the same column `tags`, so the last step takes it from the first one instead of reading it again, and only two of the three steps read rows. In 05339 the WHERE optimizer may put `m['k1'] != ''` before `length(m) = 3` based on the column sizes, and the key condition passes every row. Write that case as PREWHERE, which keeps the written order, since the test is about separate read steps, not about the order. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124553&sha=29003da91f5a35f49a43deb35dedd0055448880c&name_0=PR&name_1=Fast%20test PR: #124553 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…re-subcolumn-read-steps Keep the index-aware PREWHERE steps from master (`required_indexes`, `index_read_tasks`), grouping table columns by exact name instead of by storage column, and drop the `ColumnsDescription` argument from the new `tryBuildPrewhereSteps` call. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The WHERE optimizer orders the conditions by the on-disk size of their columns when it has no selectivity estimate. A repeated character compresses to a few bytes per row, so the expensive subcolumn could be ordered first and read for every row. Random values make the on-disk size reflect the cost of reading a column. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124553&sha=0686a448ce0ba3aa70b6aeecc1aa20a2747a7b17&name_0=PR&name_1=Fast%20test PR: #124553 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…4535-prewhere-subcolumn-read-steps
…_prefixes The `m['key']` -> `m.key_<key>` rewrite now applies only to bucketed `Map` serialization, while the test pins `basic`. Read the key subcolumn explicitly, which works for any serialization, so the test keeps measuring the size estimate of a `basic` key subcolumn. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124553&sha=2f21f04549bfebbd31b1ba4c196b8aa320e9481d&name_0=PR&name_1=Fast%20test PR: #124553 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…re-subcolumn-read-steps Keep master's separate groups for expensive conditions and the `group_of` index in `MergeTreeWhereOptimizer`, grouping conditions by their exact columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n-read-steps Group PREWHERE read steps by exact columns and rewrite `m['key']` to a key subcolumn only for bucketed `Map`
|
The regression reached 26.3 with #108396 (the backport of #107988), onto code that predates the master refactorings this PR's context lines refer to (the
On the 26.3 tree (clang-21, debug), I cannot push to |
Merge `backport/26.3/124553` and rebuild the change on it. The branch predates master's read step machinery, so instead of the master hunks: - PREWHERE steps and the WHERE optimizer group conditions by exact column sets again: the storage column grouping of #107988 is reverted as it was backported to this branch, and the `ColumnsDescription` parameter it added is removed from `tryBuildPrewhereSteps`, `getPrewhereActions` and `MergeTreeSelectProcessor`. - `m['key']` is rewritten to `m.key_<key>` only if `IStorage::hasBucketedMapSerialization` is true (`MergeTree` with `with_buckets` in either map serialization setting; Proxy, MaterializedView, Alias, Buffer, Merge and MaterializedPostgreSQL forward it). - Tests: 05339 and 05340 added; the existing tests that assert the rewrite pin `with_buckets`; edits to tests that do not exist on this branch are dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Original pull-request #124553
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job