-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
foreign_key_info is un-optimized for large sets of databases #326
Comments
The code could include JOINs to fill in the NULL gaps in the SELECT clause, but those JOIN statements would need to apply the filters directly in order to get the EXPLAIN plan benefit. This is because MySQL 5's implementation of filtering is rather kludgy and doesn't take advantage of the optimizer. For example:
Not Anyway, I can provide a PR if you like. |
The code for this can be found here: Lines 624 to 705 in 5a669fb
@SineSwiper would you be interested in submitting a PR to improve this? Also MySQL 8.0 switched to an InnoDB based data dictionary, which improves performance for at least some information_schema queries (see also https://dev.mysql.com/blog-archive/mysql-8-0-scaling-and-performance-of-information_schema/ ). This may or may not improve the performance of the queries mentioned here. Maybe someone could run some tests to benchmark the performance of the original query vs a modified one and with various MySQL major versions? |
Due to the way MySQL 5 supports
information_schema
, the SQL statement used forforeign_key_info
requires a full scan of all databases. This can break servers in environments with a large amount of databases (literally die from an OOM), or take a long time to complete in the best case. Even with filters forkey_column_usage.constraint_schema
, thetable_constraints
scan isn't filtered properly and results in an EXPLAIN plan like this:So, for table
B
, the optimizerScanned all databases
, which is bad. Thetable_constraints
inclusion is unnecessary, anyway, since all foreign/unique/PK data is available inkey_column_usage
. Better to just take out the problematic join, and fix the optimization problem at the same time.The text was updated successfully, but these errors were encountered: