Repository navigation
Description
Summary
INSERT INTO ... PARTITION (p0) and REPLACE INTO ... PARTITION (p0) parse successfully, but MatrixOne never consumes stmt.PartitionNames for ordinary (non-Iceberg, non-OVERWRITE) statements. The clause is a complete no-op:
- Any partition name is accepted, including nonexistent ones (MySQL:
ERROR 1735 (HY000): Unknown partition ... in table 'r'). - Rows whose partition key belongs to partitions outside the named target set are accepted and silently routed to their natural partition (MySQL:
ERROR 1748 (HY000): Found a row not matching the given partition set). REPLACE INTO ... PARTITION (...)behaves the same.
Because the naming/eligibility contract of the MySQL syntax is not enforced, a partition-scoped insert intent is silently widened/heavier than requested. Downstream partition-maintenance operations (for example ALTER TABLE ... DROP PARTITION, partition exchanges) then touch rows the writer never intended to place there.
Environment
- Branch Name: main
- Commit ID: 553bf39
- Other Environment Information:
- Hardware parameters: Apple silicon (macOS arm64)
- OS type: darwin (macOS)
- Others: single-node
mo-serviceviamo-service -launch(all ports offset by +20000, MySQL protocol port 26001, fresh data dir). Reference oracle: MySQL 8.0.46 (Homebrew[email protected]) on the same machine, default settings. Default sql_mode plusset @@sql_mode = ''variant tested; outcome identical. All quoted outputs are verbatim.
Actual Behavior
create table r(a int) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (100),
partition pm values less than maxvalue);
insert into r partition (p0) values (7); -- MO: Query OK, 1 row affected
insert into r partition (nosuch) values (7); -- MO: Query OK, 1 row affected
insert into r partition (pm) values (7); -- MO: Query OK, 1 row affected
insert into r partition (p0, p1) values (7); -- MO: Query OK, 1 row affected
select * from r order by a; -- MO: four rows, all a = 7
alter table r drop partition p1;
select * from r order by a; -- MO: Empty set (all four rows had landed in p1)No error, no warning (show warnings is empty) at any point. On a hash-partitioned table the same holds: insert into h partition (p0) values (2) is accepted even though 2 hashes to partition 2, and partition (pX) (nonexistent) is accepted too.
REPLACE is equally affected (it shares the INSERT planning path):
create table r2(a int primary key) partition by range (a) (...);
replace into r2 partition (p0) values (50); -- MO: Query OK, 1 row affected (50 lands in p1)
-- MySQL 8: ERROR 1748 (HY000)Expected Behavior
Match MySQL 8.0 DDL/DML semantics for explicit partition targets:
- Unknown partition name -> fail before mutation with MySQL-compatible error:
ERROR 1735 (HY000): Unknown partition 'nosuch' in table 'r'
- A row whose partition key maps to a partition outside the given partition set -> fail with:
ERROR 1748 (HY000): Found a row not matching the given partition set
(In non-strict/INSERT IGNORE contexts MySQL downgrades error 1748 to truncation warnings and skips the row - the strict-mode default is a hard error.)
These requirements are exactly the ones already spelled out for the consolidated DELETE ... PARTITION report #28312: "validate unknown/duplicate partition names ... never silently widen".
Steps to Reproduce
- Fresh single-node MO instance at commit 553bf39, default settings.
- Run:
create database loom_part; use loom_part;
create table r(a int) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (100),
partition pm values less than maxvalue);
insert into r partition (p0) values (7);
insert into r partition (nosuch) values (7);
select * from r order by a;
show warnings;
alter table r drop partition p1;
select * from r order by a;
create table h(a int) partition by hash(a) partitions 3;
insert into h partition (pX) values (2);
insert into h partition (p0) values (2);
select * from h order by a;
create table r2(a int primary key) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (100),
partition pm values less than maxvalue);
insert into r2 values (-1);
replace into r2 partition (p0) values (50);
select * from r2 order by a;- Run the identical script on MySQL 8.0.46: statements 2, 3, 9, 10, 13 all error (1748 or 1735) and nothing is stored from them; on MO every statement succeeds with
Query OK, 1 row affectedand rows land in their natural partitions.
Additional information
Root cause: bufSingleBindInsertStmt keeps the parsed PartitionNames (pkg/sql/parsers/tree/insert.go line 29, populated by the grammar at line 129) but the INSERT planner only reads it under stmt.Overwrite && len(stmt.PartitionNames) > 0 for Iceberg INSERT OVERWRITE (pkg/sql/plan/build_insert.go line 139) and INSERT PARTITION ... VALUES (which is rejected as Iceberg-only at line 142). No other branch consumes PartitionNames: ordinary INSERT, INSERT IGNORE, INSERT ... SELECT, and the REPLACE rewrite (build_insert.go line 780 copies it into tree.Replace only for it to be ignored again) never validate partition names nor restrict/verify the target partition set.
Suggested fix strategy (keep both consistent):
- Plan-time: when the target is a partitioned table and
PartitionNamesis non-empty, reject unknown names (1735) right after resolving the table def. - For VALUES rows: derive each row's partition from the evaluated partition key and reject rows outside the set (1748). Constant rows can be verified entirely at compile time, like
SetInsertValue*-style checks. - For INSERT ... SELECT: add a runtime check on the partition key (preinsert operator has partition metadata available).
Related reports and scope boundaries:
- The DELETE report [Bug]: DELETE FROM ... PARTITION ignores the partition list and deletes every row #28312 is now consolidated below. DELETE source-row selection and INSERT/REPLACE destination eligibility retain independent acceptance cases; fixing only one planner path is insufficient.
- [Bug] REPLACE has multiple MySQL compatibility gaps #24918 (closed) covered REPLACE gaps not related to partition sets; [Bug]: Partition pruning never happens — every query scans all partitions #30690/[Bug]: partition pruning panics on single-value LIST VALUES IN partitions (nil pointer deref) #30330 cover partition pruning, a separate concern.
SELECT ... FROM t PARTITION (p)is not supported by the parser today; that is out of this report's scope (explicit syntax error).
No .github doc or in-repo documentation declares the INSERT PARTITION clause unsupported; since the syntax is accepted but ignored, a hidden known limitation should not be assumed.
Full reproduction, exactly as Loom ran it
-- Minimal repro (MO commit 553bf39dbb vs MySQL 8.0.46, both default settings)
create database loom_part; use loom_part;
create table r(a int) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (100),
partition pm values less than maxvalue);
insert into r partition (p0) values (7);
-- MO: Query OK, 1 row affected
-- MySQL: ERROR 1748 (HY000): Found a row not matching the given partition set
insert into r partition (nosuch) values (7);
-- MO: Query OK, 1 row affected
-- MySQL: ERROR 1735 (HY000): Unknown partition 'nosuch' in table 'r'
insert into r partition (pm) values (7);
-- MO: Query OK, 1 row affected
-- MySQL: ERROR 1748 (HY000): Found a row not matching the given partition set
insert into r partition (p0, p1) values (7);
-- MO: Query OK, 1 row affected (7 belongs to p1, contained in the set -> MySQL accepts)
select * from r order by a;
-- MO: 4 rows: 7,7,7,7
-- MySQL: 2 rows: 7,7
alter table r drop partition p1;
select * from r order by a;
-- MO: Empty set (all four 7s had been routed to p1, the natural partition)
-- MySQL: 0 rows (7s were never accepted)
-- hash-partitioned variant
create table h(a int) partition by hash(a) partitions 3;
insert into h partition (pX) values (2);
-- MO: Query OK, 1 row affected
-- MySQL: ERROR 1735 (HY000): Unknown partition 'pX' in table 'h'
insert into h partition (p0) values (2);
-- MO: Query OK, 1 row affected (2 hashes to partition 2)
-- MySQL: ERROR 1748 (HY000): Found a row not matching the given partition set
-- REPLACE variant (shares the INSERT planning path)
create table r2(a int primary key) partition by range (a) (
partition p0 values less than (0),
partition p1 values less than (100),
partition pm values less than maxvalue);
insert into r2 values (-1);
replace into r2 partition (p0) values (50);
-- MO: Query OK, 1 row affected
-- MySQL: ERROR 1748 (HY000): Found a row not matching the given partition set
select * from r2 order by a;
-- MO: -1, 50 (50 sits in p1)
-- MySQL: -1Found by Loom bug hunt (module: sql-compile; tests: unit, white-box, black-box, concurrency; severity: S1)
Consolidated explicit-partition DML contract: #28312
#28312 reports the same accepted-but-ignored PARTITION target contract on DELETE: DELETE FROM p PARTITION(p0) deletes rows outside p0. INSERT/REPLACE destination eligibility and DELETE source-row selection use different planner paths; each remains a separate acceptance case. This is one bounded user capability to implement consistently, not a claim that the immediate causes are identical.
- DELETE only selects rows in the named partition set, preserving WHERE predicates, index/FK maintenance and affected-row counts; if unsupported, reject before mutation rather than widening the delete set.
- Preserve the existing INSERT/REPLACE requirements for unknown names and rows outside the target set, including VALUES, INSERT SELECT, prepared inputs and IGNORE behavior with a MySQL reference.
- Test hash/range/list tables, empty and multiple partition sets, failure atomicity and unqualified-DML controls. Keep SELECT partition syntax, ordinary pruning and cross-partition UPDATE routing outside this issue.
The original DELETE SQL and discussion remain at #28312. This issue retains its existing owner and severity/s1; closing the older deferred entry does not claim a fix.
Activity
[-][Bug]: INSERT and REPLACE silently ignore the explicit PARTITION (...) target list[/-][+][Bug]: Explicit PARTITION targets are ignored by INSERT, REPLACE and DELETE[/+]XuPeng-SH commentedon Oct 29, 2026
Consolidated acceptance scope from #24953: REPLACE partition selection insert-only duplicate-key and parent linkage. Please retain the original reproduction and discussion in the linked issue. This consolidation does not claim the bug is fixed.