Skip to content

Rewrite the "sync_local" query #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand on comments.
  • Loading branch information
rkistner committed May 26, 2025
commit 4a2f4485e136f1bfff96d934b5b0f0bd49882abe
5 changes: 4 additions & 1 deletion crates/core/src/sync_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl<'a> SyncOperation<'a> {
if self.data_tables.contains(&table_name) {
let quoted = quote_internal_name(type_name, false);

// is_err() is essentially a NULL check here
// is_err() is essentially a NULL check here.
// NULL data means no PUT operations found, so we delete the row.
if data.is_err() {
// DELETE
let delete_statement = self
Expand Down Expand Up @@ -190,6 +191,7 @@ impl<'a> SyncOperation<'a> {
"\
-- 1. Filter oplog by the ops added but not applied yet (oplog b).
-- We do not do any DISTINCT operation here, since that introduces a temp b-tree.
-- We filter out duplicates using the GROUP BY below.
WITH updated_rows AS (
SELECT b.row_type, b.row_id FROM ps_buckets AS buckets
CROSS JOIN ps_oplog AS b ON b.bucket = buckets.id
Expand Down Expand Up @@ -224,6 +226,7 @@ SELECT
"\
-- 1. Filter oplog by the ops added but not applied yet (oplog b).
-- We do not do any DISTINCT operation here, since that introduces a temp b-tree.
-- We filter out duplicates using the GROUP BY below.
WITH
involved_buckets (id) AS MATERIALIZED (
SELECT id FROM ps_buckets WHERE ?1 IS NULL
Expand Down