[Bug]: COPY ALTER cannot replay tables with RTREE/spatial indexes
Maintainers usually reply within 1 day
@matrix-meow is already working on this.
Since Nov 27, 2026.
Assessment
This issue has not been assessed yet.
Description
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.
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 312
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 736
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from matrixorigin/matrixone
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
matrixorigin/matrixone#33363 ·
Maintainers usually reply within 1 day
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
matrixorigin/matrixone#33362 ·
Maintainers usually reply within 1 day
-
SLEEP rejects NULL and negative durations that MySQL acceptsPossibly taken @XuPeng-SH claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
matrixorigin/matrixone#32653 ·
Maintainers usually reply within 1 day
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in matrixorigin/matrixone
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zalando/postgres-operator#3257 ·
Maintainers usually reply within 2 days
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentPossibly taken @cvas22 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
influxdata/telegraf#20264 ·
Maintainers usually reply within 1 day
-
[Bug] Standalone migration breaks existing Ingress routes using the envoy-http Service port nameOpenaccepted bug wg/enterprise-environment
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#7483 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
stacklok/toolhive-catalog#2076 ·
Maintainers usually reply within 1 day