Merge 'Stop ignoring table's max value incase of a manual update in autoincrement.' from Pavan Nambi

closes https://github.com/tursodatabase/turso/issues/3664

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3668
This commit is contained in:
Pekka Enberg
2025-10-12 18:38:13 +03:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -6412,7 +6412,7 @@ pub fn op_new_rowid(
NewRowid {
cursor,
rowid_reg,
..
prev_largest_reg,
},
insn
);
@@ -6455,6 +6455,11 @@ pub fn op_new_rowid(
return_if_io!(cursor.rowid())
};
if *prev_largest_reg > 0 {
state.registers[*prev_largest_reg] =
Register::Value(Value::Integer(current_max.unwrap_or(0)));
}
match current_max {
Some(rowid) if rowid < MAX_ROWID => {
// Can use sequential

View File

@@ -174,4 +174,17 @@ do_execsql_test_on_specific_db {:memory:} autoinc-conflict-on-nothing {
INSERT INTO t (k) VALUES ('a') ON CONFLICT DO NOTHING;
INSERT INTO t (k) VALUES ('b');
SELECT * FROM t ORDER BY id;
} {1|a 2|a 4|b}
} {1|a 2|a 4|b}
# https://github.com/tursodatabase/turso/issues/3664
do_execsql_test_on_specific_db {:memory:} autoinc-skips-manually-updated-pk {
CREATE TABLE t(a INTEGER PRIMARY KEY AUTOINCREMENT);
INSERT INTO t DEFAULT VALUES;
select * from sqlite_sequence;
UPDATE t SET a = a + 1;
SELECT * FROM sqlite_sequence;
INSERT INTO t DEFAULT VALUES;
SELECT * FROM sqlite_sequence;
} {t|1
t|1
t|3}