Details
-
Bug
-
Status: In Review (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8
-
None
-
Official mariadb Docker images, default configuration
-
Q4/2026 Server Development
Description
-
-
- How to repeat
-
```sql
CREATE TABLE t1 (a INT NOT NULL, b CHAR(1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES (1,'x'),(2,'y'),(3,'p'),(3,'q');
ALTER IGNORE TABLE t1 ADD PRIMARY KEY (a);
SELECT * FROM t1 ORDER BY a;
```
-
-
- Expected result (10.11.16, 10.6.28)
-
```
1 x
2 y
3 p
```
-
-
- Actual result (10.11.17 and later)
-
```
1 x
2 y
```
Both rows with `a = 3` are gone, and the statement returns no warning.
-
-
- Further observations
-
| Variant | 10.6.28 | 10.11.16 | 10.11.17+ |
| — | — | — | — |
| `ADD PRIMARY KEY (a)`, a NOT NULL | keeps `3 p` | keeps `3 p` | *both rows lost* |
| `ADD PRIMARY KEY (a), ALGORITHM=COPY` | keeps `3 p` | keeps `3 p` | *both rows lost* |
| `ADD UNIQUE (a)`, a NOT NULL | keeps `3 p` | keeps `3 p` | *both rows lost* |
| `ADD UNIQUE (a)`, a NULL | keeps `3 p` | keeps `3 p` | keeps `3 p` (correct) |
| rows (3,'p'),(3,'q'),(3,'r') + `ADD PRIMARY KEY` | keeps `3 p` | keeps `3 p` | keeps *`3 r`* |
The three-row case suggests what goes wrong. When the duplicate `q` is rejected, the rollback also undoes the previously inserted row `p`. `r` is then inserted into an empty slot. It looks as if the per-row undo introduced by the MDEV-36436 fix (10.11.17 / 11.4.11 / 11.8.7 /
12.3.2) rolls back one row too many. The fix discards the undo record after each inserted row.
The nullable UNIQUE case is unaffected, probably because it doesn't become the clustered index.
-
-
- Impact
-
Silent data loss on a documented statement whose purpose is to keep one row from each duplicate group. Users de-duplicating a table with `ALTER IGNORE` after upgrading to 10.11.17+ lose every duplicated key.