Skip to content

[Bug]: partition pruning panics on single-value LIST VALUES IN partitions (nil pointer deref) #30330

Open

Description

@iamlinjunhong

Proposed consolidated tracking scope: 单值 LIST 分区裁剪与 INSERT panic

These are independent reproductions grouped under one acceptance contract; a common immediate root cause is not assumed. Administrative consolidation does not claim that any defect is fixed. Original report bodies and discussions remain available at the links below.

Included reports

  • #25504 — [Bug]: INSERT into LIST COLUMNS partition table panics

Acceptance checklist

  • Retain old LIST COLUMNS INSERT as a historical regression; its reported recovery does not prove all paths fixed.
  • Cover singleton LIST and LIST COLUMNS point reads and duplicate-check reads, plus multi-value partition controls.

Summary

On current main (workspace at bac18ed24), partition pruning crashes with a nil pointer dereference for any LIST-partitioned table whose partition definitions use a single-value VALUES IN list, whenever the pruner evaluates an equality predicate on the partition column. That includes:

  • INSERT into such a table when it has a PRIMARY KEY (the internal duplicate-check read prunes partitions with an equality on the partition column) — plain INSERT ... VALUES and INSERT ... ON DUPLICATE KEY UPDATE both fail;
  • an explicit point read SELECT ... WHERE <partition column> = const.

The failure is a server-side Go panic surfaced to the client as ERROR 20101 (HY000): internal error: panic runtime error: invalid memory address or nil pointer dereference. The statement fails; the CN process survives.

1. Actual Behavior

CREATE TABLE t (id int PRIMARY KEY, v int)
  PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1), PARTITION p1 VALUES IN (2));
INSERT INTO t VALUES (1,1);
-- ERROR 20101 (HY000) at line: internal error: panic runtime error: invalid memory
-- address or nil pointer dereference:  ... listFilterExprNormalized ...
SELECT * FROM t WHERE id = 1;
-- ERROR 20101 (HY000): same panic

Reproduced 3/3 via mysql CLI and again after a server restart; also observed through mo-tester BVT-style execution (insert and insert ... on duplicate key update both panic).

2. Expected Behavior

  • The row is inserted into partition p0 / the point read returns the row.
  • The same DDL with multi-value lists (VALUES IN (1,2)) works today and yields exactly the expected rows; the insertion and the point read on the single-value DDL must behave identically.
  • MySQL 8.0 semantics: PARTITION BY LIST (id) with VALUES IN (1) is a legal definition; the statement succeeds.

3. Steps to Reproduce

Minimal SQL (deterministic):

DROP DATABASE IF EXISTS loom_repro;
CREATE DATABASE loom_repro;
USE loom_repro;
CREATE TABLE t (id int PRIMARY KEY, v int)
  PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1), PARTITION p1 VALUES IN (2));
INSERT INTO t VALUES (1,1);        -- panic (ERROR 20101)
SELECT * FROM t WHERE id = 1;      -- panic (ERROR 20101)
-- controls on the same server, same session:
CREATE TABLE t2 (id int PRIMARY KEY, v int)
  PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1,2), PARTITION p1 VALUES IN (3,4));
INSERT INTO t2 VALUES (1,1);        -- OK
SELECT count(*) FROM t2;            -- OK
CREATE TABLE t3 (id int, v int)
  PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1), PARTITION p1 VALUES IN (2));
INSERT INTO t3 VALUES (1,1);        -- OK (no PK -> no dedup read, no pruning)
SELECT count(*) FROM t;             -- OK (no filter -> no list-expr evaluation)

Also reproduces with:

  • partition expressions: PARTITION BY LIST (id+id), LIST (id*id), LIST ((id+id)*id) (fresh ODKU tables, INSERT panic);
  • PARTITION BY LIST COLUMNS(region) (varchar, composite PK): INSERT works today, but point read SELECT ... WHERE region = 'east' panics.

Deterministic Go reproducer at package level (added in workspace, not committed): pkg/partitionprune/loom_test_list_single_value_test.go builds the metadata exactly as the DDL plan binder emits it for a single-value VALUES IN and calls partitionprune.Filter:

$ CGO_CFLAGS="#cgo includes" go test ./pkg/partitionprune/ -run TestLoomListSingleValuePartitionDefDoesNotPanic -count=1
--- FAIL: TestLoomListSingleValuePartitionDefDoesNotPanic (0.00s)
    loom_test_list_single_value_test.go:63: partitionprune.Filter panicked on single-value LIST partition
    definition: runtime error: invalid memory address or nil pointer dereference

4. Additional information

Panic stack (identical for INSERT and SELECT):

github.com/matrixorigin/matrixone/pkg/container/vector.(*Vector).Length  vector.go:321
github.com/matrixorigin/matrixone/pkg/partitionprune.listFilterExprNormalized  filter.go:742
github.com/matrixorigin/matrixone/pkg/partitionprune.listFilterExpr  filter.go:658
github.com/matrixorigin/matrixone/pkg/partitionprune.listFilter  filter.go:567
github.com/matrixorigin/matrixone/pkg/partitionprune.Filter  filter.go:55
... disttae.getPruneTablesFunc / filterNilPrunedRelations / combinedTxnTable.Ranges ...
... compile.expandRanges -> buildScanParallelRun (insert dedup read and point select both reach this)

Root cause chain:

  1. pkg/sql/plan/partition_binder.go:293 re-synthesizes each PARTITION ... VALUES IN (v1,...) as tree.NewComparisonExpr(tree.IN, column, tree.NewTuple(valuesIn.ValueList)). tree.NewTuple does not set Tuple.Partition (see pkg/sql/parsers/tree/expr.go, NewTuple), so the bound expression goes down the ordinary IN path in pkg/sql/plan/base_binder.go.
  2. In base_binder.go the in-list expansion collapses a single-element list to a plain = comparison (exactSingleComparison, expansion at base_binder.go:7465). The resulting catalog PartitionDef.Def for such a partition is F("=", [col, const]), not F("in", [col, Expr_List]).
  3. At runtime partitionprune.listFilterExprNormalized (pkg/partitionprune/filter.go:742, loop over metadata.Partitions) calls extractListValues(t.Expr) (filter.go:596), which returns (nil, nil) for the equality shape, then constructVectorFromList(proc, nil) (filter.go:606) returns (nil, nil) for an empty list, and the caller unconditionally runs bat.SetRowCount(bat.Vecs[0].Length()) on the nil vector → panic.

The defect is long-latent: constructVectorFromList has returned (nil, nil) for unrecognized shapes since the list pruner was introduced, and the single-element IN collapse also applies to partition defs; no BVT inserts into or point-reads single-value LIST partitions with a PK (ddl/partition.sql uses only multi-value lists and LOAD DATA), so it escaped e2e coverage.

Relationship to existing issue #25504 ([Bug]: INSERT into LIST COLUMNS partition table panics, still open): the July repro on LIST COLUMNS VALUES IN ('east') no longer panics on current main — the INSERT path was fixed — but the same underlying pruner defect remains reachable today through (a) SELECT ... WHERE <partition column> = const on LIST COLUMNS single-value tables and (b) all single-value LIST(<expression>) DDL including INSERT via the PK duplicate-check read. This report covers the residual defect with the mechanism above; #25504 can serve as the tracking issue if maintainers prefer.

Suggested fix (either side suffices, both is best):

  • prune side: in listFilterExprNormalized, treat constructVectorFromList's (nil, nil) as "cannot prune this partition safely" — return canPrune=false (fall back to all partitions) instead of dereferencing the nil vector; alternatively have constructVectorFromList return an error;
  • plan side: preserve the partition-list semantics by marking the tuple (Tuple.Partition = true → partition_in opcode keeps the in-list node even for one element), or emit F("in", [col, Expr_List]) for partition defs.

Environment: workspace at commit bac18ed24 ("fix(vector): preserve constant selection grouping metadata (#30119)"), detached main lineage; single-binary mo-service -launch with 1 CN + 1 TN + 1 LOG service, default pessimistic/RC mode; macOS 15.5, arm64; mysql client 9.x. The panic is not load-, data-, or timing-dependent: every attempt failed identically.

Found by Loom bug hunt (module: custom-0342c965ce; tests: unit, white-box, end-to-end)

Activity

  1. added
    kind/bug
    on Oct 15, 2026
  2. zuyu commented on Dec 3, 2026

    @zuyu
    Contributor

    Additional case not covered above: a mixed LIST definition, where one partition has a multi-value list and another a single-value list. One single-value partition is enough to make every pruned read on the table panic, including point reads and inserts whose value belongs to the multi-value partition.

    Reproduced on main 66002aa3fd:

    CREATE TABLE t (id int PRIMARY KEY, val int)
      PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1, 2), PARTITION p1 VALUES IN (3));
    SELECT * FROM t WHERE id = 1;                    -- ERROR 20101 panic (1 is in multi-value p0)
    SELECT * FROM t WHERE id = 3;                    -- ERROR 20101 panic
    INSERT INTO t VALUES (1, 10);                    -- ERROR 20101 panic (row for multi-value p0)
    INSERT INTO t VALUES (3, 30);                    -- ERROR 20101 panic
    INSERT INTO t VALUES (1, 10), (2, 20), (3, 30);  -- ERROR 20101 panic
    SELECT count(*) FROM t;                          -- OK (no filter)

    Controls on the same server:

    -- the same mixed lists without a primary key
    CREATE TABLE t_nopk (id int, val int)
      PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1, 2), PARTITION p1 VALUES IN (3));
    INSERT INTO t_nopk VALUES (1, 10), (2, 20), (3, 30);   -- OK
    -- only multi-value lists, with a primary key
    CREATE TABLE t_multi (id int PRIMARY KEY, val int)
      PARTITION BY LIST (id) (PARTITION p0 VALUES IN (1, 2), PARTITION p1 VALUES IN (3, 4));
    INSERT INTO t_multi VALUES (1, 10), (2, 20), (3, 30);  -- OK

    All five failures panic at pkg/partitionprune/filter.go:744 (listFilterExprNormalized), the same site as this report. Suggest adding the mixed definition, including an equality on a value of the multi-value partition, to the acceptance checklist.

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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions