Repository navigation
Fix WITH TOTALS losing constant column values in JOIN - #108807
Conversation
The synthesized default TOTALS row in `QueryPipelineBuilder::addDefaultTotals` built every column with `type->createColumn` followed by `insertDefault`, which discarded `ColumnConst` values and collapsed them to type defaults. For a JOIN with `WITH TOTALS`, the default TOTALS row is produced for the side that has no totals of its own (for example, a constant subquery). Which side that is can change with build/probe ordering (`query_plan_join_swap_table`) or simply by the order the tables are written, so the constants were lost in some orderings but preserved in others. Now constant columns keep their value in the synthesized TOTALS row, making all orderings consistent. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [8bb32ea] Summary: ✅
AI ReviewSummaryThis PR fixes synthesized Missing context / blind spots
Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 8/8 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix WITH TOTALS losing constant column values in JOIN ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe bug reproduces as far back as the oldest tested release ( Component: cc fix PR author: @vdimir ClickGap · Finding: Triage metadata
|
|
Hi — this looks like a backport candidate for |
…totals-const-swap Fix WITH TOTALS losing constant column values in JOIN
When a
JOINhasWITH TOTALSon one side, the totals row of the other side is synthesized from default values.QueryPipelineBuilder::addDefaultTotalsbuilt every column withtype->createColumn+insertDefault, which discardedColumnConstvalues and collapsed them to type defaults.As a result, the constant values of a constant subquery (e.g.
SELECT 42 AS x, 99 AS y) were lost in the totals row whenever that subquery ended up on the side without its own totals. Which side that is depends on the order the tables are written and on build/probe swapping (query_plan_join_swap_table), so the same query could return correct constants in one ordering and zeros in another.This preserves constant column values in the synthesized totals row, making all orderings consistent. Surfaced by
03205_column_type_checkunderquery_plan_optimize_join_order_randomize.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a bug where the
WITH TOTALSrow of aJOINcould contain default values (such as0) instead of the constant values coming from a constant subquery on one side of the join. The wrong result appeared only for some join orderings or with thequery_plan_join_swap_tablesetting.🤖 Generated with Claude Code
Version info
26.7.1.311(included in26.7and later)