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
[ActiveRecord] Deduplicate optimizer hints #36706
Conversation
9c44f96
to
f1dae29
Compare
f1dae29
to
3e2535f
Compare
@@ -363,6 +363,12 @@ def test_relation_with_optimizer_hints_filters_sql_comment_delimiters | |||
assert_match %r{/\*\+ BADHINT \*/}, post_with_hint.to_sql | |||
end | |||
|
|||
def test_does_not_duplicate_optimizer_hints_on_merge | |||
expected = "SELECT /*+ OMGHINT */ `posts`.* FROM `posts`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not expected query for postgresql and sqlite3 adapters.
https://buildkite.com/rails/rails/builds/62311#86409ae0-8a89-4be7-8d6b-e7b6757648da/998-1009
https://buildkite.com/rails/rails/builds/62311#888c2216-dfbf-490a-8123-eed0a3aa1912/985-994
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Existing similar test case would be of your help.
rails/activerecord/test/cases/annotate_test.rb
Lines 9 to 16 in d3b951f
def test_annotate_wraps_content_in_an_inline_comment | |
quoted_posts_id, quoted_posts = regexp_escape_table_name("posts.id"), regexp_escape_table_name("posts") | |
assert_sql(%r{\ASELECT #{quoted_posts_id} FROM #{quoted_posts} /\* foo \*/}i) do | |
posts = Post.select(:id).annotate("foo") | |
assert posts.first | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed.
3e2535f
to
77931f4
Compare
[ActiveRecord] Deduplicate optimizer hints
When you merge two relations both having the same optimizer hint (it could come from a default_scope, for instance), you'll end up with duplicated hints in the result query.
This patch fixed that by applying
uniq
to hints.cc @kamipo @rafaelfranca