django/django — pull request #3669 by akaariai (2014-12-03 07:29:47+00:00)
Title: [WIP] Use expressions inside the compiler; refactor select_related() implementation

This pull requests does two important changes to the ORM:
1) The ORM uses internally expressions. SELECT clauses are expressions, ORDER BY clauses are expressions and so on. The conversion to expressions is currently done in the compiler to keep the scope of the
patch somewhat manageable.
2) The way select_related() queries are implemented is refactored. The compiler sets up the query, and the QuerySet iterator() uses the data generated by the compiler. Previously both the compiler and the iterator calculated the select columns which resulted in a bad DRY violation (not to mention the old get_cached_row()/get_klass_info() code was extremely ugly). The new way is 30% faster on djangobench query_select_related tests.

I had to touch the way database converters are implemented. Nothing drastic has changed in there.

What works currently:
- tests pass on SQLite and PostgreSQL. They likely fail on Oracle

What needs to be done:
- refactor gis. It should be possible to get completely rid of gis Compiler classes, and significantly improve the way gis QuerySet is implemented. There is a lot of work to do as we have to effectively rewrite gis to use expressions.
- fix remaining failures on non-gis backends
- check if the patch can be splitted to more manageable chunks