mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3646: Do not select unused columns in inner queries of Paginator #4480
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 31, 2015).
Originally assigned to: @deeky666 on GitHub.
Jira issue originally created by user MalteWunsch:
When a
Paginator count()s, it fires a query like this:an
getIterator()does something similar for joined collections to get the ids in the first place:My problem is that both the inner queries can be too heavy for a regular temporary table.
At first sight I noticed several
LEFT JOINs that could be stripped from the inner query without changing the result of the outer one. But that might have been a specially easy case, a general optimisation of theJOINclauses might be harder. I think http://www.doctrine-project.org/jira/browse/DDC-2381 deals with that.On second thought we noticed some ugly BLOB columns as part of the projection, which unhealthily bloated the temporary table. Ultimately, the BLOBs are needed for the paginated view, but they are neither needed for counting nor for getting the paginated ids.
Hence, I propose to remove unused columns from the projection in the inner queries. "Unused" means not being part of the
SELECTorORDER BYclause in the outer query (and maybe not part ofGROUP BY,HAVING... - haven't checked on this yet). The key could be the$innerSqlin theLimitSubqueryOutputWalker->walkSelectStatement(), but before investigating further, I'd like to hear from you what you think.@doctrinebot commented on GitHub (Mar 31, 2015):
Comment created by @ocramius:
Please review https://github.com/doctrine/doctrine2/pull/1353, as it might solve this issue
@doctrinebot commented on GitHub (Mar 31, 2015):
Comment created by MalteWunsch:
Thanks for your quick reply!
To be honest, I don't fully get the PR. At least it's goals look very different to me. Anyway, in
LimitSubqueryOutputWalkerthe$innerSQLis now being generated ingetInnerSQL(). In there, somehiddenAliasResultVariableare set to false (and are later restored) so that the parent SQLWalker can reference selected fields better. This might be a requirement for implementing my idea, but as far as I understand, there are no columns removed from the select clause so far?@doctrinebot commented on GitHub (Mar 31, 2015):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-1353] was closed:
https://github.com/doctrine/doctrine2/pull/1353
@doctrinebot commented on GitHub (Apr 6, 2015):
Comment created by @ocramius:
[~MalteWunsch] the PR is actually related as it affects the selected fields.
Consider checking again against
2.5.0, as we indeed fixed many paginator issues, and this issue needs to be re-validated.@doctrinebot commented on GitHub (Apr 7, 2015):
Comment created by MalteWunsch:
Great! I'll be glad to check. It might take some time, as we currently only have PHP 5.3 at our disposal (please don't tell anybody), and Doctrine 2 ORM 2.5.0 requires at least PHP 5.4. Fortunately, this is a very good trigger to put some pressure on the PHP upgrade process. I'll keep my eye on it.
@doctrinebot commented on GitHub (Apr 10, 2015):
Comment created by MalteWunsch:
[~ocramius] Unfortunately, Doctrine 2.5 had no effect on my inner original query. It still looks like this:
Just to be clear, my point is with the most inner query. If I'm correct it is generated in LimitSubqueryOutputWalker->getInnerSql(). In the special case with the query above, one could simplify it by dropping the order clause, removing the left joins and selecting only the id0 field. I have no plan for inner joins and other more complex optimisations, but I guess that removing the unused fields from the select clause might be in reach.
@doctrinebot commented on GitHub (Apr 10, 2015):
Comment created by mpdude:
When removing fields from the SELECT clause, we need to keep those that are referenced from GROUP BY or HAVING clauses (when ORDER BY is dropped).
@doctrinebot commented on GitHub (Apr 14, 2015):
Comment created by mpdude:
[http://www.doctrine-project.org/jira/browse/DDC-2381] seems to be related or identical.