Skip to content

Solves an issue with left joins being opptimised away in some queries. - #4195

Closed
slawo wants to merge 0 commit into
sequelize:masterfrom
slawo:master
Closed

slawo wants to merge 0 commit into
sequelize:masterfrom
slawo:master

Conversation

@slawo

@slawo slawo commented Jul 27, 2015

Copy link
Copy Markdown

@janmeier

Copy link
Copy Markdown
Member

Yeah, looks like a reasonable fix - needs api docs and regression tests though :)

@janmeier

Copy link
Copy Markdown
Member

I most admit I'm not 100% sure why we actually remove the includes, other than for performance (which is in itself a valid reason, I just don't remember if there is a deeper reason :D)

@mickhansen

Copy link
Copy Markdown
Contributor

I'm not totally happy with the approach here.
We remove them for performance and because they introduce complexities when you get to subquery stuff etc.

@janmeier

Copy link
Copy Markdown
Member

I was also thinking, since the only place where we do this removal of includes is findAndCount, so we might just introduce an option to not do that?

@slawo

slawo commented Jul 28, 2015

Copy link
Copy Markdown
Author

I believe this is a reasonable fix as the includes are indeed required. And the requirement is unambiguous as to its purpose.

But I am not familiar with the insides of sequelize.

@slawo

slawo commented Jul 28, 2015

Copy link
Copy Markdown
Author

@janmeier @mickhansen Either way, I would be happy to have an option to avoid the optimisation.

This way seemed to be the most flexible without adding any new keywords. But I could have a new keyword (i.e. keep) I would be happy with that.

@slawo

slawo commented Jul 28, 2015

Copy link
Copy Markdown
Author

@janmeier @mickhansen apparently the forced removal of includes from queries generates other bugs as well for example #4200.

Could it be possible to turn it off during some queries. While I appreciate the importance of speed optimisation I am currently working on a tool used internally by a few people and my primary objective is reliability not performance at this point.

Is there a way to switch those optimisations off entirely in the project?

@janmeier

Copy link
Copy Markdown
Member

@slawo #4200 is not directly related to this. In the case of limit we have to remove the includes, because we use a subquery. We need a subquery without joins in order to limit, otherwise the limit is wrong (in that case we would be limiting the number of joined rows, instead of the number of parent rows)

@slawo

slawo commented Jul 28, 2015

Copy link
Copy Markdown
Author

Ouch!

Why is the query not simply wrapped in a
SELECT * FROM (query) LIMIT 2; ?

@mickhansen

Copy link
Copy Markdown
Contributor

@slawo Because of the reason @janmeier just explained, it won't work with cartesian products since it will limit the total amount of rows (which will be multiplied because of joins) not the amount of rows in the main table (which is the intent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

findAndCountAll crashes with a query which runs in findAll

3 participants