Repository navigation
perf(plan): eliminate bounded groups on not-null unique keys - #29225
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? |
|
Fixed the BVT decimal oracle in be53fe7: SUM metadata (32,2), AVG (14,6), and six-fractional-digit AVG values. Added explicit SQL-level @metacmp(true). Verified on the isolated candidate at port 16001 (production-equivalent binary 2e9ef1afabd): strict normal comparison passed 23/23 twice, with teardown checked between runs and after completion. Base/candidate JDBC contract probes agree on the corrected metadata. This replaces the earlier BVT evidence obtained against the wrong local server. Final delta review: PASS, no P1/P2 blockers. Production code is unchanged; CI is not claimed green. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Local exact-head fallback review (Astra thread capacity unavailable), substantive result APPROVE. Reviewed head be53fe7 against base 3727c5c. The secondary-UNIQUE proof is fail-closed: ordinary persisted non-partitioned tables, built regular keys without prefixes, visible non-generated columns, complete NOT NULL metadata, and SQL-equality-compatible types are required; complete grouping coverage and prepared invalidation controls are covered. No concrete planner/runtime correctness defect found. The reported 23/23 twice with teardown and prepared DROP/ADD/recreate checks support the change; current CI status remains separate.
What type of PR is this?
Which issue(s) this PR fixes:
issue #27856 (first logical-proof phase; does not claim to complete the full roadmap)
Related roadmap issues: #27859, #27860, #27858, #27857, #27753, #27728
What this PR does / why we need it:
This PR adds a planner-local, fail-closed uniqueness proof for direct scans of ordinary tables. When a complete built secondary UNIQUE key is declared
NOT NULLand exactly covers theGROUP BYkeys, bounded singleton groups can eliminate the aggregate operator. This avoids scanning and aggregating rows that are already proven to be one row per group.The proof deliberately rejects nullable, partial, prefix, plugin, generated, hidden, partitioned, temporary, malformed, and unbuilt keys. Existing primary-key behavior is preserved. The SQL equality-domain checks are shared with
ONLY_FULL_GROUP_BYwithout changing their behavior.The BVT covers activation, nullable-UNIQUE and prepared-statement invalidation controls, including DROP UNIQUE, ADD UNIQUE, and table recreation. The metadata oracle is explicitly enabled with
-- @metacmp(true).Validation:
go test ./pkg/sql/plan ./pkg/sql/plan/rule -count=1go vet ./pkg/sql/plan ./pkg/sql/plan/rulegit_version=2e9ef1afabd; production sources are identical to PR headbe53fe749e1EXPLAINchecks confirm both rewrite activation and aggregate fallback after uniqueness is removedPerformance evidence on the same host with 1M rows and 21 fresh clients per query:
LIMIT 10OFFSET 500000WHEREHAVINGFor
LIMIT 10, the base plan scanned 1,000,000 rows and used 108.98 MiB aggregate memory; the candidate read one 8,192-row block, used 256 KiB scan memory, and built no aggregate.Roadmap disposition: