On Wed, Apr 3, 2013 at 5:47 PM, Michael Bayer <mike...@zzzcomputing.com>wrote:
> > the Python DBAPI doesn't have an explicit concept of a "prepared > statement" - the idea of preparing a statement involves that a statement > handle is established on the database server, which can then be reused. > The closest the DBAPI has is the "executemany()" call, which gives the > DBAPI itself the option of using a prepared statement behind the scenes; > but this option is not appropriate for SELECT statements since > executemany() doesn't support the return of results. > This is what I was looking for. It looks like pysqlite does it internally. > On the Python SQL construction side, SQLAlchemy deals with expression > constructs that are converted to strings given a database dialect as well > as compilation options. The amount of time in Python spent for this > compilation is relatively small and has been optimized for many years to be > as fast as possible. Nevertheless, in some cases we do try to squeeze more > performance out by caching the compiled form of these queries; the ORM in > particular will cache the compiled form of insert/update/delete statements > that are used by the unit of work. > > Right now, the string form of SELECT queries generated by the ORM are not > automatically cached. It's only worthwhile to try to cache queries that > are "fixed", such as the get() query we're referring to here as well as > some of the queries used by lazyloading of relationships. The overhead of > this compilation however is fairly minimal; reddit.com uses SQLAlchemy > expression constructs for all database queries as well, and they serve well > over two billion page views a month without any caching of the expression > string. > In my case the performance boost was 30%. I have very few queries, but pretty big loops, so compiling them in advance(outside of loop) gave me a significant gain. > There's a recipe to make use of the compiled_cache in conjunction with the > Query object right now, which is at > http://www.sqlalchemy.org/trac/wiki/UsageRecipes/BakedQuery . > Thank you! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.