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

fix(statistics): use subquery instead of join to avoid cartesian product #558

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

winged
Copy link
Member

@winged winged commented Dec 23, 2024

The way we filter in the statistics view, any added filter (that affects reports) adds a "dimension" to the cartesian product, exploding the total number of hours reported.

Instead of using JOIN, we do EXISTS(SUBQUERY) now, which should avoid this issue. Might be a tiny bit slower, but let's try to make it correct first, then fast.

Fixes #89

@winged winged requested a review from a team as a code owner December 23, 2024 13:21
The way we filter in the statistics view, any added filter (that affects
reports) adds a "dimension" to the cartesian product, exploding the total
number of hours reported.

Instead of using JOIN, we do EXISTS(SUBQUERY) now, which should avoid this
issue. Might be a tiny bit slower, but let's try to make it correct first, then fast.
@winged winged force-pushed the fix_result_explosion_in_statistics branch from 084550f to 0fcff27 Compare December 23, 2024 13:28
Copy link
Contributor

@fugal-dy fugal-dy left a comment

Choose a reason for hiding this comment

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

I agree with that. The performance bump is relatively high with small numbers but still in an acceptable range in human time. It's very soon outperformed on larger numbers, so I think that's definitely the way to go.

I would suggest that the EXISTS variant is generally preferable where large number of relations potientially exist. Even if most queries are not eligible, those few that acutally trigger those high-dimension joins will affect every other query. So basically, starting from a certain size of a table that might explode the query, that pattern is preferable. And, given the relatively small trade off when below the threshold, it's probably safe to start from here and fine tune on demand.

@winged
Copy link
Member Author

winged commented Dec 23, 2024

Note this was a one-shot attempt at fixing our issues, created during a hack session with @trowik and @MitanOmar . However it doesn't solve the issue and I think a general refactoring of the whole statistics backend is in order.

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.

statistic page loading wrong data
2 participants