-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Arel::Nodes::Cte for use in WITH expressions
SelectManager#with currently accepts As and TableAlias nodes. Neither of these support materialization hints for the query planner. Both Postgres and SQLite support such hints. This commit adds a Cte node that does support materialization hints. It continues to support As and TableAlias nodes by translating them into Cte nodes.
- Loading branch information
Showing
12 changed files
with
218 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Arel # :nodoc: all | ||
module Nodes | ||
class Cte < Arel::Nodes::Binary | ||
alias :name :left | ||
alias :relation :right | ||
attr_reader :materialized | ||
|
||
def initialize(name, relation, materialized: nil) | ||
super(name, relation) | ||
@materialized = materialized | ||
end | ||
|
||
def hash | ||
[name, relation, materialized].hash | ||
end | ||
|
||
def eql?(other) | ||
self.class == other.class && | ||
self.name == other.name && | ||
self.relation == other.relation && | ||
self.materialized == other.materialized | ||
end | ||
alias :== :eql? | ||
|
||
def to_cte | ||
self | ||
end | ||
|
||
def to_table | ||
Arel::Table.new(name) | ||
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
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../helper" | ||
|
||
module Arel | ||
module Nodes | ||
describe "Cte" do | ||
describe "equality" do | ||
it "is equal with equal ivars" do | ||
array = [ | ||
Cte.new("foo", "bar", materialized: true), | ||
Cte.new("foo", "bar", materialized: true) | ||
] | ||
|
||
assert_equal 1, array.uniq.size | ||
end | ||
|
||
it "is not equal with unequal ivars" do | ||
array = [ | ||
Cte.new("foo", "bar", materialized: true), | ||
Cte.new("foo", "bar") | ||
] | ||
|
||
assert_equal 2, array.uniq.size | ||
end | ||
end | ||
|
||
describe "#to_cte" do | ||
it "returns self" do | ||
cte = Cte.new("foo", "bar") | ||
|
||
assert_equal cte.to_cte, cte | ||
end | ||
end | ||
|
||
describe "#to_table" do | ||
it "returns an Arel::Table using the Cte's name" do | ||
table = Cte.new("foo", "bar").to_table | ||
|
||
assert_kind_of Arel::Table, table | ||
assert_equal "foo", table.name | ||
end | ||
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
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