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.
turso> 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 how
ALTER COLUMNhandles AUTOINCREMENT andsqlite_sequencecleanup. - Assistant
Implementing cleanup: delete the
sqlite_sequencerow and clearhas_autoincrementwhen ALTER COLUMN removes the INTEGER PRIMARY KEY AUTOINCREMENT column. - Assistant
Fixing the borrow checker error and removing the unused parameter.
- Assistant
Your expectation is right: once
ALTER COLUMNremovesINTEGER PRIMARY KEY AUTOINCREMENT, the table should no longer be tracked insqlite_sequence.Turso was updating the stored
CREATE TABLESQL correctly, but it left two stale pieces behind:- The
sqlite_sequencerow for the table - The in-memory
has_autoincrementflag, so later inserts could still updatesqlite_sequence
Fix
When
ALTER COLUMN(notRENAME COLUMN) changes the rowid-alias column on anAUTOINCREMENTtable:- Delete that table’s row from
sqlite_sequence - Clear
has_autoincrementon the in-memory schema
RENAME COLUMNon an autoincrement PK column still keeps thesqlite_sequenceentry (same as table rename).Changes are in:
core/translate/alter.rs— emit bytecode to delete the sequence rowcore/vdbe/execute.rs— clearhas_autoincrementin the schema cachetesting/sqltests/turso-tests/alter_column.sqltest— regression tests
After the fix, your scenario becomes:
ALTER TABLE t ALTER COLUMN a TO a2 TEXT; SELECT * FROM sqlite_sequence; -- emptyAnd inserts afterward no longer touch
sqlite_sequence.The fix is in and verified.ALTER COLUMNon anINTEGER PRIMARY KEY AUTOINCREMENTcolumn now:- deletes the table’s row from
sqlite_sequence - clears the in-memory
has_autoincrementflag so later inserts don’t touch the sequence table
RENAME COLUMNon an autoincrement PK still keeps thesqlite_sequenceentry.Regression tests were added in
testing/sqltests/turso-tests/alter_column.sqltestand they pass. - The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →