[Bug]: COPY ALTER cannot replay tables with RTREE/spatial indexes

Aperta
#33,356 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@matrix-meow ci sta già lavorando.

Dal 27/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

kind/bug needs-triage

Description

Tested on MatrixOne main c0cef5c9cce2164fedd201c188bfffe4d2d09a96 (version() = 8.0.30-MatrixOne-v1.3.0, git_version() = c0cef5c), single CN.

A table with a valid RTREE/spatial index cannot undergo COPY ALTER. Even an unrelated ADD COLUMN fails while MatrixOne executes its internal temporary CREATE TABLE statement, because COPY uses the display-only SPATIAL KEY spelling instead of the parseable replay spelling KEY ... USING RTREE.

Minimal reproduction

CREATE TABLE t(
  id INT PRIMARY KEY,
  g POINT NOT NULL,
  KEY idx_g USING RTREE(g)
);
INSERT INTO t VALUES(1,ST_GeomFromText('POINT(1 2)'));

ALTER TABLE t ALGORITHM=COPY,ADD COLUMN lead INT DEFAULT 7 FIRST;

Actual result: Error 1105 with a syntax error from the internally generated temporary CREATE TABLE statement. No changed table is published.

Expected result: the ALTER succeeds, the existing row remains with lead=7, and idx_g remains a usable RTREE index.

The original table, its inline RTREE index, spatial DML, and spatial-predicate queries are valid before the ALTER. An empty table fails in the same way, so this is not caused by GEOMETRY values or index contents.

Equivalent entry point and other COPY operations

Creating the same index through the supported standalone statement leads to the same failure:

CREATE TABLE t2(
  id INT PRIMARY KEY,
  g POINT NOT NULL
);
CREATE SPATIAL INDEX idx_g ON t2(g);
ALTER TABLE t2 ALGORITHM=COPY,ADD COLUMN lead INT DEFAULT 7 FIRST;

The internal replay failure also occurs for otherwise unrelated COPY operations including MODIFY COLUMN, RENAME COLUMN, and ALTER COLUMN SET DEFAULT. These are grouped as one schema-replay defect rather than separate issues per index-creation or ALTER entry point.

After every failure, the original SHOW CREATE, rows, and information_schema RTREE metadata remain intact in the same session and fresh connections. Subsequent spatial INSERT/UPDATE/DELETE and ST_INTERSECTS queries continue to work, and the connection remains healthy.

Positive controls

  • Removing only the RTREE index from the same GEOMETRY table allows the same COPY ADD FIRST to succeed and preserves the POINT value with lead=7.
  • An ordinary integer-column KEY idx_v(v) table also completes the same COPY successfully, and forced-index reads return the copied rows.

Thus this is not a general GEOMETRY, data-copy, ordinary-index, or ADD FIRST failure.

Root cause

pkg/sql/plan/build_show_util.go:constructCreateTableSQL deliberately builds two RTREE representations:

display: SPATIAL KEY idx_g(g)
replay:  KEY idx_g USING RTREE(g)

The replay representation is used to produce the function's parsed-statement result, but the first return value remains the display SQL. The current parser accepts inline KEY ... USING RTREE, while inline SPATIAL KEY is not a parseable replay spelling.

pkg/sql/plan/build_alter_table.go calls constructCreateTableSQL, discards the second parsed-statement return value, and stores the first display string in AlterTable.CreateTmpTableSql. pkg/sql/compile/alter.go then executes that display SQL as the internal temporary CREATE, causing every COPY rebuild of an RTREE-indexed table to fail before data publication.

Validation

The inline-RTREE and standalone-CREATE-SPATIAL-INDEX entry points, nonempty and empty tables, multiple COPY operation types, failure atomicity, fresh-connection metadata reads, subsequent spatial DML/predicates, and both positive controls passed 44/44 probe assertions in each of two independent fresh-database runs.

Duplicate check

Open and closed issue/PR searches covered RTREE, SPATIAL KEY, spatial index with ALTER/COPY/ADD COLUMN, internal syntax errors, constructCreateTableSQL, and CreateTmpTableSql. No matching issue or open fix was found.

Merged #24136 delivered GEOMETRY/RTREE functionality but does not own this COPY replay regression. Open #24491 concerns broader SPATIAL INDEX/SRID syntax support and is related, but should not absorb this report: both index-creation entry points above already succeed, and COPY can be fixed by using its existing parseable KEY ... USING RTREE replay without implementing the broader syntax request. Closed #24762 concerns string comparison after DDL and is unrelated.

Lingua principale
Go
Stelle
1.9k
Fork
312
Merge medio
22h 59m
PR unite (30g)
736

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di matrixorigin/matrixone

Tutte le issue di matrixorigin/matrixone

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.