Conversation
simolus3
added this pull request to stack #222
September 9, 2026 08:07
simolus3
force-pushed
the
raw-tables-by-default
branch
from
September 10, 2026 14:48
03e0e63 to
9542a89
Compare
Contributor
|
I think this feature will be great, but I wonder if we could remove the Or would that make the migration paths with JSON-based tables too difficult? In that case, maybe we can consider another change later (potentially breaking or opt-in) to remove |
Contributor
Author
|
I like that idea. Perhaps there could be a single flag (on the entire schema, not per-table) that does both.
|
simolus3
force-pushed
the
raw-tables-by-default
branch
from
September 16, 2026 09:21
ac9f509 to
ffb6603
Compare
simolus3
force-pushed
the
raw-tables-by-default
branch
from
September 17, 2026 09:26
30a3119 to
98cebcf
Compare
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.
This adds a new type of table next to the existing ones based on JSON data + views (easy to manage and migrate, slower to query) and raw tables (fast queries and full customizability at the expense of a higher setup complexity). Direct tables (name tbd) have the shape of raw tables with proper SQLite columns that can be queried without decoding JSON on reads.
A direct table has a shape like this:
The sync client treats this table like raw tables, automatically inferring statements to sync into it. There is no view to generate, but we generate triggers to record writes in
ps_crud.As an alternative to this table shape, I have considered keeping a
ps_data__-like table that just addsGENERATED ALWAYS AScolumns. This might seem simpler, but then you wouldn't be able to update these columns directly so we'd have to keep generating views andINSTEAD OFtriggers. The current pattern is closer to the shape one would expect SQLite tables to have.Direct tables are currently an opt-in, but we could make them the default in a future major release. An important difference in behavior is that JSON-based tables have
INSTEAD OFtriggers for tables thatCASTvalues to their expected type. Direct tables don't have triggers, so inserting into them gives you the usual SQLite behavior where epxressions have a type affinity, but no enforced type. It is thus possible to sync, insert and update "wrong" types into direct tables. I have adoptedSTRICTtables withANYcolumns for this reason: The type is dynamic either way, and this simplifies migrations because we don't have to care about changed column types.Benchmarks
Despite the fact that we have to parse rows nows, enabling direct tables seems to improve
sync_local_performance_test.dart. Using a full run with unique ids:1940ms Reads: 1291079 + 0 | Writes: 69031 + 0.1408ms (-27.4%) Reads: 1286404 (-3.6%) + 0 | Writes: 42228 + 0 (-38.8%). This is an in-memory test with an instrumented VFS so times don't mean much, but this needing fewer writes should translate to better sync performance.Since direct tables have the same structure as raw tables, they should result in similar performance benefits for queries (I did not benchmark direct tables for this specifically).
Migrations and tests
Raw tables already give us the infrastructure to sync into arbitrary tables, so most of this PR deals with migrations related to direct tables. The following things are considered and tested:
ps_untyped.