Creating redundant indexes on foreign keys for MySQL/InnoDB tables
During adding a foreign key contraint on InnoDB table, index is created automaticaly if it doesn't exist.
(MySQL 5.x manual)
"InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist. (This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail.)"
After adding FK constraint, Django creates index for every FK, which just "overwrites" index that was created in background by InnoDB engine.
It's a waist of time. It's not a big deal if you just run syncdb, but if you run unit tests waiting every time for those indexes be created is a bit annoying.
Change History
(10)
Triage Stage: |
Unreviewed → Someday/Maybe
|
Severity: |
→ Normal
|
Type: |
→ Cleanup/optimization
|
Component: |
ORM aggregation → Database layer (models, ORM)
|
Easy pickings: |
unset
|
Triage Stage: |
Someday/Maybe → Accepted
|
Has patch: |
set
|
Version: |
1.2 → master
|
Patch needs improvement: |
set
|
Patch needs improvement: |
unset
|
Triage Stage: |
Accepted → Ready for checkin
|
Owner: |
set to Claude Paroz <claude@…>
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
Any patch for this would have to include a way to auto-detect whether an appropriate engine is being used by MySQL to require indexing (InnoDB is only one of many storage engines MySQL supports). It's not something people should be required to specify in settings or anything like that.