Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to EXPLAIN select_db calls #10554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/explain_subscriber.rb
Expand Up @@ -19,7 +19,7 @@ def finish(name, id, payload)
# On the other hand, we want to monitor the performance of our real database # 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. # queries, not the performance of the access to the query cache.
IGNORED_PAYLOADS = %w(SCHEMA EXPLAIN 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) def ignore_payload?(payload)
payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS payload[:exception] || IGNORED_PAYLOADS.include?(payload[:name]) || payload[:sql] !~ EXPLAINED_SQLS
end end
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/explain_subscriber_test.rb
Expand Up @@ -43,6 +43,11 @@ def test_collects_nothing_if_the_statement_is_not_whitelisted
assert queries.empty? assert queries.empty?
end end


def test_collects_nothing_if_the_statement_is_only_partially_matched
SUBSCRIBER.finish(nil, nil, name: 'SQL', sql: 'select_db yo_mama')
assert queries.empty?
end

def teardown def teardown
ActiveRecord::ExplainRegistry.reset ActiveRecord::ExplainRegistry.reset
end end
Expand Down