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:
1. Fetch by table instance -- ~25 seconds
2. Fetch by all table columns (returning NamedTuples) -- ~27 seconds
3. Fetch with cached compiled statements -- ~11 seconds
4. Fetch with cached compiled statements + "faster" populate_instance --
~6 seconds
5. 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 :-)
Chung
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.