ISSUE DESCRIPTION alter col leaves sqlitesequence table behind note that i'm unsure of…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Now let's look at the AlterColumn handling path (around 1560-2100) for the logic that builds the new schema and whether it checks autoincrement.
Assistant
Now let's add the new function
emit_delete_sqlite_sequence_entryafteremit_rename_sqlite_sequence_entry(line ~244) and call it appropriately.Assistant
Now let's add the call site in the AlterColumn branch. Let's find the exact line numbers now (shifted after insertion).
Assistant
Now let's build the project to check for compile errors.
Assistant
Compiles fine. Now let's build the CLI (
tursodb/turso shell) to reproduce the issue scenario.Assistant
The
sqlite_sequencetable select returned no rows now, confirming the fix. Let's verify explicitly with.schemaand query row count to be extra sure.Assistant
Fix confirmed: before=1, after=0. Now let's test edge cases: renaming the autoincrement column (should NOT delete the sqlite_sequence entry, should still be renamed via emit_rename mechanism which handles table renames, not column renames — column rename shouldn't affect sqlite_sequence at all since it's keyed by table name).
Assistant
Renaming column preserves the AUTOINCREMENT sequence correctly - good, confirms
renamebranch is unaffected. Now let's test ALTER COLUMN on a non-rowid-alias column of an autoincrement table (should not affect sqlite_sequence).Assistant
Good - unrelated column changes don't affect the sqlite_sequence table. Now test that after removing autoincrement, if the table is later dropped, no error occurs (double delete safe); and test that no sqlite_sequence table exists at all case (should not crash) - test on a fresh table without autoincrement at all.
Assistant
No
sqlite_sequencetable since none was created (no AUTOINCREMENT used), and no crash occurs sinceemit_delete_sqlite_sequence_entryreturns early if the table doesn't exist. Now let's run relevant existing tests for alter table.Assistant
Let's look at how sqltests are typically run in this repo (there might be a test runner script).
Assistant
All existing alter_column tests pass. Let's also run the other alter test suite files and rename tests.
Assistant
All pass. Now let's run the broader test suite for insert/mvcc related to sqlite_sequence, and also the tcl conformance tests for alter.
Assistant
All pass. Now let's also run the full core test suite (
cargo test -p turso_core) to check nothing else broke, plus run clippy on the changed file.Assistant
No clippy warnings. Now let's run the full core lib test suite to be thorough (might take a while).
Assistant
All 1775 tests pass. Now let's test with MVCC mode too, since
emit_delete_sqlite_sequence_entryuses plainInsn::Deletewithout the MVCC delete-before-insert pattern (unlikeemit_rename_sqlite_sequence_entry). Let's test that scenario.Assistant
Good, confirmed - AUTOINCREMENT tables cannot exist under MVCC mode, so this codepath is never invoked in MVCC mode. My simpler
Delete-only implementation is safe and consistent with the existing DROP TABLE cleanup code (which also doesn't special-case MVCC). Let's clean up temp files now.Assistant
Now let's rebuild and re-run the reproduction test plus the sqltest suites once more to confirm everything still works after formatting.
Assistant
The
sqlite_sequenceselect returns nothing now (empty result set, matching the expected fix). Let's re-run the sqltest suites once more after formatting for a final sanity check.Assistant
All 463 tests pass. Final diff review:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.