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?

Thanks for the attention.

Here is the sample code:

mapper(Student, table_students, properties={
        'marks': relation(Mark, cascade='all, delete-orphan',
backref='student')
        })
mapper(Subject, table_subjects, properties={
        'marks': relation(Mark, cascade='all, delete-orphan',
backref='subject')
        })
mapper(Mark, table_marks)

[... skip ...]

mark = Mark()
s.save(mark)
mark.student = student_1
mark.subject = subject_1
mark.value = 5
s.flush()

Here is SQL output (shortened a bit for ease of reading):

SELECT * FROM marks WHERE 1 = marks.student_id        <-----
unnecessary select
SELECT * FROM marks WHERE 1 = marks.subject_id         <-----
unnecessary select
BEGIN
INSERT INTO marks (subject_id, student_id, value) VALUES (1, 1, 5)
COMMIT

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to