Repository navigation
fix(sqlite): db_version after commit_alter on reopen, and linear orphan cleanup in commit_alter (1.2.4) - #105
Merged
Merged
Conversation
…reopen pre_alter_dbversion is stored as TEXT, and TEXT sorts above every INTEGER in max(), so a new connection after cloudsync_commit_alter restarted its counter at the pre-alter value and reused versions already sent. Cast it to INTEGER, as the PostgreSQL query already does. Fixes #103 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The correlated NOT EXISTS compared each metadata row against cloudsync_pk_encode() of the base table, which no index can serve, so the base table was scanned once per metadata row. Use pk NOT IN (SELECT cloudsync_pk_encode(...) FROM base) instead, built once. The query is now built per backend; the PostgreSQL query is unchanged. Fixes #104 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…check Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two SQLite fixes in
cloudsync_commit_alter, one commit each.#103: writes from a new connection after an alter were never sent.
pre_alter_dbversionis stored as TEXT, and in SQLite TEXT sorts above every INTEGER inmax(). So every new connection restarted its db_version counter at the pre-alter value, and its writes reused versions a peer had already sent past.cloudsync_network_reset_sync_version()once after upgrading.#104:
cloudsync_commit_alterwas quadratic in the table's rows. The orphaned-metadata cleanup used a correlatedNOT EXISTSoncloudsync_pk_encode(...), which no index can serve, so it scanned the base table once per metadata row.pk NOT IN (SELECT cloudsync_pk_encode(...) FROM base WHERE ... IS NOT NULL), which builds the list of live keys once. The NULL filter keeps the result identical to the old query in every case.sql_build_gc_delete_orphaned_pk_query). The PostgreSQL query text and its arguments are unchanged.Timings for
commit_alterafterADD COLUMN(darwin-arm64):In every case the metadata left after
commit_alteris the same as before the change: same row count and same contents (pk, col_name, col_version, db_version, seq).Tests:
make unittestgives 163 OK, with two new tests:The PostgreSQL suite was not run locally; CI covers it.
Release 1.2.4: bumps
CLOUDSYNC_VERSIONand dates the CHANGELOG section.Fixes #103
Fixes #104
🤖 Generated with Claude Code