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