duckdb 0.7.2-dev1734.0 → 0.7.2-dev1867.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.
Files changed (155) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/src/catalog/catalog.cpp +27 -27
  3. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +6 -6
  4. package/src/duckdb/src/catalog/catalog_set.cpp +27 -25
  5. package/src/duckdb/src/catalog/default/default_functions.cpp +4 -4
  6. package/src/duckdb/src/catalog/default/default_types.cpp +4 -4
  7. package/src/duckdb/src/catalog/default/default_views.cpp +4 -4
  8. package/src/duckdb/src/catalog/dependency_list.cpp +7 -6
  9. package/src/duckdb/src/catalog/dependency_manager.cpp +44 -38
  10. package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +11 -6
  11. package/src/duckdb/src/common/types/batched_data_collection.cpp +2 -1
  12. package/src/duckdb/src/common/types/column_data_allocator.cpp +1 -0
  13. package/src/duckdb/src/common/types/vector.cpp +2 -2
  14. package/src/duckdb/src/common/types.cpp +2 -2
  15. package/src/duckdb/src/common/vector_operations/vector_copy.cpp +14 -11
  16. package/src/duckdb/src/execution/operator/aggregate/distinct_aggregate_data.cpp +1 -1
  17. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +51 -50
  18. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +14 -13
  19. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +20 -20
  20. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  21. package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +1 -1
  22. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +3 -3
  23. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  24. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  25. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  26. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +3 -3
  27. package/src/duckdb/src/function/cast/cast_function_set.cpp +2 -1
  28. package/src/duckdb/src/function/scalar/math/numeric.cpp +57 -0
  29. package/src/duckdb/src/function/scalar/math_functions.cpp +1 -0
  30. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +29 -29
  31. package/src/duckdb/src/function/scalar/string/damerau_levenshtein.cpp +106 -0
  32. package/src/duckdb/src/function/scalar/string/hex.cpp +261 -78
  33. package/src/duckdb/src/function/scalar/string/regexp.cpp +145 -28
  34. package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
  35. package/src/duckdb/src/function/table/checkpoint.cpp +4 -4
  36. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +24 -24
  37. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +7 -6
  38. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +1 -1
  39. package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +11 -11
  40. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +1 -1
  41. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +17 -18
  42. package/src/duckdb/src/function/table/table_scan.cpp +8 -11
  43. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  44. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +9 -9
  45. package/src/duckdb/src/include/duckdb/catalog/catalog_entry_map.hpp +38 -0
  46. package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +4 -3
  47. package/src/duckdb/src/include/duckdb/catalog/default/default_functions.hpp +2 -2
  48. package/src/duckdb/src/include/duckdb/catalog/default/default_types.hpp +2 -2
  49. package/src/duckdb/src/include/duckdb/catalog/default/default_views.hpp +2 -2
  50. package/src/duckdb/src/include/duckdb/catalog/dependency.hpp +4 -5
  51. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +4 -5
  52. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +10 -9
  53. package/src/duckdb/src/include/duckdb/common/allocator.hpp +2 -1
  54. package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +147 -0
  55. package/src/duckdb/src/include/duckdb/common/field_writer.hpp +1 -1
  56. package/src/duckdb/src/include/duckdb/common/helper.hpp +9 -0
  57. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +1 -0
  58. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +29 -6
  59. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +6 -5
  60. package/src/duckdb/src/include/duckdb/common/serializer.hpp +1 -1
  61. package/src/duckdb/src/include/duckdb/common/string_util.hpp +7 -0
  62. package/src/duckdb/src/include/duckdb/common/types/row_data_collection.hpp +1 -0
  63. package/src/duckdb/src/include/duckdb/common/types.hpp +1 -1
  64. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +2 -2
  65. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +5 -5
  66. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_create_table.hpp +2 -2
  67. package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +3 -2
  68. package/src/duckdb/src/include/duckdb/function/scalar/math_functions.hpp +4 -0
  69. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +4 -0
  70. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +4 -3
  71. package/src/duckdb/src/include/duckdb/main/query_result.hpp +3 -2
  72. package/src/duckdb/src/include/duckdb/optimizer/filter_combiner.hpp +7 -7
  73. package/src/duckdb/src/include/duckdb/optimizer/matcher/expression_matcher.hpp +11 -11
  74. package/src/duckdb/src/include/duckdb/optimizer/matcher/set_matcher.hpp +8 -8
  75. package/src/duckdb/src/include/duckdb/optimizer/rule/arithmetic_simplification.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/optimizer/rule/case_simplification.hpp +1 -1
  77. package/src/duckdb/src/include/duckdb/optimizer/rule/comparison_simplification.hpp +1 -1
  78. package/src/duckdb/src/include/duckdb/optimizer/rule/conjunction_simplification.hpp +2 -2
  79. package/src/duckdb/src/include/duckdb/optimizer/rule/constant_folding.hpp +1 -1
  80. package/src/duckdb/src/include/duckdb/optimizer/rule/date_part_simplification.hpp +1 -1
  81. package/src/duckdb/src/include/duckdb/optimizer/rule/distributivity.hpp +1 -1
  82. package/src/duckdb/src/include/duckdb/optimizer/rule/empty_needle_removal.hpp +1 -1
  83. package/src/duckdb/src/include/duckdb/optimizer/rule/enum_comparison.hpp +1 -1
  84. package/src/duckdb/src/include/duckdb/optimizer/rule/equal_or_null_simplification.hpp +1 -1
  85. package/src/duckdb/src/include/duckdb/optimizer/rule/in_clause_simplification.hpp +1 -1
  86. package/src/duckdb/src/include/duckdb/optimizer/rule/like_optimizations.hpp +1 -1
  87. package/src/duckdb/src/include/duckdb/optimizer/rule/move_constants.hpp +1 -1
  88. package/src/duckdb/src/include/duckdb/optimizer/rule/ordered_aggregate_optimizer.hpp +1 -1
  89. package/src/duckdb/src/include/duckdb/optimizer/rule/regex_optimizations.hpp +1 -1
  90. package/src/duckdb/src/include/duckdb/optimizer/rule.hpp +2 -2
  91. package/src/duckdb/src/include/duckdb/parser/base_expression.hpp +1 -1
  92. package/src/duckdb/src/include/duckdb/parser/expression_map.hpp +19 -6
  93. package/src/duckdb/src/include/duckdb/parser/expression_util.hpp +1 -1
  94. package/src/duckdb/src/include/duckdb/planner/expression.hpp +5 -2
  95. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +3 -3
  97. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +15 -7
  98. package/src/duckdb/src/include/duckdb/storage/buffer/buffer_pool.hpp +3 -0
  99. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +49 -126
  100. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp128.hpp +1 -0
  101. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/chimp_utils.hpp +0 -97
  102. package/src/duckdb/src/include/duckdb/storage/compression/patas/algorithm/patas.hpp +1 -0
  103. package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +5 -5
  104. package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +159 -0
  105. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +1 -0
  106. package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +6 -5
  107. package/src/duckdb/src/main/client_context.cpp +1 -1
  108. package/src/duckdb/src/main/database.cpp +2 -1
  109. package/src/duckdb/src/main/database_manager.cpp +4 -4
  110. package/src/duckdb/src/optimizer/common_aggregate_optimizer.cpp +2 -2
  111. package/src/duckdb/src/optimizer/cse_optimizer.cpp +4 -4
  112. package/src/duckdb/src/optimizer/deliminator.cpp +13 -11
  113. package/src/duckdb/src/optimizer/expression_rewriter.cpp +2 -2
  114. package/src/duckdb/src/optimizer/filter_combiner.cpp +67 -65
  115. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -0
  116. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +26 -25
  117. package/src/duckdb/src/optimizer/matcher/expression_matcher.cpp +23 -21
  118. package/src/duckdb/src/optimizer/rule/arithmetic_simplification.cpp +3 -3
  119. package/src/duckdb/src/optimizer/rule/case_simplification.cpp +2 -2
  120. package/src/duckdb/src/optimizer/rule/comparison_simplification.cpp +6 -7
  121. package/src/duckdb/src/optimizer/rule/conjunction_simplification.cpp +9 -8
  122. package/src/duckdb/src/optimizer/rule/constant_folding.cpp +7 -7
  123. package/src/duckdb/src/optimizer/rule/date_part_simplification.cpp +3 -3
  124. package/src/duckdb/src/optimizer/rule/distributivity.cpp +5 -5
  125. package/src/duckdb/src/optimizer/rule/empty_needle_removal.cpp +6 -6
  126. package/src/duckdb/src/optimizer/rule/enum_comparison.cpp +4 -4
  127. package/src/duckdb/src/optimizer/rule/equal_or_null_simplification.cpp +23 -26
  128. package/src/duckdb/src/optimizer/rule/in_clause_simplification_rule.cpp +2 -3
  129. package/src/duckdb/src/optimizer/rule/like_optimizations.cpp +3 -3
  130. package/src/duckdb/src/optimizer/rule/move_constants.cpp +6 -6
  131. package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +2 -2
  132. package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +11 -10
  133. package/src/duckdb/src/parser/expression_util.cpp +6 -6
  134. package/src/duckdb/src/parser/transform/helpers/transform_groupby.cpp +3 -3
  135. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +2 -2
  136. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +3 -3
  137. package/src/duckdb/src/planner/binder/query_node/bind_setop_node.cpp +5 -5
  138. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +2 -2
  139. package/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +4 -4
  140. package/src/duckdb/src/planner/expression_binder/order_binder.cpp +3 -3
  141. package/src/duckdb/src/storage/buffer/block_handle.cpp +7 -6
  142. package/src/duckdb/src/storage/buffer/block_manager.cpp +3 -1
  143. package/src/duckdb/src/storage/buffer/buffer_handle.cpp +1 -0
  144. package/src/duckdb/src/storage/buffer/buffer_pool.cpp +6 -2
  145. package/src/duckdb/src/storage/buffer/buffer_pool_reservation.cpp +7 -4
  146. package/src/duckdb/src/storage/buffer_manager.cpp +35 -726
  147. package/src/duckdb/src/storage/checkpoint_manager.cpp +2 -2
  148. package/src/duckdb/src/storage/meta_block_reader.cpp +6 -5
  149. package/src/duckdb/src/storage/standard_buffer_manager.cpp +801 -0
  150. package/src/duckdb/src/storage/wal_replay.cpp +2 -2
  151. package/src/duckdb/src/transaction/meta_transaction.cpp +13 -13
  152. package/src/duckdb/src/transaction/transaction.cpp +1 -1
  153. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
  154. package/src/duckdb/ub_src_function_scalar_string.cpp +2 -0
  155. package/src/duckdb/ub_src_storage.cpp +2 -0
@@ -11,6 +11,7 @@
11
11
  #include "duckdb/catalog/catalog_entry.hpp"
12
12
  #include "duckdb/catalog/catalog_set.hpp"
13
13
  #include "duckdb/catalog/dependency.hpp"
14
+ #include "duckdb/catalog/catalog_entry_map.hpp"
14
15
  #include "duckdb/catalog/catalog_transaction.hpp"
15
16
 
16
17
  #include <functional>
@@ -28,26 +29,26 @@ public:
28
29
  explicit DependencyManager(DuckCatalog &catalog);
29
30
 
30
31
  //! Erase the object from the DependencyManager; this should only happen when the object itself is destroyed
31
- void EraseObject(CatalogEntry *object);
32
+ void EraseObject(CatalogEntry &object);
32
33
 
33
34
  //! Scans all dependencies, returning pairs of (object, dependent)
34
- void Scan(const std::function<void(CatalogEntry *, CatalogEntry *, DependencyType)> &callback);
35
+ void Scan(const std::function<void(CatalogEntry &, CatalogEntry &, DependencyType)> &callback);
35
36
 
36
- void AddOwnership(CatalogTransaction transaction, CatalogEntry *owner, CatalogEntry *entry);
37
+ void AddOwnership(CatalogTransaction transaction, CatalogEntry &owner, CatalogEntry &entry);
37
38
 
38
39
  private:
39
40
  DuckCatalog &catalog;
40
41
  //! Map of objects that DEPEND on [object], i.e. [object] can only be deleted when all entries in the dependency map
41
42
  //! are deleted.
42
- unordered_map<CatalogEntry *, dependency_set_t> dependents_map;
43
+ catalog_entry_map_t<dependency_set_t> dependents_map;
43
44
  //! Map of objects that the source object DEPENDS on, i.e. when any of the entries in the vector perform a CASCADE
44
45
  //! drop then [object] is deleted as well
45
- unordered_map<CatalogEntry *, unordered_set<CatalogEntry *>> dependencies_map;
46
+ catalog_entry_map_t<catalog_entry_set_t> dependencies_map;
46
47
 
47
48
  private:
48
- void AddObject(CatalogTransaction transaction, CatalogEntry *object, DependencyList &dependencies);
49
- void DropObject(CatalogTransaction transaction, CatalogEntry *object, bool cascade);
50
- void AlterObject(CatalogTransaction transaction, CatalogEntry *old_obj, CatalogEntry *new_obj);
51
- void EraseObjectInternal(CatalogEntry *object);
49
+ void AddObject(CatalogTransaction transaction, CatalogEntry &object, DependencyList &dependencies);
50
+ void DropObject(CatalogTransaction transaction, CatalogEntry &object, bool cascade);
51
+ void AlterObject(CatalogTransaction transaction, CatalogEntry &old_obj, CatalogEntry &new_obj);
52
+ void EraseObjectInternal(CatalogEntry &object);
52
53
  };
53
54
  } // namespace duckdb
@@ -9,6 +9,7 @@
9
9
  #pragma once
10
10
 
11
11
  #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/optional_ptr.hpp"
12
13
 
13
14
  namespace duckdb {
14
15
  class Allocator;
@@ -56,7 +57,7 @@ public:
56
57
  void Reset();
57
58
 
58
59
  private:
59
- Allocator *allocator;
60
+ optional_ptr<Allocator> allocator;
60
61
  data_ptr_t pointer;
61
62
  idx_t allocated_size;
62
63
  };
@@ -0,0 +1,147 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/bit_utils.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/hugeint.hpp"
12
+
13
+ #ifdef _MSC_VER
14
+ #define __restrict__
15
+ #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
16
+ #define __ORDER_LITTLE_ENDIAN__ 2
17
+ #include <intrin.h>
18
+ static inline int __builtin_ctzll(unsigned long long x) {
19
+ #ifdef _WIN64
20
+ unsigned long ret;
21
+ _BitScanForward64(&ret, x);
22
+ return (int)ret;
23
+ #else
24
+ unsigned long low, high;
25
+ bool low_set = _BitScanForward(&low, (unsigned __int32)(x)) != 0;
26
+ _BitScanForward(&high, (unsigned __int32)(x >> 32));
27
+ high += 32;
28
+ return low_set ? low : high;
29
+ #endif
30
+ }
31
+ static inline int __builtin_clzll(unsigned long long mask) {
32
+ unsigned long where;
33
+ // BitScanReverse scans from MSB to LSB for first set bit.
34
+ // Returns 0 if no set bit is found.
35
+ #if defined(_WIN64)
36
+ if (_BitScanReverse64(&where, mask))
37
+ return static_cast<int>(63 - where);
38
+ #elif defined(_WIN32)
39
+ // Scan the high 32 bits.
40
+ if (_BitScanReverse(&where, static_cast<unsigned long>(mask >> 32)))
41
+ return static_cast<int>(63 - (where + 32)); // Create a bit offset from the MSB.
42
+ // Scan the low 32 bits.
43
+ if (_BitScanReverse(&where, static_cast<unsigned long>(mask)))
44
+ return static_cast<int>(63 - where);
45
+ #else
46
+ #error "Implementation of __builtin_clzll required"
47
+ #endif
48
+ return 64; // Undefined Behavior.
49
+ }
50
+
51
+ static inline int __builtin_ctz(unsigned int value) {
52
+ unsigned long trailing_zero = 0;
53
+
54
+ if (_BitScanForward(&trailing_zero, value)) {
55
+ return trailing_zero;
56
+ } else {
57
+ // This is undefined, I better choose 32 than 0
58
+ return 32;
59
+ }
60
+ }
61
+
62
+ static inline int __builtin_clz(unsigned int value) {
63
+ unsigned long leading_zero = 0;
64
+
65
+ if (_BitScanReverse(&leading_zero, value)) {
66
+ return 31 - leading_zero;
67
+ } else {
68
+ // Same remarks as above
69
+ return 32;
70
+ }
71
+ }
72
+
73
+ #endif
74
+
75
+ namespace duckdb {
76
+
77
+ template <class T>
78
+ struct CountZeros {};
79
+
80
+ template <>
81
+ struct CountZeros<uint32_t> {
82
+ inline static int Leading(uint32_t value) {
83
+ if (!value) {
84
+ return 32;
85
+ }
86
+ return __builtin_clz(value);
87
+ }
88
+ inline static int Trailing(uint32_t value) {
89
+ if (!value) {
90
+ return 32;
91
+ }
92
+ return __builtin_ctz(value);
93
+ }
94
+ };
95
+
96
+ template <>
97
+ struct CountZeros<uint64_t> {
98
+ inline static int Leading(uint64_t value) {
99
+ if (!value) {
100
+ return 64;
101
+ }
102
+ return __builtin_clzll(value);
103
+ }
104
+ inline static int Trailing(uint64_t value) {
105
+ if (!value) {
106
+ return 64;
107
+ }
108
+ return __builtin_ctzll(value);
109
+ }
110
+ };
111
+
112
+ template <>
113
+ struct CountZeros<hugeint_t> {
114
+ inline static int Leading(hugeint_t value) {
115
+ if (value == 0) {
116
+ return 128;
117
+ }
118
+
119
+ uint64_t upper = (uint64_t)value.upper;
120
+ uint64_t lower = value.lower;
121
+
122
+ int res = __builtin_clzll(upper);
123
+ if (res == 64) {
124
+ res += __builtin_clzll(lower);
125
+ }
126
+
127
+ return res;
128
+ }
129
+
130
+ inline static int Trailing(hugeint_t value) {
131
+ if (value == 0) {
132
+ return 128;
133
+ }
134
+
135
+ uint64_t upper = (uint64_t)value.upper;
136
+ uint64_t lower = value.lower;
137
+
138
+ int res = __builtin_ctzll(lower);
139
+ if (res == 64) {
140
+ res += __builtin_ctzll(upper);
141
+ }
142
+
143
+ return res;
144
+ }
145
+ };
146
+
147
+ } // namespace duckdb
@@ -167,7 +167,7 @@ public:
167
167
  return root.GetContext();
168
168
  }
169
169
 
170
- Catalog *GetCatalog() override {
170
+ optional_ptr<Catalog> GetCatalog() override {
171
171
  return root.GetCatalog();
172
172
  }
173
173
 
@@ -170,4 +170,13 @@ void AssignSharedPointer(shared_ptr<T> &target, const shared_ptr<T> &source) {
170
170
  }
171
171
  }
172
172
 
173
+ template<typename T>
174
+ using reference = std::reference_wrapper<T>;
175
+
176
+ //! Returns whether or not two reference wrappers refer to the same object
177
+ template<class T>
178
+ bool RefersToSameObject(const reference<T> &A, const reference<T> &B) {
179
+ return &A.get() == &B.get();
180
+ }
181
+
173
182
  } // namespace duckdb
@@ -1,6 +1,7 @@
1
1
  #pragma once
2
2
 
3
3
  #include "duckdb/common/winapi.hpp"
4
+ #include "duckdb/common/string.hpp"
4
5
  #include <stdint.h>
5
6
 
6
7
  namespace duckdb {
@@ -22,19 +22,42 @@ public:
22
22
  optional_ptr(const unique_ptr<T> &ptr_p) : ptr(ptr_p.get()) { // NOLINT: allow implicit creation from unique pointer
23
23
  }
24
24
 
25
+ void CheckValid() const {
26
+ if (!ptr) {
27
+ throw InternalException("Attempting to dereference an optional pointer that is not set");
28
+ }
29
+ }
30
+
25
31
  operator bool() const {
26
32
  return ptr;
27
33
  }
28
34
  T &operator*() {
29
- if (!ptr) {
30
- throw InternalException("Attempting to dereference an optional pointer that is not set");
31
- }
35
+ CheckValid();
36
+ return *ptr;
37
+ }
38
+ const T &operator*() const {
39
+ CheckValid();
32
40
  return *ptr;
33
41
  }
34
42
  T *operator->() {
35
- if (!ptr) {
36
- throw InternalException("Attempting to call a method on an optional pointer that is not set");
37
- }
43
+ CheckValid();
44
+ return ptr;
45
+ }
46
+ const T *operator->() const {
47
+ CheckValid();
48
+ return ptr;
49
+ }
50
+ T *get() {
51
+ // CheckValid();
52
+ return ptr;
53
+ }
54
+ const T *get() const {
55
+ // CheckValid();
56
+ return ptr;
57
+ }
58
+ // this looks dirty - but this is the default behavior of raw pointers
59
+ T *get_mutable() const {
60
+ // CheckValid();
38
61
  return ptr;
39
62
  }
40
63
 
@@ -14,16 +14,14 @@ namespace duckdb {
14
14
 
15
15
  class BufferedFileReader : public Deserializer {
16
16
  public:
17
- BufferedFileReader(FileSystem &fs, const char *path, ClientContext *context,
18
- FileLockType lock_type = FileLockType::READ_LOCK, FileOpener *opener = nullptr);
17
+ BufferedFileReader(FileSystem &fs, const char *path, optional_ptr<ClientContext> context,
18
+ FileLockType lock_type = FileLockType::READ_LOCK, optional_ptr<FileOpener> opener = nullptr);
19
19
 
20
20
  FileSystem &fs;
21
21
  unique_ptr<data_t[]> data;
22
22
  idx_t offset;
23
23
  idx_t read_data;
24
24
  unique_ptr<FileHandle> handle;
25
- ClientContext *context;
26
- Catalog *catalog = nullptr;
27
25
 
28
26
  public:
29
27
  void ReadData(data_ptr_t buffer, uint64_t read_size) override;
@@ -39,11 +37,14 @@ public:
39
37
 
40
38
  ClientContext &GetContext() override;
41
39
 
42
- Catalog *GetCatalog() override;
40
+ optional_ptr<Catalog> GetCatalog() override;
41
+ void SetCatalog(Catalog &catalog);
43
42
 
44
43
  private:
45
44
  idx_t file_size;
46
45
  idx_t total_read;
46
+ optional_ptr<ClientContext> context;
47
+ optional_ptr<Catalog> catalog;
47
48
  };
48
49
 
49
50
  } // namespace duckdb
@@ -120,7 +120,7 @@ public:
120
120
  };
121
121
 
122
122
  //! Gets the catalog for the deserializer
123
- virtual Catalog *GetCatalog() {
123
+ virtual optional_ptr<Catalog> GetCatalog() {
124
124
  return nullptr;
125
125
  };
126
126
 
@@ -38,6 +38,13 @@ public:
38
38
  throw InvalidInputException("Invalid input for hex digit: %s", string(c, 1));
39
39
  }
40
40
 
41
+ static uint8_t GetBinaryValue(char c) {
42
+ if (c >= '0' && c <= '1') {
43
+ return c - '0';
44
+ }
45
+ throw InvalidInputException("Invalid input for binary digit: %s", string(c, 1));
46
+ }
47
+
41
48
  DUCKDB_API static bool CharacterIsSpace(char c) {
42
49
  return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r';
43
50
  }
@@ -11,6 +11,7 @@
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/types/vector.hpp"
13
13
  #include "duckdb/storage/buffer_manager.hpp"
14
+ #include "duckdb/storage/buffer/block_handle.hpp"
14
15
 
15
16
  namespace duckdb {
16
17
 
@@ -387,7 +387,7 @@ public:
387
387
  DUCKDB_API static LogicalType DECIMAL(int width, int scale); // NOLINT
388
388
  DUCKDB_API static LogicalType VARCHAR_COLLATION(string collation); // NOLINT
389
389
  DUCKDB_API static LogicalType LIST(const LogicalType &child); // NOLINT
390
- DUCKDB_API static LogicalType STRUCT(const child_list_t<LogicalType> &children); // NOLINT
390
+ DUCKDB_API static LogicalType STRUCT(child_list_t<LogicalType> children); // NOLINT
391
391
  DUCKDB_API static LogicalType AGGREGATE_STATE(aggregate_state_t state_type); // NOLINT
392
392
  DUCKDB_API static LogicalType MAP(const LogicalType &child); // NOLINT
393
393
  DUCKDB_API static LogicalType MAP( child_list_t<LogicalType> children); // NOLINT
@@ -22,7 +22,7 @@ public:
22
22
  physical_index_vector_t<idx_t> column_index_map, vector<unique_ptr<Expression>> bound_defaults,
23
23
  idx_t estimated_cardinality);
24
24
  //! CREATE TABLE AS
25
- PhysicalBatchInsert(LogicalOperator &op, SchemaCatalogEntry *schema, unique_ptr<BoundCreateTableInfo> info,
25
+ PhysicalBatchInsert(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr<BoundCreateTableInfo> info,
26
26
  idx_t estimated_cardinality);
27
27
 
28
28
  //! The map from insert column index to table column index
@@ -34,7 +34,7 @@ public:
34
34
  //! The default expressions of the columns for which no value is provided
35
35
  vector<unique_ptr<Expression>> bound_defaults;
36
36
  //! Table schema, in case of CREATE TABLE AS
37
- SchemaCatalogEntry *schema;
37
+ optional_ptr<SchemaCatalogEntry> schema;
38
38
  //! Create table info, in case of CREATE TABLE AS
39
39
  unique_ptr<BoundCreateTableInfo> info;
40
40
  // Which action to perform on conflict
@@ -32,7 +32,7 @@ public:
32
32
  unique_ptr<Expression> on_conflict_condition, unique_ptr<Expression> do_update_condition,
33
33
  unordered_set<column_t> on_conflict_filter, vector<column_t> columns_to_fetch);
34
34
  //! CREATE TABLE AS
35
- PhysicalInsert(LogicalOperator &op, SchemaCatalogEntry *schema, unique_ptr<BoundCreateTableInfo> info,
35
+ PhysicalInsert(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr<BoundCreateTableInfo> info,
36
36
  idx_t estimated_cardinality, bool parallel);
37
37
 
38
38
  //! The map from insert column index to table column index
@@ -46,7 +46,7 @@ public:
46
46
  //! If the returning statement is present, return the whole chunk
47
47
  bool return_chunk;
48
48
  //! Table schema, in case of CREATE TABLE AS
49
- SchemaCatalogEntry *schema;
49
+ optional_ptr<SchemaCatalogEntry> schema;
50
50
  //! Create table info, in case of CREATE TABLE AS
51
51
  unique_ptr<BoundCreateTableInfo> info;
52
52
  //! Whether or not the INSERT can be executed in parallel
@@ -109,15 +109,15 @@ public:
109
109
  public:
110
110
  static void GetInsertInfo(const BoundCreateTableInfo &info, vector<LogicalType> &insert_types,
111
111
  vector<unique_ptr<Expression>> &bound_defaults);
112
- static void ResolveDefaults(TableCatalogEntry *table, DataChunk &chunk,
112
+ static void ResolveDefaults(const TableCatalogEntry &table, DataChunk &chunk,
113
113
  const physical_index_vector_t<idx_t> &column_index_map,
114
114
  ExpressionExecutor &defaults_executor, DataChunk &result);
115
115
 
116
116
  protected:
117
117
  void CombineExistingAndInsertTuples(DataChunk &result, DataChunk &scan_chunk, DataChunk &input_chunk,
118
118
  ClientContext &client) const;
119
- void OnConflictHandling(TableCatalogEntry *table, ExecutionContext &context, InsertLocalState &lstate) const;
120
- void PerformOnConflictAction(ExecutionContext &context, DataChunk &chunk, TableCatalogEntry *table,
119
+ void OnConflictHandling(TableCatalogEntry &table, ExecutionContext &context, InsertLocalState &lstate) const;
120
+ void PerformOnConflictAction(ExecutionContext &context, DataChunk &chunk, TableCatalogEntry &table,
121
121
  Vector &row_ids) const;
122
122
  void RegisterUpdatedRows(InsertLocalState &lstate, const Vector &row_ids, idx_t count) const;
123
123
  };
@@ -19,11 +19,11 @@ public:
19
19
  static constexpr const PhysicalOperatorType TYPE = PhysicalOperatorType::CREATE_TABLE;
20
20
 
21
21
  public:
22
- PhysicalCreateTable(LogicalOperator &op, SchemaCatalogEntry *schema, unique_ptr<BoundCreateTableInfo> info,
22
+ PhysicalCreateTable(LogicalOperator &op, SchemaCatalogEntry &schema, unique_ptr<BoundCreateTableInfo> info,
23
23
  idx_t estimated_cardinality);
24
24
 
25
25
  //! Schema to insert to
26
- SchemaCatalogEntry *schema;
26
+ SchemaCatalogEntry &schema;
27
27
  //! Table name to create
28
28
  unique_ptr<BoundCreateTableInfo> info;
29
29
 
@@ -97,10 +97,11 @@ public:
97
97
  };
98
98
 
99
99
  struct BindCastInput {
100
- DUCKDB_API BindCastInput(CastFunctionSet &function_set, BindCastInfo *info, optional_ptr<ClientContext> context);
100
+ DUCKDB_API BindCastInput(CastFunctionSet &function_set, optional_ptr<BindCastInfo> info,
101
+ optional_ptr<ClientContext> context);
101
102
 
102
103
  CastFunctionSet &function_set;
103
- BindCastInfo *info;
104
+ optional_ptr<BindCastInfo> info;
104
105
  optional_ptr<ClientContext> context;
105
106
 
106
107
  public:
@@ -30,6 +30,10 @@ struct FloorFun {
30
30
  static void RegisterFunction(BuiltinFunctions &set);
31
31
  };
32
32
 
33
+ struct TruncFun {
34
+ static void RegisterFunction(BuiltinFunctions &set);
35
+ };
36
+
33
37
  struct RoundFun {
34
38
  static void RegisterFunction(BuiltinFunctions &set);
35
39
  };
@@ -205,6 +205,10 @@ struct LevenshteinFun {
205
205
  static void RegisterFunction(BuiltinFunctions &set);
206
206
  };
207
207
 
208
+ struct DamerauLevenshteinFun {
209
+ static void RegisterFunction(BuiltinFunctions &set);
210
+ };
211
+
208
212
  struct JaccardFun {
209
213
  static void RegisterFunction(BuiltinFunctions &set);
210
214
  };
@@ -12,6 +12,7 @@
12
12
  #include "duckdb/common/case_insensitive_map.hpp"
13
13
  #include "duckdb/common/mutex.hpp"
14
14
  #include "duckdb/common/atomic.hpp"
15
+ #include "duckdb/common/optional_ptr.hpp"
15
16
 
16
17
  namespace duckdb {
17
18
  class AttachedDatabase;
@@ -35,7 +36,7 @@ public:
35
36
 
36
37
  void InitializeSystemCatalog();
37
38
  //! Get an attached database with the given name
38
- AttachedDatabase *GetDatabase(ClientContext &context, const string &name);
39
+ optional_ptr<AttachedDatabase> GetDatabase(ClientContext &context, const string &name);
39
40
  //! Add a new attached database to the database manager
40
41
  void AddDatabase(ClientContext &context, unique_ptr<AttachedDatabase> db);
41
42
  void DetachDatabase(ClientContext &context, const string &name, bool if_exists);
@@ -43,8 +44,8 @@ public:
43
44
  Catalog &GetSystemCatalog();
44
45
  static const string &GetDefaultDatabase(ClientContext &context);
45
46
 
46
- AttachedDatabase *GetDatabaseFromPath(ClientContext &context, const string &path);
47
- vector<AttachedDatabase *> GetDatabases(ClientContext &context);
47
+ optional_ptr<AttachedDatabase> GetDatabaseFromPath(ClientContext &context, const string &path);
48
+ vector<optional_ptr<AttachedDatabase>> GetDatabases(ClientContext &context);
48
49
 
49
50
  transaction_t GetNewQueryNumber() {
50
51
  return current_query_number++;
@@ -131,7 +131,8 @@ private:
131
131
  //! The row-based query result iterator. Invoking the
132
132
  class QueryResultIterator {
133
133
  public:
134
- explicit QueryResultIterator(QueryResult *result_p) : current_row(*this, 0), result(result_p), base_row(0) {
134
+ explicit QueryResultIterator(optional_ptr<QueryResult> result_p)
135
+ : current_row(*this, 0), result(result_p), base_row(0) {
135
136
  if (result) {
136
137
  chunk = shared_ptr<DataChunk>(result->Fetch().release());
137
138
  if (!chunk) {
@@ -142,7 +143,7 @@ private:
142
143
 
143
144
  QueryResultRow current_row;
144
145
  shared_ptr<DataChunk> chunk;
145
- QueryResult *result;
146
+ optional_ptr<QueryResult> result;
146
147
  idx_t base_row;
147
148
 
148
149
  public:
@@ -52,14 +52,14 @@ public:
52
52
  // &pushed_filters);
53
53
 
54
54
  private:
55
- FilterResult AddFilter(Expression *expr);
56
- FilterResult AddBoundComparisonFilter(Expression *expr);
55
+ FilterResult AddFilter(Expression &expr);
56
+ FilterResult AddBoundComparisonFilter(Expression &expr);
57
57
  FilterResult AddTransitiveFilters(BoundComparisonExpression &comparison);
58
- unique_ptr<Expression> FindTransitiveFilter(Expression *expr);
58
+ unique_ptr<Expression> FindTransitiveFilter(Expression &expr);
59
59
  // unordered_map<idx_t, std::pair<Value *, Value *>>
60
60
  // FindZonemapChecks(vector<idx_t> &column_ids, unordered_set<idx_t> &not_constants, Expression *filter);
61
- Expression *GetNode(Expression *expr);
62
- idx_t GetEquivalenceSet(Expression *expr);
61
+ Expression &GetNode(Expression &expr);
62
+ idx_t GetEquivalenceSet(Expression &expr);
63
63
  FilterResult AddConstantComparison(vector<ExpressionValueInformation> &info_list, ExpressionValueInformation info);
64
64
  //
65
65
  // //! Functions used to push and generate OR Filters
@@ -97,9 +97,9 @@ private:
97
97
  vector<unique_ptr<Expression>> remaining_filters;
98
98
 
99
99
  expression_map_t<unique_ptr<Expression>> stored_expressions;
100
- unordered_map<Expression *, idx_t> equivalence_set_map;
100
+ expression_map_t<idx_t> equivalence_set_map;
101
101
  unordered_map<idx_t, vector<ExpressionValueInformation>> constant_values;
102
- unordered_map<idx_t, vector<Expression *>> equivalence_map;
102
+ unordered_map<idx_t, vector<reference<Expression>>> equivalence_map;
103
103
  idx_t set_index = 0;
104
104
  //
105
105
  // //! Structures used for OR Filters
@@ -27,7 +27,7 @@ public:
27
27
 
28
28
  //! Checks if the given expression matches this ExpressionMatcher. If it does, the expression is appended to the
29
29
  //! bindings list and true is returned. Otherwise, false is returned.
30
- virtual bool Match(Expression *expr, vector<Expression *> &bindings);
30
+ virtual bool Match(Expression &expr, vector<reference<Expression>> &bindings);
31
31
 
32
32
  //! The ExpressionClass of the to-be-matched expression. ExpressionClass::INVALID for ANY.
33
33
  ExpressionClass expr_class;
@@ -40,14 +40,14 @@ public:
40
40
  //! The ExpressionEqualityMatcher matches on equality with another (given) expression
41
41
  class ExpressionEqualityMatcher : public ExpressionMatcher {
42
42
  public:
43
- explicit ExpressionEqualityMatcher(Expression *expr)
43
+ explicit ExpressionEqualityMatcher(Expression &expr)
44
44
  : ExpressionMatcher(ExpressionClass::INVALID), expression(expr) {
45
45
  }
46
46
 
47
- bool Match(Expression *expr, vector<Expression *> &bindings) override;
47
+ bool Match(Expression &expr, vector<reference<Expression>> &bindings) override;
48
48
 
49
49
  private:
50
- Expression *expression;
50
+ const Expression &expression;
51
51
  };
52
52
 
53
53
  class ConstantExpressionMatcher : public ExpressionMatcher {
@@ -61,7 +61,7 @@ public:
61
61
  CaseExpressionMatcher() : ExpressionMatcher(ExpressionClass::BOUND_CASE) {
62
62
  }
63
63
 
64
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
64
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
65
65
  };
66
66
 
67
67
  class ComparisonExpressionMatcher : public ExpressionMatcher {
@@ -74,7 +74,7 @@ public:
74
74
  //! The set matcher matching policy to use
75
75
  SetMatcher::Policy policy;
76
76
 
77
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
77
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
78
78
  };
79
79
 
80
80
  class CastExpressionMatcher : public ExpressionMatcher {
@@ -84,7 +84,7 @@ public:
84
84
  //! The matcher for the child expressions
85
85
  unique_ptr<ExpressionMatcher> matcher;
86
86
 
87
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
87
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
88
88
  };
89
89
 
90
90
  class InClauseExpressionMatcher : public ExpressionMatcher {
@@ -96,7 +96,7 @@ public:
96
96
  //! The set matcher matching policy to use
97
97
  SetMatcher::Policy policy;
98
98
 
99
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
99
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
100
100
  };
101
101
 
102
102
  class ConjunctionExpressionMatcher : public ExpressionMatcher {
@@ -109,7 +109,7 @@ public:
109
109
  //! The set matcher matching policy to use
110
110
  SetMatcher::Policy policy;
111
111
 
112
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
112
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
113
113
  };
114
114
 
115
115
  class FunctionExpressionMatcher : public ExpressionMatcher {
@@ -123,7 +123,7 @@ public:
123
123
  //! The function name to match
124
124
  unique_ptr<FunctionMatcher> function;
125
125
 
126
- bool Match(Expression *expr_, vector<Expression *> &bindings) override;
126
+ bool Match(Expression &expr_, vector<reference<Expression>> &bindings) override;
127
127
  };
128
128
 
129
129
  //! The FoldableConstant matcher matches any expression that is foldable into a constant by the ExpressionExecutor (i.e.
@@ -133,7 +133,7 @@ public:
133
133
  FoldableConstantMatcher() : ExpressionMatcher(ExpressionClass::INVALID) {
134
134
  }
135
135
 
136
- bool Match(Expression *expr, vector<Expression *> &bindings) override;
136
+ bool Match(Expression &expr, vector<reference<Expression>> &bindings) override;
137
137
  };
138
138
 
139
139
  } // namespace duckdb