Opened 3 years ago
Last modified 3 years ago
#33017 closed Bug
Fix get_storage_engine to only look at current database — at Version 1
Reported by: | Matjaz Gregoric | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 3.2 |
Severity: | Normal | Keywords: | MySQL |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
https://github.com/django/django/pull/14766
When querying the information_schema.tables for the storage engine, we have to specify table_schema in addition to table_name, otherwise the query returns a list of results for all tables with the specified name from every database in the system. If there are multiple tables with the same name but using different storage engines present in different databases in the MySQL instance, the query could return a wrong result.
We have to limit the query to the current database to make sure we get the correct result.
This also improves performance on MySQL instances with a large number of databases, since querying the information_schema table can be very slow.
The get_storage_engine function that this patch fixes is invoked when adding columns during migrations to determine whether it should index the column. We have a MySQL instance with over a thousand databases in production and this patch has cut down the time it takes to run a specific set of django migrations from 2 hours to around 15 minutes.