Skip to content

[Bug]: binary prepared ENUM/YEAR covering-index queries fail with unsupported type #26873

Closed

Description

@Ariznawlll

Environment

  • Branch: main
  • Commit: 4b38c3fdf7287bc4fa69e34cf6d9ba1d88d308b3
  • Deployment: local mo-service, 2 CN / 1 TN / 1 Log service / Proxy
  • Tested endpoints: Proxy 6001, CN 16001, CN 16002
  • Client: Go database/sql + go-sql-driver/mysql binary prepared protocol
  • Date: 2026-08-09

Bug

A binary-protocol prepared query fails with internal error: not supported type ENUM or internal error: not supported type YEAR when an ENUM/YEAR secondary
index can cover the query. The equivalent literal, SQL PREPARE ... EXECUTE USING,
index-free scan, and base-table backfill query all succeed.

Reproduction

Set up the table:

create database enum_prepare_repro;
use enum_prepare_repro;

create table t(
  id int primary key,
  e enum('red','green','blue'),
  payload varchar(20),
  index idx_e(e)
);
insert into t values
  (1,'red','one'),
  (2,'green','two'),
  (3,'blue','three'),
  (4,null,'null');

Execute through the binary prepared protocol:

db, _ := sql.Open("mysql", "user:password@tcp(127.0.0.1:6001)/enum_prepare_repro")
stmt, _ := db.Prepare("select id from t force index(idx_e) where e=?")
var id int
err := stmt.QueryRow("red").Scan(&id)
fmt.Println(id, err)

Actual:

0 Error 20101 (HY000): internal error: not supported type ENUM

Expected:

1 <nil>

Passing controls

All of these return row 1:

select id from t force index(idx_e) where e='red';

set @v='red';
prepare s from 'select id from t force index(idx_e) where e=?';
execute s using @v;

select id from t ignore index(idx_e) where e='red';

The binary protocol also succeeds when a non-indexed predicate forces base-table
backfill:

stmt, _ := db.Prepare(
  "select id from t force index(idx_e) where e=? and payload='one'",
)
// returns id=1

Coverage

Reproduced 3/3 through the Proxy and directly through both CNs.

Failing binary-protocol covering variants:

  • =, <=>, IN, and range predicates;
  • string, []byte, integer, and NULL binds;
  • single-column ENUM index;
  • composite indexes with ENUM as the leading or second part.

The same matrix was repeated for an indexed YEAR column with integer, string, and
[]byte binds. All three endpoints failed 3/3 with not supported type YEAR, while
literal, index-free scan, and backfill controls returned the expected 2026 row.

Passing controls on every run:

  • forced-index literal;
  • server-side SQL PREPARE ... EXECUTE USING @var;
  • IGNORE INDEX binary prepare;
  • natural scan binary prepare;
  • forced-index query that requires base-table backfill.

Root-cause direction

The failure is isolated to the runtime covering/index-only path. The serial encoder
supports both types.T_enum and types.T_year, but serialExtract in
pkg/sql/plan/function/func_builtin.go has neither result case and returns the exact
observed unsupported-type internal errors. A runtime binary parameter keeps the typed
residual dynamic, so the covering rewrite needs to extract the typed value from the
serialized index key; the literal and backfill paths avoid that unsupported
extraction.

This is distinct from:

Activity

  1. added
    kind/bug
    on Aug 9, 2026
  2. added this to the MO-202608 milestone on Aug 9, 2026
  3. added theissue type on Aug 9, 2026
  4. changed the title [-][Bug]: binary prepared ENUM covering-index queries fail with not supported type ENUM[/-] [+][Bug]: binary prepared ENUM/YEAR covering-index queries fail with unsupported type[/+] on Aug 9, 2026
  5. VioletQwQ-0 commented on Aug 11, 2026

    @VioletQwQ-0
    Collaborator

    Post-merge testing handoff for #26873

    Merged PR: #26943

    QA Decision

    • Required: yes
    • Reason: this changes user-visible MySQL binary prepared-statement behavior on covering secondary indexes.
    • Automated evidence: TestSerialExtractEnumAndYear, the full pkg/sql/plan/function package, TestIssue26873BinaryPreparedEnumAndYearCoveringIndex, git diff --check, and semantic preflight all passed. BVT is N/A because the SQL BVT runner cannot issue MySQL binary prepared-statement packets; the embedded-cluster issue test exercises that public protocol boundary.
    • Remaining validation: repeat the reproduction through Proxy and on a multi-CN deployment. A post-merge TKE setup job was still running at handoff time and is not treated as tester acceptance.

    Tester and expected result

    • Tester: Ariznawlll, selected because the current issue author is Ariznawlll.
    • PASS requires the binary prepared ENUM/YEAR covering-index queries to return the expected rows without unsupported-type errors, while literal, index-free, backfill, and NULL-bind controls remain correct.
    • FAIL should include the tested MatrixOne version or main head, environment/topology, reproduction command, and terminal error/result; keep this issue open for follow-up.

    The issue remains open with phase/testing until complete tester evidence is received.

  6. slyunnn commented on Aug 13, 2026

    @slyunnn

    Regression and extended verification for #26873 (2026-08-13)

    Validated the fix from PR #26943 for binary prepared ENUM and YEAR covering-index queries on current MatrixOne main.

    Verification Environment

    What Was Covered

    • OK — Original reproduction: binary prepared covering-index equality on indexed ENUM and YEAR returned expected rows
      through Proxy 6001, CN1 16001, and CN2 16002; no ERROR 20101 unsupported-type error occurred.

    • OK — Happy path: indexed ENUM and YEAR predicates with string and []byte binds returned expected rows through binary
      prepared statements on all three endpoints.

    • OK — Happy path: YEAR range predicates and composite secondary-index predicates returned expected ordered rows on
      all three endpoints.

    • OK — Unhappy path: NULL binds returned empty result sets without unsupported-type errors on all three endpoints.

    • OK — Boundary scenario: an absent YEAR boundary value 1901 returned an empty result set without errors on all three
      endpoints.

    • OK — Compatibility/control scenarios: literal queries, IGNORE INDEX, and forced-index queries requiring base-table
      backfill returned expected rows on all three endpoints.

    Findings

    The original issue does not reproduce on current main in the complete local 2 CN / 1 TN / 1 Log service / Proxy
    topology.

    The current behavior satisfies the acceptance scope: binary prepared covering-index queries for ENUM and YEAR return
    expected rows through Proxy and direct CN connections without internal error: not supported type ENUM or internal
    error: not supported type YEAR.

    Literal, index-free, and base-table-backfill controls remain consistent with binary prepared-statement results.
    Integer binding and string range semantics for ENUM were explored during test design but are outside this issue’s
    typed extraction fix and are not classified as issue regressions.

    MOTR / BVT Coverage

    • Added suites/14_issue_regression/t/issue_26873_binary_prepared_enum_year.test.

    • Added suites/14_issue_regression/r/issue_26873_binary_prepared_enum_year.result.

    • Added script/14_issue_regression/issue_26873_binary_prepared_enum_year_protocol.go and its launcher to exercise real
      binary prepared-statement packets.

    • MOTR recording passed: 22 statements.

    • MOTR replay passed: 22 statements.

    • Binary protocol scenario passed through Proxy 6001, CN1 16001, and CN2 16002.

    • The SQL case keeps stable SQL/literal controls; the scenario script is required because .test files cannot emit
      MySQL binary prepared-statement packets.

    Final Conclusion

    Fixed. PR #26943 is verified on current main in the complete local multi-CN topology. The original reproduction and
    expanded binary-protocol coverage passed through Proxy and both direct CN endpoints.

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

Metadata

Metadata

Assignees

Labels

kind/bugphase/testing

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions