Skip to content

Improve performance of queries for complex custom reports using segments #21653

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 7 commits into from
Dec 10, 2023

Conversation

bx80
Copy link
Contributor

@bx80 bx80 commented Dec 7, 2023

Description:

Some complicated custom reports can result in generated queries where the log_visit table is right joined to the segment temporary table, these queries perform poorly because the join plan starts with the right joined log_visit table which has no range conditions, resulting in the entire log_visit table being joined.

The query generator code contains an optimization which will remove any where conditions on joined log tables which duplicate the where condition on the segment temporary table. This makes perfect sense for left joined tables, but not for right joins on the log_visit table.

This PR changes the above query optimization to avoid removing where conditions from the log_visit table if it is right joined to a segment temporary table.

Ref PG-3186

Review

@bx80 bx80 added the c: Performance For when we could improve the performance / speed of Matomo. label Dec 7, 2023
@bx80 bx80 added this to the 5.0.0 milestone Dec 7, 2023
@bx80 bx80 self-assigned this Dec 7, 2023
@bx80 bx80 requested a review from a team December 7, 2023 06:24
@bx80 bx80 added the Needs Review PRs that need a code review label Dec 7, 2023
@bx80 bx80 requested review from sgiehl and mneudert December 7, 2023 06:35
…ables other than log_visit are correctly handled
Copy link
Contributor

@michalkleiner michalkleiner left a comment

Choose a reason for hiding this comment

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

Looked at code only, haven't tested actual queries locally, but the tests seem to cover the addition well.

@bx80 bx80 merged commit 37fd13d into 5.x-dev Dec 10, 2023
@bx80 bx80 deleted the pg-3186-custom-reports-right-join-slow branch December 10, 2023 19:32
@sgiehl sgiehl modified the milestones: 5.0.0, 5.0.1 Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Performance For when we could improve the performance / speed of Matomo. Needs Review PRs that need a code review
Development

Successfully merging this pull request may close these issues.

5 participants