Skip to content

Commit

Permalink
switch the query to except rather than where not exists
Browse files Browse the repository at this point in the history
sqlite executes `except` better than `not exists`
  • Loading branch information
tantaman committed Nov 21, 2023
1 parent c2639c4 commit 5ee5cb3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 2 additions & 11 deletions core/rs/core/src/backfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,13 @@ pub fn backfill_table(

let sql = format!(
"SELECT {pk_cols} FROM \"{table}\" AS t1
WHERE NOT EXISTS
(SELECT 1 FROM \"{table}__crsql_pks\" AS t2 WHERE {pk_where_conditions})",
EXCEPT SELECT {pk_cols} FROM \"{table}__crsql_pks\" AS t2",
table = crate::util::escape_ident(table),
pk_cols = pk_cols
.iter()
.map(|f| format!("t1.\"{}\"", crate::util::escape_ident(&f.name)))
.map(|f| format!("\"{}\"", crate::util::escape_ident(&f.name)))
.collect::<Vec<_>>()
.join(", "),
pk_where_conditions = pk_cols
.iter()
.map(|f| format!(
"t1.\"{col_name}\" IS t2.\"{col_name}\"",
col_name = crate::util::escape_ident(&f.name),
))
.collect::<Vec<_>>()
.join(" AND "),
);
let stmt = db.prepare_v2(&sql);

Expand Down
2 changes: 1 addition & 1 deletion py/correctness/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# source env/bin/activate
# python -m pytest tests -s -k test_cl_merging
python3 -m pytest tests -s -k test_commit_alter_perf
python3 -m pytest tests -s

0 comments on commit 5ee5cb3

Please sign in to comment.