Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35615 from kamipo/optimizer_hints
Support Optimizer Hints
- Loading branch information
Showing
20 changed files
with
184 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ def eql?(other) | |
Not | ||
Offset | ||
On | ||
OptimizerHints | ||
Ordering | ||
RollUp | ||
}.each do |name| | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
activerecord/test/cases/adapters/mysql2/optimizer_hints_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "models/post" | ||
|
||
if supports_optimizer_hints? | ||
class Mysql2OptimzerHintsTest < ActiveRecord::Mysql2TestCase | ||
fixtures :posts | ||
|
||
def test_optimizer_hints | ||
assert_sql(%r{\ASELECT /\*\+ NO_RANGE_OPTIMIZATION\(posts index_posts_on_author_id\) \*/}) do | ||
posts = Post.optimizer_hints("NO_RANGE_OPTIMIZATION(posts index_posts_on_author_id)") | ||
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 /\*\+ NO_RANGE_OPTIMIZATION\(posts index_posts_on_author_id\) \*/}) do | ||
posts = Post.optimizer_hints("/*+ NO_RANGE_OPTIMIZATION(posts index_posts_on_author_id) */") | ||
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 | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
activerecord/test/cases/adapters/postgresql/optimizer_hints_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "models/post" | ||
|
||
if supports_optimizer_hints? | ||
class PostgresqlOptimzerHintsTest < ActiveRecord::PostgreSQLTestCase | ||
fixtures :posts | ||
|
||
def setup | ||
enable_extension!("pg_hint_plan", ActiveRecord::Base.connection) | ||
end | ||
|
||
def test_optimizer_hints | ||
assert_sql(%r{\ASELECT /\*\+ SeqScan\(posts\) \*/}) do | ||
posts = Post.optimizer_hints("SeqScan(posts)") | ||
posts = posts.select(:id).where(author_id: [0, 1]) | ||
assert_includes posts.explain, "Seq Scan on posts" | ||
end | ||
|
||
assert_sql(%r{\ASELECT /\*\+ SeqScan\(posts\) \*/}) do | ||
posts = Post.optimizer_hints("/*+ SeqScan(posts) */") | ||
posts = posts.select(:id).where(author_id: [0, 1]) | ||
assert_includes posts.explain, "Seq Scan on posts" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters