Skip to content

[Compatibility]: SUBSTRING_INDEX truncates fractional DECIMAL counts #28401

Closed

Description

@Ariznawlll

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.
  • NULL remains NULL.
  • DECIMAL 1.4 and -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

  1. added this to the MO-202609 milestone on Sep 8, 2026
  2. added theissue type on Sep 8, 2026
  3. added
    severity/s0
    and removed on Sep 8, 2026
  4. assigned and unassigned on Sep 27, 2026
  5. slyunnn commented on Sep 28, 2026

    @slyunnn

    Regression and extended verification for #28401 (2026-09-28)

    Verification Environment

    • Source: latest origin/main at 9b7c2c23dba737232d975d66bd04628199e1a436 — fix(tae): reconcile replay promotion merge state before write (#29421).
    • Runtime: a Linux arm64 mo-service built from that exact source commit; its embedded build information reports branch main and commit 9b7c2c23db.
    • Topology: 1 Log service / 1 TN / 2 CN / 1 Proxy.
    • Endpoints: Proxy 6001, CN1 16001, and CN2 16002 were all connected successfully. The original SQL was executed through each endpoint using the MySQL text protocol; binary prepared coverage used Go's MySQL driver and COM_STMT_PREPARE / COM_STMT_EXECUTE on all three endpoints.
    • Compatibility reference: local MySQL 8.3.0 using the MySQL text protocol.
    • Execution was sequential; there was no engine-parallel or multi-session correctness requirement for this scalar conversion issue.
    • Associated fix: PR #28989, merged as d9609d742b9000b54279f44e34295630b7238282 (refactor: add integer parameter binding contract). It introduces the shared exact integer-argument conversion contract used by SUBSTRING_INDEX. The earlier PR #28428 was closed without merge and was superseded by this shared implementation.

    What Was Covered

    • OK Original scalar reproduction with CAST(... AS DECIMAL(4,1)) counts 1.4, 1.5, 1.9, and 2.5: returned a, a,b, a,b, and a,b,c, matching MySQL 8.3.0 on Proxy, CN1, and CN2.
    • OK Negative DECIMAL counts -1.5, -1.9, and -2.5: returned c,d, c,d, and b,c,d, matching MySQL 8.3.0 on all three endpoints.
    • OK Boundary counts 0.5 and -0.5: returned a and d; NULL returned NULL on all three endpoints.
    • OK DECIMAL(4,1) table-column input, including positive, negative, and NULL rows, matched MySQL 8.3.0 on Proxy, CN1, and CN2.
    • OK Same-session SQL PREPARE / EXECUTE with @v as DECIMAL(4,1) returned a,b for 1.5 and b,c,d for -2.5 on all three endpoints.
    • OK Binary COM_STMT_PREPARE / COM_STMT_EXECUTE with CAST(? AS DECIMAL(4,1)) returned the expected positive, negative, and NULL results on Proxy, CN1, and CN2.
    • Not covered Explicit DOUBLE count compatibility remains intentionally outside this DECIMAL-focused issue and was not used to judge the fix.

    Findings

    SUBSTRING_INDEX now routes exact DECIMAL count 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.sql already exercises SUBSTRING_INDEX with DECIMAL columns and literals, NULL, boundary/overflow controls, and reusable SQL prepared execution. The latest-main targeted planner regression tests TestIntegerArgumentMySQLSourceEvaluation, TestIntegerArgumentBoundSources, TestIntegerArgumentPreparedSourceEvaluation, and TestIntegerArgumentMixedPreparedSources passed.

    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 DECIMAL fractional-count behavior and the required extended table, SQL prepared, and binary prepared scenarios match MySQL 8.3.0 on Proxy, CN1, and CN2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions