Skip to content

Fix performance issue with many duplicate ids #40

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 1 commit into from
Oct 15, 2024

Conversation

rkistner
Copy link
Contributor

If you had a sync rules query like this: select '' as id from mytable (all rows with the same id), the JOIN sync_local query would have O(n^2) operations. For 10k rows, this is 100m operations, which takes a very long time.

While this should never be the case in a production app (you'd typically have a max of 2 or 3 duplicates), it could easily lead to a "hanging" app during development if you had a mistake in the query, making it difficult to debug.

The change in query here takes it back to O(n). It does use an additional "TEMP B-TREE" for the DISTINCT/UNION step, but does not seem to negatively affect sync performance in my testing.

@rkistner rkistner merged commit a59beae into main Oct 15, 2024
12 checks passed
@rkistner rkistner deleted the fix-duplicate-id-performance branch October 15, 2024 15:09
@rkistner rkistner mentioned this pull request Feb 3, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants