Repository navigation
fix(plan): preserve temporal prepared range types - #27882
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.
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.
## 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]>
## 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]>
## 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]>
Summary
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
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