Repository navigation
fix(frontend): advertise NEWDECIMAL for SELECT DECIMAL wire metadata - #30302
Conversation
58570dc to
e4afc0e
Compare
e4afc0e to
0a4cf01
Compare
0a4cf01 to
f8d1e26
Compare
7a7a1db to
8e6d757
Compare
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.
8e6d757 to
e185f1f
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 2 hours 38 minutes 39 seconds in the queue, with no time running CI. ReasonPull 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.
HintYou 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. Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
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's246(MYSQL_TYPE_NEWDECIMAL). For the issue's reproduction:(('metric_value', 0, None, 26, 26, 6, False),)(('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 identifierMYSQL_TYPE_DECIMALto decimal64/decimal128/decimal256 columns, andmakeColumnDefinition41Payload(pkg/frontend/mysql_protocol.go) previously wrotecolumn.ColumnType()verbatim into every outgoing ColumnDefinition41 packet. Since SELECT column definitions, COM_STMT_PREPARE responses, cachedPrepareStmt.ColDefDataandMakeColumnDefDataall share this one serializer, every wire path exposed type 0.Change
pkg/frontend/mysql_protocol.go(9 insertions, 1 deletion): inmakeColumnDefinition41Payload, derive a localwireTypeand translateMYSQL_TYPE_DECIMALtoMYSQL_TYPE_NEWDECIMALonly when writing the type byte — mirroring the existing BOOL→TINY wire-boundary translation already in the same function. The internalMysqlColumnis not mutated and keepsMYSQL_TYPE_DECIMAL, so all consumers that dispatch on the internal type are untouched: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 staysMYSQL_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— freshSendPrepareResponseand cachedPrepareStmt.ColDefDataare 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 inTestSendPrepareResponseandTestPreparedNumericFunctionBinaryProtocolMetadataupdated to NEWDECIMAL.Exact commands and results (this tree):
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).cursor.description=(('metric_value', 246, None, 26, 26, 6, False),), value exactlyDecimal('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.1.123456— 14/14 checks pass.-n -g):test/distributed/cases/dtype/decimal.test690/690 andtest/distributed/cases/dtype/decimal_256.test27/27 — 717/717 pass, exit 0. Numeric expectations unchanged.Residual risks