I'm not sure how much QuerySet optimization django should really be doing.
Databases' optimizers are really good and as we've seen there are a huge
number of edge cases in trying to do the work in Djangoland, as QuerySets
don't really correspond to the underlying data model.
Here's an example in M
On Monday, August 21, 2017 at 11:28:35 AM UTC+3, Tom Forbes wrote:
>
> > Interestingly enough, just doing a .filter(m2m_relation__foo='bar')
> might change the results
>
> Is that not because it's a filter? Would ".
> annotate(x=F('m2m_relation__foo'))" change the results in any way? Sorry if
>
> Interestingly enough, just doing a .filter(m2m_relation__foo='bar') might
change the results
Is that not because it's a filter? Would ".
annotate(x=F('m2m_relation__foo'))" change the results in any way? Sorry if
I'm not following.
On 21 Aug 2017 06:58, "Anssi Kääriäinen" wrote:
On Sunday,
On Sunday, August 20, 2017 at 2:48:23 AM UTC+3, Josh Smeaton wrote:
> Thanks for making me elaborate, because I'm probably wrong. I'll step
> through what my thinking was though.
>
> '.annotate(local=F('related__field'))' will join to the related table. If
> `related` is a nullable foreign key,
Thanks for making me elaborate, because I'm probably wrong. I'll step
through what my thinking was though.
'.annotate(local=F('related__field'))' will join to the related table. If
`related` is a nullable foreign key, then a join would do an implicit
filter, removing the row from the result set
Thanks for your reply Josh. Can you elaborate on why optimizing out '
.annotate(local=F('related__field'))' would not be safe?
On 20 Aug 2017 00:10, "Josh Smeaton" wrote:
I'd like to see this provided all bases were covered. I'll just list below
the cases where I think it wouldn't be safe.
- Fi
I'd like to see this provided all bases were covered. I'll just list below
the cases where I think it wouldn't be safe.
- Filtered annotations
- Annotations that join to anything other than a non-null foreign key:
.annotate(local=F('related__field'))
- Annotations that have a GROUP BY on fields