1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/planner/expression/bound_subquery_expression.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/enums/subquery_type.hpp" |
12 | #include "duckdb/planner/binder.hpp" |
13 | #include "duckdb/planner/bound_query_node.hpp" |
14 | #include "duckdb/planner/expression.hpp" |
15 | |
16 | namespace duckdb { |
17 | |
18 | class BoundSubqueryExpression : public Expression { |
19 | public: |
20 | static constexpr const ExpressionClass TYPE = ExpressionClass::BOUND_SUBQUERY; |
21 | |
22 | public: |
23 | explicit BoundSubqueryExpression(LogicalType return_type); |
24 | |
25 | bool IsCorrelated() { |
26 | return binder->correlated_columns.size() > 0; |
27 | } |
28 | |
29 | //! The binder used to bind the subquery node |
30 | shared_ptr<Binder> binder; |
31 | //! The bound subquery node |
32 | unique_ptr<BoundQueryNode> subquery; |
33 | //! The subquery type |
34 | SubqueryType subquery_type; |
35 | //! the child expression to compare with (in case of IN, ANY, ALL operators) |
36 | unique_ptr<Expression> child; |
37 | //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators) |
38 | ExpressionType comparison_type; |
39 | //! The LogicalType of the subquery result. Only used for ANY expressions. |
40 | LogicalType child_type; |
41 | //! The target LogicalType of the subquery result (i.e. to which type it should be casted, if child_type <> |
42 | //! child_target). Only used for ANY expressions. |
43 | LogicalType child_target; |
44 | |
45 | public: |
46 | bool HasSubquery() const override { |
47 | return true; |
48 | } |
49 | bool IsScalar() const override { |
50 | return false; |
51 | } |
52 | bool IsFoldable() const override { |
53 | return false; |
54 | } |
55 | |
56 | string ToString() const override; |
57 | |
58 | bool Equals(const BaseExpression &other) const override; |
59 | |
60 | unique_ptr<Expression> Copy() override; |
61 | |
62 | bool PropagatesNullValues() const override; |
63 | |
64 | void Serialize(FieldWriter &writer) const override; |
65 | static unique_ptr<Expression> Deserialize(ExpressionDeserializationState &state, FieldReader &reader); |
66 | }; |
67 | } // namespace duckdb |
68 |