duckdb 0.7.2-dev832.0 → 0.7.2-dev865.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 (51) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/src/catalog/catalog.cpp +21 -5
  3. package/src/duckdb/src/common/types/value.cpp +0 -93
  4. package/src/duckdb/src/execution/operator/helper/physical_limit.cpp +3 -0
  5. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +5 -8
  6. package/src/duckdb/src/function/scalar/date/date_part.cpp +2 -2
  7. package/src/duckdb/src/function/scalar/date/date_trunc.cpp +2 -2
  8. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +1 -1
  9. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +4 -0
  10. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +8 -8
  11. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  12. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
  13. package/src/duckdb/src/include/duckdb/common/types/value.hpp +0 -31
  14. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +9 -52
  15. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats_union.hpp +62 -0
  16. package/src/duckdb/src/include/duckdb/storage/table/column_checkpoint_state.hpp +2 -1
  17. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +6 -3
  18. package/src/duckdb/src/include/duckdb/storage/table/column_data_checkpointer.hpp +3 -2
  19. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +5 -3
  20. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +4 -1
  21. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +6 -3
  22. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +5 -3
  23. package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +37 -0
  24. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +8 -1
  25. package/src/duckdb/src/include/duckdb/storage/table/segment_base.hpp +4 -3
  26. package/src/duckdb/src/include/duckdb/storage/table/segment_tree.hpp +271 -26
  27. package/src/duckdb/src/parser/transform/expression/transform_array_access.cpp +11 -0
  28. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +22 -4
  29. package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +3 -11
  30. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +6 -0
  31. package/src/duckdb/src/storage/checkpoint_manager.cpp +1 -0
  32. package/src/duckdb/src/storage/compression/numeric_constant.cpp +2 -2
  33. package/src/duckdb/src/storage/data_table.cpp +1 -1
  34. package/src/duckdb/src/storage/statistics/numeric_stats.cpp +145 -83
  35. package/src/duckdb/src/storage/statistics/numeric_stats_union.cpp +65 -0
  36. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  37. package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +1 -6
  38. package/src/duckdb/src/storage/table/column_data.cpp +29 -35
  39. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +5 -5
  40. package/src/duckdb/src/storage/table/column_segment.cpp +8 -7
  41. package/src/duckdb/src/storage/table/list_column_data.cpp +2 -1
  42. package/src/duckdb/src/storage/table/persistent_table_data.cpp +2 -1
  43. package/src/duckdb/src/storage/table/row_group.cpp +9 -9
  44. package/src/duckdb/src/storage/table/row_group_collection.cpp +82 -66
  45. package/src/duckdb/src/storage/table/scan_state.cpp +22 -3
  46. package/src/duckdb/src/storage/table/standard_column_data.cpp +1 -0
  47. package/src/duckdb/src/storage/table/struct_column_data.cpp +1 -0
  48. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +11780 -11512
  49. package/src/duckdb/ub_src_storage_statistics.cpp +2 -0
  50. package/src/duckdb/ub_src_storage_table.cpp +0 -2
  51. package/src/duckdb/src/storage/table/segment_tree.cpp +0 -179
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.7.2-dev832.0",
5
+ "version": "0.7.2-dev865.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -63,20 +63,28 @@ Catalog &Catalog::GetSystemCatalog(ClientContext &context) {
63
63
  return Catalog::GetSystemCatalog(*context.db);
64
64
  }
65
65
 
66
- Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name) {
66
+ optional_ptr<Catalog> Catalog::GetCatalogEntry(ClientContext &context, const string &catalog_name) {
67
67
  auto &db_manager = DatabaseManager::Get(context);
68
68
  if (catalog_name == TEMP_CATALOG) {
69
- return ClientData::Get(context).temporary_objects->GetCatalog();
69
+ return &ClientData::Get(context).temporary_objects->GetCatalog();
70
70
  }
71
71
  if (catalog_name == SYSTEM_CATALOG) {
72
- return GetSystemCatalog(context);
72
+ return &GetSystemCatalog(context);
73
73
  }
74
74
  auto entry = db_manager.GetDatabase(
75
75
  context, IsInvalidCatalog(catalog_name) ? DatabaseManager::GetDefaultDatabase(context) : catalog_name);
76
76
  if (!entry) {
77
+ return nullptr;
78
+ }
79
+ return &entry->GetCatalog();
80
+ }
81
+
82
+ Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name) {
83
+ auto catalog = Catalog::GetCatalogEntry(context, catalog_name);
84
+ if (!catalog) {
77
85
  throw BinderException("Catalog \"%s\" does not exist!", catalog_name);
78
86
  }
79
- return entry->GetCatalog();
87
+ return *catalog;
80
88
  }
81
89
 
82
90
  //===--------------------------------------------------------------------===//
@@ -576,7 +584,15 @@ CatalogEntry *Catalog::GetEntry(ClientContext &context, CatalogType type, const
576
584
  vector<CatalogLookup> lookups;
577
585
  lookups.reserve(entries.size());
578
586
  for (auto &entry : entries) {
579
- lookups.emplace_back(Catalog::GetCatalog(context, entry.catalog), entry.schema);
587
+ if (if_exists_p) {
588
+ auto catalog_entry = Catalog::GetCatalogEntry(context, entry.catalog);
589
+ if (!catalog_entry) {
590
+ return nullptr;
591
+ }
592
+ lookups.emplace_back(*catalog_entry, entry.schema);
593
+ } else {
594
+ lookups.emplace_back(Catalog::GetCatalog(context, entry.catalog), entry.schema);
595
+ }
580
596
  }
581
597
  auto result = LookupEntry(context, lookups, type, name, if_exists_p, error_context);
582
598
  if (!result.Found()) {
@@ -1233,99 +1233,6 @@ interval_t Value::GetValueUnsafe() const {
1233
1233
  return value_.interval;
1234
1234
  }
1235
1235
 
1236
- //===--------------------------------------------------------------------===//
1237
- // GetReferenceUnsafe
1238
- //===--------------------------------------------------------------------===//
1239
- template <>
1240
- int8_t &Value::GetReferenceUnsafe() {
1241
- D_ASSERT(type_.InternalType() == PhysicalType::INT8 || type_.InternalType() == PhysicalType::BOOL);
1242
- return value_.tinyint;
1243
- }
1244
-
1245
- template <>
1246
- int16_t &Value::GetReferenceUnsafe() {
1247
- D_ASSERT(type_.InternalType() == PhysicalType::INT16);
1248
- return value_.smallint;
1249
- }
1250
-
1251
- template <>
1252
- int32_t &Value::GetReferenceUnsafe() {
1253
- D_ASSERT(type_.InternalType() == PhysicalType::INT32);
1254
- return value_.integer;
1255
- }
1256
-
1257
- template <>
1258
- int64_t &Value::GetReferenceUnsafe() {
1259
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1260
- return value_.bigint;
1261
- }
1262
-
1263
- template <>
1264
- hugeint_t &Value::GetReferenceUnsafe() {
1265
- D_ASSERT(type_.InternalType() == PhysicalType::INT128);
1266
- return value_.hugeint;
1267
- }
1268
-
1269
- template <>
1270
- uint8_t &Value::GetReferenceUnsafe() {
1271
- D_ASSERT(type_.InternalType() == PhysicalType::UINT8);
1272
- return value_.utinyint;
1273
- }
1274
-
1275
- template <>
1276
- uint16_t &Value::GetReferenceUnsafe() {
1277
- D_ASSERT(type_.InternalType() == PhysicalType::UINT16);
1278
- return value_.usmallint;
1279
- }
1280
-
1281
- template <>
1282
- uint32_t &Value::GetReferenceUnsafe() {
1283
- D_ASSERT(type_.InternalType() == PhysicalType::UINT32);
1284
- return value_.uinteger;
1285
- }
1286
-
1287
- template <>
1288
- uint64_t &Value::GetReferenceUnsafe() {
1289
- D_ASSERT(type_.InternalType() == PhysicalType::UINT64);
1290
- return value_.ubigint;
1291
- }
1292
-
1293
- template <>
1294
- float &Value::GetReferenceUnsafe() {
1295
- D_ASSERT(type_.InternalType() == PhysicalType::FLOAT);
1296
- return value_.float_;
1297
- }
1298
-
1299
- template <>
1300
- double &Value::GetReferenceUnsafe() {
1301
- D_ASSERT(type_.InternalType() == PhysicalType::DOUBLE);
1302
- return value_.double_;
1303
- }
1304
-
1305
- template <>
1306
- date_t &Value::GetReferenceUnsafe() {
1307
- D_ASSERT(type_.InternalType() == PhysicalType::INT32);
1308
- return value_.date;
1309
- }
1310
-
1311
- template <>
1312
- dtime_t &Value::GetReferenceUnsafe() {
1313
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1314
- return value_.time;
1315
- }
1316
-
1317
- template <>
1318
- timestamp_t &Value::GetReferenceUnsafe() {
1319
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1320
- return value_.timestamp;
1321
- }
1322
-
1323
- template <>
1324
- interval_t &Value::GetReferenceUnsafe() {
1325
- D_ASSERT(type_.InternalType() == PhysicalType::INTERVAL);
1326
- return value_.interval;
1327
- }
1328
-
1329
1236
  //===--------------------------------------------------------------------===//
1330
1237
  // Hash
1331
1238
  //===--------------------------------------------------------------------===//
@@ -111,6 +111,9 @@ SinkResultType PhysicalLimit::Sink(ExecutionContext &context, GlobalSinkState &g
111
111
  }
112
112
  state.data.Append(input, lstate.batch_index);
113
113
  state.current_offset += input.size();
114
+ if (state.current_offset == max_element) {
115
+ return SinkResultType::FINISHED;
116
+ }
114
117
  return SinkResultType::NEED_MORE_INPUT;
115
118
  }
116
119
 
@@ -73,20 +73,17 @@ static bool CanUsePerfectHashAggregate(ClientContext &context, LogicalAggregate
73
73
  int64_t range;
74
74
  switch (group_type.InternalType()) {
75
75
  case PhysicalType::INT8:
76
- range = int64_t(NumericStats::GetMaxUnsafe<int8_t>(nstats)) -
77
- int64_t(NumericStats::GetMinUnsafe<int8_t>(nstats));
76
+ range = int64_t(NumericStats::GetMax<int8_t>(nstats)) - int64_t(NumericStats::GetMin<int8_t>(nstats));
78
77
  break;
79
78
  case PhysicalType::INT16:
80
- range = int64_t(NumericStats::GetMaxUnsafe<int16_t>(nstats)) -
81
- int64_t(NumericStats::GetMinUnsafe<int16_t>(nstats));
79
+ range = int64_t(NumericStats::GetMax<int16_t>(nstats)) - int64_t(NumericStats::GetMin<int16_t>(nstats));
82
80
  break;
83
81
  case PhysicalType::INT32:
84
- range = int64_t(NumericStats::GetMaxUnsafe<int32_t>(nstats)) -
85
- int64_t(NumericStats::GetMinUnsafe<int32_t>(nstats));
82
+ range = int64_t(NumericStats::GetMax<int32_t>(nstats)) - int64_t(NumericStats::GetMin<int32_t>(nstats));
86
83
  break;
87
84
  case PhysicalType::INT64:
88
- if (!TrySubtractOperator::Operation(NumericStats::GetMaxUnsafe<int64_t>(nstats),
89
- NumericStats::GetMinUnsafe<int64_t>(nstats), range)) {
85
+ if (!TrySubtractOperator::Operation(NumericStats::GetMax<int64_t>(nstats),
86
+ NumericStats::GetMin<int64_t>(nstats), range)) {
90
87
  return false;
91
88
  }
92
89
  break;
@@ -180,8 +180,8 @@ struct DatePart {
180
180
  return nullptr;
181
181
  }
182
182
  // run the operator on both the min and the max, this gives us the [min, max] bound
183
- auto min = NumericStats::GetMinUnsafe<T>(nstats);
184
- auto max = NumericStats::GetMaxUnsafe<T>(nstats);
183
+ auto min = NumericStats::GetMin<T>(nstats);
184
+ auto max = NumericStats::GetMax<T>(nstats);
185
185
  if (min > max) {
186
186
  return nullptr;
187
187
  }
@@ -594,8 +594,8 @@ static unique_ptr<BaseStatistics> DateTruncStatistics(vector<BaseStatistics> &ch
594
594
  return nullptr;
595
595
  }
596
596
  // run the operator on both the min and the max, this gives us the [min, max] bound
597
- auto min = NumericStats::GetMinUnsafe<TA>(nstats);
598
- auto max = NumericStats::GetMaxUnsafe<TA>(nstats);
597
+ auto min = NumericStats::GetMin<TA>(nstats);
598
+ auto max = NumericStats::GetMax<TA>(nstats);
599
599
  if (min > max) {
600
600
  return nullptr;
601
601
  }
@@ -507,7 +507,7 @@ ScalarFunction ListUniqueFun::GetFunction() {
507
507
  }
508
508
 
509
509
  void ListAggregateFun::RegisterFunction(BuiltinFunctions &set) {
510
- set.AddFunction({"list_aggregate", "array_aggregate", "list_aggr", "array_aggr"}, GetFunction());
510
+ set.AddFunction({"list_aggregate", "array_aggregate", "list_aggr", "array_aggr", "aggregate"}, GetFunction());
511
511
  }
512
512
 
513
513
  void ListDistinctFun::RegisterFunction(BuiltinFunctions &set) {
@@ -392,6 +392,8 @@ void ListTransformFun::RegisterFunction(BuiltinFunctions &set) {
392
392
  set.AddFunction(fun);
393
393
  fun.name = "array_apply";
394
394
  set.AddFunction(fun);
395
+ fun.name = "apply";
396
+ set.AddFunction(fun);
395
397
  }
396
398
 
397
399
  void ListFilterFun::RegisterFunction(BuiltinFunctions &set) {
@@ -405,6 +407,8 @@ void ListFilterFun::RegisterFunction(BuiltinFunctions &set) {
405
407
 
406
408
  fun.name = "array_filter";
407
409
  set.AddFunction(fun);
410
+ fun.name = "filter";
411
+ set.AddFunction(fun);
408
412
  }
409
413
 
410
414
  } // namespace duckdb
@@ -81,11 +81,11 @@ struct AddPropagateStatistics {
81
81
  Value &new_max) {
82
82
  T min, max;
83
83
  // new min is min+min
84
- if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), min)) {
84
+ if (!OP::Operation(NumericStats::GetMin<T>(lstats), NumericStats::GetMin<T>(rstats), min)) {
85
85
  return true;
86
86
  }
87
87
  // new max is max+max
88
- if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), max)) {
88
+ if (!OP::Operation(NumericStats::GetMax<T>(lstats), NumericStats::GetMax<T>(rstats), max)) {
89
89
  return true;
90
90
  }
91
91
  new_min = Value::Numeric(type, min);
@@ -99,10 +99,10 @@ struct SubtractPropagateStatistics {
99
99
  static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min,
100
100
  Value &new_max) {
101
101
  T min, max;
102
- if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), min)) {
102
+ if (!OP::Operation(NumericStats::GetMin<T>(lstats), NumericStats::GetMax<T>(rstats), min)) {
103
103
  return true;
104
104
  }
105
- if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), max)) {
105
+ if (!OP::Operation(NumericStats::GetMax<T>(lstats), NumericStats::GetMin<T>(rstats), max)) {
106
106
  return true;
107
107
  }
108
108
  new_min = Value::Numeric(type, min);
@@ -489,8 +489,8 @@ unique_ptr<FunctionData> DecimalNegateBind(ClientContext &context, ScalarFunctio
489
489
  struct NegatePropagateStatistics {
490
490
  template <class T>
491
491
  static bool Operation(LogicalType type, BaseStatistics &istats, Value &new_min, Value &new_max) {
492
- auto max_value = NumericStats::GetMaxUnsafe<T>(istats);
493
- auto min_value = NumericStats::GetMinUnsafe<T>(istats);
492
+ auto max_value = NumericStats::GetMax<T>(istats);
493
+ auto min_value = NumericStats::GetMin<T>(istats);
494
494
  if (!NegateOperator::CanNegate<T>(min_value) || !NegateOperator::CanNegate<T>(max_value)) {
495
495
  return true;
496
496
  }
@@ -664,8 +664,8 @@ struct MultiplyPropagateStatistics {
664
664
  // etc
665
665
  // rather than doing all this switcheroo we just multiply all combinations of lmin/lmax with rmin/rmax
666
666
  // and check what the minimum/maximum value is
667
- T lvals[] {NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(lstats)};
668
- T rvals[] {NumericStats::GetMinUnsafe<T>(rstats), NumericStats::GetMaxUnsafe<T>(rstats)};
667
+ T lvals[] {NumericStats::GetMin<T>(lstats), NumericStats::GetMax<T>(lstats)};
668
+ T rvals[] {NumericStats::GetMin<T>(rstats), NumericStats::GetMax<T>(rstats)};
669
669
  T min = NumericLimits<T>::Maximum();
670
670
  T max = NumericLimits<T>::Minimum();
671
671
  // multiplications
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev832"
2
+ #define DUCKDB_VERSION "0.7.2-dev865"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "a12329e657"
5
+ #define DUCKDB_SOURCE_ID "61325fdd83"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -14,6 +14,7 @@
14
14
  #include "duckdb/catalog/catalog_transaction.hpp"
15
15
  #include "duckdb/common/unordered_set.hpp"
16
16
  #include "duckdb/common/atomic.hpp"
17
+ #include "duckdb/common/optional_ptr.hpp"
17
18
 
18
19
  #include <functional>
19
20
 
@@ -80,6 +81,8 @@ public:
80
81
  DUCKDB_API static Catalog &GetCatalog(ClientContext &context, const string &catalog_name);
81
82
  //! Get the specified Catalog from the DatabaseInstance
82
83
  DUCKDB_API static Catalog &GetCatalog(DatabaseInstance &db, const string &catalog_name);
84
+ //! Gets the specified Catalog from the database if it exists
85
+ DUCKDB_API static optional_ptr<Catalog> GetCatalogEntry(ClientContext &context, const string &catalog_name);
83
86
  //! Get the specific Catalog from the AttachedDatabase
84
87
  DUCKDB_API static Catalog &GetCatalog(AttachedDatabase &db);
85
88
 
@@ -531,37 +531,6 @@ DUCKDB_API timestamp_t Value::GetValueUnsafe() const;
531
531
  template <>
532
532
  DUCKDB_API interval_t Value::GetValueUnsafe() const;
533
533
 
534
- template <>
535
- DUCKDB_API int8_t &Value::GetReferenceUnsafe();
536
- template <>
537
- DUCKDB_API int16_t &Value::GetReferenceUnsafe();
538
- template <>
539
- DUCKDB_API int32_t &Value::GetReferenceUnsafe();
540
- template <>
541
- DUCKDB_API int64_t &Value::GetReferenceUnsafe();
542
- template <>
543
- DUCKDB_API hugeint_t &Value::GetReferenceUnsafe();
544
- template <>
545
- DUCKDB_API uint8_t &Value::GetReferenceUnsafe();
546
- template <>
547
- DUCKDB_API uint16_t &Value::GetReferenceUnsafe();
548
- template <>
549
- DUCKDB_API uint32_t &Value::GetReferenceUnsafe();
550
- template <>
551
- DUCKDB_API uint64_t &Value::GetReferenceUnsafe();
552
- template <>
553
- DUCKDB_API float &Value::GetReferenceUnsafe();
554
- template <>
555
- DUCKDB_API double &Value::GetReferenceUnsafe();
556
- template <>
557
- DUCKDB_API date_t &Value::GetReferenceUnsafe();
558
- template <>
559
- DUCKDB_API dtime_t &Value::GetReferenceUnsafe();
560
- template <>
561
- DUCKDB_API timestamp_t &Value::GetReferenceUnsafe();
562
- template <>
563
- DUCKDB_API interval_t &Value::GetReferenceUnsafe();
564
-
565
534
  template <>
566
535
  DUCKDB_API bool Value::IsNan(float input);
567
536
  template <>
@@ -8,9 +8,7 @@
8
8
 
9
9
  #pragma once
10
10
 
11
- #include "duckdb/common/common.hpp"
12
- #include "duckdb/common/exception.hpp"
13
- #include "duckdb/common/types/hugeint.hpp"
11
+ #include "duckdb/storage/statistics/numeric_stats_union.hpp"
14
12
  #include "duckdb/common/enums/filter_propagate_result.hpp"
15
13
  #include "duckdb/common/enums/expression_type.hpp"
16
14
  #include "duckdb/common/operator/comparison_operators.hpp"
@@ -23,28 +21,6 @@ class FieldReader;
23
21
  struct SelectionVector;
24
22
  class Vector;
25
23
 
26
- struct NumericValueUnion {
27
- union Val {
28
- int8_t boolean;
29
- int8_t tinyint;
30
- int16_t smallint;
31
- int32_t integer;
32
- int64_t bigint;
33
- uint8_t utinyint;
34
- uint16_t usmallint;
35
- uint32_t uinteger;
36
- uint64_t ubigint;
37
- hugeint_t hugeint;
38
- float float_;
39
- double double_;
40
- } value_;
41
-
42
- template <class T>
43
- T &GetReferenceUnsafe() {
44
- throw InternalException("NumericValueUnion::GetReferenceUnsafe called on unsupported type");
45
- }
46
- };
47
-
48
24
  struct NumericStatsData {
49
25
  //! Whether or not the value has a max value
50
26
  bool has_min;
@@ -109,13 +85,17 @@ struct NumericStats {
109
85
  static void Verify(const BaseStatistics &stats, Vector &vector, const SelectionVector &sel, idx_t count);
110
86
 
111
87
  template <class T>
112
- static T GetMinUnsafe(const BaseStatistics &stats) {
113
- return NumericStats::Min(stats).template GetValueUnsafe<T>();
88
+ static T GetMin(const BaseStatistics &stats) {
89
+ return NumericStats::Min(stats).GetValueUnsafe<T>();
114
90
  }
115
91
  template <class T>
116
- static T GetMaxUnsafe(const BaseStatistics &stats) {
117
- return NumericStats::Max(stats).template GetValueUnsafe<T>();
92
+ static T GetMax(const BaseStatistics &stats) {
93
+ return NumericStats::Max(stats).GetValueUnsafe<T>();
118
94
  }
95
+ template <class T>
96
+ static T GetMinUnsafe(const BaseStatistics &stats);
97
+ template <class T>
98
+ static T GetMaxUnsafe(const BaseStatistics &stats);
119
99
 
120
100
  private:
121
101
  static NumericStatsData &GetDataUnsafe(BaseStatistics &stats);
@@ -131,27 +111,4 @@ void NumericStats::Update<interval_t>(BaseStatistics &stats, interval_t new_valu
131
111
  template <>
132
112
  void NumericStats::Update<list_entry_t>(BaseStatistics &stats, list_entry_t new_value);
133
113
 
134
- template <>
135
- int8_t &NumericValueUnion::GetReferenceUnsafe();
136
- template <>
137
- int16_t &NumericValueUnion::GetReferenceUnsafe();
138
- template <>
139
- int32_t &NumericValueUnion::GetReferenceUnsafe();
140
- template <>
141
- int64_t &NumericValueUnion::GetReferenceUnsafe();
142
- template <>
143
- hugeint_t &NumericValueUnion::GetReferenceUnsafe();
144
- template <>
145
- uint8_t &NumericValueUnion::GetReferenceUnsafe();
146
- template <>
147
- uint16_t &NumericValueUnion::GetReferenceUnsafe();
148
- template <>
149
- uint32_t &NumericValueUnion::GetReferenceUnsafe();
150
- template <>
151
- uint64_t &NumericValueUnion::GetReferenceUnsafe();
152
- template <>
153
- float &NumericValueUnion::GetReferenceUnsafe();
154
- template <>
155
- double &NumericValueUnion::GetReferenceUnsafe();
156
-
157
114
  } // namespace duckdb
@@ -0,0 +1,62 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/storage/statistics/numeric_stats_union.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/exception.hpp"
13
+ #include "duckdb/common/types/hugeint.hpp"
14
+
15
+ namespace duckdb {
16
+
17
+ struct NumericValueUnion {
18
+ union Val {
19
+ bool boolean;
20
+ int8_t tinyint;
21
+ int16_t smallint;
22
+ int32_t integer;
23
+ int64_t bigint;
24
+ uint8_t utinyint;
25
+ uint16_t usmallint;
26
+ uint32_t uinteger;
27
+ uint64_t ubigint;
28
+ hugeint_t hugeint;
29
+ float float_;
30
+ double double_;
31
+ } value_;
32
+
33
+ template <class T>
34
+ T &GetReferenceUnsafe();
35
+ };
36
+
37
+ template <>
38
+ DUCKDB_API bool &NumericValueUnion::GetReferenceUnsafe();
39
+ template <>
40
+ DUCKDB_API int8_t &NumericValueUnion::GetReferenceUnsafe();
41
+ template <>
42
+ DUCKDB_API int16_t &NumericValueUnion::GetReferenceUnsafe();
43
+ template <>
44
+ DUCKDB_API int32_t &NumericValueUnion::GetReferenceUnsafe();
45
+ template <>
46
+ DUCKDB_API int64_t &NumericValueUnion::GetReferenceUnsafe();
47
+ template <>
48
+ DUCKDB_API hugeint_t &NumericValueUnion::GetReferenceUnsafe();
49
+ template <>
50
+ DUCKDB_API uint8_t &NumericValueUnion::GetReferenceUnsafe();
51
+ template <>
52
+ DUCKDB_API uint16_t &NumericValueUnion::GetReferenceUnsafe();
53
+ template <>
54
+ DUCKDB_API uint32_t &NumericValueUnion::GetReferenceUnsafe();
55
+ template <>
56
+ DUCKDB_API uint64_t &NumericValueUnion::GetReferenceUnsafe();
57
+ template <>
58
+ DUCKDB_API float &NumericValueUnion::GetReferenceUnsafe();
59
+ template <>
60
+ DUCKDB_API double &NumericValueUnion::GetReferenceUnsafe();
61
+
62
+ } // namespace duckdb
@@ -13,6 +13,7 @@
13
13
  #include "duckdb/storage/data_pointer.hpp"
14
14
  #include "duckdb/storage/statistics/segment_statistics.hpp"
15
15
  #include "duckdb/storage/table/column_segment.hpp"
16
+ #include "duckdb/storage/table/column_data.hpp"
16
17
  #include "duckdb/common/unordered_set.hpp"
17
18
 
18
19
  namespace duckdb {
@@ -28,7 +29,7 @@ struct ColumnCheckpointState {
28
29
 
29
30
  RowGroup &row_group;
30
31
  ColumnData &column_data;
31
- SegmentTree new_tree;
32
+ ColumnSegmentTree new_tree;
32
33
  vector<DataPointer> data_pointers;
33
34
  unique_ptr<BaseStatistics> global_stats;
34
35
 
@@ -15,7 +15,8 @@
15
15
  #include "duckdb/storage/data_pointer.hpp"
16
16
  #include "duckdb/storage/table/persistent_table_data.hpp"
17
17
  #include "duckdb/storage/statistics/segment_statistics.hpp"
18
- #include "duckdb/storage/table/column_checkpoint_state.hpp"
18
+ #include "duckdb/storage/table/segment_tree.hpp"
19
+ #include "duckdb/storage/table/column_segment.hpp"
19
20
  #include "duckdb/common/mutex.hpp"
20
21
 
21
22
  namespace duckdb {
@@ -31,10 +32,12 @@ struct TransactionData;
31
32
  struct DataTableInfo;
32
33
 
33
34
  struct ColumnCheckpointInfo {
34
- ColumnCheckpointInfo(CompressionType compression_type_p) : compression_type(compression_type_p) {};
35
+ explicit ColumnCheckpointInfo(CompressionType compression_type_p) : compression_type(compression_type_p) {};
35
36
  CompressionType compression_type;
36
37
  };
37
38
 
39
+ class ColumnSegmentTree : public SegmentTree<ColumnSegment> {};
40
+
38
41
  class ColumnData {
39
42
  friend class ColumnDataCheckpointer;
40
43
 
@@ -148,7 +151,7 @@ protected:
148
151
 
149
152
  protected:
150
153
  //! The segments holding the data of this column segment
151
- SegmentTree data;
154
+ ColumnSegmentTree data;
152
155
  //! The lock for the updates
153
156
  mutex update_lock;
154
157
  //! The updates for this column segment
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "duckdb/storage/table/column_data.hpp"
12
12
  #include "duckdb/function/compression_function.hpp"
13
+ #include "duckdb/storage/table/column_checkpoint_state.hpp"
13
14
 
14
15
  namespace duckdb {
15
16
 
@@ -25,7 +26,7 @@ public:
25
26
  RowGroup &GetRowGroup();
26
27
  ColumnCheckpointState &GetCheckpointState();
27
28
 
28
- void Checkpoint(vector<SegmentNode> nodes);
29
+ void Checkpoint(vector<SegmentNode<ColumnSegment>> nodes);
29
30
 
30
31
  private:
31
32
  void ScanSegments(const std::function<void(Vector &, idx_t)> &callback);
@@ -40,7 +41,7 @@ private:
40
41
  ColumnCheckpointState &state;
41
42
  bool is_validity;
42
43
  Vector intermediate;
43
- vector<SegmentNode> nodes;
44
+ vector<SegmentNode<ColumnSegment>> nodes;
44
45
  vector<CompressionFunction *> compression_functions;
45
46
  ColumnCheckpointInfo &checkpoint_info;
46
47
  };
@@ -9,7 +9,6 @@
9
9
  #pragma once
10
10
 
11
11
  #include "duckdb/storage/block.hpp"
12
- #include "duckdb/storage/table/segment_tree.hpp"
13
12
  #include "duckdb/common/types.hpp"
14
13
  #include "duckdb/common/types/vector.hpp"
15
14
  #include "duckdb/storage/buffer_manager.hpp"
@@ -17,6 +16,7 @@
17
16
  #include "duckdb/storage/storage_lock.hpp"
18
17
  #include "duckdb/storage/table/scan_state.hpp"
19
18
  #include "duckdb/function/compression_function.hpp"
19
+ #include "duckdb/storage/table/segment_base.hpp"
20
20
 
21
21
  namespace duckdb {
22
22
  class ColumnSegment;
@@ -35,10 +35,12 @@ struct ColumnAppendState;
35
35
  enum class ColumnSegmentType : uint8_t { TRANSIENT, PERSISTENT };
36
36
  //! TableFilter represents a filter pushed down into the table scan.
37
37
 
38
- class ColumnSegment : public SegmentBase {
38
+ class ColumnSegment : public SegmentBase<ColumnSegment> {
39
39
  public:
40
- ~ColumnSegment() override;
40
+ ~ColumnSegment();
41
41
 
42
+ //! The index within the segment tree
43
+ idx_t index;
42
44
  //! The database instance
43
45
  DatabaseInstance &db;
44
46
  //! The type stored in the column
@@ -22,8 +22,11 @@ public:
22
22
  explicit PersistentTableData(idx_t column_count);
23
23
  ~PersistentTableData();
24
24
 
25
- vector<RowGroupPointer> row_groups;
26
25
  TableStatistics table_stats;
26
+ idx_t total_rows;
27
+ idx_t row_group_count;
28
+ block_id_t block_id;
29
+ idx_t offset;
27
30
  };
28
31
 
29
32
  } // namespace duckdb