Skip to content

Commit

Permalink
Merge pull request #9449 from hawkfish/asof-inequality
Browse files Browse the repository at this point in the history
Issue #9396: AsOf Inequality Optimisation
  • Loading branch information
Mytherin committed Oct 24, 2023
2 parents 4c28a71 + 05dd11b commit c131b5a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/optimizer/statistics/operator/propagate_join.cpp
Expand Up @@ -67,6 +67,21 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
break;
case FilterPropagateResult::FILTER_ALWAYS_TRUE:
// filter is always true
// If this is the inequality for an AsOf join,
// then we must leave it in because it also flags
// the semantics of restricting to a single match
// so we can't replace it with an equi-join on the remaining conditions.
if (join.type == LogicalOperatorType::LOGICAL_ASOF_JOIN) {
switch (condition.comparison) {
case ExpressionType::COMPARE_GREATERTHAN:
case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
case ExpressionType::COMPARE_LESSTHAN:
case ExpressionType::COMPARE_LESSTHANOREQUALTO:
continue;
default:
break;
}
}
if (join.conditions.size() > 1) {
// there are multiple conditions: erase this condition
join.conditions.erase(join.conditions.begin() + i);
Expand Down
20 changes: 20 additions & 0 deletions test/sql/join/asof/test_asof_join.test
Expand Up @@ -17,6 +17,26 @@ INSERT INTO events0 VALUES
(8, 3)
;

# Prevent optimiser from removing true inequalities
statement ok
create table prices("when" timestamp, symbol int, price int);

statement ok
insert into prices values ('2020-01-01 00:00:00', 1, 42);

statement ok
create table trades("when" timestamp, symbol int);

statement ok
insert into trades values ('2020-01-01 00:00:03', 1);

query III
SELECT t.*, p.price
FROM trades t ASOF JOIN prices p
ON t.symbol = p.symbol AND t.when >= p.when;
----
2020-01-01 00:00:03 1 42

# Use an ASOF join inside of a correlated subquery


Expand Down

0 comments on commit c131b5a

Please sign in to comment.