KnpPaginatorBundle icon indicating copy to clipboard operation
KnpPaginatorBundle copied to clipboard

Prevent extra sql queries from to-many and to-one ORM relations

Open cassianotartari opened this issue 5 years ago • 5 comments

Hi!

I'm running "knplabs/knp-paginator-bundle": "2.8.0" pagination results in a list view. I'd like to know if it's possible to prevent run extra sql queries from to-many and to-one ORM relations. I've tried to ->setHint(UsesPaginator::HINT_FETCH_JOIN_COLLECTION, false) with no success. For example: I have a entity Order that has one-to-one relation with Cart. When I run my list with orders the class Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\QuerySubscriber\UsesPaginator make a extra sql query for each relation of Order. Is there a way to prevent this extra queries?

cassianotartari avatar May 13 '20 18:05 cassianotartari

You need to leftjoin (and to select). Anyway, I'm afraid that this unrelated to pagination

garak avatar May 13 '20 19:05 garak

Thanks for the information @garak but if I'm not wrong when you use the fetchJoinCollection to false in Doctrine paginator this fetchs doesn't happen.

cassianotartari avatar May 14 '20 10:05 cassianotartari

My previous suggestion still stands

garak avatar May 14 '20 16:05 garak

Yeah, I already knew it, but when I start to do too much leftJoin the query starts to get very slow, I'm optimizing performance of a listing.

cassianotartari avatar May 14 '20 16:05 cassianotartari

Anyway, you would get the very same problem with a normal list, without pagination. That's why I said that problem is unrelated

garak avatar May 14 '20 17:05 garak