Opened 3 years ago

Closed 3 years ago

#33017 closed Bug (fixed)

Fix get_storage_engine to only look at current database

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 Matjaz Gregoric)

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.

Change History (4)

comment:1 by Matjaz Gregoric, 3 years ago

Description: modified (diff)

comment:2 by Carlton Gibson, 3 years ago

Triage Stage: UnreviewedAccepted

OK, seems plausible. Let's take it for review. Thanks Matjaz.

comment:3 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

Resolution: fixed
Status: newclosed

In 518ce7a5:

Fixed #33017 -- Fixed storage engine introspection on MySQL.

This also improves performance on MySQL instances with a large number
of databases, since querying the information_schema table can be very
slow

Note: See TracTickets for help on using tickets.
Back to Top