Skip to content

fix prepared DECIMAL comparison coercion - #26849

Merged
XuPeng-SH merged 2 commits into
mainfrom
agent/fix-26847-decimal-parameter-coercion
Aug 9, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
agent/fix-26847-decimal-parameter-coercion

Conversation

@XuPeng-SH

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:

Fixes #26847
Fixes #26845

What this PR does / why we need it:

A direct prepared parameter is initially represented as TEXT. In binary comparisons with DECIMAL, the generic string/numeric cast matrix therefore selected DOUBLE for both operands, losing precision above 2^53 and making distinct DECIMAL values compare equal.

Derive a direct parameter marker's type from its DECIMAL peer before generic overload coercion. This covers null-safe and ordinary binary comparisons in both operand orders while leaving genuine string literal/column coercion unchanged.

Regression coverage includes DECIMAL64/128, NULL and non-NULL values above 2^53 with fractional digits, operand order, all ordinary comparisons, prepared-plan replacement/reuse, and real-string controls.

Verification

  • Focused planner regressions: pass
  • Full ./pkg/sql/plan package: pass
  • go list, go build, and go vet for ./pkg/sql/plan: pass
  • make build: pass
  • Candidate mo-tester replay: 43/43 statements pass with issue-skip handling enabled

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Verification evidence from base 45a917d7f8f7b2f32c28ca0a734318875722a00e:

Reproduction before the production fix:

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s \
  .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s \
  -run '^TestPreparedDecimal(BinaryComparisonsDeriveParamType|ComparisonPlannerReplacementAndReuse)$' \
  ./pkg/sql/plan

Failed as expected: DECIMAL64/128 <=> in both operand orders and parameter-left ordinary comparisons selected FLOAT64; prepared-plan replacement also exposed FLOAT64.

Fresh verification after the fix:

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s \
  .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s \
  -run '^(TestPreparedDecimalBinaryComparisonsDeriveParamType|TestDecimalStringComparisonsKeepMySQLCoercion|TestPreparedDecimalComparisonPlannerReplacementAndReuse)$' \
  ./pkg/sql/plan

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s \
  .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=120s ./pkg/sql/plan

Both passed. The focused matrix covers DECIMAL64/128, =, <=>, <>, <, <=, >, >=, both operand orders, NULL, values above 2^53 with fractional digits, prepared replacement/reuse, and genuine-string MySQL coercion controls.

Readonly package gates passed:

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s GOWORK=off \
CGO_CFLAGS="'-I/home/xupeng/github/matrixone-issue-26847-codex/cgo' '-I/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/include'" \
CGO_LDFLAGS="'-L/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/lib'" \
  go list -mod=readonly ./pkg/sql/plan

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s GOWORK=off \
CGO_CFLAGS="'-I/home/xupeng/github/matrixone-issue-26847-codex/cgo' '-I/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/include'" \
CGO_LDFLAGS="'-L/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/lib'" \
  go build -mod=readonly ./pkg/sql/plan

GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s GOWORK=off \
CGO_CFLAGS="'-I/home/xupeng/github/matrixone-issue-26847-codex/cgo' '-I/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/include'" \
CGO_LDFLAGS="'-L/home/xupeng/github/matrixone-issue-26847-codex/thirdparties/install/lib'" \
  go vet -mod=readonly ./pkg/sql/plan

Candidate build passed:

TMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s \
GOCACHE=/home/xupeng/.cache/codex-26847-gocache.tl7yBB \
GOTMPDIR=/home/xupeng/.cache/codex-26847-gotmp.rE053s make build

Black-box replay used only the locally built candidate on 127.0.0.1:26001 (host 10.222.1.57); the shared 10.222.1.55 service was not changed:

./run.sh \
  -p /home/xupeng/github/matrixone-issue-26847-codex/test/distributed/cases/prepare/prepare_decimal_comparison.sql \
  -m run -r 100 -g

Result: 43/43 successful, 0 failed, 0 ignored, 0 abnormal.

Self-review: ACCEPT. No resource ownership, waits, goroutines, generation state, or unbounded growth were introduced; unhappy-path Q1-Q3 are not applicable.

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Independent 10.222.1.55 candidate acceptance (single node, 6 GB cache) passed. round35_decimal_protocol_precision.go: all 36 default/PRIMARY/two-index comparisons passed; the eight baseline <=> precision failures are now zero, and hidden unique-index audit is main=10 / hidden=10 / distinct PK=10. round33_binary_protocol_differential.go (7 repeats): DECIMAL NULL reused p50 is 4.370ms versus explicit CAST 5.860ms (baseline untyped was 24.481ms). 8 workers / 10s: untyped 4936.02 QPS, typed 4980.56 QPS, both 0 failures (baseline 282.48 vs 4617.55 QPS). UTC/string DATETIME controls pass; three local-time values remain the documented go-sql-driver loc=UTC negative control. This independently confirms both #26847 correctness and #26845 performance closure.

@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 Author

Choose a reason for hiding this comment

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

Deep review: ACCEPT — no blocking findings.

Reviewed exact head afeb5500a28ad1ddae77abc7cfa841d99df0c3ec against base 0676200da47052659cf46ad9e22d67ab9654e393. The change restores the intended invariant at the narrowest shared boundary: only a direct prepared parameter paired with a DECIMAL peer is typed as that peer before generic overload coercion. Both operand orders and all binary comparison operators are covered; genuine string literals/columns and parameters explicitly wrapped as strings keep MySQL string/numeric coercion. The additional bind-time work is two direct type checks per comparison and one existing cast node only on the matched prepared-DECIMAL path, with no new per-row state, allocation, synchronization, or lifecycle ownership.

I also checked the nearby paths not exercised by the new helper itself: public PREPARE plans for DECIMAL BETWEEN ? AND ? and IN (?, ?) already derive DECIMAL through their existing contextual binders; tuple/ANY/ALL comparisons eventually bind through the same binary comparison boundary. Independent review probes for DECIMAL256, the != alias, and an explicit-string-param negative control all passed.

Fresh local gates at the exact head:

  • focused prepared DECIMAL planner tests: PASS
  • full ./pkg/sql/plan: PASS
  • go build -mod=readonly ./pkg/sql/plan: PASS
  • go vet -mod=readonly ./pkg/sql/plan: PASS
  • git diff --check: PASS

No correctness, performance, unhappy-path, resource-lifecycle, or test-oracle blockers found. GitHub does not allow XuPeng-SH to Approve a PR authored by XuPeng-SH, so this is recorded as an ACCEPT comment rather than an APPROVED review state.

@XuPeng-SH
XuPeng-SH merged commit e09f46e into main Aug 9, 2026
55 checks passed
@XuPeng-SH
XuPeng-SH deleted the agent/fix-26847-decimal-parameter-coercion branch August 9, 2026 09:54
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26847
Fixes matrixorigin#26845

## What this PR does / why we need it:

A direct prepared parameter is initially represented as TEXT. In binary
comparisons with DECIMAL, the generic string/numeric cast matrix
therefore selected DOUBLE for both operands, losing precision above 2^53
and making distinct DECIMAL values compare equal.

Derive a direct parameter marker's type from its DECIMAL peer before
generic overload coercion. This covers null-safe and ordinary binary
comparisons in both operand orders while leaving genuine string
literal/column coercion unchanged.

Regression coverage includes DECIMAL64/128, NULL and non-NULL values
above 2^53 with fractional digits, operand order, all ordinary
comparisons, prepared-plan replacement/reuse, and real-string controls.

## Verification

- Focused planner regressions: pass
- Full `./pkg/sql/plan` package: pass
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan`: pass
- `make build`: pass
- Candidate `mo-tester` replay: 43/43 statements pass with issue-skip
handling enabled

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26847
Fixes matrixorigin#26845

## What this PR does / why we need it:

A direct prepared parameter is initially represented as TEXT. In binary
comparisons with DECIMAL, the generic string/numeric cast matrix
therefore selected DOUBLE for both operands, losing precision above 2^53
and making distinct DECIMAL values compare equal.

Derive a direct parameter marker's type from its DECIMAL peer before
generic overload coercion. This covers null-safe and ordinary binary
comparisons in both operand orders while leaving genuine string
literal/column coercion unchanged.

Regression coverage includes DECIMAL64/128, NULL and non-NULL values
above 2^53 with fractional digits, operand order, all ordinary
comparisons, prepared-plan replacement/reuse, and real-string controls.

## Verification

- Focused planner regressions: pass
- Full `./pkg/sql/plan` package: pass
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan`: pass
- `make build`: pass
- Candidate `mo-tester` replay: 43/43 statements pass with issue-skip
handling enabled

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#26847
Fixes matrixorigin#26845

## What this PR does / why we need it:

A direct prepared parameter is initially represented as TEXT. In binary
comparisons with DECIMAL, the generic string/numeric cast matrix
therefore selected DOUBLE for both operands, losing precision above 2^53
and making distinct DECIMAL values compare equal.

Derive a direct parameter marker's type from its DECIMAL peer before
generic overload coercion. This covers null-safe and ordinary binary
comparisons in both operand orders while leaving genuine string
literal/column coercion unchanged.

Regression coverage includes DECIMAL64/128, NULL and non-NULL values
above 2^53 with fractional digits, operand order, all ordinary
comparisons, prepared-plan replacement/reuse, and real-string controls.

## Verification

- Focused planner regressions: pass
- Full `./pkg/sql/plan` package: pass
- `go list`, `go build`, and `go vet` for `./pkg/sql/plan`: pass
- `make build`: pass
- Candidate `mo-tester` replay: 43/43 statements pass with issue-skip
handling enabled

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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.

[Bug]: DECIMAL <=> prepared parameter loses precision through DOUBLE cast [Performance]: untyped NULL prepared parameter formats every DECIMAL row

2 participants