Commit 275dc7f3 authored by Mark Chao's avatar Mark Chao

Merge branch 'id-modify-as-with-materialized' into 'master'

Inherit from Arel::Nodes::As instead of Binary

See merge request gitlab-org/gitlab!60775
parents 2c4abf28 2fc1fa98
...@@ -6,7 +6,7 @@ module Arel ...@@ -6,7 +6,7 @@ module Arel
class Arel::Visitors::PostgreSQL class Arel::Visitors::PostgreSQL
def visit_Gitlab_Database_AsWithMaterialized(obj, collector) # rubocop:disable Naming/MethodName def visit_Gitlab_Database_AsWithMaterialized(obj, collector) # rubocop:disable Naming/MethodName
collector = visit obj.left, collector collector = visit obj.left, collector
collector << " AS#{obj.expr} " collector << " AS "
visit obj.right, collector visit obj.right, collector
end end
end end
......
...@@ -3,18 +3,14 @@ ...@@ -3,18 +3,14 @@
module Gitlab module Gitlab
module Database module Database
# This class is a special Arel node which allows optionally define the `MATERIALIZED` keyword for CTE and Recursive CTE queries. # This class is a special Arel node which allows optionally define the `MATERIALIZED` keyword for CTE and Recursive CTE queries.
class AsWithMaterialized < Arel::Nodes::Binary class AsWithMaterialized < Arel::Nodes::As
extend Gitlab::Utils::StrongMemoize extend Gitlab::Utils::StrongMemoize
MATERIALIZED = Arel.sql(' MATERIALIZED') MATERIALIZED = 'MATERIALIZED '
EMPTY_STRING = Arel.sql('')
attr_reader :expr
def initialize(left, right, materialized: true) def initialize(left, right, materialized: true)
@expr = if materialized && self.class.materialized_supported? if materialized && self.class.materialized_supported?
MATERIALIZED right.prepend(MATERIALIZED)
else
EMPTY_STRING
end end
super(left, right) super(left, right)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment