On Nov 18, 2007, at 4:54 PM, Anton V. Belyaev wrote:
> > Hello all, > > I am building a grading system for students and got unexpected > performance problems. I am using composite key for marks, which refer > to students and subjects. > > When I am creating a mark (for student_1 and subject_1), unnecessary > select operations are performed (select all marks for student_1 and > select all marks for subject_1). > > Why these selects are generated and how to avoid them? > The SQL issue looks like the "marks" collections on Student and Subject issuing a lazyload for their full collection of Mark items before the backref event appends the Mark object to each of them, i.e. the event that occurs when you issue "mark.student = subject_1". Ordinary collections currently don't handle being present in a "partial" state, so in order for an append to occur, they load their contents. As a workaround, you can use "lazy=dynamic" relations for the collections, which is a special relation that can handle append operations without the full collection being available. "lazy=noload" would work as well but then you couldn't read from your collections. A future release may look into merging some of the "dynamic" relation behavior into an ordinary un-loaded collection so that this workaround would not be needed. Actually this might not be a bad idea for 0.4.2, so ive added ticket #871. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
