Skip to content
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

feat: optimise where clause filtering #2076

Merged
merged 62 commits into from
Dec 3, 2024

Conversation

robacourt
Copy link
Contributor

Fixes #2040 and is estimated to improve Trigger.dev's replication stream processing by 400x

@balegas
Copy link
Contributor

balegas commented Dec 2, 2024

Exciting!

@robacourt robacourt force-pushed the rob/optimise-where-clause-filtering branch from 5f3005a to efe3613 Compare December 2, 2024 16:47
@robacourt robacourt marked this pull request as ready for review December 3, 2024 09:28
Copy link
Member

@alco alco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

def affected_shapes(%Filter{} = filter, %Relation{} = relation) do
def affected_shapes(%Filter{} = filter, change) do
shapes_affected_by_change(filter, change)
rescue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? What kinds of errors do we expect to see here?

Copy link
Contributor Author

@robacourt robacourt Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super safety 😄 My reasoning is that if filtering crashes, all the shapes crash, so we need to be more careful than if this was shape specific code. There's a much more targeted rescue in Table that deals with record parsing errors which is much more likely to be hit. This one is more of a catch-all just to be extra safe.

Types of error it could catch:

  1. Shape.is_affected_by_relation_change? exceptions
  2. change types the filter is not expecting are passed to affected_shapes/2

These hopefully will never happen, but if they do, we'd rather the filter didn't crash.

assert Filter.affected_shapes(filter, change("t1", %{"id" => "7"})) == MapSet.new([7])
end)

assert reductions < 500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to see this specific number explain. What is the significance of it in this test? What should we do if this assertion fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let me write a comment

@icehaunter icehaunter changed the title Optimise where clause filtering feat: optimise where clause filtering Dec 3, 2024
Copy link
Contributor

@icehaunter icehaunter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, exactly what I had in mind

Copy link

netlify bot commented Dec 3, 2024

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit 12c0644
🔍 Latest deploy log https://app.netlify.com/sites/electric-next/deploys/674f022a2317740008bd3e24
😎 Deploy Preview https://deploy-preview-2076--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@icehaunter icehaunter merged commit 37b4256 into main Dec 3, 2024
26 checks passed
@icehaunter icehaunter deleted the rob/optimise-where-clause-filtering branch December 3, 2024 13:09
robacourt added a commit that referenced this pull request Dec 3, 2024
Follow up to #2076, based on @alco 's comments, this documents the
optimisation tests.
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.

improvement: better disjoint where clause evaluation
4 participants