On Aug 17, 12:41 pm, matiskiva <mati.sk...@mobileye.com> wrote:
> The problem being that i get a huge SQL statement with [effectively]
> two joins, where the sequences and rects are joint to the detections.
> It is very slow and creates extra data [as for every rect there is
> also an occurance of sequence and so on]
> The best thing to do is to perform an eager load of rects. Than in a
> seperate statement an eager load of sequences and attach them to the
> entities
> But i do not know how to instruct SQL Alchemy to do that. Generally it
> seems that the power of multiple queries and temporary tables is not
> used much.

Yeah, two to-many eagerloads effectively generate a cartesian product
that can get slow pretty fast with increasing number of entities.
SQLAlchemy doesn't have enough information to figure out the correct
strategy automtically and no-one has had the time to implement an API
to create multi step queries.
You can still do that manually:
detections = query.options(eagerload('sequences')).all()
session.query(DetectionDB).filter(DetectionDB.id.in_([d.id for d in
detections])).options(eagerload('rects'))
This will populate the eagerloaded collections in two queries.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to