Skip to content

Implement Temporary tables#6323

Draft
PThorpe92 wants to merge 60 commits intotursodatabase:mainfrom
PThorpe92:temp_tables
Draft

Implement Temporary tables#6323
PThorpe92 wants to merge 60 commits intotursodatabase:mainfrom
PThorpe92:temp_tables

Conversation

@PThorpe92
Copy link
Copy Markdown
Collaborator

@PThorpe92 PThorpe92 commented Apr 7, 2026

Implement TEMPORARY tables, matching SQLite behavior by treating them as Connection-local, in a separate catalog as an ATTACHED database (e.g. temp.t)

Also adds temporary table usage and generation to the differential fuzzer, which found quite a few bugs. particularly with triggers

The differential fuzzer found several other issues that codex was able to fix

EDIT: simulator seems to have found an issue, fixing

Copy link
Copy Markdown

@turso-bot turso-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review @pereman2

@LeMikaelF
Copy link
Copy Markdown
Collaborator

nit for alter.rs lines 2167, 2393, 2399, 2455, 2519, 2557, 2781, 3162, 4145...: replace normalize_ident with eq_ignore_ascii_case

@PThorpe92 PThorpe92 marked this pull request as draft April 9, 2026 00:52
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two (identical?) TemporaryKeyword enums, one here, one in ast.rs. The could probably be deduplicated.

@@ -118,7 +118,7 @@ impl fmt::Display for ColumnDef {
pub struct Table {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two completely identical structs Table, and two completely identical structs Index!

}

#[turso_macros::test]
fn deferred_fk_parent_key_update_keeps_violation_until_commit(db: TempDatabase) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be replaced with a sqltest

@github-actions github-actions bot added the IO label Apr 9, 2026
// Schema was modified during the savepoint. Try to reparse
// from the restored database pages. If that fails (e.g. the
// database was empty at the savepoint), use an empty schema.
if conn.reparse_schema().is_err() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this now need to reparse temp/attached schemas too?

@LeMikaelF
Copy link
Copy Markdown
Collaborator

There's TODOs about transactions for temp schemas in transaction.rs lines 35 and 47.

@LeMikaelF
Copy link
Copy Markdown
Collaborator

Suggestion for a new test (I don't think this is tested): two connections, both with a temp table with the same name and schema, assert that they should be isolated.

begin_write_operation and begin_read_operation only added MAIN when the
corresponding DB was empty, so a temp-table statement that later
pulled in MAIN acesss via a trigger never emitted a Transaction opcode
for main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants