1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Let WITH (CTE) queries be explainable

This commit is contained in:
Vladimir Kochnev 2015-04-21 16:45:21 +03:00
parent 207f8fc7de
commit acdb006ad0
3 changed files with 10 additions and 1 deletions

View file

@ -1,3 +1,7 @@
* Let CTE queries (`WITH ...`) be explainable.
*Vladimir Kochnev*
* SQLite: `:collation` support for string and text columns.
Example:

View file

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

View file

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