Opened 19 years ago

Closed 19 years ago

Last modified 17 years ago

#243 closed defect (invalid)

lack of ordering the get_list() params

Reported by: maurycy Owned by: Adrian Holovaty
Component: Metasystem Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The next ticket with only IRC discussion. Feel free to post the comment, before closing, jackob. :-)

08:16 < maurycypw> btw. one question. do kwargs support ordering params? let's
                   say i'd like to write: SELECT * FROM table WHERE a = 'b' AND
                   = c = 'd' with the exactly the same order
08:16 < maurycypw> is it possible?
08:16 < rmunn> I don't think so. kwargs just shove everything into a standard
               dict.
08:17 < maurycypw> if i understand correctly, get_list() based on kwargs with
                   get_list(a__exact='b', c__default='d') would generate where
                   in the random manner
08:17 < rmunn> You could do tricks with naming your params like
               _01__a__exact='b', _02__c__exact='d', but that's hideous. :-)
08:17 < maurycypw> ugh
08:17 < rmunn> Right -- standard dicts make no guarantees about what order
               their keys will be in.
08:17 < maurycypw> it's quite ineffective, because sometimes the order of where
                   params could save the database time and short the query
                   execution time
08:18 -!- paolo [~wazzawazz@194-185-91-251.f5.ngi.it] has joined #django
08:18 < rmunn> People have written classes that inherit from dict and guarantee
               key order, but I don't know of any way to make Python's kwargs
               use anything but the standard dict class.
08:18 < maurycypw> in other hand, currently it's impossible to create efficient
                   complicated get_list() queries.
08:19 < maurycypw> what about you talking is a ugly hack, it should be bult-in
                   and supported by django by default
08:19 < rmunn> Perhaps you could add a keyword parameter
               clause_order=['a__exact', 'b__exact']
08:19 -!- rmunn [~rmunn@patk.mylinuxisp.com] has quit [Remote closed the
          connection]
08:20 < maurycypw> :)
08:20 < maurycypw> looks more reasonable. i'll fill the ticket.

Change History (2)

comment:1 by Jacob, 19 years ago

I'm under the impression that order doesn't matter in WHERE clauses; doesn't the query optimizer take care of ordering the WHERE clauses efficiently? In playing around with some complicated queries, I can't seem to find any case where there's a difference between SELECT ... WHERE <clause a> AND <clause b> and SELECT ... WHERE <clause b> AND <clause a>

comment:2 by Adrian Holovaty, 19 years ago

Resolution: invalid
Status: newclosed

Please post an example of a realistic query in which the order of the WHERE clauses matters, with proof from the query analyzer, and reopen the ticket if you indeed find one.

I'll tell you right now, though: This really isn't worth adding the complexity. And you can always write custom queries using custom methods on your model, if you want fine-grained control over the order of your WHERE clauses.

Note: See TracTickets for help on using tickets.
Back to Top