[Bug]: sql_require_primary_key does not enforce primary keys on CREATE or ALTER TABLE
Maintainers usually reply within 1 day
@matrix-meow is already working on this.
Since Nov 25, 2026.
Assessment
This issue has not been assessed yet.
Description
Description
Tested on MatrixOne commit 568f0f4fdee3c34373f27b04316a2adf7d32a78a.
sql_require_primary_key=1 is accepted and readable but is not enforced. With invisible-primary-key generation explicitly disabled, CREATE TABLE without a primary key and ALTER TABLE ... DROP PRIMARY KEY both succeed and leave a table with no primary key.
Minimal reproduction
DROP DATABASE IF EXISTS repro_require_primary_key;
CREATE DATABASE repro_require_primary_key;
USE repro_require_primary_key;
SET SESSION sql_generate_invisible_primary_key=0;
SET SESSION sql_require_primary_key=1;
SELECT @@sql_require_primary_key,@@sql_generate_invisible_primary_key;
-- ('1','0')
CREATE TABLE no_pk(id INT, v INT); -- unexpectedly succeeds
SHOW CREATE TABLE no_pk; -- definition has no PRIMARY KEY
CREATE TABLE has_pk(id INT PRIMARY KEY, v INT);
ALTER TABLE has_pk DROP PRIMARY KEY; -- unexpectedly succeeds
SHOW CREATE TABLE has_pk; -- PRIMARY KEY has been removed
Expected behavior
MySQL's sql_require_primary_key contract rejects statements that create a table without a primary key or alter a table so that it no longer has one. Both operations above should fail with Error 3750 (ER_TABLE_WITHOUT_PK) while the variable is enabled. Setting sql_generate_invisible_primary_key=0 ensures that an automatically generated key cannot satisfy the requirement.
Actual behavior and controls
- Both prohibited DDL statements succeed, and SHOW CREATE confirms that the resulting tables really have no primary key.
- Creating a table with an explicit primary key succeeds under the same enabled setting.
- After the incorrect DROP, ADD PRIMARY KEY succeeds.
- After
SET SESSION sql_require_primary_key=0, creating a table without a primary key is allowed as expected.
Likely root cause
pkg/frontend/variables.go declares sql_require_primary_key as a dynamic variable, but static inspection found no DDL planner/executor consumer that checks whether CREATE or ALTER would leave the table without a primary key. The admission check needs to cover both table creation and primary-key removal.
- 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