Opened 18 years ago
Last modified 17 years ago
#2306 closed defect
Many-to-many queries very slow on MySQL 3.23.58 — at Version 4
Reported by: | anonymous | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | normal | Keywords: | qs-rf-fixed |
Cc: | mir@…, freakboy3742@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
We have a MySQL 3.23.58 database with about 1000 Room and Photo objects, connected by a many-to-many relationship.
Given a room r, asking Django to evaluate r.photos.all() runs an explicit join:
SELECT `kords3_photo`.`id`,`kords3_photo`.`image` FROM `kords3_photo` LEFT OUTER JOIN `kords3_room_photos` AS `m2m_kords3_photo__room` ON `kords3_photo`.`id` = `m2m_kords3_photo__room`.`photo_id` WHERE (`m2m_kords3_photo__room`.`room_id` = 1) ORDER BY `kords3_photo`.`image` ASC
which takes around 1 second, when the same query rewritten as an implicit join:
SELECT `kords3_photo`.`id`,`kords3_photo`.`image` FROM `kords3_photo` , `kords3_room_photos` WHERE `kords3_photo`.`id` = `kords3_room_photos`.`photo_id` AND `kords3_room_photos`.`room_id` = 1 ORDER BY `kords3_photo`.`image` ASC
would take under a millisecond.
Change History (4)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
comment:3 by , 18 years ago
Cc: | added |
---|
comment:4 by , 18 years ago
Description: | modified (diff) |
---|---|
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
OK, why the heck is Django doing an outer join? This is upsetting. Thanks for pointing this out.