On Apr 14, 2011, at 5:07 PM, Chung wrote: > Thanks Michael! Re: the heavy get() workload, that's a neat trick :-) > Unfortunately for our workload, we don't really know which set of gets() are > going to fire, and we can't fit the entire table into memory. > > > > > I was curious about whether passing in fields instead of tables into Query > and getting NamedTuples back would be more efficient. I ran some (not too > rigorous) benchmarks to perform 3000 "gets" to retrieve all columns. The > table has 77 columns. I'm using 0.6.6. Results: > Fetch by table instance -- ~25 seconds > Fetch by all table columns (returning NamedTuples) -- ~27 seconds > Fetch with cached compiled statements -- ~11 seconds > Fetch with cached compiled statements + "faster" populate_instance -- ~6 > seconds > Fetch with cached compiled statements + "faster" populate_instance + cached > ResultMetaData -- ~3.4 seconds > So I imagine that getting NamedTuples back is really only cheaper if we also > select fewer columns (which we don't want to do at the moment). > > The BakedQuery recipe is interesting, though it'd require us to go through > the same Query instance whenever we want to issue a similar query. For us, > we've created a TextualQuery which allows something like this: > > session.query(Table).textual('where id=:id and createddate > :createddate', > id=id, createddate=date) > > The textual() method essentially turns the query into a Query.from_statement > query, and we use a session-wide cache for mapping textual query strings to > statement instances, as well as a session-wide compiled_cache. The reason > why we used query strings is just that we need to make sure we use the same > statement instance for the same query, and we feel safer comparing these > strings than figuring out when two Query objects are equivalent :-)
well that recipe is a scratch idea - i think you could likely adapt it so that bake() or whatever is passed a string that pulls up something that's cached (like even the Query object itself that's baked). I want to try to have it cache the whole QueryContext, or some section of it, as well. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.