#33768: MySQL ordering of nulls last/first is broken in combination with UNION
-------------------------------------+-------------------------------------
     Reporter:  Florian Apolloner    |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * cc: Simon Charette (added)


Comment:

 What if we performed a subquery pushdown instead to make compilation more
 predictable so we can have the order by clause refer to the union columns
 by name?

 {{{#!sql
 SELECT `other_num`
 FROM (
     (SELECT `queries_number`.`other_num` FROM `queries_number` WHERE
 `queries_number`.`num` <= 1)
     UNION
     (SELECT `queries_number`.`other_num` FROM `queries_number` WHERE
 `queries_number`.`num` >= 2)
 )
 ORDER BY `other_num` IS NULL
 }}}

 This is a strategy that is used successfully for aggregation for example.
 I don't see `OrderBy.as_sql` usage of `template` for compilation is an
 abuse at all; it's in charge of it's own compilation unit. As mentioned on
 #33767 I'd prefer if we errored out on constant order by usage instead of
 making leaps to support it because it has ambiguous evaluation rules.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33768#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070181363ccb00-c84b9b38-ffa3-4fba-a43e-cb7cb8a7659f-000000%40eu-central-1.amazonses.com.

Reply via email to