Skip to content

Commit bccc4c6

Browse files
committed
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 rails#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.
1 parent 18922cc commit bccc4c6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def add_options_for_index_columns(quoted_columns, **options)
206206
def data_source_sql(name = nil, type: nil)
207207
scope = quoted_scope(name, type: type)
208208

209-
sql = +"SELECT table_name FROM (SELECT * FROM information_schema.tables "
209+
sql = +"SELECT table_name FROM (SELECT table_name, table_type FROM information_schema.tables "
210210
sql << " WHERE table_schema = #{scope[:schema]}) _subquery"
211211
if scope[:type] || scope[:name]
212212
conditions = []

0 commit comments

Comments
 (0)