#9136: Oracle backend: slicing is using row_number() instead of rownum
----------------------------------------------------------------------+-----
 Reporter:  Guillaume Taglang <[EMAIL PROTECTED]>  |       Owner:  nobody    
   Status:  new                                                       |   
Milestone:            
Component:  Database layer (models, ORM)                              |     
Version:  1.0       
 Keywords:                                                            |       
Stage:  Unreviewed
Has_patch:  0                                                         |  
----------------------------------------------------------------------+-----
 Doing Entity.objects.all()[:10] is generating a query like:
 {{{
 SELECT *
 FROM   (SELECT (ROW_NUMBER() OVER (ORDER BY "ENTITY"."ID")) AS "_RN",
                "ENTITY"."ID", "ENTITY"."NAME"
         FROM   "ENTITY")
 WHERE  "_RN" > 0
 AND    "_RN" <= 10
 }}}
 This is suboptimal as a full table scan is forced (at least in 10g).
 Using ''rownum'' instead of ''row_number()'' is faster (it can use
 indexes), and doesn't require an ''order by'' clause when not required.
 The query would look like:
 {{{
 SELECT   "ENTITY"."ID", "ENTITY"."NAME"
 FROM     "ENTITY"
 WHERE    ROWNUM > 0 AND ROWNUM <= 10
 ORDER BY "ENTITY"."ID"
 }}}
 It won't make a noticeable difference with tables with a couple of rows;
 but when you are reaching the million rows, you go from minutes to
 milliseconds.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9136>
Django <http://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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to