diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-18 01:48:20 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-03-18 01:48:20 +0900 |
commit | 73d5e216086a9a3b0fd0efa6fab6f73bba3fa32e (patch) | |
tree | ff9cf3fdbd336b1f6660433922fd82fa7b076ae7 /activerecord | |
parent | b707a448a34345cd0a6609b8bd57874f1325a96c (diff) | |
download | rails-73d5e216086a9a3b0fd0efa6fab6f73bba3fa32e.tar.gz rails-73d5e216086a9a3b0fd0efa6fab6f73bba3fa32e.tar.bz2 rails-73d5e216086a9a3b0fd0efa6fab6f73bba3fa32e.zip |
Add test case for unscoping `:optimizer_hints`
Diffstat (limited to 'activerecord')
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 2603fac8b2..05ea0850d3 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -350,7 +350,7 @@ module ActiveRecord VALID_UNSCOPING_VALUES = Set.new([:where, :select, :group, :order, :lock, :limit, :offset, :joins, :left_outer_joins, - :includes, :from, :readonly, :having]) + :includes, :from, :readonly, :having, :optimizer_hints]) # Removes an unwanted relation that is already defined on a chain of relations. # This is useful when passing around chains of relations and would like to diff --git a/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb b/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb index 349de49b36..31a002e935 100644 --- a/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb +++ b/activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb @@ -19,6 +19,12 @@ if supports_optimizer_hints? posts = posts.select(:id).where(author_id: [0, 1]) assert_includes posts.explain, "| index | index_posts_on_author_id | index_posts_on_author_id |" end + + assert_sql(%r{\ASELECT `posts`\.`id`}) do + posts = Post.optimizer_hints("/*+ NO_RANGE_OPTIMIZATION(posts index_posts_on_author_id) */") + posts = posts.select(:id).where(author_id: [0, 1]) + posts.unscope(:optimizer_hints).load + end end end end diff --git a/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb b/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb index 1bfa815cac..4fac7ffdc0 100644 --- a/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb +++ b/activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb @@ -23,6 +23,12 @@ if supports_optimizer_hints? posts = posts.select(:id).where(author_id: [0, 1]) assert_includes posts.explain, "Seq Scan on posts" end + + assert_sql(%r{\ASELECT "posts"\."id"}) do + posts = Post.optimizer_hints("/*+ SeqScan(posts) */") + posts = posts.select(:id).where(author_id: [0, 1]) + posts.unscope(:optimizer_hints).load + end end end end |