Skip to content

fix(plan): preserve temporal prepared range types - #27882

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-27774
Aug 31, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
Lundomn:codex/issue-27774

Conversation

@Lundomn

@Lundomn Lundomn commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve binder-selected DATE, DATETIME, and TIMESTAMP types when binary prepared string parameters are used in range predicates
  • stop numeric-prefix specialization at implicit temporal cast boundaries while retaining the existing DECIMAL and YEAR behavior
  • add typed planner coverage plus a real database/sql and go-sql-driver/mysql two-CN regression test

Root cause

The MySQL binary protocol sends the legal DATETIME bounds as strings. Numeric-prefix classification marked strings beginning with a year as decimal candidates. For a composite temporal primary key, the planner also generated serialized prefix range filters around the binder-inserted temporal casts. Prepared-plan specialization then treated the nested parameter as decimal-eligible, crossed that temporal cast boundary, and rebound the original temporal range in the DECIMAL domain. Constant folding consequently parsed the full DATETIME text as a number and returned 20301 invalid numeric string.

Fix and compatibility

The specialization walk now treats an implicit temporal prepared-parameter cast as a semantic type boundary. DATE, TIME, DATETIME, TIMESTAMP, and INTERVAL casts cannot opt into numeric-prefix specialization; YEAR keeps its established numeric behavior. Untyped and numeric parameters, including DECIMAL controls, continue to use the existing specialization path. Temporal column predicates and serialized composite-key bounds therefore remain temporal, without adding a numeric cast to the column or changing index range planning.

Tests

  • planner binder coverage for DATE, DATETIME, and TIMESTAMP with =, <=>, !=, <, <=, >, and >=
  • prepared composite temporal range coverage for valid strings, invalid strings, NULL, serialized block filters, and a DECIMAL control
  • real two-CN database/sql binary prepared statements for DATE, DATETIME, and TIMESTAMP using > and <=, statement reuse, NULL, invalid DATETIME error semantics, literal SQL, and interpolateParams=true
  • focused regression proved failing on the unfixed main revision and passing after the fix
  • full CGo package tests passed for ./pkg/sql/plan and ./pkg/frontend
  • focused planner race test passed
  • go vet -mod=readonly ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issues passed
  • direct repository-CGo go build -mod=readonly ./cmd/mo-service passed

Validation note

The full make build reached the packaging dependency download but the 35.5 MB ONNX Runtime download timed out in the local environment. The equivalent mo-service compile and link path completed successfully, and no product change was made to mask the environmental failure.

Issue

close #27774

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

Deep-reviewed exact head fdb0f92 across the prepared specialization eligibility walk, execute-time rewrite, serialized composite-key filters, and public binary-protocol path. Binder-inserted DATE, TIME, DATETIME, TIMESTAMP, and INTERVAL casts now remain semantic boundaries, while YEAR keeps its established numeric behavior and explicit CAST remains authoritative through its existing syntax/overload gate. The tests cover comparison operators, valid/invalid/NULL bounds, prefix range structure, statement reuse, literal/interpolated controls, and a DECIMAL specialization control. The new check is constant-time per visited cast and avoids unnecessary temporal deep-copy/rebinding. I found no blocking correctness, indexability, performance, or unhappy-path issue.

@XuPeng-SH
XuPeng-SH merged commit ef4ac3e into matrixorigin:main Aug 31, 2026
16 of 20 checks passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

- preserve binder-selected DATE, DATETIME, and TIMESTAMP types when
binary prepared string parameters are used in range predicates
- stop numeric-prefix specialization at implicit temporal cast
boundaries while retaining the existing DECIMAL and YEAR behavior
- add typed planner coverage plus a real database/sql and
go-sql-driver/mysql two-CN regression test

## Root cause

The MySQL binary protocol sends the legal DATETIME bounds as strings.
Numeric-prefix classification marked strings beginning with a year as
decimal candidates. For a composite temporal primary key, the planner
also generated serialized prefix range filters around the
binder-inserted temporal casts. Prepared-plan specialization then
treated the nested parameter as decimal-eligible, crossed that temporal
cast boundary, and rebound the original temporal range in the DECIMAL
domain. Constant folding consequently parsed the full DATETIME text as a
number and returned 20301 invalid numeric string.

## Fix and compatibility

The specialization walk now treats an implicit temporal
prepared-parameter cast as a semantic type boundary. DATE, TIME,
DATETIME, TIMESTAMP, and INTERVAL casts cannot opt into numeric-prefix
specialization; YEAR keeps its established numeric behavior. Untyped and
numeric parameters, including DECIMAL controls, continue to use the
existing specialization path. Temporal column predicates and serialized
composite-key bounds therefore remain temporal, without adding a numeric
cast to the column or changing index range planning.

## Tests

- planner binder coverage for DATE, DATETIME, and TIMESTAMP with =, <=>,
!=, <, <=, >, and >=
- prepared composite temporal range coverage for valid strings, invalid
strings, NULL, serialized block filters, and a DECIMAL control
- real two-CN database/sql binary prepared statements for DATE,
DATETIME, and TIMESTAMP using > and <=, statement reuse, NULL, invalid
DATETIME error semantics, literal SQL, and interpolateParams=true
- focused regression proved failing on the unfixed main revision and
passing after the fix
- full CGo package tests passed for ./pkg/sql/plan and ./pkg/frontend
- focused planner race test passed
- go vet -mod=readonly ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issues
passed
- direct repository-CGo go build -mod=readonly ./cmd/mo-service passed

## Validation note

The full make build reached the packaging dependency download but the
35.5 MB ONNX Runtime download timed out in the local environment. The
equivalent mo-service compile and link path completed successfully, and
no product change was made to mask the environmental failure.

## Issue

close matrixorigin#27774

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

- preserve binder-selected DATE, DATETIME, and TIMESTAMP types when
binary prepared string parameters are used in range predicates
- stop numeric-prefix specialization at implicit temporal cast
boundaries while retaining the existing DECIMAL and YEAR behavior
- add typed planner coverage plus a real database/sql and
go-sql-driver/mysql two-CN regression test

## Root cause

The MySQL binary protocol sends the legal DATETIME bounds as strings.
Numeric-prefix classification marked strings beginning with a year as
decimal candidates. For a composite temporal primary key, the planner
also generated serialized prefix range filters around the
binder-inserted temporal casts. Prepared-plan specialization then
treated the nested parameter as decimal-eligible, crossed that temporal
cast boundary, and rebound the original temporal range in the DECIMAL
domain. Constant folding consequently parsed the full DATETIME text as a
number and returned 20301 invalid numeric string.

## Fix and compatibility

The specialization walk now treats an implicit temporal
prepared-parameter cast as a semantic type boundary. DATE, TIME,
DATETIME, TIMESTAMP, and INTERVAL casts cannot opt into numeric-prefix
specialization; YEAR keeps its established numeric behavior. Untyped and
numeric parameters, including DECIMAL controls, continue to use the
existing specialization path. Temporal column predicates and serialized
composite-key bounds therefore remain temporal, without adding a numeric
cast to the column or changing index range planning.

## Tests

- planner binder coverage for DATE, DATETIME, and TIMESTAMP with =, <=>,
!=, <, <=, >, and >=
- prepared composite temporal range coverage for valid strings, invalid
strings, NULL, serialized block filters, and a DECIMAL control
- real two-CN database/sql binary prepared statements for DATE,
DATETIME, and TIMESTAMP using > and <=, statement reuse, NULL, invalid
DATETIME error semantics, literal SQL, and interpolateParams=true
- focused regression proved failing on the unfixed main revision and
passing after the fix
- full CGo package tests passed for ./pkg/sql/plan and ./pkg/frontend
- focused planner race test passed
- go vet -mod=readonly ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issues
passed
- direct repository-CGo go build -mod=readonly ./cmd/mo-service passed

## Validation note

The full make build reached the packaging dependency download but the
35.5 MB ONNX Runtime download timed out in the local environment. The
equivalent mo-service compile and link path completed successfully, and
no product change was made to mask the environmental failure.

## Issue

close matrixorigin#27774

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## Summary

- preserve binder-selected DATE, DATETIME, and TIMESTAMP types when
binary prepared string parameters are used in range predicates
- stop numeric-prefix specialization at implicit temporal cast
boundaries while retaining the existing DECIMAL and YEAR behavior
- add typed planner coverage plus a real database/sql and
go-sql-driver/mysql two-CN regression test

## Root cause

The MySQL binary protocol sends the legal DATETIME bounds as strings.
Numeric-prefix classification marked strings beginning with a year as
decimal candidates. For a composite temporal primary key, the planner
also generated serialized prefix range filters around the
binder-inserted temporal casts. Prepared-plan specialization then
treated the nested parameter as decimal-eligible, crossed that temporal
cast boundary, and rebound the original temporal range in the DECIMAL
domain. Constant folding consequently parsed the full DATETIME text as a
number and returned 20301 invalid numeric string.

## Fix and compatibility

The specialization walk now treats an implicit temporal
prepared-parameter cast as a semantic type boundary. DATE, TIME,
DATETIME, TIMESTAMP, and INTERVAL casts cannot opt into numeric-prefix
specialization; YEAR keeps its established numeric behavior. Untyped and
numeric parameters, including DECIMAL controls, continue to use the
existing specialization path. Temporal column predicates and serialized
composite-key bounds therefore remain temporal, without adding a numeric
cast to the column or changing index range planning.

## Tests

- planner binder coverage for DATE, DATETIME, and TIMESTAMP with =, <=>,
!=, <, <=, >, and >=
- prepared composite temporal range coverage for valid strings, invalid
strings, NULL, serialized block filters, and a DECIMAL control
- real two-CN database/sql binary prepared statements for DATE,
DATETIME, and TIMESTAMP using > and <=, statement reuse, NULL, invalid
DATETIME error semantics, literal SQL, and interpolateParams=true
- focused regression proved failing on the unfixed main revision and
passing after the fix
- full CGo package tests passed for ./pkg/sql/plan and ./pkg/frontend
- focused planner race test passed
- go vet -mod=readonly ./pkg/sql/plan ./pkg/frontend ./pkg/tests/issues
passed
- direct repository-CGo go build -mod=readonly ./cmd/mo-service passed

## Validation note

The full make build reached the packaging dependency download but the
35.5 MB ONNX Runtime download timed out in the local environment. The
equivalent mo-service compile and link path completed successfully, and
no product change was made to mask the environmental failure.

## Issue

close matrixorigin#27774

Co-authored-by: XuPeng-SH <[email protected]>

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

size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Go prepared DATETIME range parameters fail with 20301

3 participants