You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf: speed up query for filling missing columns in refill metatable (#18)
The new query does 1 encode per source row and one indexed NOT-EXISTS probe.
The old plan does many decodes per candidate and can’t use an index to rule out matches quickly—so it burns CPU and I/O.
* Increased performance in cloudsync_refill_metatable
* chore: remove old code
* chore: bump version
---------
Co-authored-by: Marco Bambini <[email protected]>
sql=cloudsync_memory_mprintf("SELECT cloudsync_insert('%q', %s) FROM (SELECT %s FROM \"%w\" EXCEPT SELECT %s FROM \"%w_cloudsync\");", table_name, pkvalues_identifiers, pkvalues_identifiers, table_name, pkdecodeval, table_name);
1721
1716
intrc=sqlite3_exec(db, sql, NULL, NULL, NULL);
1722
1717
cloudsync_memory_free(sql);
1723
1718
if (rc!=SQLITE_OK) goto finalize;
1724
-
1719
+
1725
1720
// fill missing colums
1726
1721
// for each non-pk column:
1722
+
// The new query does 1 encode per source row and one indexed NOT-EXISTS probe.
1723
+
// The old plan does many decodes per candidate and can’t use an index to rule out matches quickly—so it burns CPU and I/O.
1727
1724
1728
-
sql=cloudsync_memory_mprintf("SELECT cloudsync_pk_encode(%s) FROM \"%w\" LEFT JOIN \"%w_cloudsync\" ON %s AND \"%w_cloudsync\".col_name = ? WHERE \"%w_cloudsync\".db_version IS NULL", pkvalues_identifiers, table_name, table_name, pkonclauseval, table_name, table_name);
1729
-
rc=sqlite3_prepare(db, sql, -1, &vm, NULL);
1725
+
sql=cloudsync_memory_mprintf("WITH _cstemp1 AS (SELECT cloudsync_pk_encode(%s) AS pk FROM \"%w\") SELECT _cstemp1.pk FROM _cstemp1 WHERE NOT EXISTS (SELECT 1 FROM \"%w_cloudsync\" _cstemp2 WHERE _cstemp2.pk = _cstemp1.pk AND _cstemp2.col_name = ?);", pkvalues_identifiers, table_name, table_name);
0 commit comments