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

Added support for STRAIGHT_JOIN in ActiveRecord; #3073 #3515

Open
wants to merge 4 commits into
base: 7.dev
Choose a base branch
from

Conversation

robinsowell
Copy link
Contributor

@robinsowell robinsowell commented Jun 13, 2023

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_JOIN exp_channel_data ON exp_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

both a flag and a join type
robinsowell added a commit to ExpressionEngine/ExpressionEngine-User-Guide that referenced this pull request Jun 13, 2023
@intoeetive intoeetive changed the title Adding straight join Added support for STRAIGHT_JOIN in ActiveRecord; #3073 Jun 14, 2023
@intoeetive intoeetive added this to the 7.4.0 milestone Jul 6, 2023
@bryannielsen
Copy link
Contributor

@robinsowell is this syntax for the second usage correct?

SELECT STRAIGHT_JOIN exp_channel_titles.entry_id FROM (exp_channel_titles

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?

@robinsowell
Copy link
Contributor Author

@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.

@intoeetive intoeetive added the docs covered Has User Guide PR, or no documentaion necessary label Oct 24, 2023
@bryannielsen
Copy link
Contributor

@robinsowell was it just the SELECT STRAIGHT_JOIN that helped the customer? I just haven't seen that used much and I think we would rather encourage specifying the join type on the join() instead. I'm leaning towards removing the ->straight(bool) for selects and just keeping it as a new join type option unless there's a benefit to having the other. If we do want to keep it I think I would remove the boolean argument so you're either forcing a query to use straight joins or not, or is there a use case for where you would use ->straight(false) to turn off the straight join behavior on a query?

@intoeetive
Copy link
Contributor

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'

@bryannielsen
Copy link
Contributor

@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

@robinsowell
Copy link
Contributor Author

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.

@bryannielsen bryannielsen self-assigned this Nov 7, 2023
@bryannielsen bryannielsen modified the milestones: 7.4.0, 7.x Nov 8, 2023
@robinsowell
Copy link
Contributor Author

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.

@TomJaeger
Copy link
Contributor

My gut is that we fall in line with the existing join_type param on the method. and add it there.

https://docs.expressionengine.com/latest/development/legacy/database/active-record.html#jointable-cond-type--

@bryannielsen bryannielsen modified the milestones: 7.x, 7.4.1 Feb 13, 2024
@intoeetive intoeetive modified the milestones: 7.4.1, 7.x Feb 16, 2024
@robinsowell robinsowell requested review from bryannielsen and removed request for matthewjohns0n April 19, 2024 17:42
@robinsowell
Copy link
Contributor Author

@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

ee()->db->select('channel_name');
ee()->db->from('channels');
ee()->db->join('comments', 'comments.channel_id = channels.channel_id', STRAIGHT);
ee()->db->join('members', 'comments.author_id = members.member_id', STRAIGHT);
$query = ee()->db->get();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development docs covered Has User Guide PR, or no documentaion necessary
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants