Don't explain except normal CRUD sql.

This commit is contained in:
kennyj 2012-09-16 10:43:30 +09:00
parent 761bc751d3
commit 5bb056d268
3 changed files with 14 additions and 1 deletions

@ -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.

@ -18,8 +18,9 @@ def finish(name, id, payload)
# 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)

@ -38,6 +38,13 @@ def test_collects_pairs_of_queries_and_binds
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