diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-13 13:34:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-13 13:34:15 +0900 |
commit | f5735ff7d470c2174f06407008e9809d8d9c1574 (patch) | |
tree | ebe2e51b7a81dbb7ada509a0fd4b384620ceebae | |
parent | 293401809dc597a61e46843019ee8be6ce731429 (diff) | |
parent | 3499d320d2e616a044b74db86fe4126de783174a (diff) | |
download | rails-f5735ff7d470c2174f06407008e9809d8d9c1574.tar.gz rails-f5735ff7d470c2174f06407008e9809d8d9c1574.tar.bz2 rails-f5735ff7d470c2174f06407008e9809d8d9c1574.zip |
Merge pull request #31425 from chiastolite/optimize_foregin_keys_query
Optimizing information_schema query for `foreign_keys`
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 479131caad..8569c76317 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -403,12 +403,13 @@ module ActiveRecord fk.constraint_name AS 'name', rc.update_rule AS 'on_update', rc.delete_rule AS 'on_delete' - FROM information_schema.key_column_usage fk - JOIN information_schema.referential_constraints rc + FROM information_schema.referential_constraints rc + JOIN information_schema.key_column_usage fk USING (constraint_schema, constraint_name) WHERE fk.referenced_column_name IS NOT NULL AND fk.table_schema = #{scope[:schema]} AND fk.table_name = #{scope[:name]} + AND rc.constraint_schema = #{scope[:schema]} AND rc.table_name = #{scope[:name]} SQL |