Skip to content
TheChatArchiveThe Chat Archive
fable-5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

alter col leaves sqlitesequence table behind note that i'm unsure of alter column rules,…

  1. 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.

  2. Assistant

    Now let me see how DROP TABLE cleans up sqlite_sequence entries, and how the table tracks autoincrement:

  3. Assistant

    Now let me check how Insn::AlterColumn updates the in-memory schema (does has_autoincrement get cleared?):

  4. Assistant

    Let me see the start of the function to understand btree, table_name, original_btree:

  5. Assistant

    Now add the call site in the ALTER COLUMN branch. First the flag, computed where the constraint checks are:

  6. Assistant

    Now emit the deletion after the sqlite_schema update loop:

  7. Assistant

    The py-turso link failure is a pre-existing environment issue (Python linker), unrelated to my change — turso_core compiles clean. Let me verify the fix with the CLI:

  8. Assistant

    All pass. Now run the full alter/autoincrement test files to check for regressions, plus fmt:

  9. Assistant

    All 37 autoinc tests pass. Now verify the new test actually fails without the fix — temporarily disable the emission and rerun:

  10. Assistant

    Both new tests fail without the fix. Restoring it:

  11. Assistant

    Clippy is clean. One final check — core unit tests touching alter:

  12. Assistant

    Fixed. ALTER TABLE ... ALTER COLUMN on the AUTOINCREMENT rowid-alias column now deletes the table's sqlite_sequence row instead of leaving it stale.

    Why it happened

    The ALTER COLUMN branch in core/translate/alter.rs rejects a new definition carrying PRIMARY KEY ("PRIMARY KEY constraint cannot be altered"), which means altering the INTEGER PRIMARY KEY AUTOINCREMENT column always strips the AUTOINCREMENT property from the rewritten schema — but nothing cleaned up the table's row in sqlite_sequence, unlike DROP TABLE (core/translate/schema.rs:2244) and RENAME TO (which renames the entry).

    The fix (core/translate/alter.rs)

    • Added emit_delete_sqlite_sequence_entry() (core/translate/alter.rs:250) — scans sqlite_sequence and deletes the row matching the table name, mirroring DROP TABLE's cleanup.
    • In the ALTER COLUMN branch, computed removes_autoincrement = !rename && btree.has_autoincrement && btree.columns()[column_index].is_rowid_alias() and emit the deletion after the sqlite_schema rewrite loop. RENAME COLUMN (rename == true) keeps constraints, so the entry survives there.

    Verification

    • Your exact repro now shows sqlite_sequence empty after the alter, and it persists across reopen with PRAGMA integrity_check → ok.
    • Scoping verified: altering a different column keeps the entry; renaming the autoincrement column keeps it (and the sequence keeps advancing); with two autoincrement tables only the altered one's row is removed.
    • Added 3 tests to testing/sqltests/turso-tests/alter_column.sqltest (skipped under MVCC since AUTOINCREMENT isn't supported there). Confirmed the two new positive tests fail without the fix and pass with it.
    • All 50 alter sqltests, all 37 autoinc sqltests, cargo test -p turso_core alter, cargo fmt, and cargo clippy -p turso_core --all-features --all-targets --deny=warnings pass. (Full-workspace build has a pre-existing py-turso linker failure in this environment, unrelated to the change.)

    One note: SQLite itself has no ALTER COLUMN — this is a Turso extension, so there's no upstream rule to match. The behavior implemented follows the same principle as DROP TABLE/RENAME TO: sqlite_sequence rows track tables that actually have AUTOINCREMENT, so removing the property removes the row.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.