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

[ActiveRecord] Deduplicate optimizer hints #36706

Merged
merged 1 commit into from Jul 19, 2019

Conversation

kirs
Copy link
Member

@kirs kirs commented Jul 18, 2019

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

@kirs
Copy link
Member Author

kirs commented Jul 19, 2019

@kamipo @kaspth thanks for feedback, updated!

@@ -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`"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

@kamipo kamipo merged commit 2caddbf into rails:master Jul 19, 2019
kamipo added a commit that referenced this pull request Jul 20, 2019
[ActiveRecord] Deduplicate optimizer hints
@kirs kirs deleted the dedup-optimizer-hints branch July 22, 2019 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants