Repository navigation
Add test: LIMIT ... WITH TIES guard in optimizeLimitForAggregationInOrder is untested - #108884
clickgapai wants to merge 5 commits into
Conversation
|
Pre-PR Validation Gate (per ClickGap pipeline): a) Deterministic repro? ✅ b) Root cause explained? ✅ c) Fix matches root cause? ✅ d) Test intent preserved? / New tests added? ✅ e) Both directions demonstrated? ✅ f) Fix is general, not a narrow patch? ✅ |
|
Workflow [PR], commit [ab4cf15] Summary: ❌
|
|
Pushed a commit. Here's the actual diff so you can review what was committed: diff --git a/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.reference b/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.reference
index ace1d56c945a..e58e9764b398 100644
--- a/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.reference
+++ b/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.reference
@@ -1,2 +1,2 @@
-1
+100
100
diff --git a/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.sql b/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.sql
index 5e27046774b9..1d49f496b8c8 100644
--- a/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.sql
+++ b/tests/queries/0_stateless/04489_aggregation_in_order_limit_with_ties.sql
@@ -16,25 +16,14 @@ SETTINGS index_granularity = 8;
-- selects every group with a = 0 (the 3rd row's a), i.e. 100 rows.
INSERT INTO t_agg_in_order_limit_with_ties SELECT number % 10 AS a, number AS b FROM numbers(1000) ORDER BY a, b;
-SELECT
-(
- SELECT count() FROM (
- SELECT a, count() FROM t_agg_in_order_limit_with_ties GROUP BY a, b ORDER BY a ASC LIMIT 3 WITH TIES
- SETTINGS optimize_aggregation_in_order = 1, optimize_aggregation_in_order_limit = 1
- )
-)
-=
-(
- SELECT count() FROM (
- SELECT a, count() FROM t_agg_in_order_limit_with_ties GROUP BY a, b ORDER BY a ASC LIMIT 3 WITH TIES
- SETTINGS optimize_aggregation_in_order = 1, optimize_aggregation_in_order_limit = 0
- )
-) AS with_ties_results_match;
+-- Push-down enabled: the WITH TIES guard must keep the full tie group (100 rows, not 3).
+SELECT count() FROM (
+ SELECT a, count() FROM t_agg_in_order_limit_with_ties GROUP BY a, b ORDER BY a ASC LIMIT 3 WITH TIES
+) SETTINGS optimize_aggregation_in_order = 1, optimize_aggregation_in_order_limit = 1;
--- Pin the actual row count so the equality above is not vacuously satisfied.
+-- Push-down disabled: control producing the same 100 rows.
SELECT count() FROM (
SELECT a, count() FROM t_agg_in_order_limit_with_ties GROUP BY a, b ORDER BY a ASC LIMIT 3 WITH TIES
- SETTINGS optimize_aggregation_in_order = 1, optimize_aggregation_in_order_limit = 1
-);
+) SETTINGS optimize_aggregation_in_order = 1, optimize_aggregation_in_order_limit = 0;
DROP TABLE t_agg_in_order_limit_with_ties;
If this isn't the change you wanted, please describe the edit concretely and I'll retry. |
|
@clickgapai Merge the changes from master to trigger the CI again |
Drop the (SELECT)=(SELECT) AS scaffold and inner SETTINGS; assert the push-down-on vs off counts directly (100/100). Guard still exercised. Requested by @Ergus
7b728a0 to
8653413
Compare
|
Pushed |
max_threads=1 alone does not force single-stream (in-order opens one stream per part); add an EXPLAIN PIPELINE assertion that no FinishAggregatingInOrderTransform is present so guard removal collapses to 3. Requested by @clickhouse-gh[bot] in ClickHouse#108884 (comment)
LLVM Coverage Report
Changed lines: No C/C++ source files changed — skipping uncovered code analysis. Newly covered by added/modified tests: 135 line(s), 28 function(s) across 57 file(s) · Details Top files
|
|
@clickgapai check the CI failures. Solve the issues that are related with this change. There ire several Check that please |
|
After investigation, the bot determined the failure in |
|
CI fix exhausted: 5 attempts on |
|
@groeneai can you take this up and open a new PR? |
|
Taking this up. Triaged against master Verified: the It will be re-filed as part of an area-grouped PR rather than its own PR, to keep reviewer load down (26 in this batch plus 18 from the earlier one today). Full triage and the grouping plan: #101781 (comment) |
|
Re-filed as #114305, the MergeTree/index group, covering this gap together with three others from the same batch. Adopted as Two additions. The counts alone stay |
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
This is a test-only PR — no source code changes. Please review: test quality, whether the claimed coverage gaps are real, and whether test output makes sense.
Adds test coverage for 1 untested code path(s), found during automated review of PR #104859.
That PR The PR adds a new query-plan optimization
optimizeLimitForAggregationInOrder(default-on via settingoptimize_aggregation_in_order_limit) that pushes aLIMITinto an in-orderAggregatingStepfor early termination. It threads alimit_hintthroughAggregatingInOrderTransform(early-stop in1.
LIMIT ... WITH TIESguard inoptimizeLimitForAggregationInOrderis untestedsrc/Processors/QueryPlan/Optimizations/optimizeLimitForAggregationInOrder.cpp:90Risk:
optimizeLimitForAggregationInOrder.cpp:90 skips the optimization whenlimit_step->withTies().LimitStep::getLimitForSorting()returnslimit + offsetregardless ofwith_ties, so if this guard were broken the aggregator would receivelimit_hint=nand stop after ~n group batches; the WITH TIES extension would then operate on a truncated prefix and drop all tied groups. Risk: wrong (silently truncated) results forLIMIT ... WITH TIESqueries over in-order aggregation.What's unique vs PR tests: The PR's tests cover negative guards for HAVING (
TotalsHavingStep), ORDER BY DESC, WITH TOTALS (overflow_row), ARRAY JOIN, extremes, FilterStep, and ExpressionStep sort-key rename, but none useLIMIT ... WITH TIES, so thewithTies()guard at line 90 is never exercised.Tags:
-- Tags: no-random-settings—no-random-settings: result depends on the exact value of optimize_aggregation_in_order_limit; random settings could override it and the on-vs-off comparison would no longer test the guardChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not applicable — test-only change.
Documentation entry for user-facing changes