Skip to content

Commit fe53d8b

Browse files
duckdblabs-botbrianwyka
authored andcommitted
Update vendored DuckDB sources to 37e5e11
1 parent 70ececd commit fe53d8b

File tree

11 files changed

+142
-43
lines changed

11 files changed

+142
-43
lines changed

src/duckdb/src/common/vector_operations/comparison_operators.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ struct ComparisonExecutor {
223223
public:
224224
template <class OP>
225225
static inline void Execute(Vector &left, Vector &right, Vector &result, idx_t count) {
226-
D_ASSERT(left.GetType() == right.GetType() && result.GetType() == LogicalType::BOOLEAN);
226+
D_ASSERT(left.GetType().InternalType() == right.GetType().InternalType() &&
227+
result.GetType() == LogicalType::BOOLEAN);
227228
// the inplace loops take the result as the last parameter
228229
switch (left.GetType().InternalType()) {
229230
case PhysicalType::BOOL:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//===----------------------------------------------------------------------===//
2+
// DuckDB
3+
//
4+
// duckdb/common/atomic_ptr.hpp
5+
//
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include "duckdb/common/exception.hpp"
12+
#include "duckdb/common/atomic.hpp"
13+
#include "duckdb/common/shared_ptr.hpp"
14+
#include "duckdb/common/unique_ptr.hpp"
15+
16+
namespace duckdb {
17+
18+
template <class T, bool SAFE = true>
19+
class atomic_ptr { // NOLINT: mimic std casing
20+
public:
21+
atomic_ptr() noexcept : ptr(nullptr) {
22+
}
23+
atomic_ptr(T *ptr_p) : ptr(ptr_p) { // NOLINT: allow implicit creation from pointer
24+
}
25+
atomic_ptr(T &ref) : ptr(&ref) { // NOLINT: allow implicit creation from reference
26+
}
27+
atomic_ptr(const unique_ptr<T> &ptr_p) : ptr(ptr_p.get()) { // NOLINT: allow implicit creation from unique pointer
28+
}
29+
atomic_ptr(const shared_ptr<T> &ptr_p) : ptr(ptr_p.get()) { // NOLINT: allow implicit creation from shared pointer
30+
}
31+
32+
void CheckValid(const T *ptr) const {
33+
if (MemorySafety<SAFE>::ENABLED) {
34+
return;
35+
}
36+
if (!ptr) {
37+
throw InternalException("Attempting to dereference an optional pointer that is not set");
38+
}
39+
}
40+
41+
T *GetPointer() {
42+
auto res = ptr.load();
43+
CheckValid(res);
44+
return res;
45+
}
46+
47+
const T *GetPointer() const {
48+
auto res = ptr.load();
49+
CheckValid(res);
50+
return res;
51+
}
52+
53+
operator bool() const { // NOLINT: allow implicit conversion to bool
54+
return ptr;
55+
}
56+
T &operator*() {
57+
return *GetPointer();
58+
}
59+
const T &operator*() const {
60+
return *GetPointer();
61+
}
62+
T *operator->() {
63+
return GetPointer();
64+
}
65+
const T *operator->() const {
66+
return GetPointer();
67+
}
68+
T *get() { // NOLINT: mimic std casing
69+
return GetPointer();
70+
}
71+
const T *get() const { // NOLINT: mimic std casing
72+
return GetPointer();
73+
}
74+
// this looks dirty - but this is the default behavior of raw pointers
75+
T *get_mutable() const { // NOLINT: mimic std casing
76+
return GetPointer();
77+
}
78+
79+
void set(T &ref) {
80+
ptr = &ref;
81+
}
82+
83+
void reset() {
84+
ptr = nullptr;
85+
}
86+
87+
bool operator==(const atomic_ptr<T> &rhs) const {
88+
return ptr.load() == rhs.ptr.load();
89+
}
90+
91+
bool operator!=(const atomic_ptr<T> &rhs) const {
92+
return ptr.load() != rhs.ptr.load();
93+
}
94+
95+
private:
96+
atomic<T *> ptr;
97+
};
98+
99+
template <typename T>
100+
using unsafe_atomic_ptr = atomic_ptr<T, false>;
101+
102+
} // namespace duckdb

src/duckdb/src/include/duckdb/common/fast_mem.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
#include "duckdb/common/types.hpp"
1212

1313
template <size_t SIZE>
14-
static inline void MemcpyFixed(void *dest, const void *src) {
14+
inline void MemcpyFixed(void *dest, const void *src) {
1515
memcpy(dest, src, SIZE);
1616
}
1717

1818
template <size_t SIZE>
19-
static inline int MemcmpFixed(const void *str1, const void *str2) {
19+
inline int MemcmpFixed(const void *str1, const void *str2) {
2020
return memcmp(str1, str2, SIZE);
2121
}
2222

2323
template <size_t SIZE>
24-
static inline void MemsetFixed(void *ptr, int value) {
24+
inline void MemsetFixed(void *ptr, int value) {
2525
memset(ptr, value, SIZE);
2626
}
2727

@@ -30,7 +30,7 @@ namespace duckdb {
3030
//! This templated memcpy is significantly faster than std::memcpy,
3131
//! but only when you are calling memcpy with a const size in a loop.
3232
//! For instance `while (<cond>) { memcpy(<dest>, <src>, const_size); ... }`
33-
static inline void FastMemcpy(void *dest, const void *src, const size_t size) {
33+
inline void FastMemcpy(void *dest, const void *src, const size_t size) {
3434
// LCOV_EXCL_START
3535
switch (size) {
3636
case 0:
@@ -556,7 +556,7 @@ static inline void FastMemcpy(void *dest, const void *src, const size_t size) {
556556
//! This templated memcmp is significantly faster than std::memcmp,
557557
//! but only when you are calling memcmp with a const size in a loop.
558558
//! For instance `while (<cond>) { memcmp(<str1>, <str2>, const_size); ... }`
559-
static inline int FastMemcmp(const void *str1, const void *str2, const size_t size) {
559+
inline int FastMemcmp(const void *str1, const void *str2, const size_t size) {
560560
// LCOV_EXCL_START
561561
switch (size) {
562562
case 0:
@@ -695,7 +695,7 @@ static inline int FastMemcmp(const void *str1, const void *str2, const size_t si
695695
// LCOV_EXCL_STOP
696696
}
697697

698-
static inline void FastMemset(void *ptr, int value, size_t size) {
698+
inline void FastMemset(void *ptr, int value, size_t size) {
699699
// LCOV_EXCL_START
700700
switch (size) {
701701
case 0:

src/duckdb/src/include/duckdb/storage/table/column_data.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "duckdb/common/mutex.hpp"
1919
#include "duckdb/common/enums/scan_vector_type.hpp"
2020
#include "duckdb/common/serializer/serialization_traits.hpp"
21+
#include "duckdb/common/atomic_ptr.hpp"
2122

2223
namespace duckdb {
2324
class ColumnData;
@@ -81,12 +82,8 @@ class ColumnData {
8182
idx_t GetAllocationSize() const {
8283
return allocation_size;
8384
}
84-
bool HasCompressionFunction() const {
85-
return compression != nullptr;
86-
}
87-
const CompressionFunction &GetCompressionFunction() const {
88-
D_ASSERT(HasCompressionFunction());
89-
return *compression;
85+
optional_ptr<const CompressionFunction> GetCompressionFunction() const {
86+
return compression.get();
9087
}
9188

9289
bool HasParent() const {
@@ -238,7 +235,7 @@ class ColumnData {
238235
optional_ptr<ColumnData> parent;
239236
//! The compression function used by the ColumnData
240237
//! This is empty if the segments have mixed compression or the ColumnData is empty
241-
optional_ptr<const CompressionFunction> compression;
238+
atomic_ptr<const CompressionFunction> compression;
242239
};
243240

244241
struct PersistentColumnData {

src/duckdb/src/parser/transform/tableref/transform_pivot.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ PivotColumn Transformer::TransformPivotColumn(duckdb_libpgquery::PGPivot &pivot,
7373
"PIVOT IN list must contain columns or lists of columns");
7474
} else {
7575
// for unpivot - we can forward the expression immediately
76+
entry.values.clear();
7677
entry.expr = std::move(expr);
7778
}
7879
}

src/duckdb/src/planner/bind_context.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,6 @@ void BindContext::AddContext(BindContext other) {
695695
}
696696
for (auto &entry : other.using_columns) {
697697
for (auto &alias : entry.second) {
698-
#ifdef DEBUG
699-
for (auto &other_alias : using_columns[entry.first]) {
700-
for (auto &col : alias.get().bindings) {
701-
D_ASSERT(std::find(other_alias.get().bindings.begin(), other_alias.get().bindings.end(), col) ==
702-
other_alias.get().bindings.end());
703-
}
704-
}
705-
#endif
706698
using_columns[entry.first].insert(alias);
707699
}
708700
}
@@ -719,22 +711,22 @@ vector<BindingAlias> BindContext::GetBindingAliases() {
719711
void BindContext::RemoveContext(const vector<BindingAlias> &aliases) {
720712
for (auto &alias : aliases) {
721713
// remove the binding from any USING columns
714+
vector<string> removed_using_columns;
722715
for (auto &using_sets : using_columns) {
723716
for (auto &using_set_ref : using_sets.second) {
724717
auto &using_set = using_set_ref.get();
725718
auto it = std::remove_if(using_set.bindings.begin(), using_set.bindings.end(),
726719
[&](const BindingAlias &using_alias) { return using_alias == alias; });
727720
using_set.bindings.erase(it, using_set.bindings.end());
728-
if (using_set.bindings.empty()) {
729-
throw InternalException(
730-
"BindContext::RemoveContext - no more tables that refer to this using binding");
731-
}
732-
if (using_set.primary_binding == alias) {
733-
throw InternalException(
734-
"BindContext::RemoveContext - cannot remove primary binding from using binding");
721+
if (using_set.bindings.empty() || using_set.primary_binding == alias) {
722+
// if the using column is no longer referred to - remove it entirely
723+
removed_using_columns.push_back(using_sets.first);
735724
}
736725
}
737726
}
727+
for (auto &removed_col : removed_using_columns) {
728+
using_columns.erase(removed_col);
729+
}
738730

739731
// remove the binding from the list of bindings
740732
auto it = std::remove_if(bindings_list.begin(), bindings_list.end(),

src/duckdb/src/planner/binder/expression/bind_window_expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
155155
return BindMacro(*macro, entry->Cast<ScalarMacroCatalogEntry>(), depth, macro_expr);
156156
}
157157

158-
auto name = window.GetName();
158+
auto name = window.alias;
159159

160160
if (inside_window) {
161161
throw BinderException(error_context, "window function calls cannot be nested");

src/duckdb/src/planner/binder/statement/bind_vacuum.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ void Binder::BindVacuumTable(LogicalVacuum &vacuum, unique_ptr<LogicalOperator>
2727
auto &columns = info.columns;
2828
if (columns.empty()) {
2929
// Empty means ALL columns should be vacuumed/analyzed
30-
auto &get = ref->get->Cast<LogicalGet>();
31-
columns.insert(columns.end(), get.names.begin(), get.names.end());
30+
for (auto &col : table.GetColumns().Physical()) {
31+
columns.push_back(col.GetName());
32+
}
3233
}
3334

3435
case_insensitive_set_t column_name_set;
@@ -45,7 +46,9 @@ void Binder::BindVacuumTable(LogicalVacuum &vacuum, unique_ptr<LogicalOperator>
4546
auto &col = table.GetColumn(col_name);
4647
// ignore generated column
4748
if (col.Generated()) {
48-
continue;
49+
throw BinderException(
50+
"cannot vacuum or analyze generated column \"%s\" - specify non-generated columns to vacuum or analyze",
51+
col.GetName());
4952
}
5053
non_generated_column_names.push_back(col_name);
5154
ColumnRefExpression colref(col_name, table.name);
@@ -56,8 +59,6 @@ void Binder::BindVacuumTable(LogicalVacuum &vacuum, unique_ptr<LogicalOperator>
5659
select_list.push_back(std::move(result.expression));
5760
}
5861
info.columns = std::move(non_generated_column_names);
59-
// Creating a table without any physical columns is not supported
60-
D_ASSERT(!select_list.empty());
6162

6263
auto table_scan = CreatePlan(*ref);
6364
D_ASSERT(table_scan->type == LogicalOperatorType::LOGICAL_GET);

src/duckdb/src/planner/subquery/flatten_dependent_join.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
414414
return plan;
415415
}
416416
} else if (join.join_type == JoinType::RIGHT) {
417-
// left outer join
417+
// right outer join
418418
if (!left_has_correlation) {
419419
// only right has correlation: push into right
420420
plan->children[1] = PushDownDependentJoinInternal(std::move(plan->children[1]),
@@ -450,6 +450,7 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
450450
this->base_binding = left_binding;
451451
} else if (join.join_type == JoinType::RIGHT) {
452452
this->base_binding = right_binding;
453+
delim_offset += plan->children[0]->GetColumnBindings().size();
453454
}
454455
// add the correlated columns to the join conditions
455456
for (idx_t i = 0; i < correlated_columns.size(); i++) {

src/duckdb/src/storage/table/column_data.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,12 @@ void ColumnData::UpdateCompressionFunction(SegmentLock &l, const CompressionFunc
571571
// if we have no segments - we have not set it yet, so assign it
572572
// if we have segments, the compression is mixed, so ignore it
573573
if (data.GetSegmentCount(l) == 0) {
574-
compression = function;
574+
compression.set(function);
575575
}
576576
} else if (compression->type != function.type) {
577577
// we already have compression set - and we are adding a segment with a different compression
578578
// compression in the segment is mixed - clear the compression pointer
579-
compression = nullptr;
579+
compression.reset();
580580
}
581581
}
582582

@@ -632,7 +632,7 @@ unique_ptr<ColumnCheckpointState> ColumnData::Checkpoint(RowGroup &row_group, Co
632632
checkpointer.FinalizeCheckpoint(data.MoveSegments(l));
633633

634634
// reset the compression function
635-
compression = nullptr;
635+
compression.reset();
636636
// replace the old tree with the new one
637637
auto new_segments = checkpoint_state->new_tree.MoveSegments();
638638
for (auto &new_segment : new_segments) {

0 commit comments

Comments
 (0)