duckdb 0.7.1-dev240.0 → 0.7.1-dev320.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 (60) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -3
  3. package/src/duckdb/extension/json/json_scan.cpp +1 -4
  4. package/src/duckdb/extension/parquet/column_reader.cpp +7 -0
  5. package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -0
  6. package/src/duckdb/extension/parquet/parquet-extension.cpp +2 -10
  7. package/src/duckdb/src/catalog/catalog.cpp +62 -13
  8. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +8 -7
  9. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  10. package/src/duckdb/src/common/file_system.cpp +23 -9
  11. package/src/duckdb/src/common/local_file_system.cpp +4 -4
  12. package/src/duckdb/src/execution/index/art/art.cpp +117 -67
  13. package/src/duckdb/src/execution/index/art/art_key.cpp +24 -12
  14. package/src/duckdb/src/execution/index/art/leaf.cpp +7 -8
  15. package/src/duckdb/src/execution/index/art/node.cpp +13 -27
  16. package/src/duckdb/src/execution/index/art/node16.cpp +5 -8
  17. package/src/duckdb/src/execution/index/art/node256.cpp +3 -5
  18. package/src/duckdb/src/execution/index/art/node4.cpp +4 -7
  19. package/src/duckdb/src/execution/index/art/node48.cpp +5 -8
  20. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -3
  21. package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +1 -9
  22. package/src/duckdb/src/execution/operator/helper/physical_set.cpp +1 -9
  23. package/src/duckdb/src/function/pragma/pragma_queries.cpp +2 -2
  24. package/src/duckdb/src/function/scalar/generic/current_setting.cpp +2 -2
  25. package/src/duckdb/src/function/table/read_csv.cpp +3 -5
  26. package/src/duckdb/src/function/table/table_scan.cpp +3 -0
  27. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  28. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +7 -1
  29. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  30. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  31. package/src/duckdb/src/include/duckdb/common/enums/wal_type.hpp +3 -0
  32. package/src/duckdb/src/include/duckdb/common/file_system.hpp +1 -1
  33. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +37 -41
  34. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +8 -11
  35. package/src/duckdb/src/include/duckdb/main/{extension_functions.hpp → extension_entries.hpp} +26 -5
  36. package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +3 -0
  37. package/src/duckdb/src/include/duckdb/planner/binder.hpp +3 -0
  38. package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +10 -3
  39. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +7 -1
  40. package/src/duckdb/src/include/duckdb/storage/index.hpp +47 -38
  41. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +7 -0
  42. package/src/duckdb/src/main/database.cpp +4 -2
  43. package/src/duckdb/src/main/extension/extension_load.cpp +22 -3
  44. package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +3 -0
  45. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +13 -0
  46. package/src/duckdb/src/planner/expression_binder/index_binder.cpp +32 -1
  47. package/src/duckdb/src/storage/buffer_manager.cpp +30 -3
  48. package/src/duckdb/src/storage/compression/bitpacking.cpp +16 -7
  49. package/src/duckdb/src/storage/data_table.cpp +66 -3
  50. package/src/duckdb/src/storage/index.cpp +1 -1
  51. package/src/duckdb/src/storage/local_storage.cpp +1 -1
  52. package/src/duckdb/src/storage/table_index_list.cpp +1 -2
  53. package/src/duckdb/src/storage/wal_replay.cpp +68 -0
  54. package/src/duckdb/src/storage/write_ahead_log.cpp +21 -1
  55. package/src/duckdb/src/transaction/commit_state.cpp +5 -2
  56. package/src/duckdb/third_party/concurrentqueue/blockingconcurrentqueue.h +2 -2
  57. package/src/statement.cpp +46 -12
  58. package/test/arrow.test.ts +3 -3
  59. package/test/prepare.test.ts +39 -1
  60. package/test/typescript_decls.test.ts +1 -1
@@ -299,16 +299,11 @@ Node *Node::Deserialize(ART &art, idx_t block_id, idx_t offset) {
299
299
  NodeType node_type((NodeType)(n));
300
300
 
301
301
  Node *deserialized_node = nullptr;
302
- auto old_memory_size = art.memory_size;
303
302
  switch (node_type) {
304
303
  case NodeType::NLeaf: {
305
304
  auto leaf = Leaf::New();
306
305
  leaf->Deserialize(art, reader);
307
- art.memory_size += leaf->MemorySize(art, false);
308
- D_ASSERT(art.memory_size >= old_memory_size);
309
- if (art.track_memory) {
310
- art.buffer_manager.IncreaseUsedMemory(art.memory_size - old_memory_size);
311
- }
306
+ art.IncreaseMemorySize(leaf->MemorySize(art, false));
312
307
  return leaf;
313
308
  }
314
309
  case NodeType::N4: {
@@ -331,11 +326,7 @@ Node *Node::Deserialize(ART &art, idx_t block_id, idx_t offset) {
331
326
  throw InternalException("Unrecognized node type");
332
327
  }
333
328
  deserialized_node->DeserializeInternal(art, reader);
334
- art.memory_size += deserialized_node->MemorySize(art, false);
335
- D_ASSERT(art.memory_size >= old_memory_size);
336
- if (art.track_memory) {
337
- art.buffer_manager.IncreaseUsedMemory(art.memory_size - old_memory_size);
338
- }
329
+ art.IncreaseMemorySize(deserialized_node->MemorySize(art, false));
339
330
  return deserialized_node;
340
331
  }
341
332
 
@@ -356,12 +347,10 @@ void SwapNodes(MergeInfo &info, ParentsOfNodes &parents) {
356
347
  auto l_node_memory_size = info.l_node->MemorySize(*info.l_art, true);
357
348
  auto r_node_memory_size = info.r_node->MemorySize(*info.r_art, true);
358
349
 
359
- D_ASSERT(info.root_l_art->memory_size >= l_node_memory_size);
360
- D_ASSERT(info.root_r_art->memory_size >= r_node_memory_size);
361
- info.root_l_art->memory_size -= l_node_memory_size;
362
- info.root_r_art->memory_size -= r_node_memory_size;
363
- info.root_l_art->memory_size += r_node_memory_size;
364
- info.root_r_art->memory_size += l_node_memory_size;
350
+ info.root_l_art->DecreaseMemorySize(l_node_memory_size);
351
+ info.root_r_art->DecreaseMemorySize(r_node_memory_size);
352
+ info.root_l_art->IncreaseMemorySize(r_node_memory_size);
353
+ info.root_r_art->IncreaseMemorySize(l_node_memory_size);
365
354
 
366
355
  // actual swap
367
356
  swap(info.l_art, info.r_art);
@@ -409,9 +398,8 @@ bool Merge(MergeInfo &info, ParentsOfNodes &parents) {
409
398
  auto r_memory_size = r_child->MemorySize(*info.r_art, true);
410
399
  Node::InsertChild(*info.root_l_art, info.l_node, key_byte, r_child);
411
400
 
412
- info.root_l_art->memory_size += r_memory_size;
413
- D_ASSERT(info.root_r_art->memory_size >= r_memory_size);
414
- info.root_r_art->memory_size -= r_memory_size;
401
+ info.root_l_art->IncreaseMemorySize(r_memory_size);
402
+ info.root_r_art->DecreaseMemorySize(r_memory_size);
415
403
  if (parents.l_parent) {
416
404
  parents.l_parent->ReplaceChildPointer(parents.l_pos, info.l_node);
417
405
  }
@@ -473,9 +461,8 @@ bool ResolvePrefixesAndMerge(MergeInfo &info, ParentsOfNodes &parents) {
473
461
  auto r_memory_size = r_node->MemorySize(*info.r_art, true);
474
462
  Node::InsertChild(*info.root_l_art, l_node, mismatch_byte, r_node);
475
463
 
476
- info.root_l_art->memory_size += r_memory_size;
477
- D_ASSERT(info.root_r_art->memory_size >= r_memory_size);
478
- info.root_r_art->memory_size -= r_memory_size;
464
+ info.root_l_art->IncreaseMemorySize(r_memory_size);
465
+ info.root_r_art->DecreaseMemorySize(r_memory_size);
479
466
  UpdateParentsOfNodes(l_node, null_parent, parents);
480
467
  r_node = nullptr;
481
468
  return true;
@@ -493,7 +480,7 @@ bool ResolvePrefixesAndMerge(MergeInfo &info, ParentsOfNodes &parents) {
493
480
  // create new node
494
481
  Node *new_node = Node4::New();
495
482
  new_node->prefix = Prefix(l_node->prefix, mismatch_pos);
496
- info.root_l_art->memory_size += new_node->MemorySize(*info.l_art, false);
483
+ info.root_l_art->IncreaseMemorySize(new_node->MemorySize(*info.l_art, false));
497
484
 
498
485
  // insert l_node, break up prefix of l_node
499
486
  auto key_byte = l_node->prefix.Reduce(*info.root_l_art, mismatch_pos);
@@ -504,9 +491,8 @@ bool ResolvePrefixesAndMerge(MergeInfo &info, ParentsOfNodes &parents) {
504
491
  auto r_memory_size = r_node->MemorySize(*info.r_art, true);
505
492
  Node4::InsertChild(*info.root_l_art, new_node, key_byte, r_node);
506
493
 
507
- info.root_l_art->memory_size += r_memory_size;
508
- D_ASSERT(info.root_r_art->memory_size >= r_memory_size);
509
- info.root_r_art->memory_size -= r_memory_size;
494
+ info.root_l_art->IncreaseMemorySize(r_memory_size);
495
+ info.root_r_art->DecreaseMemorySize(r_memory_size);
510
496
 
511
497
  l_node = new_node;
512
498
  UpdateParentsOfNodes(l_node, null_parent, parents);
@@ -104,7 +104,7 @@ void Node16::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_chil
104
104
  } else {
105
105
  // node is full, grow to Node48
106
106
  auto new_node = Node48::New();
107
- art.memory_size += new_node->MemorySize(art, false);
107
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
108
108
  new_node->count = node->count;
109
109
  new_node->prefix = std::move(n->prefix);
110
110
 
@@ -114,8 +114,7 @@ void Node16::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_chil
114
114
  n->children[i] = nullptr;
115
115
  }
116
116
 
117
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
118
- art.memory_size -= node->MemorySize(art, false);
117
+ art.DecreaseMemorySize(node->MemorySize(art, false));
119
118
  Node::Delete(node);
120
119
  node = new_node;
121
120
  Node48::InsertChild(art, node, key_byte, new_child);
@@ -130,8 +129,7 @@ void Node16::EraseChild(ART &art, Node *&node, idx_t pos) {
130
129
  // adjust the ART size
131
130
  if (n->ChildIsInMemory(pos)) {
132
131
  auto child = n->GetChild(art, pos);
133
- D_ASSERT(art.memory_size >= child->MemorySize(art, true));
134
- art.memory_size -= child->MemorySize(art, true);
132
+ art.DecreaseMemorySize(child->MemorySize(art, true));
135
133
  }
136
134
 
137
135
  // erase the child and decrease the count
@@ -155,7 +153,7 @@ void Node16::EraseChild(ART &art, Node *&node, idx_t pos) {
155
153
  if (node->count < Node4::GetSize()) {
156
154
 
157
155
  auto new_node = Node4::New();
158
- art.memory_size += new_node->MemorySize(art, false);
156
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
159
157
  new_node->prefix = std::move(n->prefix);
160
158
 
161
159
  for (idx_t i = 0; i < n->count; i++) {
@@ -164,8 +162,7 @@ void Node16::EraseChild(ART &art, Node *&node, idx_t pos) {
164
162
  n->children[i] = nullptr;
165
163
  }
166
164
 
167
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
168
- art.memory_size -= node->MemorySize(art, false);
165
+ art.DecreaseMemorySize(node->MemorySize(art, false));
169
166
  Node::Delete(node);
170
167
  node = new_node;
171
168
  }
@@ -92,8 +92,7 @@ void Node256::EraseChild(ART &art, Node *&node, idx_t pos) {
92
92
  // adjust the ART size
93
93
  if (n->ChildIsInMemory(pos)) {
94
94
  auto child = n->GetChild(art, pos);
95
- D_ASSERT(art.memory_size >= child->MemorySize(art, true));
96
- art.memory_size -= child->MemorySize(art, true);
95
+ art.DecreaseMemorySize(child->MemorySize(art, true));
97
96
  }
98
97
 
99
98
  // erase the child and decrease the count
@@ -104,7 +103,7 @@ void Node256::EraseChild(ART &art, Node *&node, idx_t pos) {
104
103
  if (node->count <= NODE_256_SHRINK_THRESHOLD) {
105
104
 
106
105
  auto new_node = Node48::New();
107
- art.memory_size += new_node->MemorySize(art, false);
106
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
108
107
  new_node->prefix = std::move(n->prefix);
109
108
 
110
109
  for (idx_t i = 0; i < Node256::GetSize(); i++) {
@@ -115,8 +114,7 @@ void Node256::EraseChild(ART &art, Node *&node, idx_t pos) {
115
114
  }
116
115
  }
117
116
 
118
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
119
- art.memory_size -= node->MemorySize(art, false);
117
+ art.DecreaseMemorySize(node->MemorySize(art, false));
120
118
  Node::Delete(node);
121
119
  node = new_node;
122
120
  }
@@ -101,7 +101,7 @@ void Node4::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_child
101
101
  } else {
102
102
  // node is full, grow to Node16
103
103
  auto new_node = Node16::New();
104
- art.memory_size += new_node->MemorySize(art, false);
104
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
105
105
  new_node->count = n->count;
106
106
  new_node->prefix = std::move(node->prefix);
107
107
 
@@ -112,8 +112,7 @@ void Node4::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_child
112
112
  }
113
113
  n->count = 0;
114
114
 
115
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
116
- art.memory_size -= node->MemorySize(art, false);
115
+ art.DecreaseMemorySize(node->MemorySize(art, false));
117
116
  Node::Delete(node);
118
117
  node = new_node;
119
118
  Node16::InsertChild(art, node, key_byte, new_child);
@@ -129,8 +128,7 @@ void Node4::EraseChild(ART &art, Node *&node, idx_t pos) {
129
128
  // adjust the ART size
130
129
  if (n->ChildIsInMemory(pos)) {
131
130
  auto child = n->GetChild(art, pos);
132
- D_ASSERT(art.memory_size >= child->MemorySize(art, true));
133
- art.memory_size -= child->MemorySize(art, true);
131
+ art.DecreaseMemorySize(child->MemorySize(art, true));
134
132
  }
135
133
 
136
134
  // erase the child and decrease the count
@@ -158,8 +156,7 @@ void Node4::EraseChild(ART &art, Node *&node, idx_t pos) {
158
156
  // ensure that when deleting the node, we do not delete the child (because we move it)
159
157
  n->children[0] = nullptr;
160
158
 
161
- D_ASSERT(art.memory_size >= n->MemorySize(art, false));
162
- art.memory_size -= n->MemorySize(art, false);
159
+ art.DecreaseMemorySize(n->MemorySize(art, false));
163
160
  Node::Delete(node);
164
161
  node = child_ref;
165
162
  }
@@ -105,7 +105,7 @@ void Node48::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_chil
105
105
  } else {
106
106
  // node is full, grow to Node256
107
107
  auto new_node = Node256::New();
108
- art.memory_size += new_node->MemorySize(art, false);
108
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
109
109
  new_node->count = n->count;
110
110
  new_node->prefix = std::move(n->prefix);
111
111
 
@@ -116,8 +116,7 @@ void Node48::InsertChild(ART &art, Node *&node, uint8_t key_byte, Node *new_chil
116
116
  }
117
117
  }
118
118
 
119
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
120
- art.memory_size -= node->MemorySize(art, false);
119
+ art.DecreaseMemorySize(node->MemorySize(art, false));
121
120
  Node::Delete(node);
122
121
  node = new_node;
123
122
  Node256::InsertChild(art, node, key_byte, new_child);
@@ -130,8 +129,7 @@ void Node48::EraseChild(ART &art, Node *&node, idx_t pos) {
130
129
  // adjust the ART size
131
130
  if (n->ChildIsInMemory(pos)) {
132
131
  auto child = n->GetChild(art, pos);
133
- D_ASSERT(art.memory_size >= child->MemorySize(art, true));
134
- art.memory_size -= child->MemorySize(art, true);
132
+ art.DecreaseMemorySize(child->MemorySize(art, true));
135
133
  }
136
134
 
137
135
  // erase the child and decrease the count
@@ -143,7 +141,7 @@ void Node48::EraseChild(ART &art, Node *&node, idx_t pos) {
143
141
  if (node->count < NODE_48_SHRINK_THRESHOLD) {
144
142
 
145
143
  auto new_node = Node16::New();
146
- art.memory_size += new_node->MemorySize(art, false);
144
+ art.IncreaseMemorySize(new_node->MemorySize(art, false));
147
145
  new_node->prefix = std::move(n->prefix);
148
146
 
149
147
  for (idx_t i = 0; i < Node256::GetSize(); i++) {
@@ -154,8 +152,7 @@ void Node48::EraseChild(ART &art, Node *&node, idx_t pos) {
154
152
  }
155
153
  }
156
154
 
157
- D_ASSERT(art.memory_size >= node->MemorySize(art, false));
158
- art.memory_size -= node->MemorySize(art, false);
155
+ art.DecreaseMemorySize(node->MemorySize(art, false));
159
156
  Node::Delete(node);
160
157
  node = new_node;
161
158
  }
@@ -113,7 +113,7 @@ void Prefix::Overwrite(uint32_t new_size, uint8_t *data) {
113
113
 
114
114
  void Prefix::Concatenate(ART &art, uint8_t key, Prefix &other) {
115
115
  auto new_size = size + 1 + other.size;
116
- art.memory_size += (new_size - size) * sizeof(uint8_t);
116
+ art.IncreaseMemorySize((new_size - size) * sizeof(uint8_t));
117
117
  // have to allocate space in our prefix array
118
118
  auto new_prefix = AllocateArray<uint8_t>(new_size);
119
119
  idx_t new_prefix_idx = 0;
@@ -136,8 +136,7 @@ void Prefix::Concatenate(ART &art, uint8_t key, Prefix &other) {
136
136
 
137
137
  uint8_t Prefix::Reduce(ART &art, uint32_t n) {
138
138
  auto new_size = size - n - 1;
139
- D_ASSERT(art.memory_size >= (size - new_size) * sizeof(uint8_t));
140
- art.memory_size -= (size - new_size) * sizeof(uint8_t);
139
+ art.DecreaseMemorySize((size - new_size) * sizeof(uint8_t));
141
140
  auto prefix = GetPrefixData();
142
141
  auto partial_key = prefix[n];
143
142
 
@@ -27,15 +27,7 @@ void PhysicalReset::GetData(ExecutionContext &context, DataChunk &chunk, GlobalS
27
27
  auto &config = DBConfig::GetConfig(context.client);
28
28
  auto entry = config.extension_parameters.find(name);
29
29
  if (entry == config.extension_parameters.end()) {
30
- // it is not!
31
- // get a list of all options
32
- vector<string> potential_names = DBConfig::GetOptionNames();
33
- for (auto &entry : config.extension_parameters) {
34
- potential_names.push_back(entry.first);
35
- }
36
-
37
- throw CatalogException("unrecognized configuration parameter \"%s\"\n%s", name,
38
- StringUtil::CandidatesErrorMessage(potential_names, name, "Did you mean"));
30
+ throw Catalog::UnrecognizedConfigurationError(context.client, name);
39
31
  }
40
32
  ResetExtensionVariable(context, config, entry->second);
41
33
  return;
@@ -30,15 +30,7 @@ void PhysicalSet::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSou
30
30
  auto &config = DBConfig::GetConfig(context.client);
31
31
  auto entry = config.extension_parameters.find(name);
32
32
  if (entry == config.extension_parameters.end()) {
33
- // it is not!
34
- // get a list of all options
35
- vector<string> potential_names = DBConfig::GetOptionNames();
36
- for (auto &entry : config.extension_parameters) {
37
- potential_names.push_back(entry.first);
38
- }
39
-
40
- throw CatalogException("unrecognized configuration parameter \"%s\"\n%s", name,
41
- StringUtil::CandidatesErrorMessage(potential_names, name, "Did you mean"));
33
+ throw Catalog::UnrecognizedConfigurationError(context.client, name);
42
34
  }
43
35
  SetExtensionVariable(context.client, entry->second, name, scope, value);
44
36
  return;
@@ -22,8 +22,8 @@ string PragmaShowTablesExpanded(ClientContext &context, const FunctionParameters
22
22
  return R"(
23
23
  SELECT
24
24
  t.table_name,
25
- LIST(c.column_name order by c.column_name) AS column_names,
26
- LIST(c.data_type order by c.column_name) AS column_types,
25
+ LIST(c.column_name order by c.column_index) AS column_names,
26
+ LIST(c.data_type order by c.column_index) AS column_types,
27
27
  FIRST(t.temporary) AS temporary
28
28
  FROM duckdb_tables t
29
29
  JOIN duckdb_columns c
@@ -4,7 +4,7 @@
4
4
  #include "duckdb/main/client_context.hpp"
5
5
  #include "duckdb/planner/expression/bound_function_expression.hpp"
6
6
  #include "duckdb/execution/expression_executor.hpp"
7
-
7
+ #include "duckdb/catalog/catalog.hpp"
8
8
  namespace duckdb {
9
9
 
10
10
  struct CurrentSettingBindData : public FunctionData {
@@ -51,7 +51,7 @@ unique_ptr<FunctionData> CurrentSettingBind(ClientContext &context, ScalarFuncti
51
51
  auto key = StringUtil::Lower(key_str);
52
52
  Value val;
53
53
  if (!context.TryGetCurrentSetting(key, val)) {
54
- throw InvalidInputException("unrecognized configuration parameter \"%s\"", key_str);
54
+ throw Catalog::UnrecognizedConfigurationError(context, key);
55
55
  }
56
56
 
57
57
  bound_function.return_type = val.type();
@@ -28,10 +28,7 @@ unique_ptr<CSVFileHandle> ReadCSV::OpenCSV(const string &file_path, FileCompress
28
28
  void ReadCSVData::InitializeFiles(ClientContext &context, const vector<string> &patterns) {
29
29
  auto &fs = FileSystem::GetFileSystem(context);
30
30
  for (auto &file_pattern : patterns) {
31
- auto found_files = fs.Glob(file_pattern, context);
32
- if (found_files.empty()) {
33
- throw FileSystem::MissingFileException(file_pattern, context);
34
- }
31
+ auto found_files = fs.GlobFiles(file_pattern, context);
35
32
  files.insert(files.end(), found_files.begin(), found_files.end());
36
33
  }
37
34
  }
@@ -312,7 +309,7 @@ public:
312
309
  progress = double(bytes_read) / double(file_size);
313
310
  }
314
311
  // now get the total percentage of files read
315
- double percentage = double(file_index) / total_files;
312
+ double percentage = double(file_index - 1) / total_files;
316
313
  percentage += (double(1) / double(total_files)) * progress;
317
314
  return percentage * 100;
318
315
  }
@@ -584,6 +581,7 @@ struct SingleThreadedCSVState : public GlobalTableFunctionState {
584
581
  {
585
582
  lock_guard<mutex> l(csv_lock);
586
583
  if (initial_reader) {
584
+ total_size = initial_reader->file_handle ? initial_reader->file_handle->FileSize() : 0;
587
585
  return std::move(initial_reader);
588
586
  }
589
587
  if (next_file >= total_files) {
@@ -287,9 +287,12 @@ void TableScanPushdownComplexFilter(ClientContext &context, LogicalGet &get, Fun
287
287
  // behold
288
288
  storage.info->indexes.Scan([&](Index &index) {
289
289
  // first rewrite the index expression so the ColumnBindings align with the column bindings of the current table
290
+
290
291
  if (index.unbound_expressions.size() > 1) {
292
+ // NOTE: index scans are not (yet) supported for compound index keys
291
293
  return false;
292
294
  }
295
+
293
296
  auto index_expression = index.unbound_expressions[0]->Copy();
294
297
  bool rewrite_possible = true;
295
298
  RewriteIndexExpression(index, get, *index_expression, rewrite_possible);
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.1-dev240"
2
+ #define DUCKDB_VERSION "0.7.1-dev320"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "661b09da10"
5
+ #define DUCKDB_SOURCE_ID "4a6205db95"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -29,6 +29,7 @@ struct CreateFunctionInfo;
29
29
  struct CreateViewInfo;
30
30
  struct CreateSequenceInfo;
31
31
  struct CreateCollationInfo;
32
+ struct CreateIndexInfo;
32
33
  struct CreateTypeInfo;
33
34
  struct CreateTableInfo;
34
35
  struct DatabaseSize;
@@ -137,6 +138,9 @@ public:
137
138
  //! Creates a collation in the catalog
138
139
  DUCKDB_API CatalogEntry *CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info);
139
140
  DUCKDB_API CatalogEntry *CreateCollation(ClientContext &context, CreateCollationInfo *info);
141
+ //! Creates an index in the catalog
142
+ DUCKDB_API CatalogEntry *CreateIndex(CatalogTransaction transaction, CreateIndexInfo *info);
143
+ DUCKDB_API CatalogEntry *CreateIndex(ClientContext &context, CreateIndexInfo *info);
140
144
 
141
145
  //! Creates a table in the catalog.
142
146
  DUCKDB_API CatalogEntry *CreateTable(CatalogTransaction transaction, SchemaCatalogEntry *schema,
@@ -153,7 +157,7 @@ public:
153
157
  //! Create a scalar or aggregate function in the catalog
154
158
  DUCKDB_API CatalogEntry *CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
155
159
  CreateFunctionInfo *info);
156
- //! Creates a table in the catalog.
160
+ //! Creates a view in the catalog
157
161
  DUCKDB_API CatalogEntry *CreateView(CatalogTransaction transaction, SchemaCatalogEntry *schema,
158
162
  CreateViewInfo *info);
159
163
  //! Creates a table in the catalog.
@@ -251,6 +255,8 @@ public:
251
255
 
252
256
  virtual void Verify();
253
257
 
258
+ static CatalogException UnrecognizedConfigurationError(ClientContext &context, const string &name);
259
+
254
260
  protected:
255
261
  //! Reference to the database
256
262
  AttachedDatabase &db;
@@ -1,7 +1,7 @@
1
1
  //===----------------------------------------------------------------------===//
2
2
  // DuckDB
3
3
  //
4
- // duckdb/catalog/catalog_entry/dindex_catalog_entry.hpp
4
+ // duckdb/catalog/catalog_entry/duck_index_entry.hpp
5
5
  //
6
6
  //
7
7
  //===----------------------------------------------------------------------===//
@@ -34,7 +34,7 @@ public:
34
34
 
35
35
  public:
36
36
  string ToSQL() override;
37
- void Serialize(duckdb::MetaBlockWriter &serializer);
37
+ void Serialize(Serializer &serializer);
38
38
  static unique_ptr<CreateIndexInfo> Deserialize(Deserializer &source, ClientContext &context);
39
39
 
40
40
  virtual string GetSchemaName() = 0;
@@ -41,6 +41,9 @@ enum class WALType : uint8_t {
41
41
  CREATE_TABLE_MACRO = 21,
42
42
  DROP_TABLE_MACRO = 22,
43
43
 
44
+ CREATE_INDEX = 23,
45
+ DROP_INDEX = 24,
46
+
44
47
  // -----------------------------
45
48
  // Data
46
49
  // -----------------------------
@@ -188,6 +188,7 @@ public:
188
188
  //! Runs a glob on the file system, returning a list of matching files
189
189
  DUCKDB_API virtual vector<string> Glob(const string &path, FileOpener *opener = nullptr);
190
190
  DUCKDB_API virtual vector<string> Glob(const string &path, ClientContext &context);
191
+ DUCKDB_API vector<string> GlobFiles(const string &path, ClientContext &context);
191
192
 
192
193
  //! registers a sub-file system to handle certain file name prefixes, e.g. http:// etc.
193
194
  DUCKDB_API virtual void RegisterSubSystem(unique_ptr<FileSystem> sub_fs);
@@ -201,7 +202,6 @@ public:
201
202
 
202
203
  //! Whether or not a sub-system can handle a specific file path
203
204
  DUCKDB_API virtual bool CanHandleFile(const string &fpath);
204
- DUCKDB_API static IOException MissingFileException(const string &file_path, ClientContext &context);
205
205
 
206
206
  //! Set the file pointer of a file handle to a specified location. Reads and writes will happen from this location
207
207
  DUCKDB_API virtual void Seek(FileHandle &handle, idx_t location);
@@ -29,24 +29,21 @@ namespace duckdb {
29
29
  class ConflictManager;
30
30
 
31
31
  struct ARTIndexScanState : public IndexScanState {
32
- ARTIndexScanState() : checked(false), result_index(0) {
33
- }
34
32
 
33
+ //! Scan predicates (single predicate scan or range scan)
35
34
  Value values[2];
35
+ //! Expressions of the scan predicates
36
36
  ExpressionType expressions[2];
37
- bool checked;
37
+ bool checked = false;
38
+ //! All scanned row IDs
38
39
  vector<row_t> result_ids;
39
40
  Iterator iterator;
40
- //! Stores the current leaf
41
- Leaf *cur_leaf = nullptr;
42
- //! Offset to leaf
43
- idx_t result_index = 0;
44
41
  };
45
42
 
46
43
  enum class VerifyExistenceType : uint8_t {
47
- APPEND = 0, // for purpose to append into table
48
- APPEND_FK = 1, // for purpose to append into table has foreign key
49
- DELETE_FK = 2 // for purpose to delete from table related to foreign key
44
+ APPEND = 0, // appends to a table
45
+ APPEND_FK = 1, // appends to a table that has a foreign key
46
+ DELETE_FK = 2 // delete from a table that has a foreign key
50
47
  };
51
48
 
52
49
  class ART : public Index {
@@ -62,47 +59,44 @@ public:
62
59
  Node *tree;
63
60
 
64
61
  public:
65
- //! Initialize a scan on the index with the given expression and column ids
66
- //! to fetch from the base table for a single predicate
62
+ //! Initialize a single predicate scan on the index with the given expression and column IDs
67
63
  unique_ptr<IndexScanState> InitializeScanSinglePredicate(const Transaction &transaction, const Value &value,
68
64
  ExpressionType expression_type) override;
69
-
70
- //! Initialize a scan on the index with the given expression and column ids
71
- //! to fetch from the base table for two predicates
65
+ //! Initialize a two predicate scan on the index with the given expression and column IDs
72
66
  unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, const Value &low_value,
73
67
  ExpressionType low_expression_type, const Value &high_value,
74
68
  ExpressionType high_expression_type) override;
75
-
76
- //! Perform a lookup on the index
69
+ //! Performs a lookup on the index, fetching up to max_count result IDs. Returns true if all row IDs were fetched,
70
+ //! and false otherwise
77
71
  bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
78
72
  vector<row_t> &result_ids) override;
79
- //! Append entries to the index
73
+
74
+ //! Called when data is appended to the index. The lock obtained from InitializeLock must be held
80
75
  bool Append(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
81
- //! Verify that data can be appended to the index
76
+ //! Verify that data can be appended to the index without a constraint violation
82
77
  void VerifyAppend(DataChunk &chunk) override;
83
- //! Verify that data can be appended to the index
78
+ //! Verify that data can be appended to the index without a constraint violation using the conflict manager
84
79
  void VerifyAppend(DataChunk &chunk, ConflictManager &conflict_manager) override;
85
- //! Verify that data can be appended to the index for foreign key constraint
86
- void VerifyAppendForeignKey(DataChunk &chunk) override;
87
- //! Verify that data can be delete from the index for foreign key constraint
88
- void VerifyDeleteForeignKey(DataChunk &chunk) override;
89
- //! Delete entries in the index
80
+ //! Delete a chunk of entries from the index. The lock obtained from InitializeLock must be held
90
81
  void Delete(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
91
- //! Insert data into the index
82
+ //! Insert a chunk of entries into the index
92
83
  bool Insert(IndexLock &lock, DataChunk &data, Vector &row_ids) override;
93
84
 
94
85
  //! Construct an ART from a vector of sorted keys
95
86
  bool ConstructFromSorted(idx_t count, vector<Key> &keys, Vector &row_identifiers);
96
87
 
97
- //! Search Equal and fetches the row IDs
88
+ //! Search equal values and fetches the row IDs
98
89
  bool SearchEqual(Key &key, idx_t max_count, vector<row_t> &result_ids);
99
- //! Search Equal used for Joins that do not need to fetch data
90
+ //! Search equal values used for joins that do not need to fetch data
100
91
  void SearchEqualJoinNoFetch(Key &key, idx_t &result_size);
101
- //! Serialized the ART
92
+
93
+ //! Serializes the index and returns the pair of block_id offset positions
102
94
  BlockPointer Serialize(duckdb::MetaBlockWriter &writer) override;
103
95
 
104
- //! Merge two ARTs
96
+ //! Merge another index into this index. The lock obtained from InitializeLock must be held, and the other
97
+ //! index must also be locked during the merge
105
98
  bool MergeIndexes(IndexLock &state, Index *other_index) override;
99
+
106
100
  //! Generate ART keys for an input chunk
107
101
  static void GenerateKeys(ArenaAllocator &allocator, DataChunk &input, vector<Key> &keys);
108
102
 
@@ -110,30 +104,32 @@ public:
110
104
  string GenerateErrorKeyName(DataChunk &input, idx_t row);
111
105
  //! Generate the matching error message for a constraint violation
112
106
  string GenerateConstraintErrorMessage(VerifyExistenceType verify_type, const string &key_name);
107
+ //! Performs constraint checking for a chunk of input data
108
+ void CheckConstraintsForChunk(DataChunk &input, ConflictManager &conflict_manager) override;
113
109
 
114
110
  //! Returns the string representation of an ART
115
111
  string ToString() override;
116
- //! Verifies that the memory_size value of the ART matches its actual size
112
+ //! Verifies that the in-memory size value of the index matches its actual size
117
113
  void Verify() override;
114
+ //! Increases the memory size by the difference between the old size and the current size
115
+ //! and performs verifications
116
+ void IncreaseAndVerifyMemorySize(idx_t old_memory_size) override;
118
117
 
119
118
  private:
120
- //! Insert a row id into a leaf node
119
+ //! Insert a row ID into a leaf
121
120
  bool InsertToLeaf(Leaf &leaf, row_t row_id);
122
- //! Insert the leaf value into the tree
121
+ //! Insert a key into the tree
123
122
  bool Insert(Node *&node, Key &key, idx_t depth, row_t row_id);
124
-
125
- //! Erase element from leaf (if leaf has more than one value) or eliminate the leaf itself
123
+ //! Erase a key from the tree (if a leaf has more than one value) or erase the leaf itself
126
124
  void Erase(Node *&node, Key &key, idx_t depth, row_t row_id);
127
-
128
- //! Perform 'Lookup' for an entire chunk, marking which succeeded
129
- void LookupValues(DataChunk &input, ConflictManager &conflict_manager) final override;
130
-
131
- //! Find the node with a matching key, optimistic version
125
+ //! Find the node with a matching key, or return nullptr if not found
132
126
  Leaf *Lookup(Node *node, Key &key, idx_t depth);
133
-
127
+ //! Returns all row IDs belonging to a key greater (or equal) than the search key
134
128
  bool SearchGreater(ARTIndexScanState *state, Key &key, bool inclusive, idx_t max_count, vector<row_t> &result_ids);
129
+ //! Returns all row IDs belonging to a key less (or equal) than the upper_bound
135
130
  bool SearchLess(ARTIndexScanState *state, Key &upper_bound, bool inclusive, idx_t max_count,
136
131
  vector<row_t> &result_ids);
132
+ //! Returns all row IDs belonging to a key within the range of lower_bound and upper_bound
137
133
  bool SearchCloseRange(ARTIndexScanState *state, Key &lower_bound, Key &upper_bound, bool left_inclusive,
138
134
  bool right_inclusive, idx_t max_count, vector<row_t> &result_ids);
139
135
  };