Skip to content

Validate sqlite_schema before AUTOINCREMENT schema writes#5683

Merged
penberg merged 2 commits intotursodatabase:mainfrom
kumarUjjawal:fix/autoincrement_scheama_validation
Mar 4, 2026
Merged

Validate sqlite_schema before AUTOINCREMENT schema writes#5683
penberg merged 2 commits intotursodatabase:mainfrom
kumarUjjawal:fix/autoincrement_scheama_validation

Conversation

@kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Mar 2, 2026

Description

  • Hardened translate_create_table to verify sqlite_schema exists before using it.
  • Replaced panic-prone unwrap() calls with:
    • bail_parse_error!("sqlite_schema table not found in schema")

Motivation and context

Issue #3764 called out a possible SQLite parity edge case around AUTOINCREMENT behavior when schema metadata is unusual/corrupted (notably relevant to future PRAGMA writable_schema support).

Description of AI Usage

Copy link

@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 @sivukhin

Copy link
Collaborator

@sivukhin sivukhin left a comment

Choose a reason for hiding this comment

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

Hi @kumarUjjawal!
Thanks for the contribution.

I think that for case you handled it is actually fine to crash - because at the moment of translation we must have properly parsed schema and if we are not - we must return NOT A DB error earlier.

Also, I think that the original issue in sqlite (https://sqlite.org/src/info/d8dc2b3a58cd5dc29) focused on the cases where sqlite_sequence table is corruption - not the case when whole schema is broken and can't be parsed.

So, I think that unwrap in the current code is ok. Instead we better to add more safe guards related to the sqlite_sequence logic particularly.

@Pavan-Nambi
Copy link
Contributor

Yeah the issue isn't about panic..

Also can u edit pr description so bot won't autoclose the issue ?imo even with guards I think we should have issue open until we support writable_schema...

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 2, 2026

Merging this PR will degrade performance by 15.72%

❌ 1 regressed benchmark
✅ 278 untouched benchmarks
⏩ 105 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation concat_blobs 1.4 µs 1.7 µs -15.72%

Comparing kumarUjjawal:fix/autoincrement_scheama_validation (e614db5) with main (b8ca98b)

Open in CodSpeed

Footnotes

  1. 105 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@kumarUjjawal kumarUjjawal requested a review from sivukhin March 3, 2026 05:56
@penberg penberg merged commit 0f4692f into tursodatabase:main Mar 4, 2026
90 checks passed
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.

4 participants