Skip to content

Commit 8297f8a

Browse files
committed
Merge pull request rails#37465 from alpaca-tc/optimize_primary_keys
Fixed performance regression introduced MySQL 8.0
1 parent 278f2c4 commit 8297f8a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
2+
3+
*Hiroyuki Ishii*
4+
15
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
26

37
*Eugene Kenny*

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,11 @@ def primary_keys(table_name) # :nodoc:
440440

441441
query_values(<<~SQL, "SCHEMA")
442442
SELECT column_name
443-
FROM information_schema.key_column_usage
444-
WHERE constraint_name = 'PRIMARY'
443+
FROM information_schema.statistics
444+
WHERE index_name = 'PRIMARY'
445445
AND table_schema = #{scope[:schema]}
446446
AND table_name = #{scope[:name]}
447-
ORDER BY ordinal_position
447+
ORDER BY seq_in_index
448448
SQL
449449
end
450450

0 commit comments

Comments
 (0)