-
Notifications
You must be signed in to change notification settings - Fork 118
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
Added support for STRAIGHT_JOIN
in ActiveRecord; #3073
#3515
base: 7.dev
Are you sure you want to change the base?
Conversation
both a flag and a join type
STRAIGHT_JOIN
in ActiveRecord; #3073
@robinsowell is this syntax for the second usage correct?
I don't have much experience with Straight Joins but in the little research I did it seems like it should be used in a similar way as other Joins. I can't find any references where it is part of the SELECT clause, maybe you can send me some links on that? |
@bryannielsen Does this help? https://blog.sqlauthority.com/2014/03/12/mysql-how-to-do-straight-join-in-mysql/ I was puzzled by the two different approaches at first, but poked around and added it for someone who had a really big speed improvement using it in one particular circumstance- thing it was actually in a solspace add-on. But we needed it in native AR to apply it. It did/does work for the end user, so even though obscure, I added it. |
@robinsowell was it just the |
Robin to say final word, but I think straight_join is a modifier for select, not actually join type. And it needs to be treated sane way as 'distinct' |
@intoeetive I don't think that's actually the intended usage though. The docs only mention using it as a join type - https://dev.mysql.com/doc/refman/8.0/en/join.html but I think it's possible to use it through a select, just like you can technically join tables without a join statement. I just think if there's no benefit to this approach we shouldn't bother supporting it as it just causes more confusion |
In truth, this was a pure FR from a user- I think they wanted to use it on a Solspace Calendar query that was being super slow for them (had to be something to do with the way mysql was doing the join), and having the flag was a billion times easier to implement. I'll see if I can find the support discussion. |
Agreed- I think adding the straight_join as a join type makes sense. I'll drop the flag as it looks like it's non-recommended. |
My gut is that we fall in line with the existing join_type param on the method. and add it there. |
@bryannielsen When you get a chance, can you take a look at this one again? I pulled out the flag/keyword, so it's just adding a straight join type. Tested doing
|
Added straight as a join type
Not adding it as a flag/keyword, though first commit has both
NOTE - removed the flag from the final commit per discussion
per user request, adding a straight join flag and join type.
used as join('channel_data', "channel_data.entry_id = channel_titles.entry_id", "straight");
SELECT
exp_channel_titles
.entry_id
FROM (exp_channel_titles
) STRAIGHT_JOINexp_channel_data
ONexp_channel_data
.entry_id
used as ->straight()
SELECT STRAIGHT_JOIN
exp_channel_titles
.entry_id
FROM (exp_channel_titles
docs pr: ExpressionEngine/ExpressionEngine-User-Guide#678