fix(opt): correct multi-conjunct HAVING over GROUP (AND-split bug)#260
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A multi-conjunct HAVING predicate over a GROUP (e.g.
HAVING (sum v) > 10 AND (max v) < 30) returned a schema error (or row-count mismatch) on the default-optimized plan. This is a pre-existing correctness defect on master, previously papered over by tests that executed only the un-optimized baseline.Root cause:
pass_filter_reorder→split_and_filterrewritesFILTER(AND(a,b), GROUP)into a chainFILTER(b, FILTER(a, GROUP)). The executor's HAVING fusion (exec.c) swapsg->tableto the GROUP output only when a filter's direct child isOP_GROUP— so in the chain, the outer conjunct evaluates against the base table, which lacks the aggregate-output columns (→ schema error) or has a different row count (→ mismatch).Fix: one guard in
split_and_filter— don't split a filter whose data input is a GROUP. The intactFILTER(AND, GROUP)is then handled correctly by the existing single-level HAVING fusion. This is zero-cost: a filter directly over GROUP feeds on the (small) group output with nothing useful to reorder past, and key-predicate pushdown below GROUP is handled by a separate pass. The guard's direct-child condition is exactly aligned with the fusion's, so coverage matches precisely.Triggers fixed (all on default optimization, no knobs):
AND(agg, agg),AND(key, agg), andAND(key, key)with pushdown disabled.Test Plan
group_pushdown/having_and_agg_exec—AND(agg,agg)over GROUP executes the optimized plan, asserts un-split shape + 2 rows (no coverage before).group_pushdown/and_split_non_group— pins guard narrowness: a non-GROUPFILTER(AND)still splits.group_pushdown/no_push_mixed_predflipped from baseline-only to executing the optimizedAND(key,agg)plan.group_pushdown/diff_and_of_keys— stale "row-count mismatch" comment corrected; added a disabled-pushdown assertion proving the previously-documented failure now executes (knob restored before asserts, no cross-test leak).group_pushdown18/18;opt/filterreorder suites green.Correctness-only change — no perf gate (removes a broken, benefit-free split in one case; the common path is byte-untouched).