Repository navigation
fix(plan): preserve TPCH Q19 hash key for widening CHAR casts - #28048
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head c26469b from correctness, planner-safety, unhappy-path, counterexample, and performance angles.
No blocking findings. The new proof is narrowly limited to bounded same-charset CHAR/VARCHAR -> CHAR casts whose target is at least as wide as the source. That matches the executor rune-width behavior, cannot expose truncation/error in this domain, and remains fail-closed for narrowing, unbounded, charset-changing, TEXT, and unrelated casts. I also checked the shared single-row aggregate/LIMIT uses of singleRowCastIsTotal; they retain the same totality invariant. The Q19-shaped test proves hash-key exposure and result equivalence, while the existing fallible/single-table counterexamples stay on their legacy paths. Runtime overhead is only constant-time type metadata checks during planning; the affected Q19 execution recovers the keyed hash join.
Local exact-head validation passed:
- go test -count=1 -timeout=10m ./pkg/sql/plan
- go test -count=1 -timeout=5m -run ^TestNullableExistsMarkKeepsHashEqualityAndBooleanResults$ ./pkg/tests/issues
Merge Queue Status
This pull request spent 19 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
…origin#28048) matrixorigin#27915 correctly keeps DNF factoring behind a totality check, but the check did not recognize the comparison casts from bounded VARCHAR/CHAR operands to a wider fixed CHAR domain. TPCH Q19 therefore kept its repeated full DNF as the join condition and lost the common `l_partkey = p_partkey` hash key. This PR adds one narrow, type-domain proof: a CHAR/VARCHAR-to-CHAR cast is total only when both declared widths are bounded, the charset is unchanged, and the target is not narrower. The existing all-or-nothing safety gate remains unchanged; narrowing, unbounded, charset-changing, TEXT, and other fallible casts remain rejected. Benefits and validation: - TPCH SF=1 Q19 restores `INNER hashOnPK` with `l_partkey = p_partkey`; its plan is byte-for-byte equal to the compatibility-control plan. - The issue reproduction took 20.06s on the regressed cold path. On this head, the first real Q19 execution after process startup took 203ms and returned the same `4028540.3287` result as the compatibility control (~99x restoration versus the reported regression). - Across all 22 TPCH plans, only Q19 changes. - Across all 99 TPC-DS SF=1000 plans, the stable plans are byte-for-byte unchanged. - Added focused totality boundaries, a typed Q19-shaped DNF rewrite test, and a public SQL plan/result-equivalence regression. Validation commands: ```text .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/plan .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=5m -run '^TestNullableExistsMarkKeepsHashEqualityAndBooleanResults$' ./pkg/tests/issues ``` Approved by: @XuPeng-SH
…origin#28048) matrixorigin#27915 correctly keeps DNF factoring behind a totality check, but the check did not recognize the comparison casts from bounded VARCHAR/CHAR operands to a wider fixed CHAR domain. TPCH Q19 therefore kept its repeated full DNF as the join condition and lost the common `l_partkey = p_partkey` hash key. This PR adds one narrow, type-domain proof: a CHAR/VARCHAR-to-CHAR cast is total only when both declared widths are bounded, the charset is unchanged, and the target is not narrower. The existing all-or-nothing safety gate remains unchanged; narrowing, unbounded, charset-changing, TEXT, and other fallible casts remain rejected. Benefits and validation: - TPCH SF=1 Q19 restores `INNER hashOnPK` with `l_partkey = p_partkey`; its plan is byte-for-byte equal to the compatibility-control plan. - The issue reproduction took 20.06s on the regressed cold path. On this head, the first real Q19 execution after process startup took 203ms and returned the same `4028540.3287` result as the compatibility control (~99x restoration versus the reported regression). - Across all 22 TPCH plans, only Q19 changes. - Across all 99 TPC-DS SF=1000 plans, the stable plans are byte-for-byte unchanged. - Added focused totality boundaries, a typed Q19-shaped DNF rewrite test, and a public SQL plan/result-equivalence regression. Validation commands: ```text .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/plan .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=5m -run '^TestNullableExistsMarkKeepsHashEqualityAndBooleanResults$' ./pkg/tests/issues ``` Approved by: @XuPeng-SH
…origin#28048) matrixorigin#27915 correctly keeps DNF factoring behind a totality check, but the check did not recognize the comparison casts from bounded VARCHAR/CHAR operands to a wider fixed CHAR domain. TPCH Q19 therefore kept its repeated full DNF as the join condition and lost the common `l_partkey = p_partkey` hash key. This PR adds one narrow, type-domain proof: a CHAR/VARCHAR-to-CHAR cast is total only when both declared widths are bounded, the charset is unchanged, and the target is not narrower. The existing all-or-nothing safety gate remains unchanged; narrowing, unbounded, charset-changing, TEXT, and other fallible casts remain rejected. Benefits and validation: - TPCH SF=1 Q19 restores `INNER hashOnPK` with `l_partkey = p_partkey`; its plan is byte-for-byte equal to the compatibility-control plan. - The issue reproduction took 20.06s on the regressed cold path. On this head, the first real Q19 execution after process startup took 203ms and returned the same `4028540.3287` result as the compatibility control (~99x restoration versus the reported regression). - Across all 22 TPCH plans, only Q19 changes. - Across all 99 TPC-DS SF=1000 plans, the stable plans are byte-for-byte unchanged. - Added focused totality boundaries, a typed Q19-shaped DNF rewrite test, and a public SQL plan/result-equivalence regression. Validation commands: ```text .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=10m ./pkg/sql/plan .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=5m -run '^TestNullableExistsMarkKeepsHashEqualityAndBooleanResults$' ./pkg/tests/issues ``` Approved by: @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
issue #28030
What this PR does / why we need it:
#27915 correctly keeps DNF factoring behind a totality check, but the check did not recognize the comparison casts from bounded VARCHAR/CHAR operands to a wider fixed CHAR domain. TPCH Q19 therefore kept its repeated full DNF as the join condition and lost the common
l_partkey = p_partkeyhash key.This PR adds one narrow, type-domain proof: a CHAR/VARCHAR-to-CHAR cast is total only when both declared widths are bounded, the charset is unchanged, and the target is not narrower. The existing all-or-nothing safety gate remains unchanged; narrowing, unbounded, charset-changing, TEXT, and other fallible casts remain rejected.
Benefits and validation:
INNER hashOnPKwithl_partkey = p_partkey; its plan is byte-for-byte equal to the compatibility-control plan.4028540.3287result as the compatibility control (~99x restoration versus the reported regression).Validation commands: