Skip to content

Commit

Permalink
chore: Update vendored sources to duckdb/duckdb@1feb042
Browse files Browse the repository at this point in the history
Merge pull request duckdb/duckdb#13291 from Mytherin/lateraljoingroupingsetsfix
  • Loading branch information
krlmlr committed Aug 3, 2024
1 parent 264dcf6 commit 640065a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/duckdb/src/function/table/version/pragma_version.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DUCKDB_PATCH_VERSION
#define DUCKDB_PATCH_VERSION "1-dev3764"
#define DUCKDB_PATCH_VERSION "1-dev3769"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 0
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.0.1-dev3764"
#define DUCKDB_VERSION "v1.0.1-dev3769"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "186e4b5255"
#define DUCKDB_SOURCE_ID "1feb0424de"
#endif
#include "duckdb/function/table/system_functions.hpp"
#include "duckdb/main/database.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct FlattenDependentJoins {
bool MarkSubtreeCorrelated(LogicalOperator &op);

//! Push the dependent join down a LogicalOperator
unique_ptr<LogicalOperator> PushDownDependentJoin(unique_ptr<LogicalOperator> plan);
unique_ptr<LogicalOperator> PushDownDependentJoin(unique_ptr<LogicalOperator> plan,
bool propagates_null_values = true);

Binder &binder;
ColumnBinding base_binding;
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/planner/binder/query_node/plan_subquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ unique_ptr<LogicalOperator> Binder::PlanLateralJoin(unique_ptr<LogicalOperator>
// first we check which logical operators have correlated expressions in the first place
flatten.DetectCorrelatedExpressions(*right, true);
// now we push the dependent join down
auto dependent_join = flatten.PushDownDependentJoin(std::move(right));
auto dependent_join = flatten.PushDownDependentJoin(std::move(right), join_type != JoinType::INNER);

// now the dependent join is fully eliminated
// we only need to create the join conditions between the LHS and the RHS
Expand Down
30 changes: 22 additions & 8 deletions src/duckdb/src/planner/subquery/flatten_dependent_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ bool FlattenDependentJoins::MarkSubtreeCorrelated(LogicalOperator &op) {
return has_correlation;
}

unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoin(unique_ptr<LogicalOperator> plan) {
bool propagate_null_values = true;
unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoin(unique_ptr<LogicalOperator> plan,
bool propagate_null_values) {
auto result = PushDownDependentJoinInternal(std::move(plan), propagate_null_values, 0);
if (!replacement_map.empty()) {
// check if we have to replace any COUNT aggregates into "CASE WHEN X IS NULL THEN 0 ELSE COUNT END"
Expand Down Expand Up @@ -255,18 +255,32 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
delim_column_offset = aggr.groups.size() - correlated_columns.size();
delim_data_offset = aggr.groups.size();
}
if (aggr.groups.size() == new_group_count) {
// we have to perform a LEFT OUTER JOIN between the result of this aggregate and the delim scan
// FIXME: this does not always have to be a LEFT OUTER JOIN, depending on whether aggr.expressions return
bool ungrouped_join = false;
if (aggr.grouping_sets.empty()) {
ungrouped_join = aggr.groups.size() == new_group_count;
} else {
for (auto &grouping_set : aggr.grouping_sets) {
if (grouping_set.size() == new_group_count) {
ungrouped_join = true;
}
}
}
if (ungrouped_join) {
// we have to perform an INNER or LEFT OUTER JOIN between the result of this aggregate and the delim scan
// this does not always have to be a LEFT OUTER JOIN, depending on whether aggr.expressions return
// NULL or a value
unique_ptr<LogicalComparisonJoin> join = make_uniq<LogicalComparisonJoin>(JoinType::INNER);
JoinType join_type = JoinType::INNER;
if (any_join || !parent_propagate_null_values) {
join_type = JoinType::LEFT;
}
for (auto &aggr_exp : aggr.expressions) {
auto &b_aggr_exp = aggr_exp->Cast<BoundAggregateExpression>();
if (!b_aggr_exp.PropagatesNullValues() || any_join || !parent_propagate_null_values) {
join = make_uniq<LogicalComparisonJoin>(JoinType::LEFT);
if (!b_aggr_exp.PropagatesNullValues()) {
join_type = JoinType::LEFT;
break;
}
}
unique_ptr<LogicalComparisonJoin> join = make_uniq<LogicalComparisonJoin>(join_type);
auto left_index = binder.GenerateTableIndex();
delim_scan = make_uniq<LogicalDelimGet>(left_index, delim_types);
join->children.push_back(std::move(delim_scan));
Expand Down

0 comments on commit 640065a

Please sign in to comment.