On Jun 18, 2009, at 11:09 AM, Daniel wrote:
>
> Hi list!
>
> It's been a long time since I've posted here. SA is still the best
> Python ORM; thanks for all your hard work Mike!
>
> Now, the question. I've got a set of related entities:
>
> Order (has items)
> Item (has attributes)
> Attribute
>
> I am working on optimizing the loading and have run into a situation
> that I can't figure out how to make SA optimize. Here's the scenario:
>
> First I load the order (1 query)
> Next I load the related items (1 query)
> Next I load the related attributes for each item (1 query for each
> item)
>
> I have tried eager loading (i.e. setting lazy=False on the
> item.attributes relationship), but that generates a HUGE result set
> that takes MUCH longer to load than loading the attributes
> individually for each item as listed above.
>
> What I'd like to have SA do is do a single query to load all
> attributes for all items of the order when the first item's attributes
> are requested. Here's the revised scenario from above:
>
> First I load the order (1 query)
> Next I load the related items (1 query)
> Next I load the related attributes for each item (1 query loads all
> attributes for the entire order)
>
> Is this possible or do I have to roll my own extension to orm.relation
> (actually orm.properties.PropertyLoader) ? -- that doesn't look very
> fun.
I dont really understand the case here.
a query that loads all attributes for the entire order would
necesssarily return just as many rows as the original query using an
eager load. if the order had 5 related items, and each item had 10
attributes, its 50 rows. the phrase "1 query loads all attributes
for the entire order" would be loading the same 50 rows. So i dont
see how the result set is "HUGE" in one case and not the other
(assuming HUGE means, number of rows. if number of columns, SQLA
ignores columns for entities which it already has during a load).
Normally, if you wanted the attributes to eagerload off the related
items, but not from the order, you would specify eagerloading on only
those attributes which you want eagerloaded.
query(Order).options(eagerload("items", "attributes"))
the above will set up order.items.attributes as an eagerload, but
nothing else. it sounds like you already did this. So i dont
really understand the problem.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---