Skip to content

Commit

Permalink
chore: Update vendored sources to duckdb/duckdb@f9e96b1 (#438)
Browse files Browse the repository at this point in the history
Bugfixes (duckdb/duckdb#13982)

Co-authored-by: krlmlr <[email protected]>
  • Loading branch information
github-actions[bot] and krlmlr authored Sep 27, 2024
1 parent 672611a commit 47cb18b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 14 deletions.
16 changes: 16 additions & 0 deletions src/duckdb/src/common/types/column/column_data_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "duckdb/common/types/column/column_data_collection_segment.hpp"
#include "duckdb/storage/buffer/block_handle.hpp"
#include "duckdb/storage/buffer/buffer_pool.hpp"
#include "duckdb/storage/buffer_manager.hpp"

namespace duckdb {
Expand Down Expand Up @@ -45,6 +46,21 @@ ColumnDataAllocator::ColumnDataAllocator(ColumnDataAllocator &other) {
}
}

ColumnDataAllocator::~ColumnDataAllocator() {
if (type == ColumnDataAllocatorType::IN_MEMORY_ALLOCATOR) {
return;
}
for (auto &block : blocks) {
block.handle->SetDestroyBufferUpon(DestroyBufferUpon::UNPIN);
}
const auto data_size = SizeInBytes();
blocks.clear();
if (Allocator::SupportsFlush() &&
data_size > alloc.buffer_manager->GetBufferPool().GetAllocatorBulkDeallocationFlushThreshold()) {
Allocator::FlushAll();
}
}

BufferHandle ColumnDataAllocator::Pin(uint32_t block_id) {
D_ASSERT(type == ColumnDataAllocatorType::BUFFER_MANAGER_ALLOCATOR || type == ColumnDataAllocatorType::HYBRID);
shared_ptr<BlockHandle> handle;
Expand Down
5 changes: 5 additions & 0 deletions src/duckdb/src/common/types/row/tuple_data_segment.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "duckdb/common/types/row/tuple_data_segment.hpp"

#include "duckdb/common/types/row/tuple_data_allocator.hpp"
#include "duckdb/storage/buffer/buffer_pool.hpp"

namespace duckdb {

Expand Down Expand Up @@ -118,6 +119,10 @@ TupleDataSegment::~TupleDataSegment() {
}
pinned_row_handles.clear();
pinned_heap_handles.clear();
if (Allocator::SupportsFlush() && allocator &&
data_size > allocator->GetBufferManager().GetBufferPool().GetAllocatorBulkDeallocationFlushThreshold()) {
Allocator::FlushAll();
}
allocator.reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,12 @@ OperatorResultType PhysicalPiecewiseMergeJoin::ResolveComplexJoin(ExecutionConte

if (tail_count < result_count) {
result_count = tail_count;
chunk.Slice(*sel, result_count);
if (result_count == 0) {
// Need to reset here otherwise we may use the non-flat chunk when constructing LEFT/OUTER
chunk.Reset();
} else {
chunk.Slice(*sel, result_count);
}
}
}

Expand Down
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-dev223"
#define DUCKDB_PATCH_VERSION "1-dev236"
#endif
#ifndef DUCKDB_MINOR_VERSION
#define DUCKDB_MINOR_VERSION 1
Expand All @@ -8,10 +8,10 @@
#define DUCKDB_MAJOR_VERSION 1
#endif
#ifndef DUCKDB_VERSION
#define DUCKDB_VERSION "v1.1.1-dev223"
#define DUCKDB_VERSION "v1.1.1-dev236"
#endif
#ifndef DUCKDB_SOURCE_ID
#define DUCKDB_SOURCE_ID "2ff9c687e2"
#define DUCKDB_SOURCE_ID "f9e96b1910"
#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 @@ -32,6 +32,7 @@ class ColumnDataAllocator {
explicit ColumnDataAllocator(BufferManager &buffer_manager);
ColumnDataAllocator(ClientContext &context, ColumnDataAllocatorType allocator_type);
ColumnDataAllocator(ColumnDataAllocator &allocator);
~ColumnDataAllocator();

//! Returns an allocator object to allocate with. This returns the allocator in IN_MEMORY_ALLOCATOR, and a buffer
//! allocator in case of BUFFER_MANAGER_ALLOCATOR.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class BufferPool {

//! If bulk deallocation larger than this occurs, flush outstanding allocations
void SetAllocatorBulkDeallocationFlushThreshold(idx_t threshold);
idx_t GetAllocatorBulkDeallocationFlushThreshold();

void UpdateUsedMemory(MemoryTag tag, int64_t size);

Expand Down
7 changes: 6 additions & 1 deletion src/duckdb/src/optimizer/filter_pushdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,14 @@ unique_ptr<LogicalOperator> FilterPushdown::Rewrite(unique_ptr<LogicalOperator>
// we can just push directly through these operations without any rewriting
op->children[0] = Rewrite(std::move(op->children[0]));
return op;
case LogicalOperatorType::LOGICAL_MATERIALIZED_CTE:
case LogicalOperatorType::LOGICAL_MATERIALIZED_CTE: {
// we can't push filters into the materialized CTE (LHS), but we do want to recurse into it
FilterPushdown pushdown(optimizer, convert_mark_joins);
op->children[0] = pushdown.Rewrite(std::move(op->children[0]));
// we can push filters into the rest of the query plan (RHS)
op->children[1] = Rewrite(std::move(op->children[1]));
return op;
}
case LogicalOperatorType::LOGICAL_GET:
return PushdownGet(std::move(op));
case LogicalOperatorType::LOGICAL_LIMIT:
Expand Down
22 changes: 14 additions & 8 deletions src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#include "duckdb/common/enums/join_type.hpp"
#include "duckdb/common/limits.hpp"
#include "duckdb/common/printer.hpp"
#include "duckdb/planner/expression_iterator.hpp"
#include "duckdb/function/table/table_scan.hpp"
#include "duckdb/optimizer/join_order/join_node.hpp"
#include "duckdb/optimizer/join_order/query_graph_manager.hpp"
#include "duckdb/planner/expression_iterator.hpp"
#include "duckdb/planner/operator/logical_comparison_join.hpp"
#include "duckdb/storage/data_table.hpp"

Expand Down Expand Up @@ -291,10 +291,18 @@ DenomInfo CardinalityEstimator::GetDenominator(JoinRelationSet &set) {
// and we start to choose the filters that join relations in the set.

// edges are guaranteed to be in order of largest tdom to smallest tdom.
unordered_set<idx_t> unused_edge_tdoms;
auto edges = GetEdges(relations_to_tdoms, set);
for (auto &edge : edges) {
auto subgraph_connections = SubgraphsConnectedByEdge(edge, subgraphs);
if (subgraphs.size() == 1 && subgraphs.at(0).relations->ToString() == set.ToString()) {
// the first subgraph has connected all the desired relations, just skip the rest of the edges
if (edge.has_tdom_hll) {
unused_edge_tdoms.insert(edge.tdom_hll);
}
continue;
}

auto subgraph_connections = SubgraphsConnectedByEdge(edge, subgraphs);
if (subgraph_connections.empty()) {
// create a subgraph out of left and right, then merge right into left and add left to subgraphs.
// this helps cover a case where there are no subgraphs yet, and the only join filter is a SEMI JOIN
Expand Down Expand Up @@ -342,13 +350,11 @@ DenomInfo CardinalityEstimator::GetDenominator(JoinRelationSet &set) {
[](Subgraph2Denominator &s) { return !s.relations; });
subgraphs.erase(remove_start, subgraphs.end());
}
if (subgraphs.size() == 1 && subgraphs.at(0).relations->ToString() == set.ToString()) {
// the first subgraph has connected all the desired relations, no need to iterate
// through the rest of the edges.
break;
}
}

// Slight penalty to cardinality for unused edges
auto denom_multiplier = 1.0 + static_cast<double>(unused_edge_tdoms.size());

// It's possible cross-products were added and are not present in the filters in the relation_2_tdom
// structures. When that's the case, merge all remaining subgraphs.
if (subgraphs.size() > 1) {
Expand All @@ -367,7 +373,7 @@ DenomInfo CardinalityEstimator::GetDenominator(JoinRelationSet &set) {
// denominator is 1 and numerators are a cross product of cardinalities.
return DenomInfo(set, 1, 1);
}
return DenomInfo(*subgraphs.at(0).numerator_relations, 1, subgraphs.at(0).denom);
return DenomInfo(*subgraphs.at(0).numerator_relations, 1, subgraphs.at(0).denom * denom_multiplier);
}

template <>
Expand Down
3 changes: 2 additions & 1 deletion src/duckdb/src/planner/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ unique_ptr<BoundQueryNode> Binder::BindNode(QueryNode &node) {

BoundStatement Binder::Bind(QueryNode &node) {
BoundStatement result;
if (context.db->config.options.disabled_optimizers.find(OptimizerType::MATERIALIZED_CTE) ==
if (node.type != QueryNodeType::CTE_NODE && // Issue #13850 - Don't auto-materialize if users materialize (for now)
context.db->config.options.disabled_optimizers.find(OptimizerType::MATERIALIZED_CTE) ==
context.db->config.options.disabled_optimizers.end() &&
context.config.enable_optimizer && OptimizeCTEs(node)) {
switch (node.type) {
Expand Down
4 changes: 4 additions & 0 deletions src/duckdb/src/storage/buffer/buffer_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ void BufferPool::SetAllocatorBulkDeallocationFlushThreshold(idx_t threshold) {
allocator_bulk_deallocation_flush_threshold = threshold;
}

idx_t BufferPool::GetAllocatorBulkDeallocationFlushThreshold() {
return allocator_bulk_deallocation_flush_threshold;
}

BufferPool::MemoryUsage::MemoryUsage() {
for (auto &v : memory_usage) {
v = 0;
Expand Down

0 comments on commit 47cb18b

Please sign in to comment.