[Bug]: COPY ALTER doubles apostrophes in CHECK and INCLUDE identifiers
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.
COPY schema replay incorrectly doubles an apostrophe inside a backtick-quoted identifier. This produces two user-visible failures from the same formatting root cause:
- An unrelated successful COPY silently changes a CHECK constraint name from
c'ktoc''k. - FULLTEXT2 and IVFFLAT indexes whose INCLUDE column contains an apostrophe make an unrelated COPY fail with 20301 because replay looks for the doubled, nonexistent column name.
The symptoms are reported together because both come from applying string-literal escaping to quoted identifiers in the temporary CREATE replay.
Problem 1: COPY persists a different CHECK constraint name
CREATE TABLE ck_copy(
id INT PRIMARY KEY,
CONSTRAINT `c'k` CHECK(id>0)
);
INSERT INTO ck_copy VALUES(1);
ALTER TABLE ck_copy ALGORITHM=COPY,ADD COLUMN marker INT DEFAULT 7 FIRST;
-- Succeeds; the constraint identity should remain c'k
SELECT HEX(constraint_name),constraint_name
FROM information_schema.table_constraints
WHERE table_schema=DATABASE()
AND table_name='ck_copy'
AND constraint_type='CHECK';
Actual result:
6327276B | c''k
Expected result:
63276B | c'k
The doubled name becomes the durable identity:
ALTER TABLE ck_copy DROP CONSTRAINT `c'k`;
-- Actual: Error 1091
ALTER TABLE ck_copy DROP CONSTRAINT `c''k`;
-- Actual: succeeds
The base row remains (marker=7,id=1), and the CHECK still rejects id=-1, although the error uses the renamed c''k. This report therefore concerns silent constraint-identity mutation, not lost CHECK enforcement or lost base rows.
Problem 2: apostrophe INCLUDE columns make COPY fail
CREATE TABLE ivf_bad(
id BIGINT PRIMARY KEY,
v VECF32(3),
`pay'load` INT
);
INSERT INTO ivf_bad VALUES(1,'[1,2,3]',100),(2,'[1,2,4]',200);
CREATE INDEX iv USING IVFFLAT ON ivf_bad(v)
LISTS=1 OP_TYPE 'vector_l2_ops' INCLUDE(`pay'load`);
ALTER TABLE ivf_bad ALGORITHM=COPY,ADD COLUMN marker INT DEFAULT 7 FIRST;
Actual result:
Error 20301: INCLUDE column 'pay''load' is not exist
Expected result: COPY succeeds, both rows are preserved with marker=7, and the INCLUDE column remains pay'load.
A FULLTEXT2 index with INCLUDE(`sta'tus`) fails at the same replay stage with 20301 while looking for sta''tus. The IVFFLAT and FULLTEXT2 cases are acceptance variants of the same identifier-formatting defect, not independent root causes.
Positive controls and failure atomicity
- Without COPY, the apostrophe CHECK can be dropped by its original name.
- An ordinary CHECK name such as
ckremainsckthrough the same COPY. - Ordinary IVFFLAT/FULLTEXT2 INCLUDE names such as
payload/statussurvive the same COPY, including covered ANN/MATCH queries and subsequent fresh-connection reads. - After either failing INCLUDE COPY, SHOW CREATE has no new
marker, both original rows and the original index remain, and covered MATCH/ANN results are unchanged in fresh connections.
MySQL 8.0.46 was also checked for the CHECK case: its SHOW CREATE consistently displays CONSTRAINT `c'k` , the same ALGORITHM=COPY preserves catalog HEX 63276B, and the original name remains droppable.
One pre-existing display symptom should be noted explicitly: MatrixOne's SHOW CREATE text already doubles these apostrophes before COPY. This report owns the additional COPY outcomes—persisted CHECK-name mutation and COPY failure for INCLUDE columns—while a complete fix should correct both the display and internal replay uses of the shared helper.
Root cause
In pkg/sql/plan/build_show_util.go:
indexIncludeColumnsToStringemits`<name>`usingformatStr(resolvedName);constructCheckDefsemitsCONSTRAINT `<name>`usingformatStr(check.Name).
formatStr doubles backticks and also unconditionally changes ' to ''. Doubling apostrophes is string-literal escaping and is incorrect inside a backtick-quoted identifier. The MySQL scanner only collapses doubled backticks in that context, so replay really parses c'k/pay'load as the different names c''k/pay''load.
Ordinary base-column formatting uses sqlquote.Ident, so the base column itself retains its name. INCLUDE validation then cannot find the doubled name. CHECK replay regenerates the constraint under the doubled name.
Finally, pkg/sql/plan/build_alter_table.go places this generated text in CreateTmpTableSql, and pkg/sql/compile/alter.go executes it as the internal temporary CREATE. The display-formatting error therefore becomes a durable COPY result.
Validation
The CHECK mutation, original/doubled-name DROP behavior, no-COPY and ordinary-name controls, both INCLUDE failures, ordinary INCLUDE controls, failure atomicity, fresh-connection reads, and base-row/enforcement checks passed 35/35 assertions in each of two independent fresh-database runs. The MySQL 8.0.46 CHECK control also completed successfully and preserved the original constraint name.
Duplicate check
Open and closed issue/PR searches covered apostrophes in quoted identifiers, CHECK constraint names, INCLUDE replay, formatStr, and the exact INCLUDE error. No matching issue or open fix was found.
Closed #30550 concerns embedded backticks in table names during internal DROP. Closed #30545/#30549 concern metadata-query escaping for other SHOW statements. Closed #29015/#29016 concern asynchronous serialization of INCLUDE values, and open #33280 concerns pending ASYNC IVFFLAT initialization. None owns CHECK/INCLUDE identifier replay through formatStr.
- 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