Skip to content

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

Closed

Description

@Ariznawlll

Description

MatrixOne returns 20301 when a Go MySQL client executes a valid prepared range predicate against a DATETIME column and binds the time values as strings.

Environment

  • Branch: main
  • MatrixOne commit: a73f76d109bd528ae2e53a4b8ab294422fb13e21
  • Deployment: 7-pod distributed stability cluster (2 CN, 1 DN, 3 LogService, 1 Proxy)
  • Test date: 2026-08-28

Steps to reproduce

  1. Use Go database/sql with github.com/go-sql-driver/mysql.

  2. Execute this statement through QueryRowContext, binding both markers as Go strings:

    SELECT COUNT(*)
    FROM mo_cloud.storage
    WHERE collecttime > ? AND collecttime <= ?
  3. Bind "2026-05-01 08:55:23" and "2026-05-19 04:14:00".

mo_cloud.storage.collecttime is DATETIME NOT NULL and has a primary key beginning with collecttime.

Actual behavior

The Go-driver execution fails before the load test starts:

Error 20301 (HY000): invalid input: "2026-05-01 08:55:23" is invalid numeric string

The failure is stable: 3/3 identical read-only executions failed (26.90 s, 1.36 s, 1.26 s).

Expected behavior

MatrixOne should accept valid string temporal parameters for comparison with a DATETIME column and return the count, as MySQL-compatible prepared statements do.

Stability and controls

  • The normal control used the same SQL, same two values, and server-side PREPARE/EXECUTE; it returned 48,934,000 rows in 3/3 executions.
  • The test connected successfully, verified the table exists, and verified the collecttime primary-key column before the failing statement.
  • All reproductions were read-only. No new pod restart, panic, or leftover process was observed in the target stability cluster.

Evidence

Code analysis

The reproducer sends the two valid datetime values through the Go MySQL driver's binary prepared-statement protocol. MatrixOne appears to attempt numeric conversion for the temporal string during this path. This is a confirmed protocol/temporal-parameter behavior difference; the exact server-side conversion location remains to be investigated.

Regression coverage

After a product fix, add a stable public-SQL regression that covers binary-protocol prepared DATETIME range predicates with string temporal parameters.

Activity

  1. added
    kind/bug
    on Aug 28, 2026
  2. added theissue type on Aug 28, 2026
  3. added this to the MO-202608 milestone on Aug 28, 2026
  4. added a commit that references this issue on Aug 31, 2026
    ef4ac3e
  5. reopened this on Sep 4, 2026
  6. assigned and unassigned on Sep 4, 2026
  7. slyunnn commented on Sep 8, 2026

    @slyunnn

    Regression and extended verification for #27774 (2026-09-08)

    Verification Environment

    • MatrixOne baseline: origin/main at 8198fd4d7ec0c616a6c8b138f3c86284d70b2a5a — fix(sql): preserve cluster table account default on truncate (#28374).
    • Related fix: PR #27882, merge commit ef4ac3ed9b44474257e72b911bb5e4fa1b6c8c4b; product commit fdb0f921cb3eb958282eda0625414c06ea3d9b92 — fix(plan): preserve temporal prepared range types.
    • Standalone protocol and MOTR topology: one Log Service, one TN, and one CN, with the CN SQL listener at 127.0.0.1:26001; no Proxy and no multi-CN routing.
    • Existing focused MatrixOne integration test topology: the repository test TestIssue27774PreparedTemporalCompositeRange on the embedded base cluster; PR #27882 documents this regression as a real two-CN Go database/sql and go-sql-driver/mysql test.
    • Test entry point 1: exact-main focused CGo test TestIssue27774PreparedTemporalCompositeRange in pkg/tests/issues.
    • Test entry point 2: new MOTR Go protocol script against 127.0.0.1:26001.
    • Test entry point 3: new MOTR SQL record and replay case against 127.0.0.1:26001.
    • Client protocol: Go database/sql with github.com/go-sql-driver/mysql; interpolateParams=false exercises COM_STMT_PREPARE and COM_STMT_EXECUTE with string parameters. interpolateParams=true and the SQL case provide MySQL text-query protocol controls.

    What Was Covered

    • OK Original reproduction: a binary prepared DATETIME composite-primary-key range predicate with string bounds returns the expected count 2 and does not return error 20301.
    • OK Happy path: binary prepared DATE, DATETIME, and TIMESTAMP ranges each accept valid string bounds and return the expected count.
    • OK Boundary and reuse: the same prepared statement is reused with a narrower range and then a NULL lower bound; results are 1 and 0 respectively.
    • OK Unhappy path: not-a-datetime returns error 20301 containing invalid datetime value, not invalid numeric string.
    • OK Recovery: a valid DATETIME execution after the invalid execution still returns 2, proving the failed execute does not poison the prepared statement.
    • OK Compatibility controls: interpolateParams=true, server-side SQL PREPARE / EXECUTE, and literal SQL produce the same temporal range counts.
    • OK Fixture lifecycle: the protocol test drops its database and verifies no catalog residue remains.
    • Not covered The original seven-pod deployment topology (2 CN, 1 DN, 3 LogService, 1 Proxy), external MySQL differential execution, and load-test throughput/latency measurement.

    Findings

    The original 20301 failure is not reproducible on current origin/main. Valid Go string DATETIME bounds retain their temporal domain through binary prepared execution instead of being re-specialized as DECIMAL values.

    Large-data regression is not needed. The root cause is prepared-parameter type specialization at an implicit temporal cast boundary, not cardinality, block/batch size, memory/spill, concurrency, skew, network transport volume, or resource scale. The minimum four-row composite-primary-key fixture exercises the relevant temporal range contract without adding unrelated CI cost.

    MOTR / BVT Coverage

    • Added SQL control case suites/14_issue_regression/t/issue_27774_prepared_datetime_range.test and recorded result suites/14_issue_regression/r/issue_27774_prepared_datetime_range.result.
    • Added binary-protocol script script/14_issue_regression/issue_27774_prepared_datetime_range_protocol.go, launch script, and recorded output baseline.
    • MOTR SQL record: 14 statements, 14 expected outcomes, passed.
    • MOTR SQL replay: 14 statements, 14 expected outcomes, passed.
    • Protocol script replay: DATE, DATETIME, TIMESTAMP, invalid input, recovery, text control, and cleanup assertions all passed with an exact output match.
    • Commit: 0645d67e3e29c2600cfe75070443f04fe965c22d — test: add MOTR regression for #27774.
    • Backup branch: test/issue-27774-prepared-datetime-range in matrixorigin/motr.

    Final Conclusion

    Fixed. Current origin/main accepts valid Go binary prepared temporal range parameters and returns a temporal validation error only for invalid DATETIME values. No large-data regression is required for the reasons above.

  8. added 3 commits that reference this issue on Sep 17, 2026
    fcc3ad0
    ad2697b
    15d1bde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions