Changes between Initial Version and Version 1 of Ticket #30130, comment 4


Ignore:
Timestamp:
Jan 24, 2019, 6:51:08 PM (6 years ago)
Author:
Simon Charette

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30130, comment 4

    initial v1  
    1515
    1616{{{#!sql
    17 SELECT COUNT(*) FROM (SELECT DISTINCT "ticket_30130_foo"."bat" AS Col1, "ticket_30130_foo"."baz" AS Col2 FROM "ticket_30130_foo") subquery
     17SELECT COUNT(*) FROM (SELECT DISTINCT "machine", "cluster" FROM "resources") subquery
    1818}}}
    1919
    20 It looks like the issue is that [https://github.com/django/django/blob/7e978fdc4228eb44cf97cb4243adc7b7bfd586c7/django/db/models/sql/query.py#L439-L443 we clear the ordering when we shouldn't] on the `.count()`. I think the logic needs to be adjusted to branch of `not self.distinct` instead of `self.distinct_fields`.
     20It looks like the issue is that [https://github.com/django/django/blob/7e978fdc4228eb44cf97cb4243adc7b7bfd586c7/django/db/models/sql/query.py#L439-L443 we clear the ordering when we shouldn't] on the `.count()`. I think the logic needs to be adjusted to branch of `not self.distinct` instead of `self.distinct_fields`. Thing is switching this line generate this really nasty double nested query
     21
     22{{{#!sql
     23SELECT COUNT(*) FROM (
     24    SELECT "machine", "cluster" FROM (
     25        SELECT DISTINCT "machine", "cluster", "ordering" FROM "resources" ORDER BY "ordering" ASC subquery
     26    )) subquery
     27}}}
     28
     29Ideally we'd want
     30
     31{{{#!sql
     32SELECT COUNT(*) FROM (SELECT DISTINCT "machine", "cluster", "ordering" FROM "resources") subquery
     33}}}
     34
     35Where the `ORDER BY` is cleared as it's not necessary but the columns that would have made it to `SELECT` clause to satisfy the `DISTINCT`/`ORDER BY` rule are all included.
Back to Top