Skip to content

Commit

Permalink
Merge pull request #44350 from fatkodima/explain-prefix-comment
Browse files Browse the repository at this point in the history
Fix ActiveRecord's explain for queries starting with comments
  • Loading branch information
byroot committed Feb 12, 2022
2 parents 269948f + f47b03b commit a32c54e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/explain_subscriber.rb
Expand Up @@ -21,7 +21,7 @@ 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)
EXPLAINED_SQLS = /\A\s*(with|select|update|delete|insert)\b/i
EXPLAINED_SQLS = /\A\s*(\/\*.*\*\/)?\s*(with|select|update|delete|insert)\b/i
def ignore_payload?(payload)
payload[:exception] ||
payload[:cached] ||
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/explain_subscriber_test.rb
Expand Up @@ -55,6 +55,11 @@ def test_collects_cte_queries
assert_equal 1, queries.size
end

def test_collects_queries_starting_with_comment
SUBSCRIBER.finish(nil, nil, name: "SQL", sql: "/* comment */ select 1 from users")
assert_equal 1, queries.size
end

teardown do
ActiveRecord::ExplainRegistry.reset
end
Expand Down

0 comments on commit a32c54e

Please sign in to comment.