You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: nextval() inside a rolled-back transaction re-issues the same value (sequence advancement is transactional) #30896
nextval() inside a transaction that rolls back reuses the issued value. The same value is handed out twice, so "unique id from a sequence" can collide.
Repro (main@3ad9adbb4c, fresh instance)
createsequences2 increment by 1 start with 1;
select nextval('s2'); -- 1begin;
select nextval('s2'); -- 2 (issued inside the txn)rollback;
select nextval('s2'); -- 2 <-- SAME VALUE RE-ISSUED
Second observation (committed path behaves monotonically, so this is specifically rollback):
PostgreSQL (and any sequence semantics MO's nextval mirrors) treats sequence advancement as non-transactional: a rolled-back transaction does not return the value, so nextval never repeats. MySQL has no sequences, so there is no MySQL fallback to match.
If MO intends transactional sequences instead, that must be documented, because the current behaviour silently produces duplicate values for an idiom (nextval for surrogate keys) where uniqueness is the entire point.
Impact
Two rows created in different transactions can receive the same primary key, failing later with 1062 or, worse, silently keying different rows to the same value when the column is not constrained.
Any application that retries a rolled-back transaction will hit this immediately.
Notes
Reproduced twice on a fresh data directory; not environment-dependent.
Related area: 309f618995 (preserve sequence issued state through cross-session ALTER SEQUENCE) — that fix preserves state across ALTER, but the rollback path still rewinds the issued counter.
Verification suggestion
begin; nextval; rollback; then compare the two values: they must differ. Also worth a BVT that a rolled-back nextval never collides with a committed one.
Tracking consolidated into #30359. The canonical issue now includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed; the original reproduction and discussion are preserved here.
Activity
XuPeng-SH commentedon Oct 24, 2026
Tracking consolidated into #30359. The canonical issue now includes this report's independent scope and acceptance criteria. This is administrative consolidation, not a claim that the defect is fixed; the original reproduction and discussion are preserved here.
fix(sql): keep sequence ownership and state consistent across DML, DD…
fix(sql): keep sequence ownership and state consistent across DML, DD…
fix(sql): keep sequence ownership and state consistent across DML, DD…
fix(sql): keep sequence ownership and state consistent across DML, DD…