Opened 13 years ago
Closed 12 years ago
#18304 closed Bug (fixed)
MySQL generates an unecessary select when updating inherited models
Reported by: | Anssi Kääriäinen | Owned by: | anonymous |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | mysql |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | yes | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | yes |
Description
The reason is in !SQLUpdateCompiler.pre_sql_setup(): it checks if there are multiple tables in the query, and if the backend can't do a self select on update ("update_can_self_select" db feature) the pre_sql_setup will run a query to fetch the pks to update. However, in inheritance cases this leads to queries like:
SELECT U0.`person_ptr_id` FROM `update_only_fields_employee` U0 WHERE U0.`person_ptr_id` = 2
which is non-necessary to run.
The problem was spotted when running update_only_fields tests on MySQL - the test will be skipped on MySQL, but the test_num_queries_inheritance test shows the problem if the skip is removed.
Change History (5)
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
https://github.com/django/django/pull/61 contains an RFC patch.
comment:3 by , 13 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
Needs documentation: | set |
Needs tests: | set |
Patch needs improvement: | set |
UI/UX: | set |
comment:4 by , 13 years ago
Owner: | changed from | to
---|
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Avoided test failure on MySQL by skipping a failing test
MySQL generates an extra query in inheritance cases when doing an update.
This results in a test failure when checking for number of queries in
update_only_fields tests. Added a skip temporarily to avoid this test
failure. Refs #18304.