Version 4 (modified by 17 years ago) ( diff ) | ,
---|
The queryset-refactor branch
This branch contains a major refactoring of the django.db.models.query.QuerySet
class to fix a group of SQL problems and make SQL generation easier for database backends requiring customization.
How to get the branch
svn co http://code.djangoproject.com/svn/django/branches/queryset-refactor
See our branch policy for full information on how to use a branch.
Status
Branch was created on 13 September, 2007.
At the moment, the branch is fairly unusable. All the tests pass, but there are a lot of other places in the code that attempt to construct SQL fragments and pass them around and they will tend to break.
The focus right now is on correctness, but some significant performance profiling and tuning will need to be done. Current performance is quite a bit slower than the existing code. The good news here is that there are some obvious places to speed things up and, no doubt, some unobvious as well once we get to that point. An optimisation pass is still some way off at the moment; getting all the relevant bugs fixed is the current focus.
Tickets of interest for this branch are marked with qs-rf (and qs-rf-fixed when fixed) in the keywords field in Trac. This report shows all the tickets being worked on (To view qs-rf with the qs-rf-fixed tagged tickets, view this report).
Changes introduced on the branch
A few backwards incompatible changes are created by the changes in this branch. Most people won't be affected by many of these, and porting code is reasonably straightforward.
- The
Options.get_order_sql()
method is now gone indjango.db.models.options
. There appears to be no use for this method any longer. - Ordering querysets across related models has a new syntax that is the same as the way you specify relations in a filter:
field1__field2__field3
, etc. Previously, you had to specify the database table name and the model field name, separated by a period. This led to some problems with multiple joins, as well as requiring you to remember the database table name, which depended on things like the application name. The new syntax is more natural and consistent, as well as helping solve a few bugs. See theorder_by()
documentation in db-api.txt for more information and some examples. Q
objects have changed internally. This is only relevant if you have created custom Q-like objects. You would have created aget_sql()
method that returned a data structure that was inserted into the query. In the new code, you create aadd_to_query()
method that accepts one argument -- thedjango.db.models.sql.query.Query
instance for the current query. Your Q-like object can then add to the various attributes of this class (select
,where
, etc) to have whatever effect it likes on the result. Note that theadd_to_query()
method is called when the object is added to theQuery
object and more changes may be made before it is turned into SQL and executed against the database.