Sqlite3. Substitution of names in query.

Carsten Haese carsten.haese at gmail.com
Tue Nov 3 14:19:10 CET 2009


Lawrence D'Oliveiro wrote:
> In message <mailman.2504.1257216390.2807.python-list at python.org>, Carsten 
> Haese wrote:
> 
>> With all due respect, but if your experience is exclusive to
>> MySQL/MySQLdb, your experience means very little for database
>> programming practices in general.
> 
> I wonder about the veracity of your claims, because:
>
>> And here are the corresponding results on my laptop:
>> $ python -mtimeit -s "from querytest import Tester; t=Tester()"
>> 't.with_params()'
>> 10000 loops, best of 3: 20.9 usec per loop
>> $ python -mtimeit -s "from querytest import Tester; t=Tester()"
>> 't.without_params()'
>> 10000 loops, best of 3: 36.2 usec per loop
> 
> Didn't you say previously that there should be a "seven orders of magnitude" 
> difference? What happened to that claim?

"That claim" was an exaggeration I resorted to after you distorted the
concept of choosing the right tool for the job into premature
optimization. It wasn't my initial claim.

The "seven orders" (which is actually log-10 orders of however often the
same query is executed with different values) is of course only the cost
increase on parsing the query itself, which as you pointed out is
drowned out by other fixed costs associated with performing database
queries. However, you can't dispute the fact that using string
interpolation *is* in general less efficient than parameter binding, and
that was my initial claim.

--
Carsten Haese
http://informixdb.sourceforge.net




More information about the Python-list mailing list