Reusable criterias generates, under some circumstances, a non fast SQL statement #10482
Unanswered
alexpozzi
asked this question in
Support Questions
Replies: 2 comments
-
What makes this query slow is the left join rather than the criteria being applied at the wrong side of the join. An inner join should yield the same result with a better performance. But I feel this doesn't really answer your question. 😓 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Not really, even when using an inner join the query is slower then using the condition on the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given
When
I query my articles by category using the following code (simplified in order to stay in the context):
Then
The generated SQL is the following
Now this is working and I get the right articles but it's not super fast (especially with more complex queries) as the category filter is applied on the joined
category.id
field instead of directly to thearticle.category_id
field.I noticed that this is caused by the fact that my criteria's factory doesn't specify the name of the main entity when generating the DQL expression (uses just
category
instead ofarticle.category
).If I change the expression used in my criteria's factory to
Criteria::expr()->in('article.category', $categories)
everything works as expected and the generated SQL looks like:The problem is that it makes my criteria's factory non-reusable.
I know I can pass the name of the as an input table and concatenate that to my expression but I was wondering if there was a way to tell Doctrine to apply the criteria to the from instead of to a join.
Beta Was this translation helpful? Give feedback.
All reactions