Skip to content

[Bug]: non-unique indexes cannot serialize DECIMAL256 keys #28586

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues, including open and closed issues.

Branch Name

main

Commit ID

fc621e3

Other Environment Information

  • MatrixOne: locally built from the commit above (8.0.30-MatrixOne-v1.3.0)
  • MySQL baseline: 8.0.46
  • Verification date: 2026-09-10

Actual Behavior

Non-unique secondary indexes cannot serialize a DECIMAL256 key (DECIMAL precision 39 through 76).

There are two externally visible failure modes:

  1. CREATE INDEX on a populated Decimal256 column fails immediately with internal error: not supported type DECIMAL256.
  2. Declaring the same index in CREATE TABLE succeeds and the index appears in SHOW INDEX, but the first INSERT fails with the same internal error and writes no row.

The behavior starts exactly at the Decimal128/Decimal256 boundary: DECIMAL(38,0) with the same ordinary index can be populated and queried, while DECIMAL(39,0) cannot. It also affects scaled Decimal256 keys, composite indexes containing a Decimal256 component, and an index on a Decimal256 generated column.

This is specific to ordinary secondary-index serialization. Decimal256 values work in heap-table writes, scans, predicates, grouping, ordering, prepared statements, stored generated columns, primary keys, and unique indexes. Duplicate enforcement by a Decimal256 unique index also works.

MySQL 8.0.46 accepts and populates the equivalent ordinary indexes for its supported Decimal precision range.

Expected Behavior

An ordinary secondary index should accept Decimal256 key components and remain writable after creation, just as primary and unique indexes do. At minimum, DDL must not succeed and leave a table whose ordinary inserts fail with an internal error.

MatrixOne's current DECIMAL documentation describes Decimal256 as the representation for precision 39 through 76, and the CREATE INDEX documentation does not exclude DECIMAL keys:

Steps to Reproduce

DROP DATABASE IF EXISTS decimal256_index;
CREATE DATABASE decimal256_index;
USE decimal256_index;

-- Populated-table DDL path.
CREATE TABLE base_t (
  id INT PRIMARY KEY,
  d DECIMAL(40,0),
  s DECIMAL(50,10)
);
INSERT INTO base_t VALUES
  (1,9999999999999999999999999999999999999999,
     1234567890123456789012345678901234567890.1234567890),
  (2,1,-0.0000000001),
  (3,-1,0.0000000001);

CREATE INDEX idx_d ON base_t(d);
CREATE INDEX idx_s ON base_t(s);
CREATE INDEX idx_id_d ON base_t(id,d);

-- Empty-table DDL succeeds, but the write path fails.
CREATE TABLE inline_t (
  id INT PRIMARY KEY,
  d DECIMAL(40,0),
  INDEX idx_d(d)
);
SHOW INDEX FROM inline_t;
INSERT INTO inline_t VALUES
  (1,9999999999999999999999999999999999999999);
SELECT * FROM inline_t;

-- Boundary control: Decimal128 ordinary index works.
CREATE TABLE d38_t (
  id INT PRIMARY KEY,
  d DECIMAL(38,0),
  INDEX idx_d(d)
);
INSERT INTO d38_t VALUES
  (1,99999999999999999999999999999999999999);
SELECT * FROM d38_t
WHERE d=99999999999999999999999999999999999999;

-- The smallest Decimal256 precision already fails.
CREATE TABLE d39_t (
  id INT PRIMARY KEY,
  d DECIMAL(39,0),
  INDEX idx_d(d)
);
INSERT INTO d39_t VALUES
  (1,999999999999999999999999999999999999999);

Additional information

The index-key path depends on serial / serial_full. Calling those functions directly with a Decimal256 column reproduces the same internal error. In pkg/sql/plan/function/func_builtin.go, the serialization type switches handle Decimal64 and Decimal128 but have no T_decimal256 case, even though the packer and other execution subsystems now support Decimal256.

The full matrix above, including DDL-time, write-time, scale, composite, generated-column, boundary, primary-key, unique-key, and duplicate controls, was reproduced three times on the same latest-main build.

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added
    kind/bug
    on Sep 10, 2026
  3. added theissue type on Sep 10, 2026
  4. assigned and unassigned on Sep 17, 2026
  5. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    Verified on latest main 4c31142f4d0c46e9674b365826acc015b35ac2. The fixing change e4511d6af4 (PR #28845, explicitly linked to #28586) is included.

    Revalidated ordinary secondary-index serialization for Decimal256 on a fresh local standalone cluster:

    • Populated DECIMAL(40,0) / DECIMAL(50,10) table: ordinary indexes created successfully after data was present (idx_d, idx_s, and composite idx_id_d). Forced-index reads returned all values in the expected decimal order.
    • Inline DDL path: a table declared with INDEX idx_d(d) on DECIMAL(40,0) accepted its first Decimal256 INSERT, and a forced-index read returned the exact 40-digit value.
    • Boundary control: both DECIMAL(38,0) and the first Decimal256 width DECIMAL(39,0) accepted indexed inserts and equality lookup through the ordinary index.
    • Scaled and composite Decimal256 path: DECIMAL(50,10) ordinary and composite indexes accepted positive and negative scaled values; forced-index aggregation returned the exact expected sum.
    • Stored generated Decimal256 column with an ordinary index also accepted INSERT and forced-index equality lookup.
    • Focused serialization coverage passes: TestSerialEncodedTypeSizeBound, TestSerialEncodedTypeSizeBoundCoversRuntimeValue, and TestSerialDecimal256Encoding.

    No not supported type DECIMAL256 error occurred on the populated-table DDL path or on the post-DDL write path. Closing as fixed.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions