On Thu, 2006-07-20 at 17:34 -0400, Dan Hristodorescu wrote:
> Hi Ivan,
> 
> I looked in the code and it seems that QuerySet class needs some
> serious refactoring to support MSSQL paging.
> For SQL 2005 the SQL string should look like this:
> 
> WITH myTable AS
> (SELECT fields, ROW_NUMBER() OVER (order by orderclause) AS RowNumber
> FROM table) 
> SELECT * FROM myTable 
> WHERE RowNumber between offset AND offset+limit
> 
> and for SQL 2000 should look like this:
> 
> SELECT fields FROM table
>         WHERE primary key IN
>             (SELECT TOP limit primary_key FROM table 
>                 WHERE primary_key NOT IN
>                     (SELECT TOP offset primary_key FROM table
>                         WHERE filter_conditions
>                         ORDER BY sort_field)
>                 AND filter_criteria 
>                 ORDER BY sort_field)
>         ORDER BY sort_field
>         
> And with join tables it looks completely crazy (I've only used it
> using DISTINCT with joins), but that's the optimal way to do.
> 
> A proper implementation should consider both cases since the
> ROW_NUMBER in SQL 2005 is the native implementation and it's a lot
> faster.
> I'll start working on it although during the process I might need
> feedback from Django lead developers since I'm trying to refactor a
> core class. 
> I wouldn't want the patch to be rejected in the end.

Heads up: that file (django/db/models/query.py) is undergoing a bit of a
rewrite at the moment (as per [1]), so you may wish to hold off for a
little while until its done. Or maybe just keep charging ahead and
backport in the near future. Anyway, just letting you know in case you
hadn't noticed this.

[1]
http://groups.google.com/group/django-developers/browse_frm/thread/1026181083385c58/08f0d7258c0659af?lnk=gst&q=freeze&rnum=1#08f0d7258c0659af

Regards,
Malcolm




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to