Skip to content

When trying to find a join for segmentation, also look for available ways to join in both directions #20149

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 3 commits into from
Jan 23, 2023

Conversation

diosmosis
Copy link
Member

Description:

Suppose we have two extra log tables in a plugin: log_thing_event and log_thing. log_thing_event joins log_visit on idvisit, while log_thing joins log_thing_event on idlogthing.

If we try to use Segment to generate SQL that queries log_thing_event, it will automatically join on log_visit to get segmentation to work. BUT if we try to use it to generate SQL that queries log_thing, it will not be able to make segmentation work, even though it can be joined to log_visit through log_thing_event.

This PR fixes this case. When looking for joins, the existing code tries to join a table to one of the previously seen tables in the $from array. It will look to see if it is directly joinable to log_visit, otherwise it will look in the getWaysToJoinOtherTables() of the table to join. This doesn't work in our case where $from = ['log_thing', 'log_thing_event'], because 'log_thing_event' won't be in the getWaysToJoinOtherTables() of 'log_thing'. Instead, log_thing will be in the getWaysToJoinOtherTables() of log_thing_event. So this adds the reverse of the existing check to make this type of query work.

The use case here is that log_thing will have far less rows than log_thing_event and querying over it first instead of log_thing_event can in some cases be far more efficient.

Review

…n in available table, not just in the table to join
@diosmosis diosmosis added the Needs Review PRs that need a code review label Jan 2, 2023
@github-actions
Copy link
Contributor

This issue is in "needs review" but there has been no activity for 7 days. ping @matomo-org/core-reviewers

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Jan 10, 2023
@sgiehl
Copy link
Member

sgiehl commented Jan 10, 2023

@diosmosis is it possible to add some test for that? The ExampleLogTables plugin has some additional log tables, maybe those could be used for testing...

@diosmosis
Copy link
Member Author

@sgiehl yes it's possible, I'll add them soon.

@github-actions github-actions bot removed the Stale The label used by the Close Stale Issues action label Jan 11, 2023
@sgiehl sgiehl added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. and removed Needs Review PRs that need a code review labels Jan 16, 2023
@tsteur
Copy link
Member

tsteur commented Jan 20, 2023

@diosmosis could you maybe have a look at this one at some point? It be great to get this merged so we can deploy the new feature on demo or demo2 soon for a test on an actual site.

@diosmosis
Copy link
Member Author

@tsteur @sgiehl added a test

@tsteur tsteur added this to the 4.13.2 milestone Jan 22, 2023
@tsteur tsteur added Needs Review PRs that need a code review and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Jan 22, 2023
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

LGTM

@sgiehl sgiehl merged commit bb104e7 into 4.x-dev Jan 23, 2023
@sgiehl sgiehl deleted the auto-join-segment-from-right branch January 23, 2023 08:48
@bx80 bx80 changed the title when trying to find a join for segmentation, also look for available ways to join in both directions When trying to find a join for segmentation, also look for available ways to join in both directions Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Development

Successfully merging this pull request may close these issues.

3 participants