1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't SELECT * FROM information_schema.tables

Depending on MySQL version and configuration, this is more than two
orders of magnitude slower than selecting only the two columns we need
for this query, which don't require reading any of the data files or
recalculating innodb stats.

https://dev.mysql.com/doc/refman/5.6/en/information-schema-optimization.html

Performance regression was introduced in #39712, before then the query
took around 40-50ms on my test environment, after it took 4-8s. With
this change it's back to 40-50ms.
This commit is contained in:
Chris Griego 2021-10-27 14:29:54 -05:00
parent 18922cccd4
commit bccc4c6226
No known key found for this signature in database
GPG key ID: FB11D3502B613386

View file

@ -206,7 +206,7 @@ module ActiveRecord
def data_source_sql(name = nil, type: nil)
scope = quoted_scope(name, type: type)
sql = +"SELECT table_name FROM (SELECT * FROM information_schema.tables "
sql = +"SELECT table_name FROM (SELECT table_name, table_type FROM information_schema.tables "
sql << " WHERE table_schema = #{scope[:schema]}) _subquery"
if scope[:type] || scope[:name]
conditions = []