Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #7078 from kennyj/logging_query_plan

Log query plan when we use count_by_sql method.
  • Loading branch information...
commit fa3c84fabee01847c3468cd1e8e32003693bc629 2 parents 2897bf1 + 1b25283
@rafaelfranca rafaelfranca authored
View
6 activerecord/lib/active_record/querying.rb
@@ -62,8 +62,10 @@ def find_by_sql(sql, binds = [])
#
# Product.count_by_sql "SELECT COUNT(*) FROM sales s, customers c WHERE s.customer_id = c.id"
def count_by_sql(sql)
- sql = sanitize_conditions(sql)
- connection.select_value(sql, "#{name} Count").to_i
+ logging_query_plan do
+ sql = sanitize_conditions(sql)
+ connection.select_value(sql, "#{name} Count").to_i
+ end
end
end
end
View
10 activerecord/test/cases/explain_test.rb
@@ -68,6 +68,16 @@ def test_collecting_queries_for_explain
assert_equal [cars(:honda)], result
end
+ def test_logging_query_plan_when_counting_by_sql
+ base.logger.expects(:warn).with do |message|
+ message.starts_with?('EXPLAIN for:')
+ end
+
+ with_threshold(0) do
+ Car.count_by_sql "SELECT COUNT(*) FROM cars WHERE name = 'honda'"
+ end
+ end
+
def test_exec_explain_with_no_binds
sqls = %w(foo bar)
binds = [[], []]
Please sign in to comment.
Something went wrong with that request. Please try again.