Repository navigation
Conversation
|
Workflow [PR], commit [f71e7ed] Summary: ⏳
|
|
@shankar-iyer @alexey-milovidov you can review the MR again |
6256575 to
7c731cf
Compare
7c731cf to
a7b92ca
Compare
a7b92ca to
706e14a
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces an experimental LIMIT ... SHUFFLE clause for SELECT, gated by a new setting, and wires it through parsing, analyzer/planner, query plan steps, and stateless tests/docs. It also adds an optimization path that may intentionally drop preservation of the final randomized order to reduce overhead for SHUFFLE queries.
Changes:
- Add SQL syntax/AST support for
LIMIT n SHUFFLE, with validation againstORDER BY,OFFSET, andWITH TIES. - Add analyzer/planner support by rewriting
LIMIT SHUFFLEintoORDER BY rand() LIMIT nand propagating an “unordered output allowed” hint into sorting + lazy materialization. - Add an experimental setting
allow_experimental_shuffle_query, plus documentation and stateless tests.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04257_limit_shuffle.sql | Adds stateless queries covering parser errors, analyzer gating, and basic behavior. |
| tests/queries/0_stateless/04257_limit_shuffle.reference | Expected outputs for AST/SYNTAX/plan explain and deterministic checks. |
| src/Processors/Transforms/LazyMaterializingTransform.h | Extends transform API with preserve_output_order flag. |
| src/Processors/Transforms/LazyMaterializingTransform.cpp | Implements optional order preservation behavior for lazy materialization join. |
| src/Processors/QueryPlan/SortingStep.h | Adds allow_unordered_output flag + accessors to SortingStep. |
| src/Processors/QueryPlan/Optimizations/optimizeLazyMaterialization.cpp | Threads unordered-output hint into lazy materialization eligibility and join step creation. |
| src/Processors/QueryPlan/JoinLazyColumnsStep.h | Adds preserve_output_order parameter/state to join-lazy-columns step. |
| src/Processors/QueryPlan/JoinLazyColumnsStep.cpp | Passes preserve_output_order into LazyMaterializingTransform. |
| src/Planner/Planner.cpp | Rewrites LIMIT SHUFFLE as ORDER BY rand() and allows unordered output in sorting steps. |
| src/Parsers/ParserSelectQuery.cpp | Parses SHUFFLE after LIMIT and enforces mutual-exclusion constraints. |
| src/Parsers/CommonParsers.h | Adds SHUFFLE keyword. |
| src/Parsers/ASTSelectQuery.h | Adds limit_shuffle flag to ASTSelectQuery. |
| src/Parsers/ASTSelectQuery.cpp | Includes limit_shuffle in hashing and formatting output. |
| src/Interpreters/InterpreterFactory.cpp | Rejects LIMIT SHUFFLE when analyzer is disabled; blocks use in mutation queries. |
| src/Interpreters/InterpreterExplainQuery.cpp | Adds analyzer gating for EXPLAIN variants that require analysis/planning. |
| src/Databases/enableAllExperimentalSettings.cpp | Enables allow_experimental_shuffle_query in “enable all experimental” helper. |
| src/Core/SettingsChangesHistory.cpp | Registers settings history entry for allow_experimental_shuffle_query. |
| src/Core/Settings.cpp | Declares new experimental setting allow_experimental_shuffle_query. |
| src/Analyzer/QueryTreeBuilder.cpp | Enforces allow_experimental_shuffle_query gate and sets query-node shuffle flag. |
| src/Analyzer/QueryNode.h | Adds query-node flags for shuffle and shuffle-for-unordered-output. |
| src/Analyzer/QueryNode.cpp | Adds equality/hash/clone/AST conversion support for new shuffle flags. |
| docs/en/sql-reference/statements/select/limit-shuffle.md | New user docs page for LIMIT SHUFFLE and its experimental gating. |
| docs/en/sql-reference/statements/select/index.md | Adds LIMIT SHUFFLE to SELECT syntax and links to the new doc page. |
Move the old-analyzer rejection into `InterpreterSelectQuery` and `InterpreterSelectWithUnionQuery` so stored and refreshable materialized-view queries cannot silently treat `LIMIT SHUFFLE` as plain `LIMIT`. Also fix the `04257_limit_shuffle` `INSERT ... VALUES` syntax from the failed Fast test report. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105338&sha=324cb72454d492eeb2feb730fd2e6f256cbf0824&name_0=PR&name_1=Fast%20test PR: ClickHouse#105338
Move `allow_experimental_shuffle_query` to the current `26.9` settings-history block, add the standalone `LIMIT SHUFFLE` page to navigation without editing generated `SELECT` overview content, and refresh the `04257_limit_shuffle` reference for single-record `EXPLAIN SYNTAX` output. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105338&sha=02cd45685d7b812d834c5ea45767137fd81b2d8d&name_0=PR PR: ClickHouse#105338
|
@alexey-milovidov , is there any more changes do we need |
The latest PR build failed in because the compatibility entry was split into its own block, leaving the rest of the initializer outside . Keep the entry inside the existing list. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=105338&sha=d4c42fc960f61f7b0240cc0658051a249a82371a&name_0=PR&name_1=Fast%20test PR: ClickHouse#105338
|
🕵 @xuir268 — I updated the branch for you (pushed Merged
Since Two build failures, both mechanical merge artifacts where master changed code immediately adjacent to this branch's insertions (
Also regenerated Verified locally (release build, aarch64):
There are no unresolved review threads. The pull request still needs a maintainer review. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes174 object files changed (+116.86 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units972 translation units recompiled, 6537 s compile time in total, 972 of them have a recent master baseline. |
|
@alexey-milovidov Thanks for your help and I really hope we can the review as earliest possible |
|
@alexey-milovidov @shankar-iyer @novikd Could you please take another look at this PR when you have time? I have pushed the latest merge-conflict resolutions and CI fixes, and CI is running again. This PR has been open for several months; I would appreciate a maintainer review of the current design and any remaining changes needed before it can be merged. Thank you. |
Plan explicit `LIMIT SHUFFLE` through random top-N selection and lazy materialization without promising output ordering. Preserve plain `ORDER BY` semantics, add query-cache and mutation guards, regression tests, and documentation. Includes stored and parameterized view mutation review fixes. PR: ClickHouse#105338 Review: ClickHouse#105338 (comment) Review: ClickHouse#105338 (comment)
Gate the exclusion on the old unreadable reference spelling; retain corrected-test coverage and all upgrade error checks. The replica-test race fix is now included in master and is not duplicated here. Related: ClickHouse#121506 PR: ClickHouse#105338 CI: https://github.com/ClickHouse/ClickHouse/actions/runs/35963033445/job/107560097729?pr=105338
…ed-mr Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Hi @alexey-milovidov , can you tag someone from maintainer repo to review this MR |
|
Hi @rschu1ze , can you review the MR or tag anyone from maintainer , it is now really long time for review |
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Git merged the master and PR changes to `LazyMaterializingTransform` and `JoinLazyColumnsStep` constructors without conflict markers, but left two parameter lists side by side. Keep master's `index_column_name` parameter in its place and append the PR's `preserve_output_order` after it, so that no existing caller passing a `String` can silently bind to the `bool`. Force ordered output when the index column is `Nullable`: the permutation then covers only the matched rows and cannot reorder the main chunk. Master switched `ExplainAnalyzedSyntaxMatcher` from `InterpreterSelectQuery` to the analyzer, so the PR's workaround that kept `LIMIT SHUFFLE` selects away from that interpreter is obsolete. `QueryTreeBuilder` already checks `allow_experimental_shuffle_query`. Take master's version of `InterpreterExplainQuery.cpp`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master added sealed `SQL SECURITY DEFINER` views, and
`inlineViewSubqueryIfNeeded` returned for them before the dry-run validation
of view bodies in mutations. So `ALTER TABLE ... UPDATE value = (SELECT ...
FROM view)` over a view with `LIMIT SHUFFLE` was queued and failed only while
the mutation ran. Treat a sealed view as not inlinable instead, so it goes
through the same validation.
A view whose body is a bare `{source:Identifier}` cannot be created on current
master (`Both table name and UUID are empty`), so the test now parameterizes
the database of the view it reads.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
|
|
The changes are understandable, but they are not what was initially planned. The shuffle transform should be a first-class processor in the pipeline, including full shuffle, partial shuffle, and merging shuffled streams. This is more efficient than The shuffle clause should replace ORDER BY, not LIMIT. And we should be able to write Queries with A setting that adds random ORDER BY for testing will be adapted to add the SHUFFLE clause. |
|
I see that it was confused here: #100305 (comment) But @rschu1ze and @shankar-iyer set this task in the wrong direction... Let's close this and reopen the previous PR. |
Adds experimental random sampling with
LIMIT ... SHUFFLE, using the existing random top-N and lazy materialization paths. The sample does not guarantee random output order.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the experimental
LIMIT ... SHUFFLEclause forSELECT, which returns a random sample of rows. Enable it withallow_experimental_shuffle_query.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/105338]