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

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

Open
cassianotartari opened this issue May 13, 2020 · 5 comments
Open

Comments

@cassianotartari
Copy link

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?

@garak
Copy link
Collaborator

garak commented May 13, 2020

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

@cassianotartari
Copy link
Author

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.

@garak
Copy link
Collaborator

garak commented May 14, 2020

My previous suggestion still stands

@cassianotartari
Copy link
Author

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.

@garak
Copy link
Collaborator

garak commented May 14, 2020

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

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

No branches or pull requests

2 participants