1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/planner/joinside.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/unordered_set.hpp"
12#include "duckdb/planner/expression.hpp"
13
14namespace duckdb {
15
16//! JoinCondition represents a left-right comparison join condition
17struct JoinCondition {
18public:
19 JoinCondition() {
20 }
21
22 //! Turns the JoinCondition into an expression; note that this destroys the JoinCondition as the expression inherits
23 //! the left/right expressions
24 static unique_ptr<Expression> CreateExpression(JoinCondition cond);
25 static unique_ptr<Expression> CreateExpression(vector<JoinCondition> conditions);
26
27 //! Serializes a JoinCondition to a stand-alone binary blob
28 void Serialize(Serializer &serializer) const;
29 //! Deserializes a blob back into a JoinCondition
30 static JoinCondition Deserialize(Deserializer &source, PlanDeserializationState &state);
31
32public:
33 unique_ptr<Expression> left;
34 unique_ptr<Expression> right;
35 ExpressionType comparison;
36};
37
38class JoinSide {
39public:
40 enum JoinValue : uint8_t { NONE, LEFT, RIGHT, BOTH };
41
42 JoinSide() = default;
43 constexpr JoinSide(JoinValue val) : value(val) { // NOLINT: Allow implicit conversion from `join_value`
44 }
45
46 bool operator==(JoinSide a) const {
47 return value == a.value;
48 }
49 bool operator!=(JoinSide a) const {
50 return value != a.value;
51 }
52
53 static JoinSide CombineJoinSide(JoinSide left, JoinSide right);
54 static JoinSide GetJoinSide(idx_t table_binding, const unordered_set<idx_t> &left_bindings,
55 const unordered_set<uint64_t> &right_bindings);
56 static JoinSide GetJoinSide(Expression &expression, const unordered_set<idx_t> &left_bindings,
57 const unordered_set<idx_t> &right_bindings);
58 static JoinSide GetJoinSide(const unordered_set<idx_t> &bindings, const unordered_set<idx_t> &left_bindings,
59 const unordered_set<idx_t> &right_bindings);
60
61private:
62 JoinValue value;
63};
64
65} // namespace duckdb
66