Hey all,

We were wondering if you had any advice on having a large (~10) number of 
polymorphic subclasses for a single base class. Using with_polymorphic: '*' 
causes SQLAlchemy to joinedload all subclasses like this:

SELECT ...
FROM base_table
LEFT OUTER JOIN sub_table_1 ON base_table.id = sub_table_1.id
LEFT OUTER JOIN sub_table_2 ON base_table.id = sub_table_2.id
...

Postgres buckles under too many joins, and these queries start taking a 
really long time.

One other note is that for most of our queries, only a few of these 
sub-tables are actually needed, so most of the joins are wasted. 
Unfortunately, ahead of time, we don't know which tables will be needed -- 
we're relying on the discriminator.

Ideally, we'd be able to specify that the ORM should subqueryload the 
subclasses (and only execute subqueries on the types that are present). 
This would have to happen both when querying the base table, but also when 
accessing relationships. We'd want it to execute a query on the base table, 
then execute one query for each present subclass.

Another solution might be to use some kind of hook that

- is executed after a query returns with results (or after a list of models 
are added to the session?)
- groups the models by type and runs its own subqueries to load the data

Any help here is greatly appreciated!


Thanks,
Damon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to