On Feb 6, 2014, at 12:34 PM, Rick Otten <rottenwindf...@gmail.com> wrote:

> Hello,
> 
> I'm using SQLAlchemy 0.8.4 with PostgreSQL 9.3.  I have a situation where I 
> need to run the same set of queries millions of times in one session.  

After sending that, I just read the words “same set of queries millions of 
times in one session”.  That raises a red flag for me.   If it were me and I 
had to pull millions of rows from a database I’d be looking for ways to SELECT 
lots of rows at once, in batches.    Millions of individual queries with no 
option for batching suggests that each subsequent query somehow relies upon the 
results of the previous one, which would be a pretty exotic case in itself but 
I still might see if a more advanced feature like window functions can be used 
to help with that (a window function lets you write criteria against the rows 
that have already been returned thus far).

That said, if you truly need to run millions of queries, you might want to 
consider using psycopg2 directly, or at best you’d use only SQLAlchemy Core (no 
ORM) and probably make use of the compiled_cache feature (see 
http://docs.sqlalchemy.org/en/rel_0_9/core/connections.html?highlight=execution_options#sqlalchemy.engine.Connection.execution_options.params.compiled_cache).
     It’s going to be a time consuming operation in any case.






Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to