duckdb 0.7.2-dev3441.0 → 0.7.2-dev3515.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 +2 -2
- package/src/duckdb/extension/json/json_functions/json_create.cpp +1 -1
- package/src/duckdb/src/catalog/default/default_functions.cpp +1 -0
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +4 -4
- package/src/duckdb/src/common/compressed_file_system.cpp +2 -2
- package/src/duckdb/src/common/file_system.cpp +2 -2
- package/src/duckdb/src/common/row_operations/row_gather.cpp +2 -2
- package/src/duckdb/src/common/serializer/binary_deserializer.cpp +1 -1
- package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +1 -1
- package/src/duckdb/src/common/serializer/buffered_file_writer.cpp +1 -1
- package/src/duckdb/src/common/serializer/buffered_serializer.cpp +4 -3
- package/src/duckdb/src/common/serializer.cpp +1 -1
- package/src/duckdb/src/common/sort/radix_sort.cpp +5 -5
- package/src/duckdb/src/common/string_util.cpp +2 -2
- package/src/duckdb/src/common/types/bit.cpp +2 -2
- package/src/duckdb/src/common/types/blob.cpp +2 -2
- package/src/duckdb/src/common/types/data_chunk.cpp +2 -2
- package/src/duckdb/src/common/types/date.cpp +1 -1
- package/src/duckdb/src/common/types/decimal.cpp +2 -2
- package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +14 -2
- package/src/duckdb/src/common/types/selection_vector.cpp +1 -1
- package/src/duckdb/src/common/types/time.cpp +1 -1
- package/src/duckdb/src/common/types/vector.cpp +7 -7
- package/src/duckdb/src/common/virtual_file_system.cpp +4 -0
- package/src/duckdb/src/common/windows_util.cpp +2 -2
- package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +6 -3
- package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +2 -5
- package/src/duckdb/src/core_functions/scalar/string/printf.cpp +1 -1
- package/src/duckdb/src/execution/aggregate_hashtable.cpp +1 -1
- package/src/duckdb/src/execution/join_hashtable.cpp +3 -3
- package/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +2 -2
- package/src/duckdb/src/execution/operator/join/outer_join_marker.cpp +1 -1
- package/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +1 -1
- package/src/duckdb/src/execution/operator/join/physical_range_join.cpp +1 -1
- package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +2 -7
- package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +4 -41
- package/src/duckdb/src/execution/operator/persistent/csv_file_handle.cpp +158 -0
- package/src/duckdb/src/execution/operator/projection/physical_pivot.cpp +1 -1
- package/src/duckdb/src/execution/perfect_aggregate_hashtable.cpp +2 -2
- package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +3 -4
- package/src/duckdb/src/execution/window_segment_tree.cpp +1 -1
- package/src/duckdb/src/function/pragma/pragma_queries.cpp +1 -1
- package/src/duckdb/src/function/scalar/strftime_format.cpp +1 -1
- package/src/duckdb/src/function/scalar/string/concat.cpp +1 -1
- package/src/duckdb/src/function/scalar/string/like.cpp +2 -2
- package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +5 -5
- package/src/duckdb/src/function/table/copy_csv.cpp +1 -1
- package/src/duckdb/src/function/table/read_csv.cpp +43 -35
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/common/allocator.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/compressed_file_system.hpp +3 -3
- package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -5
- package/src/duckdb/src/include/duckdb/common/helper.hpp +22 -9
- package/src/duckdb/src/include/duckdb/common/memory_safety.hpp +15 -0
- package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_writer.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/serializer/buffered_serializer.hpp +3 -2
- package/src/duckdb/src/include/duckdb/common/serializer/serialization_traits.hpp +2 -3
- package/src/duckdb/src/include/duckdb/common/sort/duckdb_pdqsort.hpp +11 -6
- package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +2 -1
- package/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +3 -3
- package/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp +4 -4
- package/src/duckdb/src/include/duckdb/common/unique_ptr.hpp +53 -22
- package/src/duckdb/src/include/duckdb/common/vector.hpp +5 -2
- package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +4 -4
- package/src/duckdb/src/include/duckdb/execution/operator/join/outer_join_marker.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/perfect_hash_join_executor.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/base_csv_reader.hpp +0 -2
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/buffered_csv_reader.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +27 -127
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/parallel_csv_reader.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/perfect_aggregate_hashtable.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/window_segment_tree.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +2 -4
- package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +3 -3
- package/src/duckdb/src/include/duckdb/parser/statement/insert_statement.hpp +5 -0
- package/src/duckdb/src/include/duckdb/storage/arena_allocator.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/buffer/buffer_handle.hpp +9 -2
- package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/append_state.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +2 -2
- package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +5 -5
- package/src/duckdb/src/optimizer/unnest_rewriter.cpp +14 -6
- package/src/duckdb/src/parser/statement/insert_statement.cpp +4 -1
- package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +10 -0
- package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +32 -7
- package/src/duckdb/src/storage/arena_allocator.cpp +1 -1
- package/src/duckdb/src/storage/buffer/buffer_handle.cpp +2 -11
- package/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp +1 -1
- package/src/duckdb/src/storage/compression/string_uncompressed.cpp +2 -2
- package/src/duckdb/src/storage/statistics/list_stats.cpp +1 -1
- package/src/duckdb/src/storage/statistics/struct_stats.cpp +1 -1
- package/src/duckdb/src/storage/table/row_group.cpp +2 -2
- package/src/duckdb/src/storage/table/update_segment.cpp +7 -6
- package/src/duckdb/third_party/fsst/libfsst.cpp +1 -2
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +9 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +13 -12
- package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +2 -1
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +12537 -12415
- package/src/duckdb/ub_src_execution_operator_persistent.cpp +2 -0
- package/src/statement.cpp +15 -13
@@ -1,8 +1,8 @@
|
|
1
1
|
#ifndef DUCKDB_VERSION
|
2
|
-
#define DUCKDB_VERSION "0.7.2-
|
2
|
+
#define DUCKDB_VERSION "0.7.2-dev3515"
|
3
3
|
#endif
|
4
4
|
#ifndef DUCKDB_SOURCE_ID
|
5
|
-
#define DUCKDB_SOURCE_ID "
|
5
|
+
#define DUCKDB_SOURCE_ID "12638bd156"
|
6
6
|
#endif
|
7
7
|
#include "duckdb/function/table/system_functions.hpp"
|
8
8
|
#include "duckdb/main/database.hpp"
|
@@ -18,8 +18,8 @@ struct StreamData {
|
|
18
18
|
// various buffers & pointers
|
19
19
|
bool write = false;
|
20
20
|
bool refresh = false;
|
21
|
-
|
22
|
-
|
21
|
+
unsafe_array_ptr<data_t> in_buff;
|
22
|
+
unsafe_array_ptr<data_t> out_buff;
|
23
23
|
data_ptr_t out_buff_start = nullptr;
|
24
24
|
data_ptr_t out_buff_end = nullptr;
|
25
25
|
data_ptr_t in_buff_start = nullptr;
|
@@ -59,7 +59,7 @@ public:
|
|
59
59
|
class CompressedFile : public FileHandle {
|
60
60
|
public:
|
61
61
|
DUCKDB_API CompressedFile(CompressedFileSystem &fs, unique_ptr<FileHandle> child_handle_p, const string &path);
|
62
|
-
DUCKDB_API
|
62
|
+
DUCKDB_API ~CompressedFile() override;
|
63
63
|
|
64
64
|
CompressedFileSystem &compressed_fs;
|
65
65
|
unique_ptr<FileHandle> child_handle;
|
@@ -21,11 +21,6 @@ namespace duckdb {
|
|
21
21
|
using std::move;
|
22
22
|
#endif
|
23
23
|
|
24
|
-
// template <class _Tp, class _Dp = std::default_delete<_Tp>>
|
25
|
-
// class unique_ptr;
|
26
|
-
|
27
|
-
// using data_ptr = unique_ptr<char[]>;
|
28
|
-
|
29
24
|
// NOTE: there is a copy of this in the Postgres' parser grammar (gram.y)
|
30
25
|
#define DEFAULT_SCHEMA "main"
|
31
26
|
#define INVALID_SCHEMA ""
|
@@ -37,10 +37,10 @@ namespace duckdb {
|
|
37
37
|
#define DUCKDB_EXPLICIT_FALLTHROUGH
|
38
38
|
#endif
|
39
39
|
|
40
|
-
template<class _Tp>
|
40
|
+
template<class _Tp, bool SAFE = true>
|
41
41
|
struct __unique_if
|
42
42
|
{
|
43
|
-
typedef unique_ptr<_Tp> __unique_single;
|
43
|
+
typedef unique_ptr<_Tp, SAFE> __unique_single;
|
44
44
|
};
|
45
45
|
|
46
46
|
template<class _Tp>
|
@@ -57,19 +57,32 @@ struct __unique_if<_Tp[_Np]>
|
|
57
57
|
|
58
58
|
template<class _Tp, class... _Args>
|
59
59
|
inline
|
60
|
-
typename __unique_if<_Tp>::__unique_single
|
60
|
+
typename __unique_if<_Tp, true>::__unique_single
|
61
61
|
make_uniq(_Args&&... __args)
|
62
62
|
{
|
63
|
-
return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
|
63
|
+
return unique_ptr<_Tp, true>(new _Tp(std::forward<_Args>(__args)...));
|
64
64
|
}
|
65
65
|
|
66
|
-
template<class _Tp>
|
66
|
+
template<class _Tp, class... _Args>
|
67
67
|
inline
|
68
|
-
typename __unique_if<_Tp>::
|
69
|
-
|
68
|
+
typename __unique_if<_Tp, false>::__unique_single
|
69
|
+
make_unsafe_uniq(_Args&&... __args)
|
70
|
+
{
|
71
|
+
return unique_ptr<_Tp, false>(new _Tp(std::forward<_Args>(__args)...));
|
72
|
+
}
|
73
|
+
|
74
|
+
template<class _Tp>
|
75
|
+
inline unique_ptr<_Tp[], true>
|
76
|
+
make_array(size_t __n)
|
77
|
+
{
|
78
|
+
return unique_ptr<_Tp[], true>(new _Tp[__n]());
|
79
|
+
}
|
80
|
+
|
81
|
+
template<class _Tp>
|
82
|
+
inline unique_ptr<_Tp[], false>
|
83
|
+
make_unsafe_array(size_t __n)
|
70
84
|
{
|
71
|
-
|
72
|
-
return unique_ptr<_Tp>(new _Up[__n]());
|
85
|
+
return unique_ptr<_Tp[], false>(new _Tp[__n]());
|
73
86
|
}
|
74
87
|
|
75
88
|
template<class _Tp, class... _Args>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
namespace duckdb {
|
4
|
+
|
5
|
+
template <bool ENABLED>
|
6
|
+
struct MemorySafety {
|
7
|
+
#ifdef DEBUG
|
8
|
+
// In DEBUG mode safety is always on
|
9
|
+
static constexpr bool enabled = true;
|
10
|
+
#else
|
11
|
+
static constexpr bool enabled = ENABLED;
|
12
|
+
#endif
|
13
|
+
};
|
14
|
+
|
15
|
+
} // namespace duckdb
|
@@ -18,7 +18,7 @@ public:
|
|
18
18
|
FileLockType lock_type = FileLockType::READ_LOCK, optional_ptr<FileOpener> opener = nullptr);
|
19
19
|
|
20
20
|
FileSystem &fs;
|
21
|
-
|
21
|
+
unsafe_array_ptr<data_t> data;
|
22
22
|
idx_t offset;
|
23
23
|
idx_t read_data;
|
24
24
|
unique_ptr<FileHandle> handle;
|
@@ -9,13 +9,14 @@
|
|
9
9
|
#pragma once
|
10
10
|
|
11
11
|
#include "duckdb/common/serializer.hpp"
|
12
|
+
#include "duckdb/common/unique_ptr.hpp"
|
12
13
|
|
13
14
|
namespace duckdb {
|
14
15
|
|
15
16
|
#define SERIALIZER_DEFAULT_SIZE 1024
|
16
17
|
|
17
18
|
struct BinaryData {
|
18
|
-
|
19
|
+
unsafe_array_ptr<data_t> data;
|
19
20
|
idx_t size;
|
20
21
|
};
|
21
22
|
|
@@ -25,7 +26,7 @@ public:
|
|
25
26
|
//! writing past the initial threshold
|
26
27
|
DUCKDB_API explicit BufferedSerializer(idx_t maximum_size = SERIALIZER_DEFAULT_SIZE);
|
27
28
|
//! Serializes to a provided (owned) data pointer
|
28
|
-
BufferedSerializer(
|
29
|
+
BufferedSerializer(unsafe_array_ptr<data_t> data, idx_t size);
|
29
30
|
BufferedSerializer(data_ptr_t data, idx_t size);
|
30
31
|
|
31
32
|
idx_t maximum_size;
|
@@ -65,10 +65,9 @@ struct is_unordered_map<typename std::unordered_map<Args...>> : std::true_type {
|
|
65
65
|
template <typename T>
|
66
66
|
struct is_unique_ptr : std::false_type {};
|
67
67
|
|
68
|
-
template <typename T
|
69
|
-
struct is_unique_ptr<unique_ptr<T
|
68
|
+
template <typename T>
|
69
|
+
struct is_unique_ptr<unique_ptr<T>> : std::true_type {
|
70
70
|
typedef T ELEMENT_TYPE;
|
71
|
-
typedef D DELETER_TYPE;
|
72
71
|
};
|
73
72
|
|
74
73
|
template <typename T>
|
@@ -25,6 +25,7 @@ applications, and to alter it and redistribute it freely, subject to the followi
|
|
25
25
|
#include "duckdb/common/fast_mem.hpp"
|
26
26
|
#include "duckdb/common/helper.hpp"
|
27
27
|
#include "duckdb/common/types.hpp"
|
28
|
+
#include "duckdb/common/unique_ptr.hpp"
|
28
29
|
|
29
30
|
#include <algorithm>
|
30
31
|
#include <cstddef>
|
@@ -38,6 +39,10 @@ using duckdb::idx_t;
|
|
38
39
|
using duckdb::data_t;
|
39
40
|
using duckdb::data_ptr_t;
|
40
41
|
using duckdb::unique_ptr;
|
42
|
+
using duckdb::array_ptr;
|
43
|
+
using duckdb::unsafe_array_ptr;
|
44
|
+
using duckdb::make_array;
|
45
|
+
using duckdb::make_unsafe_array;
|
41
46
|
using duckdb::FastMemcpy;
|
42
47
|
using duckdb::FastMemcmp;
|
43
48
|
|
@@ -73,9 +78,9 @@ inline int log2(T n) {
|
|
73
78
|
struct PDQConstants {
|
74
79
|
PDQConstants(idx_t entry_size, idx_t comp_offset, idx_t comp_size, data_ptr_t end)
|
75
80
|
: entry_size(entry_size), comp_offset(comp_offset), comp_size(comp_size),
|
76
|
-
tmp_buf_ptr(
|
77
|
-
iter_swap_buf_ptr(
|
78
|
-
swap_offsets_buf_ptr(
|
81
|
+
tmp_buf_ptr(make_unsafe_array<data_t>(entry_size)), tmp_buf(tmp_buf_ptr.get()),
|
82
|
+
iter_swap_buf_ptr(make_unsafe_array<data_t>(entry_size)), iter_swap_buf(iter_swap_buf_ptr.get()),
|
83
|
+
swap_offsets_buf_ptr(make_unsafe_array<data_t>(entry_size)),
|
79
84
|
swap_offsets_buf(swap_offsets_buf_ptr.get()), end(end) {
|
80
85
|
}
|
81
86
|
|
@@ -83,13 +88,13 @@ struct PDQConstants {
|
|
83
88
|
const idx_t comp_offset;
|
84
89
|
const idx_t comp_size;
|
85
90
|
|
86
|
-
|
91
|
+
unsafe_array_ptr<data_t> tmp_buf_ptr;
|
87
92
|
const data_ptr_t tmp_buf;
|
88
93
|
|
89
|
-
|
94
|
+
unsafe_array_ptr<data_t> iter_swap_buf_ptr;
|
90
95
|
const data_ptr_t iter_swap_buf;
|
91
96
|
|
92
|
-
|
97
|
+
unsafe_array_ptr<data_t> swap_offsets_buf_ptr;
|
93
98
|
const data_ptr_t swap_offsets_buf;
|
94
99
|
|
95
100
|
const data_ptr_t end;
|
@@ -124,7 +124,8 @@ public:
|
|
124
124
|
//! Turn all the vectors from the chunk into flat vectors
|
125
125
|
DUCKDB_API void Flatten();
|
126
126
|
|
127
|
-
DUCKDB_API
|
127
|
+
// FIXME: this is DUCKDB_API, might need conversion back to regular unique ptr?
|
128
|
+
DUCKDB_API unsafe_array_ptr<UnifiedVectorFormat> ToUnifiedFormat();
|
128
129
|
|
129
130
|
DUCKDB_API void Slice(const SelectionVector &sel_vector, idx_t count);
|
130
131
|
|
@@ -24,7 +24,7 @@ struct TemplatedValidityData {
|
|
24
24
|
public:
|
25
25
|
inline explicit TemplatedValidityData(idx_t count) {
|
26
26
|
auto entry_count = EntryCount(count);
|
27
|
-
owned_data =
|
27
|
+
owned_data = make_unsafe_array<V>(entry_count);
|
28
28
|
for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
|
29
29
|
owned_data[entry_idx] = MAX_ENTRY;
|
30
30
|
}
|
@@ -32,13 +32,13 @@ public:
|
|
32
32
|
inline TemplatedValidityData(const V *validity_mask, idx_t count) {
|
33
33
|
D_ASSERT(validity_mask);
|
34
34
|
auto entry_count = EntryCount(count);
|
35
|
-
owned_data =
|
35
|
+
owned_data = make_unsafe_array<V>(entry_count);
|
36
36
|
for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
|
37
37
|
owned_data[entry_idx] = validity_mask[entry_idx];
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
|
-
|
41
|
+
unsafe_array_ptr<V> owned_data;
|
42
42
|
|
43
43
|
public:
|
44
44
|
static inline idx_t EntryCount(idx_t count) {
|
@@ -71,10 +71,10 @@ public:
|
|
71
71
|
}
|
72
72
|
explicit VectorBuffer(idx_t data_size) : buffer_type(VectorBufferType::STANDARD_BUFFER) {
|
73
73
|
if (data_size > 0) {
|
74
|
-
data =
|
74
|
+
data = make_unsafe_array<data_t>(data_size);
|
75
75
|
}
|
76
76
|
}
|
77
|
-
explicit VectorBuffer(
|
77
|
+
explicit VectorBuffer(unsafe_array_ptr<data_t> data_p)
|
78
78
|
: buffer_type(VectorBufferType::STANDARD_BUFFER), data(std::move(data_p)) {
|
79
79
|
}
|
80
80
|
virtual ~VectorBuffer() {
|
@@ -87,7 +87,7 @@ public:
|
|
87
87
|
return data.get();
|
88
88
|
}
|
89
89
|
|
90
|
-
void SetData(
|
90
|
+
void SetData(unsafe_array_ptr<data_t> new_data) {
|
91
91
|
data = std::move(new_data);
|
92
92
|
}
|
93
93
|
|
@@ -120,7 +120,7 @@ public:
|
|
120
120
|
protected:
|
121
121
|
VectorBufferType buffer_type;
|
122
122
|
unique_ptr<VectorAuxiliaryData> aux_data;
|
123
|
-
|
123
|
+
unsafe_array_ptr<data_t> data;
|
124
124
|
};
|
125
125
|
|
126
126
|
//! The DictionaryBuffer holds a selection vector
|
@@ -2,38 +2,45 @@
|
|
2
2
|
|
3
3
|
#include "duckdb/common/exception.hpp"
|
4
4
|
#include "duckdb/common/likely.hpp"
|
5
|
+
#include "duckdb/common/memory_safety.hpp"
|
5
6
|
|
6
7
|
#include <memory>
|
7
8
|
#include <type_traits>
|
8
9
|
|
9
10
|
namespace duckdb {
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
template <class _Tp, bool SAFE = true>
|
13
|
+
class unique_ptr : public std::unique_ptr<_Tp, std::default_delete<_Tp>> {
|
14
|
+
public:
|
15
|
+
using original = std::unique_ptr<_Tp, std::default_delete<_Tp>>;
|
16
|
+
using original::original;
|
17
|
+
|
18
|
+
private:
|
19
|
+
static inline void AssertNotNull(const bool null) {
|
20
|
+
#if defined(DUCKDB_DEBUG_NO_SAFETY) || defined(DUCKDB_CLANG_TIDY)
|
21
|
+
return;
|
22
|
+
#else
|
23
|
+
if (DUCKDB_UNLIKELY(null)) {
|
24
|
+
throw duckdb::InternalException("Attempted to dereference unique_ptr that is NULL!");
|
17
25
|
}
|
18
26
|
#endif
|
19
27
|
}
|
20
|
-
};
|
21
|
-
} // namespace
|
22
28
|
|
23
|
-
template <class _Tp, class _Dp = std::default_delete<_Tp>>
|
24
|
-
class unique_ptr : public std::unique_ptr<_Tp, _Dp> {
|
25
29
|
public:
|
26
|
-
using original = std::unique_ptr<_Tp, _Dp>;
|
27
|
-
using original::original;
|
28
|
-
|
29
30
|
typename std::add_lvalue_reference<_Tp>::type operator*() const {
|
30
|
-
|
31
|
-
|
31
|
+
const auto ptr = original::get();
|
32
|
+
if (MemorySafety<SAFE>::enabled) {
|
33
|
+
AssertNotNull(!ptr);
|
34
|
+
}
|
35
|
+
return *ptr;
|
32
36
|
}
|
33
37
|
|
34
38
|
typename original::pointer operator->() const {
|
35
|
-
|
36
|
-
|
39
|
+
const auto ptr = original::get();
|
40
|
+
if (MemorySafety<SAFE>::enabled) {
|
41
|
+
AssertNotNull(!ptr);
|
42
|
+
}
|
43
|
+
return ptr;
|
37
44
|
}
|
38
45
|
|
39
46
|
#ifdef DUCKDB_CLANG_TIDY
|
@@ -46,16 +53,40 @@ public:
|
|
46
53
|
}
|
47
54
|
};
|
48
55
|
|
49
|
-
template <class _Tp,
|
50
|
-
class unique_ptr<_Tp[],
|
56
|
+
template <class _Tp, bool SAFE>
|
57
|
+
class unique_ptr<_Tp[], SAFE> : public std::unique_ptr<_Tp[], std::default_delete<_Tp[]>> {
|
51
58
|
public:
|
52
|
-
using original = std::unique_ptr<_Tp[],
|
59
|
+
using original = std::unique_ptr<_Tp[], std::default_delete<_Tp[]>>;
|
53
60
|
using original::original;
|
54
61
|
|
62
|
+
private:
|
63
|
+
static inline void AssertNotNull(const bool null) {
|
64
|
+
#if defined(DUCKDB_DEBUG_NO_SAFETY) || defined(DUCKDB_CLANG_TIDY)
|
65
|
+
return;
|
66
|
+
#else
|
67
|
+
if (DUCKDB_UNLIKELY(null)) {
|
68
|
+
throw duckdb::InternalException("Attempted to dereference unique_ptr that is NULL!");
|
69
|
+
}
|
70
|
+
#endif
|
71
|
+
}
|
72
|
+
|
73
|
+
public:
|
55
74
|
typename std::add_lvalue_reference<_Tp>::type operator[](size_t __i) const {
|
56
|
-
|
57
|
-
|
75
|
+
const auto ptr = original::get();
|
76
|
+
if (MemorySafety<SAFE>::enabled) {
|
77
|
+
AssertNotNull(!ptr);
|
78
|
+
}
|
79
|
+
return ptr[__i];
|
58
80
|
}
|
59
81
|
};
|
60
82
|
|
83
|
+
template <typename T>
|
84
|
+
using array_ptr = unique_ptr<T[], true>;
|
85
|
+
|
86
|
+
template <typename T>
|
87
|
+
using unsafe_array_ptr = unique_ptr<T[], false>;
|
88
|
+
|
89
|
+
template <typename T>
|
90
|
+
using unsafe_unique_ptr = unique_ptr<T, false>;
|
91
|
+
|
61
92
|
} // namespace duckdb
|
@@ -12,6 +12,7 @@
|
|
12
12
|
#include "duckdb/common/typedefs.hpp"
|
13
13
|
#include "duckdb/common/likely.hpp"
|
14
14
|
#include "duckdb/common/exception.hpp"
|
15
|
+
#include "duckdb/common/memory_safety.hpp"
|
15
16
|
#include <vector>
|
16
17
|
|
17
18
|
namespace duckdb {
|
@@ -25,6 +26,7 @@ public:
|
|
25
26
|
using const_reference = typename original::const_reference;
|
26
27
|
using reference = typename original::reference;
|
27
28
|
|
29
|
+
private:
|
28
30
|
static inline void AssertIndexInBounds(idx_t index, idx_t size) {
|
29
31
|
#if defined(DUCKDB_DEBUG_NO_SAFETY) || defined(DUCKDB_CLANG_TIDY)
|
30
32
|
return;
|
@@ -35,6 +37,7 @@ public:
|
|
35
37
|
#endif
|
36
38
|
}
|
37
39
|
|
40
|
+
public:
|
38
41
|
#ifdef DUCKDB_CLANG_TIDY
|
39
42
|
// This is necessary to tell clang-tidy that it reinitializes the variable after a move
|
40
43
|
[[clang::reinitializes]]
|
@@ -55,7 +58,7 @@ public:
|
|
55
58
|
|
56
59
|
template <bool _SAFE = false>
|
57
60
|
inline typename original::reference get(typename original::size_type __n) {
|
58
|
-
if (_SAFE) {
|
61
|
+
if (MemorySafety<_SAFE>::enabled) {
|
59
62
|
AssertIndexInBounds(__n, original::size());
|
60
63
|
}
|
61
64
|
return original::operator[](__n);
|
@@ -63,7 +66,7 @@ public:
|
|
63
66
|
|
64
67
|
template <bool _SAFE = false>
|
65
68
|
inline typename original::const_reference get(typename original::size_type __n) const {
|
66
|
-
if (_SAFE) {
|
69
|
+
if (MemorySafety<_SAFE>::enabled) {
|
67
70
|
AssertIndexInBounds(__n, original::size());
|
68
71
|
}
|
69
72
|
return original::operator[](__n);
|
@@ -73,7 +73,7 @@ struct AggregateHTAppendState {
|
|
73
73
|
SelectionVector empty_vector;
|
74
74
|
SelectionVector new_groups;
|
75
75
|
Vector addresses;
|
76
|
-
|
76
|
+
unsafe_array_ptr<UnifiedVectorFormat> group_data;
|
77
77
|
DataChunk group_chunk;
|
78
78
|
|
79
79
|
TupleDataChunkState chunk_state;
|
@@ -65,12 +65,12 @@ public:
|
|
65
65
|
//! returned by the JoinHashTable::Scan function and can be used to resume a
|
66
66
|
//! probe.
|
67
67
|
struct ScanStructure {
|
68
|
-
|
68
|
+
unsafe_array_ptr<UnifiedVectorFormat> key_data;
|
69
69
|
Vector pointers;
|
70
70
|
idx_t count;
|
71
71
|
SelectionVector sel_vector;
|
72
72
|
// whether or not the given tuple has found a match
|
73
|
-
|
73
|
+
unsafe_array_ptr<bool> found_match;
|
74
74
|
JoinHashTable &ht;
|
75
75
|
bool finished;
|
76
76
|
|
@@ -212,8 +212,8 @@ private:
|
|
212
212
|
//! Insert the given set of locations into the HT with the given set of hashes
|
213
213
|
void InsertHashes(Vector &hashes, idx_t count, data_ptr_t key_locations[], bool parallel);
|
214
214
|
|
215
|
-
idx_t PrepareKeys(DataChunk &keys,
|
216
|
-
SelectionVector &sel, bool build_side);
|
215
|
+
idx_t PrepareKeys(DataChunk &keys, unsafe_array_ptr<UnifiedVectorFormat> &key_data,
|
216
|
+
const SelectionVector *¤t_sel, SelectionVector &sel, bool build_side);
|
217
217
|
|
218
218
|
//! Lock for combining data_collection when merging HTs
|
219
219
|
mutex data_lock;
|
package/src/duckdb/src/include/duckdb/execution/operator/join/perfect_hash_join_executor.hpp
CHANGED
@@ -68,7 +68,7 @@ private:
|
|
68
68
|
//! Build and probe statistics
|
69
69
|
PerfectHashJoinStats perfect_join_statistics;
|
70
70
|
//! Stores the occurences of each value in the build side
|
71
|
-
|
71
|
+
unsafe_array_ptr<bool> bitmap_build_idx;
|
72
72
|
//! Stores the number of unique keys in the build side
|
73
73
|
idx_t unique_keys = 0;
|
74
74
|
};
|
@@ -83,7 +83,7 @@ public:
|
|
83
83
|
//! The total number of rows in the RHS
|
84
84
|
atomic<idx_t> count;
|
85
85
|
//! A bool indicating for each tuple in the RHS if they found a match (only used in FULL OUTER JOIN)
|
86
|
-
|
86
|
+
unsafe_array_ptr<bool> found_match;
|
87
87
|
//! Memory usage per thread
|
88
88
|
idx_t memory_per_thread;
|
89
89
|
};
|
@@ -60,12 +60,12 @@ public:
|
|
60
60
|
virtual ~BufferedCSVReader() {
|
61
61
|
}
|
62
62
|
|
63
|
-
|
63
|
+
unsafe_array_ptr<char> buffer;
|
64
64
|
idx_t buffer_size;
|
65
65
|
idx_t position;
|
66
66
|
idx_t start = 0;
|
67
67
|
|
68
|
-
vector<
|
68
|
+
vector<unsafe_array_ptr<char>> cached_buffers;
|
69
69
|
|
70
70
|
unique_ptr<CSVFileHandle> file_handle;
|
71
71
|
|