aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-11 16:01:44 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-05-11 16:01:44 -0700
commit5c6cf4e59e3e9c75395541162f2741b82347af0a (patch)
tree322bb73eb0638494e12e33faa183d5e0dcca858f /activerecord
parente2804c62dfdd1946a11048196ea32aae17a7edd5 (diff)
parentddaa5d5181e8ed576c4a033062545b0d41a7da72 (diff)
downloadrails-5c6cf4e59e3e9c75395541162f2741b82347af0a.tar.gz
rails-5c6cf4e59e3e9c75395541162f2741b82347af0a.tar.bz2
rails-5c6cf4e59e3e9c75395541162f2741b82347af0a.zip
Merge pull request #10571 from dasch/dasch/restore-explain-fix
Don't try to EXPLAIN select_db calls
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/explain_subscriber.rb2
-rw-r--r--activerecord/test/cases/explain_subscriber_test.rb7
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 117e527133..d27b11bddd 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## unreleased ##
+* Make sure the `EXPLAIN` command is never triggered by a `select_db` call.
+
+ *Daniel Schierbeck*
+
* Revert changes on `pluck` that was ignoring the select clause when the relation already
has one. This caused a regression since it changed the behavior in a stable release.
diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb
index 859c8edfc5..1d861a57db 100644
--- a/activerecord/lib/active_record/explain_subscriber.rb
+++ b/activerecord/lib/active_record/explain_subscriber.rb
@@ -15,7 +15,7 @@ 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
+ EXPLAINED_SQLS = /\A\s*(select|update|delete|insert)\b/i
def ignore_payload?(payload)
payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
end
diff --git a/activerecord/test/cases/explain_subscriber_test.rb b/activerecord/test/cases/explain_subscriber_test.rb
index 7b852a625d..0546e793fe 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_the_statement_is_only_partially_matched
+ with_queries([]) do |queries|
+ SUBSCRIBER.call(:name => 'SQL', :sql => 'select_db yo_mama')
+ assert queries.empty?
+ end
+ end
+
def test_collects_nothing_if_unexplained_sqls
with_queries([]) do |queries|
SUBSCRIBER.call(:name => 'SQL', :sql => 'SHOW max_identifier_length')