Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
No issue was found for fractional DECIMAL count handling in SUBSTRING_INDEX().
Branch Name
main
Commit ID
f72ca9efbeb3a7c673701e4a135cc6670c33cfde
Other Environment Information
- Local standalone MatrixOne
- Reference: MySQL 8.3.0
Actual Behavior
SUBSTRING_INDEX(str, delim, count) truncates a DECIMAL count toward zero in MatrixOne. MySQL converts the DECIMAL count to the nearest integer, so fractional counts at and above .5 select a different number of delimited components.
SELECT
SUBSTRING_INDEX('a,b,c,d', ',', CAST(1.4 AS DECIMAL(4,1))),
SUBSTRING_INDEX('a,b,c,d', ',', CAST(1.5 AS DECIMAL(4,1))),
SUBSTRING_INDEX('a,b,c,d', ',', CAST(1.9 AS DECIMAL(4,1))),
SUBSTRING_INDEX('a,b,c,d', ',', CAST(2.5 AS DECIMAL(4,1)));MatrixOne: a, a, a, a,b
MySQL 8.3: a, a,b, a,b, a,b,c
The negative direction is affected in the same way:
SELECT
SUBSTRING_INDEX('a,b,c,d', ',', CAST(-1.5 AS DECIMAL(4,1))),
SUBSTRING_INDEX('a,b,c,d', ',', CAST(-1.9 AS DECIMAL(4,1))),
SUBSTRING_INDEX('a,b,c,d', ',', CAST(-2.5 AS DECIMAL(4,1)));MatrixOne: d, d, c,d
MySQL 8.3: c,d, c,d, b,c,d
The difference also occurs for DECIMAL table columns and for a server-side prepared statement executed with a DECIMAL session variable:
CREATE TABLE t(id INT, n DECIMAL(4,1));
INSERT INTO t VALUES (1,1.4),(2,1.5),(3,1.9),(4,-1.5);
SELECT id, SUBSTRING_INDEX('a,b,c,d', ',', n) FROM t ORDER BY id;
PREPARE stmt FROM 'SELECT SUBSTRING_INDEX("a,b,c,d", ",", ?)';
SET @v=CAST(1.5 AS DECIMAL(4,1));
EXECUTE stmt USING @v;For the prepared execution, MatrixOne returns a; MySQL returns a,b.
Each scalar form was repeated three times.
Expected Behavior
A DECIMAL count should use the same integer conversion as MySQL before SUBSTRING_INDEX() selects components. Values at and above the half boundary should not be truncated toward zero.
Controls and scope
- Integer counts, including negative, zero, one, two, and counts larger than the number of delimiters, agree with MySQL.
NULLremainsNULL.- DECIMAL
1.4and-1.4, which remain one after nearest-integer conversion, agree with MySQL. - MySQL 8.3 shows context-dependent behavior for explicitly cast DOUBLE constants versus DOUBLE columns. That ambiguous DOUBLE behavior is deliberately excluded from this issue; the reproduction relies only on DECIMAL, whose constant, column, and prepared paths are consistent.
Root cause
SUBSTRING_INDEX routes noninteger numeric input through its FLOAT64 overload. getCount() converts FLOAT64 with Go's int64(v), which truncates toward zero.
Activity
slyunnn commentedon Sep 28, 2026
Regression and extended verification for #28401 (2026-09-28)
Verification Environment
origin/mainat9b7c2c23dba737232d975d66bd04628199e1a436—fix(tae): reconcile replay promotion merge state before write (#29421).arm64mo-servicebuilt from that exact source commit; its embedded build information reports branchmainand commit9b7c2c23db.1 Log service / 1 TN / 2 CN / 1 Proxy.6001, CN116001, and CN216002were all connected successfully. The original SQL was executed through each endpoint using the MySQL text protocol; binary prepared coverage used Go's MySQL driver andCOM_STMT_PREPARE/COM_STMT_EXECUTEon all three endpoints.8.3.0using the MySQL text protocol.d9609d742b9000b54279f44e34295630b7238282(refactor: add integer parameter binding contract). It introduces the shared exact integer-argument conversion contract used bySUBSTRING_INDEX. The earlier PR #28428 was closed without merge and was superseded by this shared implementation.What Was Covered
CAST(... AS DECIMAL(4,1))counts1.4,1.5,1.9, and2.5: returneda,a,b,a,b, anda,b,c, matching MySQL8.3.0on Proxy, CN1, and CN2.DECIMALcounts-1.5,-1.9, and-2.5: returnedc,d,c,d, andb,c,d, matching MySQL8.3.0on all three endpoints.0.5and-0.5: returnedaandd;NULLreturnedNULLon all three endpoints.DECIMAL(4,1)table-column input, including positive, negative, andNULLrows, matched MySQL8.3.0on Proxy, CN1, and CN2.PREPARE/EXECUTEwith@vasDECIMAL(4,1)returneda,bfor1.5andb,c,dfor-2.5on all three endpoints.COM_STMT_PREPARE/COM_STMT_EXECUTEwithCAST(? AS DECIMAL(4,1))returned the expected positive, negative, andNULLresults on Proxy, CN1, and CN2.DOUBLEcount compatibility remains intentionally outside this DECIMAL-focused issue and was not used to judge the fix.Findings
SUBSTRING_INDEXnow routes exactDECIMALcount arguments through the shared integer-argument conversion path before overload selection. The original fractional-count truncation is not reproducible on the latest main runtime. The service and all three SQL endpoints remained healthy after the checks.MOTR / BVT Coverage
No new MOTR case or commit was needed. Existing distributed BVT coverage in
test/distributed/cases/function/integer_parameter_coercion.sqlalready exercisesSUBSTRING_INDEXwithDECIMALcolumns and literals,NULL, boundary/overflow controls, and reusable SQL prepared execution. The latest-main targeted planner regression testsTestIntegerArgumentMySQLSourceEvaluation,TestIntegerArgumentBoundSources,TestIntegerArgumentPreparedSourceEvaluation, andTestIntegerArgumentMixedPreparedSourcespassed.Large-data regression is not required: this is a scalar argument type-conversion and overload-binding issue, independent of row count, block/batch boundaries, memory/spill, concurrency, data skew, network transfer, or resource scale. Increasing data volume would not exercise an additional relevant execution boundary.
Final Conclusion
Fixed. The original
DECIMALfractional-count behavior and the required extended table, SQL prepared, and binary prepared scenarios match MySQL8.3.0on Proxy, CN1, and CN2.