Skip to content

Commit

Permalink
Merge pull request #11347 from hawkfish/iejoin-scan
Browse files Browse the repository at this point in the history
Issue #11234: IEJoin Scan Reset
  • Loading branch information
Mytherin authored Mar 26, 2024
2 parents 9be6a9f + 4aa9d1c commit 7935b7c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/execution/operator/join/physical_iejoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ struct IEJoinUnion {
DataChunk payload;
payload.Initialize(Allocator::DefaultAllocator(), gstate.payload_layout.GetTypes());
for (;;) {
payload.Reset();
scanner.Scan(payload);
const auto count = payload.size();
if (!count) {
Expand Down Expand Up @@ -301,6 +302,7 @@ idx_t IEJoinUnion::AppendKey(SortedTable &table, ExpressionExecutor &executor, S

idx_t inserted = 0;
for (auto rid = base; table_idx < valid;) {
scanned.Reset();
scanner.Scan(scanned);

// NULLs are at the end, so stop when we reach them
Expand Down
64 changes: 64 additions & 0 deletions test/sql/join/iejoin/predicate_expressions.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# name: test/sql/join/iejoin/predicate_expressions.test
# description: Predicate expressions should work with multiple chunks
# group: [iejoin]

statement ok
PRAGMA enable_verification

# Create a range of dates
statement ok
create table calendar as SELECT *
FROM range(DATE '2022-01-01', DATE '2024-02-01', INTERVAL '1' MONTH);

# Create an SCD2 dummy table with nullable end dates
statement ok
create table scd2 as
select
range as range_start,
case when date_part('year', range) < 2023 then range + interval 4 month - interval 1 day end as range_end,
n
from calendar
cross join generate_series(1, 85) as n

# Create an SCD2 dummy table with non-nullable end dates
statement ok
create table scd2_non_null as
select
range as range_start,
case when date_part('year', range) < 2023 then range + interval 4 month - interval 1 day else '2099-01-01' end as range_end,
n
from calendar
cross join generate_series(1, 85) as n

# Aggregate each table by using a range join
query II nosort expected
select
range,
count(*) as n
from scd2_non_null
inner join calendar
on range between range_start and ifnull(range_end,'2099-01-01')
group by range
order by range

# First key should work
query II nosort expected
select
range,
count(*) as n
from scd2
inner join calendar
on range <= ifnull(range_end,'2099-01-01') and range_start <= range
group by range
order by range

# Second key should work
query II nosort expected
select
range,
count(*) as n
from scd2
inner join calendar
on range between range_start and ifnull(range_end,'2099-01-01')
group by range
order by range

0 comments on commit 7935b7c

Please sign in to comment.