Antoine Pitrou wrote: > Hello, > >> just in case you're not motivated to share mappings here, I would note >> that an incorrect placement of a >> flag like "remote_side" on a relation() may be causing this. > > I would have to produce anonymized mappings, but I will do so if it's > useful. What do you mean by "incorrect placement of a flag like > `remote_side`"? I do have one (exactly one) relation with a > `remote_side` flag, but the class it is defined on isn't involved in > the script I have timed here. (it is on a recursive relation)
if its "backwards" versus a backref that is also present, it can create an overly complex dependency chain. > >> yet another thought, which again reveals how much easier this would be >> with some sample code - >> if you're in a loop that is calling query(), then changing things, then >> around again, you may have >> excessive triggering of autoflush going on, which also can result in >> lots of _save_obj() calls. Set the >> "autoflush" flag on your Session to be false, which you can do >> temporarily within a particular section or >> across the whole session. Calling commit() will issue a flush(), or >> alternatively you can call flush() every >> few thousand new records. > > Ah, a very useful tip. Setting autoflush to False does speed up things > quite a bit (a sample run of the script is 2x faster). > I haven't found how to enable it temporarily, though. I'm using a > ScopedSession instance and if I call `db_session.configure > (autoflush=False)`, or set the autoflush attribute, autoflushing still > happens. An example: the configure only takes effect for the next session created. so if you said Session.remove(); Session.configure(); Session(), that would do it. Easier for this is to hit the flag directly: Session().autoflush = False > >>>> db_session > <sqlalchemy.orm.scoping.ScopedSession object at 0x2e467d0> >>>> db_session.autoflush = False >>>> lg = db_session.query(Logement)[0] > [ SNIP long SELECT ] >>>> lg.tel1 = "abc" >>>> db_session.query(Zone)[0] > 2009-12-17 00:11:35,161 INFO sqlalchemy.engine.base.Engine.0x...c550 > UPDATE logement SET date_modif=%s, tel1=%s WHERE logement.id_logement > = %s > 2009-12-17 00:11:35,162 INFO sqlalchemy.engine.base.Engine.0x...c550 > [datetime.datetime(2009, 12, 17, 0, 11, 35, 161436), 'abc', 4L] > 2009-12-17 00:11:35,167 INFO sqlalchemy.engine.base.Engine.0x...c550 > SELECT zone.id_zone AS zone_id_zone, zone.cp AS zone_cp > FROM zone > LIMIT 0, 1 > 2009-12-17 00:11:35,168 INFO sqlalchemy.engine.base.Engine.0x...c550 > [] > <xxx.Zone object at 0x3309150> >>>> > > (as you see, an UPDATE is issued before the SELECT for the query) > > Regards > > Antoine. > > -- > > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.