alter col leaves sqlitesequence table behind note that i'm unsure of alter column rules,…
- User
alter col leaves sqlite_sequence table behind note that i'm unsure of alter column rules, i was not able to find any docs or rules around this, but my expectation is when we change a autoincrement col to plain text there shouldn't be a stale sqlite_sequence.
sqlturso> CREATE TABLE t(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); INSERT INTO t(b) VALUES('x'),('y'); ALTER TABLE t ALTER COLUMN a TO a2 TEXT; SELECT * FROM sqlite_sequence; SELECT sql FROM sqlite_schema WHERE name='t'; ┌──────┬─────┐ │ name │ seq │ ├──────┼─────┤ │ t │ 2 │ └──────┴─────┘ ┌──────────────────────────────────┐ │ sql │ ├──────────────────────────────────┤ │ CREATE TABLE t (a2 TEXT, b TEXT) │ └──────────────────────────────────┘ turso> select * from sqlite_schema; ┌───────┬─────────────────┬─────────────────┬──────────┬────────────────────────────────────────┐ │ type │ name │ tbl_name │ rootpage │ sql │ ├───────┼─────────────────┼─────────────────┼──────────┼────────────────────────────────────────┤ │ table │ sqlite_sequence │ sqlite_sequence │ 2 │ CREATE TABLE sqlite_sequence(name,seq) │ ├───────┼─────────────────┼─────────────────┼──────────┼────────────────────────────────────────┤ │ table │ t │ t │ 3 │ CREATE TABLE t (a2 TEXT, b TEXT) │ └───────┴─────────────────┴─────────────────┴──────────┴────────────────────────────────────────┘Interface
No new interfaces are introduced.
- Assistant
Investigating ALTER COLUMN behavior and how
sqlite_sequenceis managed when AUTOINCREMENT is removed. - Assistant
Implementing the fix: adding sqlite_sequence cleanup when ALTER COLUMN removes AUTOINCREMENT, and updating the in-memory schema flag.
- Assistant
Fixed. When
ALTER COLUMNremoved AUTOINCREMENT (e.g. changingINTEGER PRIMARY KEY AUTOINCREMENTtoTEXT), Turso updated the table schema but left thesqlite_sequencerow and kepthas_autoincrement = truein memory.Changes:
-
core/translate/alter.rs— Detect when ALTER COLUMN drops autoincrement from the rowid-alias column, and emit bytecode to delete the table'ssqlite_sequenceentry (same pattern asDROP TABLE). -
core/vdbe/execute.rs— Clearhas_autoincrementon the in-memory schema when autoincrement is removed, so subsequent inserts don't touchsqlite_sequence. -
testing/sqltests/turso-tests/alter_column.sqltest— Regression test for this scenario.
After the fix:
sql -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.