Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework merge join to support all join types, not just INNER and MARK …
…joins
- Loading branch information
Showing
12 changed files
with
283 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
add_library_unity(duckdb_merge_join | ||
OBJECT | ||
merge_join.cpp | ||
merge_join_inner.cpp | ||
merge_join_mark.cpp) | ||
merge_join_complex.cpp | ||
merge_join_simple.cpp) | ||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:duckdb_merge_join> | ||
PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "duckdb/common/operator/comparison_operators.hpp" | ||
#include "duckdb/common/vector_operations/vector_operations.hpp" | ||
#include "duckdb/execution/merge_join.hpp" | ||
#include "duckdb/parser/expression/comparison_expression.hpp" | ||
|
||
using namespace std; | ||
|
||
namespace duckdb { | ||
|
||
template<class T, class OP> | ||
idx_t merge_join_complex_lt(ScalarMergeInfo &l, ScalarMergeInfo &r) { | ||
if (r.pos >= r.order.count) { | ||
return 0; | ||
} | ||
auto ldata = (T *)l.order.vdata.data; | ||
auto rdata = (T *)r.order.vdata.data; | ||
auto &lorder = l.order.order; | ||
auto &rorder = r.order.order; | ||
idx_t result_count = 0; | ||
while (true) { | ||
if (l.pos < l.order.count) { | ||
auto lidx = lorder.get_index(l.pos); | ||
auto ridx = rorder.get_index(r.pos); | ||
auto dlidx = l.order.vdata.sel->get_index(lidx); | ||
auto dridx = r.order.vdata.sel->get_index(ridx); | ||
if (OP::Operation(ldata[dlidx], rdata[dridx])) { | ||
// left side smaller: found match | ||
l.result.set_index(result_count, lidx); | ||
r.result.set_index(result_count, ridx); | ||
result_count++; | ||
// move left side forward | ||
l.pos++; | ||
if (result_count == STANDARD_VECTOR_SIZE) { | ||
// out of space! | ||
break; | ||
} | ||
continue; | ||
} | ||
} | ||
// right side smaller or equal, or left side exhausted: move | ||
// right pointer forward reset left side to start | ||
l.pos = 0; | ||
r.pos++; | ||
if (r.pos == r.order.count) { | ||
break; | ||
} | ||
} | ||
return result_count; | ||
|
||
} | ||
|
||
template <class T> idx_t MergeJoinComplex::LessThan::Operation(ScalarMergeInfo &l, ScalarMergeInfo &r) { | ||
return merge_join_complex_lt<T, duckdb::LessThan>(l, r); | ||
} | ||
|
||
template <class T> idx_t MergeJoinComplex::LessThanEquals::Operation(ScalarMergeInfo &l, ScalarMergeInfo &r) { | ||
return merge_join_complex_lt<T, duckdb::LessThanEquals>(l, r); | ||
} | ||
|
||
INSTANTIATE_MERGEJOIN_TEMPLATES(MergeJoinComplex, LessThan, ScalarMergeInfo, ScalarMergeInfo); | ||
INSTANTIATE_MERGEJOIN_TEMPLATES(MergeJoinComplex, LessThanEquals, ScalarMergeInfo, ScalarMergeInfo); | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.