aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-11-26 07:43:43 -0800
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-22 19:54:01 -0200
commit29d564add926307fea8cd3f77caf88d735e252a1 (patch)
tree44e0642936dbab6d9d3f261e727bc924c6a8999a /activerecord/lib/active_record
parent97a4db91d69d1795fe9079027968f0c0453bd0a1 (diff)
downloadrails-29d564add926307fea8cd3f77caf88d735e252a1.tar.gz
rails-29d564add926307fea8cd3f77caf88d735e252a1.tar.bz2
rails-29d564add926307fea8cd3f77caf88d735e252a1.zip
Merge pull request #6197 from blakesmith/connection_adapters_without_explain_support
Don't run explain on slow queries for database adapters that don't support it
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/explain.rb13
-rw-r--r--activerecord/lib/active_record/railtie.rb7
2 files changed, 14 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb
index bdccf535ea..236834fd84 100644
--- a/activerecord/lib/active_record/explain.rb
+++ b/activerecord/lib/active_record/explain.rb
@@ -11,11 +11,12 @@ module ActiveRecord
end
end
- # If auto explain is enabled, this method triggers EXPLAIN logging for the
- # queries triggered by the block if it takes more than the threshold as a
- # whole. That is, the threshold is not checked against each individual
- # query, but against the duration of the entire block. This approach is
- # convenient for relations.
+ # If the database adapter supports explain and auto explain is enabled,
+ # this method triggers EXPLAIN logging for the queries triggered by the
+ # block if it takes more than the threshold as a whole. That is, the
+ # threshold is not checked against each individual query, but against the
+ # duration of the entire block. This approach is convenient for relations.
+
#
# The available_queries_for_explain thread variable collects the queries
# to be explained. If the value is nil, it means queries are not being
@@ -26,7 +27,7 @@ module ActiveRecord
threshold = auto_explain_threshold_in_seconds
current = Thread.current
- if threshold && current[:available_queries_for_explain].nil?
+ if connection.supports_explain? && threshold && current[:available_queries_for_explain].nil?
begin
queries = current[:available_queries_for_explain] = []
start = Time.now
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 13b7c6e214..055d27d85c 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -83,6 +83,13 @@ module ActiveRecord
end
end
+ initializer "active_record.validate_explain_support" do |app|
+ if app.config.active_record[:auto_explain_threshold_in_seconds] &&
+ !ActiveRecord::Base.connection.supports_explain?
+ warn "auto_explain_threshold_in_seconds is set but will be ignored because your adapter does not support this feature. Please unset the configuration to avoid this warning."
+ end
+ end
+
# Expose database runtime to controller for logging.
initializer "active_record.log_runtime" do |app|
require "active_record/railties/controller_runtime"