1#include "duckdb/optimizer/filter_pushdown.hpp"
2#include "duckdb/planner/operator/logical_comparison_join.hpp"
3
4namespace duckdb {
5
6using Filter = FilterPushdown::Filter;
7
8unique_ptr<LogicalOperator> FilterPushdown::PushdownSingleJoin(unique_ptr<LogicalOperator> op,
9 unordered_set<idx_t> &left_bindings,
10 unordered_set<idx_t> &right_bindings) {
11 D_ASSERT(op->Cast<LogicalJoin>().join_type == JoinType::SINGLE);
12 FilterPushdown left_pushdown(optimizer), right_pushdown(optimizer);
13 // now check the set of filters
14 for (idx_t i = 0; i < filters.size(); i++) {
15 auto side = JoinSide::GetJoinSide(bindings: filters[i]->bindings, left_bindings, right_bindings);
16 if (side == JoinSide::LEFT) {
17 // bindings match left side: push into left
18 left_pushdown.filters.push_back(x: std::move(filters[i]));
19 // erase the filter from the list of filters
20 filters.erase(position: filters.begin() + i);
21 i--;
22 }
23 }
24 op->children[0] = left_pushdown.Rewrite(op: std::move(op->children[0]));
25 op->children[1] = right_pushdown.Rewrite(op: std::move(op->children[1]));
26 return PushFinalFilters(op: std::move(op));
27}
28
29} // namespace duckdb
30