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 look at how DROP TABLE cleans up sqlite_sequence, for reference:

  3. Assistant

    Let me look at emit_rename_sqlite_sequence_entry in alter.rs and check how insert uses has_autoincrement:

  4. Assistant

    Now let me reproduce the issue and check current in-session behavior:

  5. Assistant

    Now I'll make the edits. First, the helper in alter.rs:

  6. Assistant

    Now compute the condition and emit the deletion in the AlterColumn branch:

  7. Assistant

    Now the schema SQL rewrite in execute.rs. Check the AST definition first:

  8. Assistant

    Now the in-memory schema update in op_alter_column:

  9. Assistant

    Found it — in op_alter_column, the column is replaced (line 13056) before my check reads is_rowid_alias(), so it sees the new column. I need to capture the flag before replacement:

  10. Assistant

    Now add tests to alter_column.sqltest:

  11. Assistant

    That ran suspiciously fast — the filter may not have matched anything. Let me verify tests actually run:

  12. Assistant

    Let me verify the @skip-if mvcc directive actually works as expected when the runner is in MVCC mode:

  13. Assistant

    Everything checks out. Let me run the full sqltest suite as a final sweep since the schema-rewrite change touches a shared code path:

  14. Assistant

    Final check — run the TCL conformance alter tests and review the complete diff:

  15. Assistant

    TCL isn't available in this environment, but the preferred sqltest runner covers this fully. Let me review the final diff:

  16. Assistant

    Done. The fix is complete and verified.

    Summary

    Your expectation was right: when ALTER COLUMN targets the AUTOINCREMENT column, the replacement definition can never carry AUTOINCREMENT (a PRIMARY KEY constraint in the new definition is explicitly rejected), so the table always loses the autoincrement property — and the sqlite_sequence row must go with it. Investigating also surfaced two adjacent bugs in the same path.

    Fixes

    1. Stale sqlite_sequence row (reported bug) — core/translate/alter.rs When ALTER COLUMN targets the autoincrement rowid-alias column, the program now deletes the table's sqlite_sequence entry (new emit_delete_sqlite_sequence_entry, mirroring the existing rename-table handling and DROP TABLE cleanup).

    2. Schema corruption with table-level PK (found while fixing #1) — core/vdbe/execute.rs schema rewrite CREATE TABLE t(a INTEGER, b TEXT, PRIMARY KEY(a AUTOINCREMENT)) + ALTER TABLE t ALTER COLUMN a TO a2 TEXT previously produced ... PRIMARY KEY (a2 AUTOINCREMENT) on a TEXT column — invalid SQL that made the database unopenable (Parse error: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY). The rewrite now strips the AUTOINCREMENT keyword from a table-level PK when its column is altered (rename keeps it).

    3. Same-connection staleness — core/vdbe/execute.rs op_alter_column The in-memory schema kept has_autoincrement = true, so inserts after the ALTER on the same connection kept maintaining (even recreating) the sequence row. It's now cleared when the altered column was the rowid alias.

    Verification

    • Your exact repro: sqlite_sequence is empty after the ALTER, stays empty after further inserts, on both the same and fresh connections; PRAGMA integrity_check ok
    • The table-level PK database now reopens correctly
    • Rename of the autoincrement column and ALTER of unrelated columns correctly keep the sequence entry; only the altered table's row is removed
    • 4 new tests in testing/sqltests/turso-tests/alter_column.sqltest (skipped under MVCC, where AUTOINCREMENT is unsupported); full sqltest suite: 10529 passed, 0 failed with the prescribed --snapshot-filter __never__
    • cargo fmt + cargo clippy -p turso_core --all-features --all-targets --deny=warnings clean

    Note: the 8 snapshot mismatches seen when running snapshot tests are pre-existing build-profile artifacts — the committed snapshots embed the release hash-join budget (67108864) while debug builds use 32768 (core/vdbe/hash_table.rs:27), which is why the project's standard test command excludes them.

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