aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorVladimir Kochnev <hashtable@yandex.ru>2015-04-21 16:45:21 +0300
committerVladimir Kochnev <hashtable@yandex.ru>2015-05-28 14:10:09 +0300
commitacdb006ad0e3926702e9df13effd4577db4dd0ad (patch)
tree565b5eb9f84b5cf8936d4eaad4989e1a896be6c8 /activerecord
parent207f8fc7debec1e9173f797e5208527e97235af3 (diff)
downloadrails-acdb006ad0e3926702e9df13effd4577db4dd0ad.tar.gz
rails-acdb006ad0e3926702e9df13effd4577db4dd0ad.tar.bz2
rails-acdb006ad0e3926702e9df13effd4577db4dd0ad.zip
Let WITH (CTE) queries be explainable
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.rb5
3 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index edbfe38753..9eee0699d9 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Let CTE queries (`WITH ...`) be explainable.
+
+ *Vladimir Kochnev*
+
* SQLite: `:collation` support for string and text columns.
Example:
diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb
index 6a49936644..9adabd7819 100644
--- a/activerecord/lib/active_record/explain_subscriber.rb
+++ b/activerecord/lib/active_record/explain_subscriber.rb
@@ -19,7 +19,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)\b/i
+ EXPLAINED_SQLS = /\A\s*(with|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 8de2ddb10d..2dee8a26a5 100644
--- a/activerecord/test/cases/explain_subscriber_test.rb
+++ b/activerecord/test/cases/explain_subscriber_test.rb
@@ -48,6 +48,11 @@ if ActiveRecord::Base.connection.supports_explain?
assert queries.empty?
end
+ def test_collects_cte_queries
+ SUBSCRIBER.finish(nil, nil, name: 'SQL', sql: 'with s as (values(3)) select 1 from s')
+ assert_equal 1, queries.size
+ end
+
teardown do
ActiveRecord::ExplainRegistry.reset
end