duckdb 0.8.1-dev327.0 → 0.8.1-dev341.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -0
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/optimizer/unnest_rewriter.hpp +4 -0
- package/src/duckdb/src/optimizer/unnest_rewriter.cpp +27 -16
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +0 -1
package/package.json
CHANGED
@@ -1270,6 +1270,7 @@ void WindowLocalSourceState::GeneratePartition(WindowGlobalSinkState &gstate, co
|
|
1270
1270
|
// Overwrite the collections with the sorted data
|
1271
1271
|
hash_group = std::move(gsink.hash_groups[hash_bin]);
|
1272
1272
|
hash_group->ComputeMasks(partition_mask, order_mask);
|
1273
|
+
external = hash_group->global_sort->external;
|
1273
1274
|
MaterializeSortedData();
|
1274
1275
|
} else {
|
1275
1276
|
return;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
#ifndef DUCKDB_VERSION
|
2
|
-
#define DUCKDB_VERSION "0.8.1-
|
2
|
+
#define DUCKDB_VERSION "0.8.1-dev341"
|
3
3
|
#endif
|
4
4
|
#ifndef DUCKDB_SOURCE_ID
|
5
|
-
#define DUCKDB_SOURCE_ID "
|
5
|
+
#define DUCKDB_SOURCE_ID "b7d8029940"
|
6
6
|
#endif
|
7
7
|
#include "duckdb/function/table/system_functions.hpp"
|
8
8
|
#include "duckdb/main/database.hpp"
|
@@ -45,6 +45,8 @@ public:
|
|
45
45
|
|
46
46
|
//! Contains all bindings that need to be updated
|
47
47
|
vector<ReplaceBinding> replace_bindings;
|
48
|
+
//! Stores the table index of the former child of the LOGICAL_UNNEST
|
49
|
+
idx_t overwritten_tbl_idx;
|
48
50
|
};
|
49
51
|
|
50
52
|
//! The UnnestRewriter optimizer traverses the logical operator tree and rewrites duplicate
|
@@ -79,6 +81,8 @@ private:
|
|
79
81
|
vector<LHSBinding> lhs_bindings;
|
80
82
|
//! Stores the table index of the former child of the LOGICAL_UNNEST
|
81
83
|
idx_t overwritten_tbl_idx;
|
84
|
+
//! The number of distinct columns to unnest
|
85
|
+
idx_t distinct_unnest_count;
|
82
86
|
};
|
83
87
|
|
84
88
|
} // namespace duckdb
|
@@ -26,11 +26,7 @@ void UnnestRewriterPlanUpdater::VisitExpression(unique_ptr<Expression> *expressi
|
|
26
26
|
for (idx_t i = 0; i < replace_bindings.size(); i++) {
|
27
27
|
if (bound_column_ref.binding == replace_bindings[i].old_binding) {
|
28
28
|
bound_column_ref.binding = replace_bindings[i].new_binding;
|
29
|
-
|
30
|
-
// previously pointing to the LOGICAL_DELIM_GET
|
31
|
-
if (bound_column_ref.binding.table_index == replace_bindings[i].old_binding.table_index &&
|
32
|
-
replace_bindings[i].old_binding.column_index == DConstants::INVALID_INDEX) {
|
33
|
-
bound_column_ref.binding = replace_bindings[i].new_binding;
|
29
|
+
break;
|
34
30
|
}
|
35
31
|
}
|
36
32
|
}
|
@@ -49,6 +45,7 @@ unique_ptr<LogicalOperator> UnnestRewriter::Optimize(unique_ptr<LogicalOperator>
|
|
49
45
|
|
50
46
|
// rearrange the logical operators
|
51
47
|
if (RewriteCandidate(candidate)) {
|
48
|
+
updater.overwritten_tbl_idx = overwritten_tbl_idx;
|
52
49
|
// update the bindings of the BOUND_UNNEST expression
|
53
50
|
UpdateBoundUnnestBindings(updater, candidate);
|
54
51
|
// update the sequence of LOGICAL_PROJECTION(s)
|
@@ -106,7 +103,6 @@ void UnnestRewriter::FindCandidates(unique_ptr<LogicalOperator> *op_ptr,
|
|
106
103
|
if (curr_op->get()->type == LogicalOperatorType::LOGICAL_UNNEST) {
|
107
104
|
candidates.push_back(op_ptr);
|
108
105
|
}
|
109
|
-
return;
|
110
106
|
}
|
111
107
|
|
112
108
|
bool UnnestRewriter::RewriteCandidate(unique_ptr<LogicalOperator> *candidate) {
|
@@ -147,6 +143,11 @@ bool UnnestRewriter::RewriteCandidate(unique_ptr<LogicalOperator> *candidate) {
|
|
147
143
|
auto &unnest = curr_op->get()->Cast<LogicalUnnest>();
|
148
144
|
D_ASSERT(unnest.children[0]->type == LogicalOperatorType::LOGICAL_DELIM_GET);
|
149
145
|
overwritten_tbl_idx = unnest.children[0]->Cast<LogicalDelimGet>().table_index;
|
146
|
+
|
147
|
+
D_ASSERT(!unnest.children.empty());
|
148
|
+
auto &delim_get = unnest.children[0]->Cast<LogicalDelimGet>();
|
149
|
+
D_ASSERT(delim_get.chunk_types.size() > 1);
|
150
|
+
distinct_unnest_count = delim_get.chunk_types.size();
|
150
151
|
unnest.children[0] = std::move(lhs_op);
|
151
152
|
|
152
153
|
// replace the LOGICAL_DELIM_JOIN with its RHS child operator
|
@@ -168,10 +169,11 @@ void UnnestRewriter::UpdateRHSBindings(unique_ptr<LogicalOperator> *plan_ptr, un
|
|
168
169
|
D_ASSERT(curr_op->get()->type == LogicalOperatorType::LOGICAL_PROJECTION);
|
169
170
|
auto &proj = curr_op->get()->Cast<LogicalProjection>();
|
170
171
|
|
171
|
-
// pop the
|
172
|
-
D_ASSERT(proj.expressions.size() >
|
173
|
-
|
174
|
-
|
172
|
+
// pop the unnest columns and the delim index
|
173
|
+
D_ASSERT(proj.expressions.size() > distinct_unnest_count);
|
174
|
+
for (idx_t i = 0; i < distinct_unnest_count; i++) {
|
175
|
+
proj.expressions.pop_back();
|
176
|
+
}
|
175
177
|
|
176
178
|
// store all shifted current bindings
|
177
179
|
idx_t tbl_idx = proj.table_index;
|
@@ -263,14 +265,23 @@ void UnnestRewriter::UpdateBoundUnnestBindings(UnnestRewriterPlanUpdater &update
|
|
263
265
|
auto &unnest = curr_op->get()->Cast<LogicalUnnest>();
|
264
266
|
|
265
267
|
D_ASSERT(unnest.children.size() == 1);
|
266
|
-
auto
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
268
|
+
auto unnest_cols = unnest.children[0]->GetColumnBindings();
|
269
|
+
|
270
|
+
for (idx_t i = 0; i < delim_columns.size(); i++) {
|
271
|
+
auto delim_binding = delim_columns[i];
|
272
|
+
|
273
|
+
auto unnest_it = unnest_cols.begin();
|
274
|
+
while (unnest_it != unnest_cols.end()) {
|
275
|
+
auto unnest_binding = *unnest_it;
|
276
|
+
|
277
|
+
if (delim_binding.table_index == unnest_binding.table_index) {
|
278
|
+
unnest_binding.table_index = overwritten_tbl_idx;
|
279
|
+
unnest_binding.column_index++;
|
280
|
+
updater.replace_bindings.emplace_back(unnest_binding, delim_binding);
|
281
|
+
unnest_cols.erase(unnest_it);
|
272
282
|
break;
|
273
283
|
}
|
284
|
+
unnest_it++;
|
274
285
|
}
|
275
286
|
}
|
276
287
|
|