Skip to content

[Bug]: Extra predicates on a single-column unique index decode the raw key as a tuple #26818

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

I searched open and closed MatrixOne issues and PRs for the exact tuple-decode error, serial_extract, single-column unique indexes, extra filters, and FORCE INDEX.

This is distinct from:

Branch Name

main

Commit ID

08770e1beeb23239c91165492f2fe85243a3c66a

Other Environment Information

  • Local single-node MatrixOne on Linux
  • Built from the commit above with Go 1.26.4
  • MySQL client against port 6001
  • Reproduces before and after an explicit TN flush

Actual Behavior

An equality lookup through an ordinary single-column unique secondary index succeeds by itself, but adding another valid predicate on the same indexed column makes the query fail with an internal tuple-decoding error.

The failure also occurs without FORCE INDEX because the optimizer chooses the unique index naturally.

ERROR 20101 (HY000): internal error: unable to decode tuple element with unknown typecode 61

IGNORE INDEX returns the expected row. An extra predicate on a non-indexed payload also succeeds, which isolates the bug to pushing a second predicate on the indexed column.

Expected Behavior

Adding a redundant or narrowing predicate must not turn a valid unique-index lookup into an internal error. The indexed and base-table paths should both return row (1, 'abcdx', 'p1').

Steps to Reproduce

DROP DATABASE IF EXISTS unique_index_extra_filter_repro;
CREATE DATABASE unique_index_extra_filter_repro;
USE unique_index_extra_filter_repro;

CREATE TABLE t (
  id INT PRIMARY KEY,
  a VARCHAR(32),
  payload VARCHAR(32),
  UNIQUE INDEX uq_a(a)
);

INSERT INTO t VALUES
  (1, 'abcdx', 'p1'),
  (2, 'abce0', 'p2');

-- Control: the point lookup succeeds.
SELECT id, a, payload
FROM t FORCE INDEX(uq_a)
WHERE a = 'abcdx';
-- 1, abcdx, p1

-- Wrong: an additional predicate on the unique-key column crashes.
SELECT id, a, payload
FROM t FORCE INDEX(uq_a)
WHERE a = 'abcdx' AND a LIKE 'abcdx%';
-- ERROR 20101 ... unable to decode tuple element with unknown typecode 61

SELECT id, a, payload
FROM t FORCE INDEX(uq_a)
WHERE a = 'abcdx' AND a > 'abcdw';
-- same internal error

-- Correct base-table control.
SELECT id, a, payload
FROM t IGNORE INDEX(uq_a)
WHERE a = 'abcdx' AND a LIKE 'abcdx%';
-- 1, abcdx, p1

-- A predicate on a non-indexed column also succeeds.
SELECT id, a, payload
FROM t FORCE INDEX(uq_a)
WHERE a = 'abcdx' AND payload = 'p1';
-- 1, abcdx, p1

SELECT mo_ctl('dn', 'flush', 'unique_index_extra_filter_repro.t');
-- Repeat the failing and control queries: behavior is unchanged.

Additional Information

EXPLAIN VERBOSE exposes the invalid filter on the hidden unique-index table:

Index Table Scan on t.uq_a
  Filter Cond:
    (__mo_index_idx_col = 'abcdx'),
    prefix_eq(serial_extract(__mo_index_idx_col, 0, VARCHAR))

A one-part unique index stores __mo_index_idx_col directly in the indexed column's type. It is not a serial_full tuple. However, applyExtraFiltersOnIndex rewrites every extra predicate on an indexed part through MakeSerialExtractExpr, so execution interprets the raw VARCHAR bytes as tuple-encoded data.

The safe mapping is shape-dependent:

  • direct one-part unique key: use __mo_index_idx_col directly;
  • serialized composite/non-unique key: use serial_extract;
  • lossy prefix part: do not push a full-value predicate to the hidden index; retain the base-table residual.

Please retain black-box coverage for default / FORCE / IGNORE paths, same-column versus payload predicates, in-memory and post-flush reads, plus a planner assertion that a direct one-part key never receives serial_extract.

Activity

  1. self-assigned this
    on Aug 9, 2026
  2. LeftHandCold commented on Aug 9, 2026

    @LeftHandCold
    CollaboratorAuthor

    Fixed locally in commit 02c916393dbaf305913dd8a5100e2f6dffc415ef.

    The fix makes extra-filter pushdown follow the hidden key's physical representation:

    • a direct single-column unique key is referenced directly;
    • a serialized composite or non-unique key still uses serial_extract;
    • a lossy prefix part is not used for a full-value extra predicate, which remains a base-table residual.

    Validated on a locally built MO service:

    • focused and full pkg/sql/plan tests passed;
    • controlled CGo go vet and make build passed;
    • new distributed regression passed 24/24, covering default/FORCE/IGNORE, operand order, non-indexed backfill control, composite control, prefix control, and post-flush reads.
  3. added a commit that references this issue on Aug 9, 2026
    ac33944
  4. added
    kind/bug
    severity/s0
    on Aug 11, 2026
  5. LeftHandCold commented on Aug 11, 2026

    @LeftHandCold
    CollaboratorAuthor

    Validation result — fixed by #26829.

    Verified on the exact merge commit ac339444b558daf2c3d7fe63f755743449db7696, with an 08770e1 baseline comparison.

    Baseline: FORCE INDEX on a one-column unique key plus a second predicate on that same column failed with ERROR 20101 ... unknown typecode 61.
    Fix verification: LIKE, forward/reverse range, and non-indexed payload residual predicates all return the expected row through FORCE and IGNORE, before and after TN flush. The planner now keeps a one-part unique raw key as a raw value; serial_extract remains limited to serialized composite-key shapes.

    Focused and complete pkg/catalog + pkg/sql/plan tests and the PR BVT case passed.

    Conclusion: the reported planner/execution defect is fixed. Closing.

  6. added 3 commits that reference this issue on Sep 17, 2026
    b5b2b81
    31e4bad
    0c59fbb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions