Skip to content

Commit

Permalink
Don't SELECT * FROM information_schema.tables
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cgriego committed Oct 27, 2021
1 parent 18922cc commit bccc4c6
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def add_options_for_index_columns(quoted_columns, **options)
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 = []
Expand Down

0 comments on commit bccc4c6

Please sign in to comment.