mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Paginator/groupBy seems very slow #5276
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 @zstiggz on GitHub (Sep 28, 2016).
Originally assigned to: @Ocramius on GitHub.
Originally posted this question on StackOverflow:
http://stackoverflow.com/questions/39736173/doctrine-paginator-selects-entire-table-very-slow
This is related to a previous question here:
http://stackoverflow.com/questions/39721673/doctrine-symfony-query-builder-add-select-on-left-join
I want to perform a complex join query using Doctrine ORM. I want to select 10 paginated blog posts, left joining a single author, like value for current user, and hashtags on the post. My query builder looks like this:
Strangely, count($result) on the paginator shows the total number of rows in my table (over 80,000) but traversing the $result with foreach outputs 10 Post entities, as expected. Do I need to do some additional configuration to properly limit my paginator?
If this is a limitation of the paginator class what other options do I have? Writing custom paginator code or other paginator libraries?
EDIT (bonus): How can I hydrate an array, like $query->getQuery()->getArrayResult();?
Things I tried:
@Ocramius commented on GitHub (Sep 28, 2016):
The paginator counts the total (without limits) for the selection you have, not just the 10 you get.
Custom DQL, probably. You can also simply use
min(count($paginator), $query->getMaxResults())to count the current selection.The paginator doesn't use
GROUP BY, but rather anIN()subquery.We can't directly help with the
GROUP BYslowness, but I suggest passing it through a query planner, and seeing what is going on. theIN()subquery acts on the primary key, so we have at least some sort of direct hit on an existing index.Closing, since this is not an issue, but a question.
@zstiggz commented on GitHub (Sep 28, 2016):
@Ocramius, thanks for the response!
Yeah, this was more of a question - I suppose the "issue" was more unexpected behavior of the paginator. I would have expected
$query->getResult()andnew Paginator($query)to have comparable performance without the addSelects, but found the paginator to be much slower - regardless of whether or not I add leftJoins and/or addSelects to my query.At any rate, thanks for the tips. I'm still pretty stumped though - is there a doctrine message board or something where I might go to probe this question further?
@Ocramius commented on GitHub (Sep 28, 2016):
We have doctrine-user, but stackoverflow is quite efficient at this already.
On 28 Sep 2016 05:07, "Z" notifications@github.com wrote:
@zstiggz commented on GitHub (Sep 28, 2016):
Roger that. I'll cross my fingers and hope something pans out on my stackoverflow questions.