On 28.02.2006., at 17:37, Michael Bayer wrote:


how many classes do you want to be able to add to this ? doing a giant SELECT that outerjoins many tables, with only one being used for each row, will perform very poorly.

4-5 classes

Yes it would be slow, but I see two alternatives:

1) have a big table which combines all the objects (having a phisical layout similar to the output of the outerjoin (without the foreign keys)
  which is maybe faster
2) generate a new select for every child in order to get the additional attributes (perhaps lazily)

One solution could be doing N selects one for each class and combine the result but would work only for one level of inheritance. For example I assume that there can be instances of Base that are not Persons and Organizations. Combining Persons and Organizations would exclude pure Bases. Including all Base objects will duplicate objects. (this also apply for deeper hierarchies)

Do you mean slow because of sending null values accross the connection or slow doing the select itself?

One possible solution would be to create a select that selects only bases for which there are no related subclass instances but I imagine the overhead would be very similar to the outerjoin in term of index access (still faster because will not send null fields accross the connection).

One of the reasions I need to do that is that with zope3 I can assign particular views/viewlets/adapters with particular classes and exploit inheritance.

anyway, create_instance is not too different from the append_result you already figured out:

class MyExt(MapperExtension):
        def create_instance(self, mapper, row, imap, class_):
                if row['col1'] == 'foo':
                        return Organization(_mapper_nohistory=True)
                else:
                        return Person(_mapper_nohistory=True)

Ah nice.
When I select objects from Person.select() I get the same instance. Is possible to obtain this behaviour using custom object creation?




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to