You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AbstractMySQLPlatform::getListTableForeignKeysSQL is significantly slower than 3.2 because it introduces an inefficient join between INFORMATION_SCHEMA.KEY_COLUMN_USAGE and INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS in mysql 5.7.
This problem does not manifest in smaller databases since size of the two tables is relatively small.
select k.CONSTRAINT_NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME /*!50116 , c.UPDATE_RULE, c.DELETE_RULE */
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE k /*!50116 INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c ON c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND c.TABLE_NAME = k.TABLE_NAME AND c.CONSTRAINT_SCHEMA = k.CONSTRAINT_SCHEMA */
where k.TABLE_NAME = 'foo' and k.TABLE_SCHEMA = 'bar' order by k.ORDINAL_POSITION
Execution time: ~800ms
Explain
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
------ ----------- ------ ---------- ------ ------------- ----------------------- ------- ------ ------ -------- --------------------------------------------------------------------------------------------
1 SIMPLE k (NULL) ALL (NULL) TABLE_SCHEMA,TABLE_NAME (NULL) (NULL) (NULL) (NULL) Using where; Open_full_table; Scanned 0 databases; Using temporary; Using filesort
1 SIMPLE c (NULL) ALL (NULL) (NULL) (NULL) (NULL) (NULL) (NULL) Using where; Open_full_table; Scanned all databases; Using join buffer (Block Nested Loop)
Expected behavior
Moving the table name back into the join (as was in 3.2) fixes the issue
select k.CONSTRAINT_NAME, k.COLUMN_NAME, k.REFERENCED_TABLE_NAME, k.REFERENCED_COLUMN_NAME /*!50116 , c.UPDATE_RULE, c.DELETE_RULE */
from INFORMATION_SCHEMA.KEY_COLUMN_USAGE k /*!50116 INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS c ON c.CONSTRAINT_NAME = k.CONSTRAINT_NAME AND c.TABLE_NAME = 'foo' AND c.CONSTRAINT_SCHEMA = k.CONSTRAINT_SCHEMA */
where k.TABLE_NAME = 'foo' and k.TABLE_SCHEMA = 'bar' order by k.ORDINAL_POSITION
Execution time: ~5ms
Explain
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
------ ----------- ------ ---------- ------ ------------- ----------------------- ------- ------ ------ -------- -----------------------------------------------------------------------------------------
1 SIMPLE k (NULL) ALL (NULL) TABLE_SCHEMA,TABLE_NAME (NULL) (NULL) (NULL) (NULL) Using where; Open_full_table; Scanned 0 databases; Using temporary; Using filesort
1 SIMPLE c (NULL) ALL (NULL) TABLE_NAME (NULL) (NULL) (NULL) (NULL) Using where; Open_full_table; Scanned 1 database; Using join buffer (Block Nested Loop)
While the two queries are logically equivalent, the optimizer is hinting at something different via scanned all database vs scanned 1 database.
The text was updated successfully, but these errors were encountered:
Bug Report
Summary
AbstractMySQLPlatform::getListTableForeignKeysSQL
is significantly slower than3.2
because it introduces an inefficient join betweenINFORMATION_SCHEMA.KEY_COLUMN_USAGE
andINFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
in mysql 5.7.This problem does not manifest in smaller databases since size of the two tables is relatively small.
Current behavior
Here is the
3.3
SQLWith a sample query
Execution time: ~800ms
Explain
Expected behavior
Moving the table name back into the join (as was in
3.2
) fixes the issueExecution time: ~5ms
Explain
While the two queries are logically equivalent, the optimizer is hinting at something different via
scanned all database
vsscanned 1 database
.The text was updated successfully, but these errors were encountered: