aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-07-28 16:29:26 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-07-28 16:29:26 +0900
commit5546f2d7122241d5b0c95fafeb4e70718a255f90 (patch)
tree1ad70752b5c304f63741420a99d2390d0863d88d /activerecord/lib/active_record
parent4211a29902eac95e67e9fed2b9dfce7a1f1d2799 (diff)
downloadrails-5546f2d7122241d5b0c95fafeb4e70718a255f90.tar.gz
rails-5546f2d7122241d5b0c95fafeb4e70718a255f90.tar.bz2
rails-5546f2d7122241d5b0c95fafeb4e70718a255f90.zip
Avoid calling `current_database` in `table_comment`
`current_database` executes a query and `table_comment` is called to all tables even if a table does not have a comment. Using `current_database` increases extra queries.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb6
1 files changed, 4 insertions, 2 deletions
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 01395d8ceb..c73159b796 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -410,11 +410,13 @@ module ActiveRecord
end
def table_comment(table_name) # :nodoc:
+ schema, name = extract_schema_qualified_name(table_name)
+
select_value(<<-SQL.strip_heredoc, 'SCHEMA')
SELECT table_comment
FROM information_schema.tables
- WHERE table_schema=#{quote(current_database)}
- AND table_name=#{quote(table_name)}
+ WHERE table_schema = #{quote(schema)}
+ AND table_name = #{quote(name)}
SQL
end