When trying to find a join for segmentation, also look for available ways to join in both directions #20149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Suppose we have two extra log tables in a plugin:
log_thing_event
andlog_thing
.log_thing_event
joinslog_visit
onidvisit
, whilelog_thing
joinslog_thing_event
onidlogthing
.If we try to use
Segment
to generate SQL that querieslog_thing_event
, it will automatically join onlog_visit
to get segmentation to work. BUT if we try to use it to generate SQL that querieslog_thing
, it will not be able to make segmentation work, even though it can be joined tolog_visit
throughlog_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 thegetWaysToJoinOtherTables()
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 thegetWaysToJoinOtherTables()
of'log_thing'
. Instead,log_thing
will be in thegetWaysToJoinOtherTables()
oflog_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 thanlog_thing_event
and querying over it first instead oflog_thing_event
can in some cases be far more efficient.Review