I've been discussing this idea for some time now, and was reminded of it
recently... and akaariai has pushed me to put forward this proposal.

Prepared Statements.

The benefit of prepared statements, for those who don't know, is it avoids
repeating the time the Query Planner in the DBMS takes to figure out how it
will execute the query.  This can sometimes be quite a significant portion
of the query execution time.

API:

My idea includes two new classes, and one new queryset method.

One class is a handle for a prepared statement, which is a callable
accepting all the bound parameters of the prepared statement.

The other is used for denoting bound parameters in QuerySet construction -
so far we've been calling this Param.

The new QuerySet method would be something like "prepare", which returns a
prepared statement class.

So, a sample of constructing a prepared statement would be:

ps = MyModel.objects.filter(foo__lt=Param('a').prepare()

The result is now a callable that accepts one parameter - "a".  To invoke
the query:

results = ps(a=1000)


Clearly it's early days yet - I've written no code.  And akaariai has
pointed out already there's some corners cases which won't work well with
existing behaviours (e.g. foo=None being silently translated to
foo__isnull=True), but it's best to get this idea under wider public
scrutiny earlier, rather than later.

--
C

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAG_XiSCtzeA%2BzcMqLatJi2Vnabbsi2okO_6UXvVExdCEnLKCXA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to