Skip to content

fix(plan): preserve TPCH Q19 hash key for widening CHAR casts - #28048

Merged
mergify[bot] merged 1 commit into
mainfrom
fix/28030-char-cast-totality
Sep 3, 2026
Merged

mergify[bot] merged 1 commit into
mainfrom
fix/28030-char-cast-totality

Conversation

@aptend

@aptend aptend commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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_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:

.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

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@mergify mergify Bot added the queued label Sep 3, 2026
@mergify

mergify Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-03 05:13 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-03 05:13 UTC · at d37cc0f7b14c3dbd5bc810fc85950cf4da1e9a9b · squash

This pull request spent 19 seconds in the queue, including 2 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit d37cc0f into main Sep 3, 2026
35 checks passed
@mergify
mergify Bot deleted the fix/28030-char-cast-totality branch September 3, 2026 05:13
@mergify mergify Bot removed the queued label Sep 3, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…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

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants