diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 182460d4d8..ff9a368178 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Fixed the performance regression for `primary_keys` introduced MySQL 8.0. + + *Hiroyuki Ishii* + * Add support for `belongs_to` to `has_many` inversing. *Gannon McGibbon* 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 7737aa488d..c03def9106 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -433,11 +433,11 @@ module ActiveRecord query_values(<<~SQL, "SCHEMA") SELECT column_name - FROM information_schema.key_column_usage - WHERE constraint_name = 'PRIMARY' + FROM information_schema.statistics + WHERE index_name = 'PRIMARY' AND table_schema = #{scope[:schema]} AND table_name = #{scope[:name]} - ORDER BY ordinal_position + ORDER BY seq_in_index SQL end