for this application, pretty much 100% of the extra time is spent cascading relationships when objects are attached to each other.  when you use the "threadlocal" mod, objects are automatically placed in the session without much need for the cascading.  if you change the add_property lines to this:

T1.mapper.add_property( 't2s', relation(T2, backref=backref("t1", cascade=""), cascade=""))
T2.mapper.add_property ( 't3s', relation(T3, backref=backref("t2",cascade=""), cascade="") )
T3.mapper.add_property( 't4s', relation(T4, backref=backref("t3", cascade=""), cascade="") )

you get performance about the same as in version 0.1.7.

ill see if theres some more things I can do in that area.


On Jun 7, 2006, at 10:38 PM, Robert Taylor wrote:

import sqlalchemy.mods.threadlocal
from sqlalchemy import *

dbEngine = create_engine('postgres://[EMAIL PROTECTED]:5432/mydb')
metadata = BoundMetaData(dbEngine)

t1s = Table( 't1s', metadata,
    Column( 'id', Integer, primary_key=True))

t2s = Table( 't2s', metadata,
    Column( 'id', Integer, primary_key=True),
    Column( 't1id', Integer, ForeignKey("t1s.id"), nullable=True ))

t3s = Table( 't3s', metadata,
    Column( 'id', Integer, primary_key=True),
    Column( 't2id', Integer, ForeignKey("t2s.id"), nullable=True ))

t4s = Table( 't4s', metadata,
    Column( 'id', Integer, primary_key=True),
    Column( 't3id', Integer, ForeignKey("t3s.id"), nullable=True ))

class T1( object ): pass
class T2( object ): pass
class T3( object ): pass
class T4( object ): pass

assign_mapper( T1, t1s )
assign_mapper( T2, t2s )      
assign_mapper( T3, t3s )      
assign_mapper( T4, t4s )      

T1.mapper.add_property( 't2s', relation(T2, backref="t1"))
T2.mapper.add_property ( 't3s', relation(T3, backref="t2"))
T3.mapper.add_property( 't4s', relation(T4, backref="t3"))

metadata.drop_all()
metadata.create_all()

print "start"       
o1 = T1()
for i2 in range(10):
    o2 = T2()
    o1.t2s.append( o2 )
   
    for i3 in range( 10 ):
        o3 = T3()
        o2.t3s.append( o3 )
       
        for i4 in range( 10 ):
            o3.t4s.append ( T4() )
            print i2, i3, i4
           
print "flushing"
objectstore.flush()

print "done"

_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to