Repository navigation
perf(plan): remove constant sort after singleton grouping - #27889
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
71e9137 to
ed26383
Compare
aptend
left a comment
There was a problem hiding this comment.
Deep review completed at exact head ed26383e96c754ecf8591deed6b29003da365362. I reviewed the design, full diff, and current review history, and validated the exact head in an isolated worktree. The constant-order sort-removal proof, provenance guard, and pagination barriers look sound, but the interval panic-closure path is not complete, so I am requesting changes. Validation: make thirdparties, make cgo, go test ./pkg/sql/plan ./pkg/sql/plan/rule -count=1, go vet ./pkg/sql/plan ./pkg/sql/plan/rule, plus review-only counterexample tests (removed afterward).
| } | ||
|
|
||
| func rejectStandaloneIntervalExpr(ctx context.Context, expr *plan.Expr, clause string) error { | ||
| if expr != nil && expr.Typ.Id == int32(types.T_interval) { |
There was a problem hiding this comment.
[P1] This guard checks only the outer expression type, so nested generic scalar/aggregate consumers still let the internal INTERVAL Expr_List escape. At this exact head, both SELECT INTERVAL 1 DAY IS NULL; and SELECT COUNT(INTERVAL 1 DAY) FROM select_test.bind_select; build successfully, and their plans retain a raw T_interval list under isnull / count. A review-only executor test evaluating that same list produced a BIGINT vector of length 2 with values [1 2036425731] (the bytes of day were interpreted as an integer), rather than one scalar value. That means a public executable plan can silently corrupt row/aggregate semantics instead of returning the intended not-supported error. Please reject unconsumed interval pseudo-expressions recursively at every generic scalar/aggregate boundary, while continuing to allow only explicit temporal/window consumers, and add public tests for both IS NULL and COUNT cases.
There was a problem hiding this comment.
Confirmed. The new guards validate only the outer expression type, so wrapping the retained T_interval pseudo-expression in a generic scalar or aggregate hides it from every added boundary check. Since this PR intentionally changes constant folding from panic to retention, letting that internal list reach execution is a real wrong-result path, not merely a diagnostic gap. Please make the validation recursive and consumer-aware (only the explicit temporal/window consumers may consume an interval), and keep the IS NULL and COUNT counterexamples as public regressions.
There was a problem hiding this comment.
Fixed at 87cf1d4d42091c4bc1010d0f203048618dc96364. Unconsumed T_interval is now rejected recursively at generic scalar/aggregate boundaries; the explicit temporal/window consumer set must rewrite it before function publication. The same invariant now covers predicate roots and IN/NOT IN/ANY subquery paths before their internal Expr_List can be mistaken for row arity. Added public IS NULL and COUNT(INTERVAL ...) BVT regressions, nested tuple/direct-plan/predicate/subquery unit counterexamples, and valid-consumer controls. Rebased on current main; full plan/rule tests, CGo-configured vet, build, isolated 31/31 BVT twice, and live 20105 probes pass.
0624454 to
13ea58e
Compare
|
Fixed the PROXY BVT compatibility regression at head 13ea58e. Root cause: the interval no-escape guard ran before builtin overload resolution, replacing established ErrInvalidArg diagnostics for known functions with a generic standalone-INTERVAL error. The fix now:
Regression coverage includes all four failed CI statements (uuid_v4 and the three greatest variants), plus ISNULL, COUNT, nested interval, valid temporal consumers, unsupported arithmetic, and unknown/UDF fallback. Post-rebase validation on upstream/main 3f05ced:
The branch was rebased and pushed with force-with-lease. I did not wait for CI. |
13ea58e to
f15951f
Compare
What type of PR is this?
Which issue(s) this PR fixes:
Refs #27858
Depends on #27850. The non-primary unique-key and ordered-access extensions
remain separate work in #27856 and #27857, so this PR does not auto-close the
umbrella issue.
What this PR does / why we need it:
The complete-primary-key grouping rewrite proves one input row per group, so
COUNT(*)is the constant1. Queries such asGROUP BY pk ORDER BY COUNT(*) LIMIT Knevertheless retained a blocking Sort,which prevented the existing bounded-demand pushdown from reaching TableScan.
This change removes that Sort only when:
the current singleton-group rewrite pass;
The provenance requirement keeps this from becoming a global constant-order
rewrite. Dynamic parameters, volatile/erroring expressions, row-dependent tie
breakers, nullable COUNT, rank options, FOUND_ROWS, malformed shapes, and unsafe
pagination all retain Sort.
Counterexample review also found that a standalone
INTERVALcould panic bothconstant-folding paths and later crash sort/group/window execution. The fix
separates the two required contracts:
standalone interval instead of panicking;
PARTITION/ORDER boundaries reject a bare interval with error 20105; and
date_add(..., INTERVAL ...)and interval windowframes remain valid.
Validation:
matrixorigin/mainat89740fae15;public scalar-boundary tests;
pkg/sql/planandpkg/sql/plan/ruletests through the repositoryCGo harness after the final rebase;
go vet ./pkg/sql/plan ./pkg/sql/plan/ruleandmake build;PR counterexample, valid temporal consumption, and a temporal RANGE frame;
TableScan and improves 100 fresh-client executions from 3.00s to 0.90s;
23.359ms base versus 8.668ms current (2.70x); 50M-row medians are 166.745ms
versus 8.853ms (18.83x). Base reads all rows, while current reads one
8,192-row block; and
27.433ms current, nullable COUNT 52.181ms versus 52.523ms.
The proof, alternatives, semantic barriers, rollback boundary, and complete
validation evidence are documented in
docs/design/singleton_group_constant_order_elimination.md.