aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-09-16 10:43:30 +0900
committerkennyj <kennyj@gmail.com>2012-09-17 00:22:34 +0900
commit5bb056d268c9fc8c08c04ef04aef0c499b08a12c (patch)
treedcf5a5ca4516a996bb5b78bd4d79b66ba3aeae9e /activerecord
parent761bc751d31c22e2c2fdae2b4cdd435b68b6d783 (diff)
downloadrails-5bb056d268c9fc8c08c04ef04aef0c499b08a12c.tar.gz
rails-5bb056d268c9fc8c08c04ef04aef0c499b08a12c.tar.bz2
rails-5bb056d268c9fc8c08c04ef04aef0c499b08a12c.zip
Don't explain except normal CRUD sql.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/explain_subscriber.rb3
-rw-r--r--activerecord/test/cases/explain_subscriber_test.rb7
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 71dc960309..a4ba956477 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Explain only normal CRUD sql (select / update / insert / delete).
+ Fix problem that explains unexplainable sql. Closes #7544 #6458.
+
+ *kennyj*
+
* Fix `find_in_batches` when primary_key is set other than id.
You can now use this method with the primary key which is not integer-based.
diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb
index d5ba343b4c..0f927496fb 100644
--- a/activerecord/lib/active_record/explain_subscriber.rb
+++ b/activerecord/lib/active_record/explain_subscriber.rb
@@ -18,8 +18,9 @@ module ActiveRecord
# On the other hand, we want to monitor the performance of our real database
# queries, not the performance of the access to the query cache.
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN CACHE)
+ EXPLAINED_SQLS = /\A\s*(select|update|delete|insert)/i
def ignore_payload?(payload)
- payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name])
+ payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
end
ActiveSupport::Notifications.subscribe("sql.active_record", new)
diff --git a/activerecord/test/cases/explain_subscriber_test.rb b/activerecord/test/cases/explain_subscriber_test.rb
index 91e1df91cd..b425967678 100644
--- a/activerecord/test/cases/explain_subscriber_test.rb
+++ b/activerecord/test/cases/explain_subscriber_test.rb
@@ -38,6 +38,13 @@ if ActiveRecord::Base.connection.supports_explain?
end
end
+ def test_collects_nothing_if_unexplained_sqls
+ with_queries([]) do |queries|
+ SUBSCRIBER.finish(nil, nil, :name => 'SQL', :sql => 'SHOW max_identifier_length')
+ assert queries.empty?
+ end
+ end
+
def with_queries(queries)
Thread.current[:available_queries_for_explain] = queries
yield queries