Performance Issues of MySQL with Python

Andy Dustman farcepest at gmail.com
Thu Feb 10 20:08:04 EST 2005


There aren't any "issues", but there are a few things to keep in mind.

First of all, prior to 4.1, MySQL does no parameter binding, which
means that the parameters must be inserted into your SQL statements as
literals. MySQLdb will do this for you automatically, but keep in mind
that you will be creating a string that is big as your original SQL
statement plus the size of all the parameters. If you are doing a large
INSERT (via executemany()), this could be pretty big. However, this is
no worse a problem with Python than it is with anything else.

MySQL-4.1 *does* support parameter binding, but MySQLdb does not yet.
The next major release will, but that is months off.

The other factor to account for is your result set. By default, MySQLdb
uses the mysql_store_result() C API function, which fetches the entire
result set into the client. The bigger this is, the longer it will take
for your your query to run. You can also use a different cursor type
which uses mysql_use_result(), which fetches the result set row by row.
The drawback to this are that you must fetch the entire result set
before you can issue another query. But again, this is not an issue
with Python.

Make sure you read PEP-249 and then the User's Guide.




More information about the Python-list mailing list