Skip to content

fix(frontend): advertise NEWDECIMAL for SELECT DECIMAL wire metadata - #30302

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-30283-fc983e98
Oct 16, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-30283-fc983e98

Conversation

@gouhongshen

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:

Related to #30283

What this PR does / why we need it:

Problem

Ordinary MySQL-protocol SELECT results containing DECIMAL are returned with the legacy wire metadata type 0 (MYSQL_TYPE_DECIMAL) instead of MySQL 8's 246 (MYSQL_TYPE_NEWDECIMAL). For the issue's reproduction:

SELECT CAST(1.123456 AS DECIMAL(24,6)) AS metric_value;
  • MatrixOne baseline: (('metric_value', 0, None, 26, 26, 6, False),)
  • MySQL 8.0.30: (('metric_value', 246, None, 26, 26, 6, False),)

PyMySQL names type 0 as DECIMAL; consumers such as Superset then take a client-defective tuple-mutation path ('tuple' object does not support item assignment). Emitting the modern NEWDECIMAL identifier matches MySQL 8 and avoids that client path.

Root cause

convertEngineTypeToMysqlType (pkg/frontend/mysql_cmd_executor.go) assigns the legacy internal identifier MYSQL_TYPE_DECIMAL to decimal64/decimal128/decimal256 columns, and makeColumnDefinition41Payload (pkg/frontend/mysql_protocol.go) previously wrote column.ColumnType() verbatim into every outgoing ColumnDefinition41 packet. Since SELECT column definitions, COM_STMT_PREPARE responses, cached PrepareStmt.ColDefData and MakeColumnDefData all share this one serializer, every wire path exposed type 0.

Change

pkg/frontend/mysql_protocol.go (9 insertions, 1 deletion): in makeColumnDefinition41Payload, derive a local wireType and translate MYSQL_TYPE_DECIMAL to MYSQL_TYPE_NEWDECIMAL only when writing the type byte — mirroring the existing BOOL→TINY wire-boundary translation already in the same function. The internal MysqlColumn is not mutated and keeps MYSQL_TYPE_DECIMAL, so all consumers that dispatch on the internal type are untouched:

  • result-row encoders — decimal rows remain length-encoded decimal text, which is exactly the byte format MySQL 8 clients decode for advertised NEWDECIMAL (per the MySQL binary resultset protocol documentation);
  • MysqlType.GetLength, CSV/Parquet export dispatch, and Data Branch DIFF result materialization (Fix data branch decimal results on main #24894), which already accept both identifiers 0 and 246 on input.

Tests

Implementation and regressions live entirely in pkg/frontend:

  • pkg/frontend/decimal_wire_metadata_test.go (new, 418 lines, 6 tests):
    • TestDecimalColumnDefinitionWireMetadata — packet decode for 8 width/scale cases incl. the issue's DECIMAL(24,6) → 246/len 26/scale 6, precision transitions 18/19 and 38/39, supported precision 65, scale 0 and scale=precision; asserts internal type stays MYSQL_TYPE_DECIMAL, repeated serialization byte-identical, source column unmutated.
    • TestColumnDefinitionWireMetadataControls — a preconstructed NEWDECIMAL column stays 246; int/varchar/double/blob/date/null wire ids unchanged; BOOL→TINY translation preserved.
    • TestDecimalWireMetadataFromSql — real plan build of the exact issue query, serialized and decoded.
    • TestDecimalPrepareAndCachedMetadata — fresh SendPrepareResponse and cached PrepareStmt.ColDefData are byte-identical and advertise 246; decimal parameter columns too.
    • TestDecimalMakeColumnDefData — mixed decimal/non-decimal column set.
    • TestDecimalPrepareExecuteBinaryRoundTrip — COM_STMT_PREPARE metadata decode (246/20/3 plus a non-decimal neighbor), then two COM_STMT_EXECUTE-style binary row encodings; every row packet is independently decoded trusting only the advertised wire metadata (0x00 header, offset-2 NULL bitmap, length-encoded decimals, fixed-width ints), asserting exact positive/negative/zero/trailing-zero decimal texts, a NULL decimal field, the neighbor value, whole-packet consumption, and byte-identical rows across repeated executions.
  • pkg/frontend/mysql_protocol_test.go — 3 legacy-type-0 wire assertions in TestSendPrepareResponse and TestPreparedNumericFunctionBinaryProtocolMetadata updated to NEWDECIMAL.

Exact commands and results (this tree):

  • Baseline proof: new tests fail on the pre-fix code (expected 0xf6, actual 0x0); a baseline server binary reproduces the issue descriptor type 0 with exact value.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s -run '^(TestDecimalColumnDefinitionWireMetadata|TestColumnDefinitionWireMetadataControls|TestDecimalWireMetadataFromSql|TestDecimalPrepareAndCachedMetadata|TestDecimalMakeColumnDefData|TestDecimalPrepareExecuteBinaryRoundTrip|TestSendPrepareResponse|TestPreparedNumericFunctionBinaryProtocolMetadata)$' ./pkg/frontend → 8/8 PASS.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=1800s ./pkg/frontend → ok github.com/matrixorigin/matrixone/pkg/frontend 34.587s (full package suite, zero failures).
  • Live against a locally built server:
    • PyMySQL: cursor.description = (('metric_value', 246, None, 26, 26, 6, False),), value exactly Decimal('1.123456'); extended checks over DECIMAL(18,3)/(38,10)/(65,30) table reads (signed/zero/trailing-zero/NULL), empty results, SUM aggregate, mixed columns, two interleaved sessions, SQL-level PREPARE/EXECUTE — all pass.
    • go-sql-driver v1.9.3 binary-protocol client (real COM_STMT_PREPARE + repeated COM_STMT_EXECUTE with cached metadata, distinct from SQL-level PREPARE/EXECUTE): prepared table read executed twice with exact decimal texts, NULL row and INT neighbor; prepared issue query returns exactly 1.123456 — 14/14 checks pass.
    • Live Data Branch DIFF over decimal columns returns 246 metadata with exact diff rows (Fix data branch decimal results on main #24894 behavior preserved).
  • mo-tester BVT in the CI-equivalent metadata mode (-n -g): test/distributed/cases/dtype/decimal.test 690/690 and test/distributed/cases/dtype/decimal_256.test 27/27 — 717/717 pass, exit 0. Numeric expectations unchanged.

Residual risks

  • Consumers that intentionally depended on raw wire type id 0 for result-set decimals will now observe the MySQL-conformant 246; row value bytes are unchanged, and Connector/J (decompiled 8.0.15) maps ids 0 and 246 identically, so JDBC behavior is unchanged. PyMySQL and go-sql-driver verified live.
  • Prepared-parameter parsing continues to accept both 0 and 246 — unchanged, covered by the existing package suite.

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 15, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Oct 15, 2026
@gouhongshen
gouhongshen force-pushed the agent/issue-30283-fc983e98 branch from 58570dc to e4afc0e Compare October 15, 2026 14:14
@gouhongshen
gouhongshen force-pushed the agent/issue-30283-fc983e98 branch from e4afc0e to 0a4cf01 Compare October 15, 2026 14:21
@gouhongshen
gouhongshen force-pushed the agent/issue-30283-fc983e98 branch from 0a4cf01 to f8d1e26 Compare October 15, 2026 14:59
Ordinary SELECT results containing DECIMAL were sent with the legacy
MySQL wire type 0 (MYSQL_TYPE_DECIMAL) instead of MySQL 8's 246
(MYSQL_TYPE_NEWDECIMAL), because makeColumnDefinition41Payload wrote
the internal column type verbatim. PyMySQL names type 0 DECIMAL, which
activates a client-defective mutation path in consumers such as
Superset.

Translate MYSQL_TYPE_DECIMAL to MYSQL_TYPE_NEWDECIMAL only when writing
the ColumnDefinition41 type byte, mirroring the existing BOOL-to-TINY
wire-boundary translation. The internal MysqlColumn keeps
MYSQL_TYPE_DECIMAL, so row encoders, CSV/Parquet export, GetLength and
Data Branch materialization keep dispatching on the established
identifier; row bytes stay length-encoded decimal text, which is
exactly what clients decode for advertised NEWDECIMAL.

Regression proof: packet-decoding unit tests across decimal64/128/256
widths, boundary precisions 18/19, 38/39 and 65, scale zero and
fractional scales, fresh and cached COM_STMT_PREPARE metadata, mixed
and non-decimal control columns, BOOL translation, and a
COM_STMT_PREPARE -> repeated COM_STMT_EXECUTE binary round trip
decoding exact values, NULL and a non-decimal neighbor through the
advertised metadata alone. Verified live with PyMySQL (descriptor
246/26/6, exact Decimal('1.123456')) and a go-sql-driver binary
prepare/execute client against a locally built server, plus
CI-equivalent mo-tester runs of dtype/decimal.test (690/690) and
decimal_256.test (27/27). Related to matrixorigin#30283.
@XuPeng-SH

XuPeng-SH commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: e185f1f153c0211d2782a3c968c9921156abe050

Review completed. Read the assessment.

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

mo-bot review · mo-bot-local · review

Commit: e185f1f153c0211d2782a3c968c9921156abe050

Assessment: approve

Reviewed the complete three-file delta and affected callers. Normalizing DECIMAL at the shared wire serializer is the appropriate design: it preserves internal types, row encoding, exports and cached metadata contracts. The change adds one comparison per column definition, with no new allocations or per-row work. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Verified the frozen head, complete patch and unchanged source. Reconciled commands, source fingerprints, exit receipts and retained logs in /home/xupeng/.local/state/mo-bot/jobs/3b8f22f0ba470906b17283a4/attempt-1/review-evidence.json.

  • Isolation preflight passed. Verified 192 current native inputs and 19 retained build artifacts against the repository build-owner provenance.

  • Eight focused frontend tests passed. The complete frontend suite passed 2,463 top-level cases; one existing test, TestRuleCacheDoubleCheckLocking, skipped itself.

  • A diagnostic test-only overlay passed against a live server using go-sql-driver/mysql: raw metadata and exact decimal values verified for ordinary queries, preparation, repeated binary execution, decimal64/128/256, signed values, zero, NULL, empty results and aggregates.

  • The regression test failed as expected with the merge-base serializer overlaid: expected wire type 246, actual 0. The candidate passed the same test.

  • go vet ./pkg/frontend and git diff --check passed. Final evidence audit passed with receipt 1792126646407214224-3.json.

Limitations:

  • No Superset or PyMySQL application run was performed; live validation covered raw wire metadata and the pinned Go client.

  • Linked issue bodies were absent from frozen evidence; the exact reproduction and required behavior were supplied in the PR text. Author-reported executions without retained receipts were not counted as independently verified.

  • No performance benchmark was run; the cost assessment follows the bounded serializer change and its callers.

@mergify mergify Bot added the queued label Oct 16, 2026
@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 04:58 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 07:37 UTC · at 867827d95b6f016b267412477c8c464e6b3589bd

This pull request spent 2 hours 38 minutes 39 seconds in the queue, with no time running CI.

Reason

Pull request #30302 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 867827d9 Deployed Oct 16, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued 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