duckdb 0.7.2-dev1901.0 → 0.7.2-dev2233.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 (198) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/parquet/column_reader.cpp +3 -0
  4. package/src/duckdb/extension/parquet/include/parquet_writer.hpp +1 -1
  5. package/src/duckdb/extension/parquet/parquet_metadata.cpp +4 -2
  6. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  7. package/src/duckdb/src/common/arrow/arrow_appender.cpp +69 -44
  8. package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
  9. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +20 -2
  10. package/src/duckdb/src/common/box_renderer.cpp +4 -2
  11. package/src/duckdb/src/common/constants.cpp +10 -1
  12. package/src/duckdb/src/common/filename_pattern.cpp +41 -0
  13. package/src/duckdb/src/common/hive_partitioning.cpp +144 -15
  14. package/src/duckdb/src/common/radix_partitioning.cpp +101 -369
  15. package/src/duckdb/src/common/row_operations/row_aggregate.cpp +8 -9
  16. package/src/duckdb/src/common/row_operations/row_external.cpp +1 -1
  17. package/src/duckdb/src/common/row_operations/row_gather.cpp +5 -3
  18. package/src/duckdb/src/common/row_operations/row_match.cpp +117 -22
  19. package/src/duckdb/src/common/row_operations/row_scatter.cpp +2 -2
  20. package/src/duckdb/src/common/sort/partition_state.cpp +1 -1
  21. package/src/duckdb/src/common/sort/sort_state.cpp +2 -1
  22. package/src/duckdb/src/common/sort/sorted_block.cpp +1 -1
  23. package/src/duckdb/src/common/types/{column_data_allocator.cpp → column/column_data_allocator.cpp} +2 -2
  24. package/src/duckdb/src/common/types/{column_data_collection.cpp → column/column_data_collection.cpp} +29 -6
  25. package/src/duckdb/src/common/types/{column_data_collection_segment.cpp → column/column_data_collection_segment.cpp} +2 -1
  26. package/src/duckdb/src/common/types/{column_data_consumer.cpp → column/column_data_consumer.cpp} +1 -1
  27. package/src/duckdb/src/common/types/{partitioned_column_data.cpp → column/partitioned_column_data.cpp} +11 -9
  28. package/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +316 -0
  29. package/src/duckdb/src/common/types/{row_data_collection.cpp → row/row_data_collection.cpp} +1 -1
  30. package/src/duckdb/src/common/types/{row_data_collection_scanner.cpp → row/row_data_collection_scanner.cpp} +2 -2
  31. package/src/duckdb/src/common/types/{row_layout.cpp → row/row_layout.cpp} +1 -1
  32. package/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +465 -0
  33. package/src/duckdb/src/common/types/row/tuple_data_collection.cpp +511 -0
  34. package/src/duckdb/src/common/types/row/tuple_data_iterator.cpp +96 -0
  35. package/src/duckdb/src/common/types/row/tuple_data_layout.cpp +119 -0
  36. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +1200 -0
  37. package/src/duckdb/src/common/types/row/tuple_data_segment.cpp +170 -0
  38. package/src/duckdb/src/common/types/vector.cpp +1 -1
  39. package/src/duckdb/src/execution/aggregate_hashtable.cpp +252 -290
  40. package/src/duckdb/src/execution/join_hashtable.cpp +192 -328
  41. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +4 -4
  42. package/src/duckdb/src/execution/operator/helper/physical_execute.cpp +3 -3
  43. package/src/duckdb/src/execution/operator/helper/physical_limit_percent.cpp +2 -3
  44. package/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +2 -3
  45. package/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +36 -21
  46. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +2 -2
  47. package/src/duckdb/src/execution/operator/join/physical_cross_product.cpp +1 -1
  48. package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +2 -2
  49. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +166 -144
  50. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +5 -5
  51. package/src/duckdb/src/execution/operator/join/physical_join.cpp +2 -10
  52. package/src/duckdb/src/execution/operator/join/physical_positional_join.cpp +0 -1
  53. package/src/duckdb/src/execution/operator/order/physical_top_n.cpp +2 -2
  54. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +3 -0
  55. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +71 -22
  56. package/src/duckdb/src/execution/operator/persistent/csv_buffer.cpp +17 -13
  57. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +0 -7
  58. package/src/duckdb/src/execution/operator/persistent/parallel_csv_reader.cpp +124 -29
  59. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +13 -11
  60. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +3 -2
  61. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +25 -24
  62. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +1 -1
  63. package/src/duckdb/src/execution/operator/persistent/physical_update.cpp +4 -3
  64. package/src/duckdb/src/execution/operator/scan/physical_table_scan.cpp +1 -1
  65. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +1 -1
  66. package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +3 -3
  67. package/src/duckdb/src/execution/partitionable_hashtable.cpp +9 -37
  68. package/src/duckdb/src/execution/physical_operator.cpp +1 -1
  69. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +19 -18
  70. package/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +2 -1
  71. package/src/duckdb/src/execution/physical_plan/plan_execute.cpp +2 -2
  72. package/src/duckdb/src/execution/physical_plan/plan_explain.cpp +5 -6
  73. package/src/duckdb/src/execution/physical_plan/plan_expression_get.cpp +2 -2
  74. package/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +3 -3
  75. package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -1
  76. package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +39 -17
  77. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +2 -2
  78. package/src/duckdb/src/function/table/pragma_detailed_profiling_output.cpp +5 -5
  79. package/src/duckdb/src/function/table/pragma_last_profiling_output.cpp +2 -2
  80. package/src/duckdb/src/function/table/read_csv.cpp +124 -58
  81. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  82. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  83. package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
  84. package/src/duckdb/src/include/duckdb/common/constants.hpp +2 -0
  85. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
  86. package/src/duckdb/src/include/duckdb/common/fast_mem.hpp +528 -0
  87. package/src/duckdb/src/include/duckdb/common/filename_pattern.hpp +34 -0
  88. package/src/duckdb/src/include/duckdb/common/helper.hpp +10 -0
  89. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +13 -3
  90. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +8 -0
  91. package/src/duckdb/src/include/duckdb/common/perfect_map_set.hpp +34 -0
  92. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +80 -27
  93. package/src/duckdb/src/include/duckdb/common/reference_map.hpp +38 -0
  94. package/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +7 -6
  95. package/src/duckdb/src/include/duckdb/common/sort/comparators.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +1 -1
  97. package/src/duckdb/src/include/duckdb/common/sort/sort.hpp +1 -1
  98. package/src/duckdb/src/include/duckdb/common/sort/sorted_block.hpp +2 -2
  99. package/src/duckdb/src/include/duckdb/common/types/batched_data_collection.hpp +1 -1
  100. package/src/duckdb/src/include/duckdb/common/types/{column_data_allocator.hpp → column/column_data_allocator.hpp} +4 -4
  101. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection.hpp → column/column_data_collection.hpp} +4 -4
  102. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_iterators.hpp → column/column_data_collection_iterators.hpp} +2 -2
  103. package/src/duckdb/src/include/duckdb/common/types/{column_data_collection_segment.hpp → column/column_data_collection_segment.hpp} +3 -3
  104. package/src/duckdb/src/include/duckdb/common/types/{column_data_consumer.hpp → column/column_data_consumer.hpp} +8 -4
  105. package/src/duckdb/src/include/duckdb/common/types/{column_data_scan_states.hpp → column/column_data_scan_states.hpp} +1 -1
  106. package/src/duckdb/src/include/duckdb/common/types/{partitioned_column_data.hpp → column/partitioned_column_data.hpp} +15 -7
  107. package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +140 -0
  108. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection.hpp → row/row_data_collection.hpp} +1 -1
  109. package/src/duckdb/src/include/duckdb/common/types/{row_data_collection_scanner.hpp → row/row_data_collection_scanner.hpp} +2 -2
  110. package/src/duckdb/src/include/duckdb/common/types/{row_layout.hpp → row/row_layout.hpp} +3 -1
  111. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_allocator.hpp +116 -0
  112. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +239 -0
  113. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_iterator.hpp +64 -0
  114. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_layout.hpp +113 -0
  115. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_segment.hpp +124 -0
  116. package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +74 -0
  117. package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +3 -0
  118. package/src/duckdb/src/include/duckdb/common/types/value.hpp +4 -12
  119. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +34 -31
  120. package/src/duckdb/src/include/duckdb/execution/base_aggregate_hashtable.hpp +2 -2
  121. package/src/duckdb/src/include/duckdb/execution/execution_context.hpp +3 -2
  122. package/src/duckdb/src/include/duckdb/execution/expression_executor.hpp +1 -1
  123. package/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +41 -67
  124. package/src/duckdb/src/include/duckdb/execution/nested_loop_join.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_execute.hpp +2 -2
  126. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_result_collector.hpp +1 -1
  127. package/src/duckdb/src/include/duckdb/execution/operator/join/outer_join_marker.hpp +2 -2
  128. package/src/duckdb/src/include/duckdb/execution/operator/join/perfect_hash_join_executor.hpp +1 -1
  129. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_cross_product.hpp +1 -1
  130. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +0 -2
  131. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_index_join.hpp +2 -2
  132. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_positional_join.hpp +1 -1
  133. package/src/duckdb/src/include/duckdb/execution/operator/persistent/buffered_csv_reader.hpp +4 -1
  134. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_buffer.hpp +8 -3
  135. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +5 -7
  136. package/src/duckdb/src/include/duckdb/execution/operator/persistent/parallel_csv_reader.hpp +5 -1
  137. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +4 -1
  138. package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +1 -1
  139. package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +1 -1
  140. package/src/duckdb/src/include/duckdb/execution/partitionable_hashtable.hpp +2 -2
  141. package/src/duckdb/src/include/duckdb/function/function.hpp +2 -0
  142. package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +25 -0
  143. package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -0
  144. package/src/duckdb/src/include/duckdb/main/config.hpp +0 -2
  145. package/src/duckdb/src/include/duckdb/main/materialized_query_result.hpp +1 -1
  146. package/src/duckdb/src/include/duckdb/main/query_result.hpp +14 -1
  147. package/src/duckdb/src/include/duckdb/optimizer/expression_rewriter.hpp +3 -3
  148. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +16 -16
  149. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +8 -8
  150. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_order_optimizer.hpp +23 -15
  151. package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +9 -10
  152. package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph.hpp +18 -11
  153. package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +1 -1
  154. package/src/duckdb/src/include/duckdb/parser/parsed_data/exported_table_data.hpp +5 -1
  155. package/src/duckdb/src/include/duckdb/parser/parsed_data/vacuum_info.hpp +3 -2
  156. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +4 -2
  157. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +9 -35
  158. package/src/duckdb/src/include/duckdb/planner/binder.hpp +24 -23
  159. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +3 -3
  160. package/src/duckdb/src/include/duckdb/planner/operator/logical_column_data_get.hpp +1 -1
  161. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +3 -1
  162. package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +1 -1
  163. package/src/duckdb/src/main/appender.cpp +6 -6
  164. package/src/duckdb/src/main/client_context.cpp +1 -1
  165. package/src/duckdb/src/main/connection.cpp +2 -2
  166. package/src/duckdb/src/main/query_result.cpp +13 -0
  167. package/src/duckdb/src/main/settings/settings.cpp +3 -4
  168. package/src/duckdb/src/optimizer/expression_rewriter.cpp +4 -4
  169. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +91 -105
  170. package/src/duckdb/src/optimizer/join_order/join_node.cpp +5 -8
  171. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +163 -160
  172. package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +30 -30
  173. package/src/duckdb/src/optimizer/join_order/query_graph.cpp +37 -38
  174. package/src/duckdb/src/parallel/executor.cpp +1 -1
  175. package/src/duckdb/src/parallel/meta_pipeline.cpp +2 -2
  176. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +1 -1
  177. package/src/duckdb/src/parser/transform/tableref/transform_subquery.cpp +1 -1
  178. package/src/duckdb/src/parser/transformer.cpp +50 -9
  179. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +13 -0
  180. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +15 -5
  181. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +19 -17
  182. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +4 -4
  183. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +20 -21
  184. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +24 -22
  185. package/src/duckdb/src/planner/binder/tableref/bind_subqueryref.cpp +2 -2
  186. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +9 -0
  187. package/src/duckdb/src/planner/binder.cpp +16 -19
  188. package/src/duckdb/src/planner/expression_binder.cpp +8 -8
  189. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +3 -3
  190. package/src/duckdb/src/storage/checkpoint_manager.cpp +23 -23
  191. package/src/duckdb/src/storage/standard_buffer_manager.cpp +1 -1
  192. package/src/duckdb/src/storage/table_index_list.cpp +3 -3
  193. package/src/duckdb/src/verification/statement_verifier.cpp +1 -1
  194. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +5552 -5598
  195. package/src/duckdb/ub_src_common.cpp +2 -0
  196. package/src/duckdb/ub_src_common_types.cpp +0 -16
  197. package/src/duckdb/ub_src_common_types_column.cpp +10 -0
  198. package/src/duckdb/ub_src_common_types_row.cpp +20 -0
@@ -1,7 +1,7 @@
1
1
  //===----------------------------------------------------------------------===//
2
2
  // DuckDB
3
3
  //
4
- // duckdb/common/types/row_layout.hpp
4
+ // duckdb/common/types/row/row_layout.hpp
5
5
  //
6
6
  //
7
7
  //===----------------------------------------------------------------------===//
@@ -17,6 +17,8 @@ namespace duckdb {
17
17
 
18
18
  class RowLayout {
19
19
  public:
20
+ friend class TupleDataLayout;
21
+
20
22
  using Aggregates = vector<AggregateObject>;
21
23
  using ValidityBytes = TemplatedValidityMask<uint8_t>;
22
24
 
@@ -0,0 +1,116 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/types/row/tuple_data_allocator.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/types/row/tuple_data_layout.hpp"
12
+ #include "duckdb/common/types/row/tuple_data_states.hpp"
13
+
14
+ namespace duckdb {
15
+
16
+ struct TupleDataSegment;
17
+ struct TupleDataChunk;
18
+ struct TupleDataChunkPart;
19
+
20
+ struct TupleDataBlock {
21
+ public:
22
+ TupleDataBlock(BufferManager &buffer_manager, idx_t capacity_p);
23
+
24
+ //! Disable copy constructors
25
+ TupleDataBlock(const TupleDataBlock &other) = delete;
26
+ TupleDataBlock &operator=(const TupleDataBlock &) = delete;
27
+
28
+ //! Enable move constructors
29
+ TupleDataBlock(TupleDataBlock &&other) noexcept;
30
+ TupleDataBlock &operator=(TupleDataBlock &&) noexcept;
31
+
32
+ public:
33
+ //! Remaining capacity (in bytes)
34
+ idx_t RemainingCapacity() const {
35
+ D_ASSERT(size <= capacity);
36
+ return capacity - size;
37
+ }
38
+
39
+ //! Remaining capacity (in rows)
40
+ idx_t RemainingCapacity(idx_t row_width) const {
41
+ return RemainingCapacity() / row_width;
42
+ }
43
+
44
+ public:
45
+ //! The underlying row block
46
+ shared_ptr<BlockHandle> handle;
47
+ //! Capacity (in bytes)
48
+ idx_t capacity;
49
+ //! Occupied size (in bytes)
50
+ idx_t size;
51
+ };
52
+
53
+ class TupleDataAllocator {
54
+ public:
55
+ TupleDataAllocator(BufferManager &buffer_manager, const TupleDataLayout &layout);
56
+ TupleDataAllocator(TupleDataAllocator &allocator);
57
+
58
+ //! Get the buffer allocator
59
+ Allocator &GetAllocator();
60
+ //! Get the layout
61
+ const TupleDataLayout &GetLayout() const;
62
+ //! Number of row blocks
63
+ idx_t RowBlockCount() const;
64
+ //! Number of heap blocks
65
+ idx_t HeapBlockCount() const;
66
+
67
+ public:
68
+ //! Builds out the chunks for next append, given the metadata in the append state
69
+ void Build(TupleDataSegment &segment, TupleDataPinState &pin_state, TupleDataChunkState &chunk_state,
70
+ const idx_t append_offset, const idx_t append_count);
71
+ //! Initializes a chunk, making its pointers valid
72
+ void InitializeChunkState(TupleDataSegment &segment, TupleDataPinState &pin_state, TupleDataChunkState &chunk_state,
73
+ idx_t chunk_idx, bool init_heap);
74
+ static void RecomputeHeapPointers(Vector &old_heap_ptrs, const SelectionVector &old_heap_sel,
75
+ const data_ptr_t row_locations[], Vector &new_heap_ptrs, const idx_t offset,
76
+ const idx_t count, const TupleDataLayout &layout, const idx_t base_col_offset);
77
+ //! Releases or stores any handles in the management state that are no longer required
78
+ void ReleaseOrStoreHandles(TupleDataPinState &state, TupleDataSegment &segment, TupleDataChunk &chunk,
79
+ bool release_heap);
80
+ //! Releases or stores ALL handles in the management state
81
+ void ReleaseOrStoreHandles(TupleDataPinState &state, TupleDataSegment &segment);
82
+
83
+ private:
84
+ //! Builds out a single part (grabs the lock)
85
+ TupleDataChunkPart BuildChunkPart(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state,
86
+ const idx_t append_offset, const idx_t append_count);
87
+ //! Internal function for InitializeChunkState
88
+ void InitializeChunkStateInternal(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, idx_t offset,
89
+ bool recompute, bool init_heap_pointers, bool init_heap_sizes,
90
+ vector<TupleDataChunkPart *> &parts);
91
+ //! Internal function for ReleaseOrStoreHandles
92
+ static void ReleaseOrStoreHandlesInternal(TupleDataSegment &segment, vector<BufferHandle> &pinned_row_handles,
93
+ unordered_map<uint32_t, BufferHandle> &handles,
94
+ const unordered_set<uint32_t> &block_ids, vector<TupleDataBlock> &blocks,
95
+ TupleDataPinProperties properties);
96
+ //! Pins the given row block
97
+ BufferHandle &PinRowBlock(TupleDataPinState &state, const TupleDataChunkPart &part);
98
+ //! Pins the given heap block
99
+ BufferHandle &PinHeapBlock(TupleDataPinState &state, const TupleDataChunkPart &part);
100
+ //! Gets the pointer to the rows for the given chunk part
101
+ data_ptr_t GetRowPointer(TupleDataPinState &state, const TupleDataChunkPart &part);
102
+ //! Gets the base pointer to the heap for the given chunk part
103
+ data_ptr_t GetBaseHeapPointer(TupleDataPinState &state, const TupleDataChunkPart &part);
104
+
105
+ private:
106
+ //! The buffer manager
107
+ BufferManager &buffer_manager;
108
+ //! The layout of the data
109
+ const TupleDataLayout layout;
110
+ //! Blocks storing the fixed-size rows
111
+ vector<TupleDataBlock> row_blocks;
112
+ //! Blocks storing the variable-size data of the fixed-size rows (e.g., string, list)
113
+ vector<TupleDataBlock> heap_blocks;
114
+ };
115
+
116
+ } // namespace duckdb
@@ -0,0 +1,239 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/types/row/tuple_data_collection.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/types/row/tuple_data_layout.hpp"
12
+ #include "duckdb/common/types/row/tuple_data_segment.hpp"
13
+ #include "duckdb/common/types/row/tuple_data_states.hpp"
14
+
15
+ namespace duckdb {
16
+
17
+ class TupleDataAllocator;
18
+ struct TupleDataScatterFunction;
19
+ struct TupleDataGatherFunction;
20
+
21
+ typedef void (*tuple_data_scatter_function_t)(const Vector &source, const TupleDataVectorFormat &source_format,
22
+ const SelectionVector &append_sel, const idx_t append_count,
23
+ const TupleDataLayout &layout, Vector &row_locations,
24
+ Vector &heap_locations, const idx_t col_idx,
25
+ const UnifiedVectorFormat &list_format,
26
+ const vector<TupleDataScatterFunction> &child_functions);
27
+
28
+ struct TupleDataScatterFunction {
29
+ tuple_data_scatter_function_t function;
30
+ vector<TupleDataScatterFunction> child_functions;
31
+ };
32
+
33
+ typedef void (*tuple_data_gather_function_t)(const TupleDataLayout &layout, Vector &row_locations, const idx_t col_idx,
34
+ const SelectionVector &scan_sel, const idx_t scan_count, Vector &target,
35
+ const SelectionVector &target_sel, Vector &list_vector,
36
+ const vector<TupleDataGatherFunction> &child_functions);
37
+
38
+ struct TupleDataGatherFunction {
39
+ tuple_data_gather_function_t function;
40
+ vector<TupleDataGatherFunction> child_functions;
41
+ };
42
+
43
+ //! TupleDataCollection represents a set of buffer-managed data stored in row format
44
+ //! FIXME: rename to RowDataCollection after we phase it out
45
+ class TupleDataCollection {
46
+ friend class TupleDataChunkIterator;
47
+
48
+ public:
49
+ //! Constructs a TupleDataCollection with the specified layout
50
+ TupleDataCollection(BufferManager &buffer_manager, const TupleDataLayout &layout);
51
+ //! Constructs a TupleDataCollection with the same (shared) allocator
52
+ explicit TupleDataCollection(shared_ptr<TupleDataAllocator> allocator);
53
+
54
+ ~TupleDataCollection();
55
+
56
+ public:
57
+ //! The layout of the stored rows
58
+ const TupleDataLayout &GetLayout() const;
59
+ //! The number of rows stored in the tuple data collection
60
+ const idx_t &Count() const;
61
+ //! The number of chunks stored in the tuple data collection
62
+ idx_t ChunkCount() const;
63
+ //! The size (in bytes) of the blocks held by this tuple data collection
64
+ idx_t SizeInBytes() const;
65
+ //! Get pointers to the pinned blocks
66
+ void GetBlockPointers(vector<data_ptr_t> &block_pointers) const;
67
+ //! Unpins all held pins
68
+ void Unpin();
69
+
70
+ //! Gets the scatter function for the given type
71
+ static TupleDataScatterFunction GetScatterFunction(const LogicalType &type, bool within_list = false);
72
+ //! Gets the gather function for the given type
73
+ static TupleDataGatherFunction GetGatherFunction(const LogicalType &type, bool within_list = false);
74
+
75
+ //! Initializes an Append state - useful for optimizing many appends made to the same tuple data collection
76
+ void InitializeAppend(TupleDataAppendState &append_state,
77
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE);
78
+ //! Initializes an Append state - useful for optimizing many appends made to the same tuple data collection
79
+ void InitializeAppend(TupleDataAppendState &append_state, vector<column_t> column_ids,
80
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE);
81
+ //! Initializes the Pin state of an Append state
82
+ //! - Useful for optimizing many appends made to the same tuple data collection
83
+ void InitializeAppend(TupleDataPinState &pin_state,
84
+ TupleDataPinProperties = TupleDataPinProperties::UNPIN_AFTER_DONE);
85
+ //! Initializes the Chunk state of an Append state
86
+ //! - Useful for optimizing many appends made to the same tuple data collection
87
+ void InitializeAppend(TupleDataChunkState &chunk_state, vector<column_t> column_ids = {});
88
+ //! Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally
89
+ void Append(DataChunk &new_chunk, const SelectionVector &append_sel = *FlatVector::IncrementalSelectionVector(),
90
+ idx_t append_count = DConstants::INVALID_INDEX);
91
+ //! Append a DataChunk directly to this TupleDataCollection - calls InitializeAppend and Append internally
92
+ void Append(DataChunk &new_chunk, vector<column_t> column_ids,
93
+ const SelectionVector &append_sel = *FlatVector::IncrementalSelectionVector(),
94
+ const idx_t append_count = DConstants::INVALID_INDEX);
95
+ //! Append a DataChunk to this TupleDataCollection using the specified Append state
96
+ void Append(TupleDataAppendState &append_state, DataChunk &new_chunk,
97
+ const SelectionVector &append_sel = *FlatVector::IncrementalSelectionVector(),
98
+ const idx_t append_count = DConstants::INVALID_INDEX);
99
+ //! Append a DataChunk to this TupleDataCollection using the specified pin and Chunk states
100
+ void Append(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, DataChunk &new_chunk,
101
+ const SelectionVector &append_sel = *FlatVector::IncrementalSelectionVector(),
102
+ const idx_t append_count = DConstants::INVALID_INDEX);
103
+ //! Append a DataChunk to this TupleDataCollection using the specified pin and Chunk states
104
+ //! - ToUnifiedFormat has already been called
105
+ void AppendUnified(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, DataChunk &new_chunk,
106
+ const SelectionVector &append_sel = *FlatVector::IncrementalSelectionVector(),
107
+ const idx_t append_count = DConstants::INVALID_INDEX);
108
+
109
+ //! Creates a UnifiedVectorFormat in the given Chunk state for the given DataChunk
110
+ static void ToUnifiedFormat(TupleDataChunkState &chunk_state, DataChunk &new_chunk);
111
+ //! Gets the UnifiedVectorFormat from the Chunk state as an array
112
+ static void GetVectorData(const TupleDataChunkState &chunk_state, UnifiedVectorFormat result[]);
113
+ //! Computes the heap sizes for the new DataChunk that will be appended
114
+ static void ComputeHeapSizes(TupleDataChunkState &chunk_state, const DataChunk &new_chunk,
115
+ const SelectionVector &append_sel, const idx_t append_count);
116
+
117
+ //! Builds out the buffer space for the specified Chunk state
118
+ void Build(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const idx_t append_offset,
119
+ const idx_t append_count);
120
+ //! Scatters the given DataChunk to the rows in the specified Chunk state
121
+ void Scatter(TupleDataChunkState &chunk_state, const DataChunk &new_chunk, const SelectionVector &append_sel,
122
+ const idx_t append_count) const;
123
+ //! Scatters the given Vector to the given column id to the rows in the specified Chunk state
124
+ void Scatter(TupleDataChunkState &chunk_state, const Vector &source, const column_t column_id,
125
+ const SelectionVector &append_sel, const idx_t append_count) const;
126
+ //! Copy rows from input to the built Chunk state
127
+ void CopyRows(TupleDataChunkState &chunk_state, TupleDataChunkState &input, const SelectionVector &append_sel,
128
+ const idx_t append_count) const;
129
+
130
+ //! Finalizes the Pin state, releasing or storing blocks
131
+ void FinalizePinState(TupleDataPinState &pin_state, TupleDataSegment &segment);
132
+ //! Finalizes the Pin state, releasing or storing blocks
133
+ void FinalizePinState(TupleDataPinState &pin_state);
134
+
135
+ //! Appends the other TupleDataCollection to this, destroying the other data collection
136
+ void Combine(TupleDataCollection &other);
137
+ //! Appends the other TupleDataCollection to this, destroying the other data collection
138
+ void Combine(unique_ptr<TupleDataCollection> other);
139
+ //! Resets the TupleDataCollection, clearing all data
140
+ void Reset();
141
+
142
+ //! Initializes a chunk with the correct types that can be used to call Append/Scan
143
+ void InitializeChunk(DataChunk &chunk) const;
144
+ //! Initializes a chunk with the correct types for a given scan state
145
+ void InitializeScanChunk(TupleDataScanState &state, DataChunk &chunk) const;
146
+ //! Initializes a Scan state for scanning all columns
147
+ void InitializeScan(TupleDataScanState &state,
148
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE) const;
149
+ //! Initializes a Scan state for scanning a subset of the columns
150
+ void InitializeScan(TupleDataScanState &state, vector<column_t> column_ids,
151
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE) const;
152
+ //! Initialize a parallel scan over the tuple data collection over all columns
153
+ void InitializeScan(TupleDataParallelScanState &state,
154
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE) const;
155
+ //! Initialize a parallel scan over the tuple data collection over a subset of the columns
156
+ void InitializeScan(TupleDataParallelScanState &gstate, vector<column_t> column_ids,
157
+ TupleDataPinProperties properties = TupleDataPinProperties::UNPIN_AFTER_DONE) const;
158
+ //! Scans a DataChunk from the TupleDataCollection
159
+ bool Scan(TupleDataScanState &state, DataChunk &result);
160
+ //! Scans a DataChunk from the TupleDataCollection
161
+ bool Scan(TupleDataParallelScanState &gstate, TupleDataLocalScanState &lstate, DataChunk &result);
162
+
163
+ //! Gathers a DataChunk from the TupleDataCollection, given the specific row locations (requires full pin)
164
+ void Gather(Vector &row_locations, const SelectionVector &scan_sel, const idx_t scan_count, DataChunk &result,
165
+ const SelectionVector &target_sel) const;
166
+ //! Gathers a DataChunk (only the columns given by column_ids) from the TupleDataCollection,
167
+ //! given the specific row locations (requires full pin)
168
+ void Gather(Vector &row_locations, const SelectionVector &scan_sel, const idx_t scan_count,
169
+ const vector<column_t> &column_ids, DataChunk &result, const SelectionVector &target_sel) const;
170
+ //! Gathers a Vector (from the given column id) from the TupleDataCollection
171
+ //! given the specific row locations (requires full pin)
172
+ void Gather(Vector &row_locations, const SelectionVector &sel, const idx_t scan_count, const column_t column_id,
173
+ Vector &result, const SelectionVector &target_sel) const;
174
+
175
+ //! Converts this TupleDataCollection to a string representation
176
+ string ToString();
177
+ //! Prints the string representation of this TupleDataCollection
178
+ void Print();
179
+
180
+ //! Verify that all blocks are pinned
181
+ void VerifyEverythingPinned() const;
182
+
183
+ private:
184
+ //! Initializes the TupleDataCollection (called by the constructor)
185
+ void Initialize();
186
+ //! Gets all column ids
187
+ void GetAllColumnIDs(vector<column_t> &column_ids);
188
+
189
+ //! Computes the heap sizes for the specific Vector that will be appended
190
+ static void ComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v, TupleDataVectorFormat &source,
191
+ const SelectionVector &append_sel, const idx_t append_count);
192
+ //! Computes the heap sizes for the specific Vector that will be appended (within a list)
193
+ static void WithinListHeapComputeSizes(Vector &heap_sizes_v, const Vector &source_v,
194
+ TupleDataVectorFormat &source_format, const SelectionVector &append_sel,
195
+ const idx_t append_count, const UnifiedVectorFormat &list_data);
196
+ //! Computes the heap sizes for the fixed-size type Vector that will be appended (within a list)
197
+ static void ComputeFixedWithinListHeapSizes(Vector &heap_sizes_v, const Vector &source_v,
198
+ TupleDataVectorFormat &source_format, const SelectionVector &append_sel,
199
+ const idx_t append_count, const UnifiedVectorFormat &list_data);
200
+ //! Computes the heap sizes for the string Vector that will be appended (within a list)
201
+ static void StringWithinListComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v,
202
+ TupleDataVectorFormat &source_format,
203
+ const SelectionVector &append_sel, const idx_t append_count,
204
+ const UnifiedVectorFormat &list_data);
205
+ //! Computes the heap sizes for the struct Vector that will be appended (within a list)
206
+ static void StructWithinListComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v,
207
+ TupleDataVectorFormat &source_format,
208
+ const SelectionVector &append_sel, const idx_t append_count,
209
+ const UnifiedVectorFormat &list_data);
210
+ //! Computes the heap sizes for the list Vector that will be appended (within a list)
211
+ static void ListWithinListComputeHeapSizes(Vector &heap_sizes_v, const Vector &source_v,
212
+ TupleDataVectorFormat &source_format, const SelectionVector &append_sel,
213
+ const idx_t append_count, const UnifiedVectorFormat &list_data);
214
+
215
+ //! Get the next segment/chunk index for the scan
216
+ bool NextScanIndex(TupleDataScanState &scan_state, idx_t &segment_index, idx_t &chunk_index);
217
+ //! Scans the chunk at the given segment/chunk indices
218
+ void ScanAtIndex(TupleDataPinState &pin_state, TupleDataChunkState &chunk_state, const vector<column_t> &column_ids,
219
+ idx_t segment_index, idx_t chunk_index, DataChunk &result);
220
+
221
+ //! Verify counts of the segments in this collection
222
+ void Verify() const;
223
+
224
+ private:
225
+ //! The layout of the TupleDataCollection
226
+ const TupleDataLayout layout;
227
+ //! The TupleDataAllocator
228
+ shared_ptr<TupleDataAllocator> allocator;
229
+ //! The number of entries stored in the TupleDataCollection
230
+ idx_t count;
231
+ //! The data segments of the TupleDataCollection
232
+ vector<TupleDataSegment> segments;
233
+ //! The set of scatter functions
234
+ vector<TupleDataScatterFunction> scatter_functions;
235
+ //! The set of gather functions
236
+ vector<TupleDataGatherFunction> gather_functions;
237
+ };
238
+
239
+ } // namespace duckdb
@@ -0,0 +1,64 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/types/row/tuple_data_iterator.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/types/row/tuple_data_collection.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ class TupleDataChunkIterator {
16
+ public:
17
+ //! Creates a TupleDataChunkIterator that iterates over all DataChunks in the TupleDataCollection
18
+ TupleDataChunkIterator(TupleDataCollection &collection, TupleDataPinProperties properties, bool init_heap);
19
+ //! Creates a TupleDataChunkIterator that iterates over the specified DataChunk range in the TupleDataCollection
20
+ TupleDataChunkIterator(TupleDataCollection &collection, TupleDataPinProperties properties, idx_t chunk_idx_from,
21
+ idx_t chunk_idx_to, bool init_heap);
22
+
23
+ public:
24
+ //! Whether the iterator is done
25
+ bool Done() const;
26
+ //! Fetches the next STANDARD_VECTOR_SIZE row locations (and heap locations/sizes if init_heap is true)
27
+ bool Next();
28
+ //! Resets the scan indices to the start
29
+ void Reset();
30
+ //! Get the count of the current "DataChunk"
31
+ idx_t GetCurrentChunkCount() const;
32
+ //! Get the Chunk state of the scan state of this iterator
33
+ TupleDataChunkState &GetChunkState();
34
+ //! Get the array holding the row locations
35
+ data_ptr_t *GetRowLocations();
36
+ //! Get the array holding the heap locations
37
+ data_ptr_t *GetHeapLocations();
38
+ //! Get the array holding the heap sizes
39
+ idx_t *GetHeapSizes();
40
+
41
+ private:
42
+ //! Initializes the row locations (and heap locations/sizes if init_heap is true) at the current scan indices
43
+ void InitializeCurrentChunk();
44
+
45
+ private:
46
+ //! The collection being iterated over
47
+ TupleDataCollection &collection;
48
+ //! Whether or not to fetch the heap locations/sizes while iterating
49
+ bool init_heap;
50
+
51
+ //! Start indices
52
+ idx_t start_segment_idx;
53
+ idx_t start_chunk_idx;
54
+ //! End indices
55
+ idx_t end_segment_idx;
56
+ idx_t end_chunk_idx;
57
+
58
+ //! Current scan state and scan indices
59
+ TupleDataScanState state;
60
+ idx_t current_segment_idx;
61
+ idx_t current_chunk_idx;
62
+ };
63
+
64
+ } // namespace duckdb
@@ -0,0 +1,113 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/types/row/tuple_data_layout.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/types/row/row_layout.hpp"
13
+ #include "duckdb/common/types/validity_mask.hpp"
14
+ #include "duckdb/execution/operator/aggregate/aggregate_object.hpp"
15
+ #include "duckdb/planner/expression.hpp"
16
+
17
+ namespace duckdb {
18
+
19
+ class TupleDataLayout {
20
+ public:
21
+ using Aggregates = vector<AggregateObject>;
22
+ using ValidityBytes = TemplatedValidityMask<uint8_t>;
23
+
24
+ //! Creates an empty TupleDataLayout
25
+ TupleDataLayout();
26
+ //! Create a copy of this TupleDataLayout
27
+ TupleDataLayout Copy() const;
28
+
29
+ public:
30
+ //! Initializes the TupleDataLayout with the specified types and aggregates to an empty TupleDataLayout
31
+ void Initialize(vector<LogicalType> types_p, Aggregates aggregates_p, bool align = true, bool heap_offset = true);
32
+ //! Initializes the TupleDataLayout with the specified types to an empty TupleDataLayout
33
+ void Initialize(vector<LogicalType> types, bool align = true, bool heap_offset = true);
34
+ //! Initializes the TupleDataLayout with the specified aggregates to an empty TupleDataLayout
35
+ void Initialize(Aggregates aggregates_p, bool align = true, bool heap_offset = true);
36
+
37
+ //! Returns the number of data columns
38
+ inline idx_t ColumnCount() const {
39
+ return types.size();
40
+ }
41
+ //! Returns a list of the column types for this data chunk
42
+ inline const vector<LogicalType> &GetTypes() const {
43
+ return types;
44
+ }
45
+ //! Returns the number of aggregates
46
+ inline idx_t AggregateCount() const {
47
+ return aggregates.size();
48
+ }
49
+ //! Returns a list of the aggregates for this data chunk
50
+ inline Aggregates &GetAggregates() {
51
+ return aggregates;
52
+ }
53
+ //! Returns a map from column id to the struct TupleDataLayout
54
+ const inline TupleDataLayout &GetStructLayout(idx_t col_idx) const {
55
+ D_ASSERT(struct_layouts->find(col_idx) != struct_layouts->end());
56
+ return struct_layouts->find(col_idx)->second;
57
+ }
58
+ //! Returns the total width required for each row, including padding
59
+ inline idx_t GetRowWidth() const {
60
+ return row_width;
61
+ }
62
+ //! Returns the offset to the start of the data
63
+ inline idx_t GetDataOffset() const {
64
+ return flag_width;
65
+ }
66
+ //! Returns the total width required for the data, including padding
67
+ inline idx_t GetDataWidth() const {
68
+ return data_width;
69
+ }
70
+ //! Returns the offset to the start of the aggregates
71
+ inline idx_t GetAggrOffset() const {
72
+ return flag_width + data_width;
73
+ }
74
+ //! Returns the total width required for the aggregates, including padding
75
+ inline idx_t GetAggrWidth() const {
76
+ return aggr_width;
77
+ }
78
+ //! Returns the column offsets into each row
79
+ inline const vector<idx_t> &GetOffsets() const {
80
+ return offsets;
81
+ }
82
+ //! Returns whether all columns in this layout are constant size
83
+ inline bool AllConstant() const {
84
+ return all_constant;
85
+ }
86
+ inline idx_t GetHeapSizeOffset() const {
87
+ return heap_size_offset;
88
+ }
89
+
90
+ private:
91
+ //! The types of the data columns
92
+ vector<LogicalType> types;
93
+ //! The aggregate functions
94
+ Aggregates aggregates;
95
+ //! Structs are a recursive TupleDataLayout
96
+ unique_ptr<unordered_map<idx_t, TupleDataLayout>> struct_layouts;
97
+ //! The width of the validity header
98
+ idx_t flag_width;
99
+ //! The width of the data portion
100
+ idx_t data_width;
101
+ //! The width of the aggregate state portion
102
+ idx_t aggr_width;
103
+ //! The width of the entire row
104
+ idx_t row_width;
105
+ //! The offsets to the columns and aggregate data in each row
106
+ vector<idx_t> offsets;
107
+ //! Whether all columns in this layout are constant size
108
+ bool all_constant;
109
+ //! Offset to the heap size of every row
110
+ idx_t heap_size_offset;
111
+ };
112
+
113
+ } // namespace duckdb
@@ -0,0 +1,124 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/types/row/tuple_data_segment.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/common.hpp"
12
+ #include "duckdb/common/mutex.hpp"
13
+ #include "duckdb/common/unordered_set.hpp"
14
+ #include "duckdb/common/vector.hpp"
15
+ #include "duckdb/storage/buffer_manager.hpp"
16
+
17
+ namespace duckdb {
18
+
19
+ class TupleDataAllocator;
20
+ class TupleDataLayout;
21
+
22
+ struct TupleDataChunkPart {
23
+ public:
24
+ TupleDataChunkPart();
25
+
26
+ //! Disable copy constructors
27
+ TupleDataChunkPart(const TupleDataChunkPart &other) = delete;
28
+ TupleDataChunkPart &operator=(const TupleDataChunkPart &) = delete;
29
+
30
+ //! Enable move constructors
31
+ TupleDataChunkPart(TupleDataChunkPart &&other) noexcept;
32
+ TupleDataChunkPart &operator=(TupleDataChunkPart &&) noexcept;
33
+
34
+ static constexpr const uint32_t INVALID_INDEX = (uint32_t)-1;
35
+
36
+ public:
37
+ //! Index/offset of the row block
38
+ uint32_t row_block_index;
39
+ uint32_t row_block_offset;
40
+ //! Pointer/index/offset of the heap block
41
+ uint32_t heap_block_index;
42
+ uint32_t heap_block_offset;
43
+ data_ptr_t base_heap_ptr;
44
+ //! Total heap size for this chunk part
45
+ uint32_t total_heap_size;
46
+ //! Tuple count for this chunk part
47
+ uint32_t count;
48
+ //! Lock for recomputing heap pointers
49
+ mutex lock;
50
+ };
51
+
52
+ struct TupleDataChunk {
53
+ public:
54
+ TupleDataChunk();
55
+
56
+ //! Disable copy constructors
57
+ TupleDataChunk(const TupleDataChunk &other) = delete;
58
+ TupleDataChunk &operator=(const TupleDataChunk &) = delete;
59
+
60
+ //! Enable move constructors
61
+ TupleDataChunk(TupleDataChunk &&other) noexcept;
62
+ TupleDataChunk &operator=(TupleDataChunk &&) noexcept;
63
+
64
+ //! Add a part to this chunk
65
+ void AddPart(TupleDataChunkPart &&part, const TupleDataLayout &layout);
66
+ //! Tries to merge the last chunk part into the second-to-last one
67
+ void MergeLastChunkPart(const TupleDataLayout &layout);
68
+ //! Verify counts of the parts in this chunk
69
+ void Verify() const;
70
+
71
+ public:
72
+ //! The parts of this chunk
73
+ vector<TupleDataChunkPart> parts;
74
+ //! The row block ids referenced by the chunk
75
+ unordered_set<uint32_t> row_block_ids;
76
+ //! The heap block ids referenced by the chunk
77
+ unordered_set<uint32_t> heap_block_ids;
78
+ //! Tuple count for this chunk
79
+ idx_t count;
80
+ };
81
+
82
+ struct TupleDataSegment {
83
+ public:
84
+ explicit TupleDataSegment(shared_ptr<TupleDataAllocator> allocator);
85
+
86
+ ~TupleDataSegment();
87
+
88
+ //! Disable copy constructors
89
+ TupleDataSegment(const TupleDataSegment &other) = delete;
90
+ TupleDataSegment &operator=(const TupleDataSegment &) = delete;
91
+
92
+ //! Enable move constructors
93
+ TupleDataSegment(TupleDataSegment &&other) noexcept;
94
+ TupleDataSegment &operator=(TupleDataSegment &&) noexcept;
95
+
96
+ //! The number of chunks in this segment
97
+ idx_t ChunkCount() const;
98
+ //! The size (in bytes) of this segment
99
+ idx_t SizeInBytes() const;
100
+ //! Unpins all held pins
101
+ void Unpin();
102
+
103
+ //! Verify counts of the chunks in this segment
104
+ void Verify() const;
105
+ //! Verify that all blocks in this segment are pinned
106
+ void VerifyEverythingPinned() const;
107
+
108
+ public:
109
+ //! The allocator for this segment
110
+ shared_ptr<TupleDataAllocator> allocator;
111
+ //! The chunks of this segment
112
+ vector<TupleDataChunk> chunks;
113
+ //! The tuple count of this segment
114
+ idx_t count;
115
+
116
+ //! Lock for modifying pinned_handles
117
+ mutex pinned_handles_lock;
118
+ //! Where handles to row blocks will be stored with TupleDataPinProperties::KEEP_EVERYTHING_PINNED
119
+ vector<BufferHandle> pinned_row_handles;
120
+ //! Where handles to heap blocks will be stored with TupleDataPinProperties::KEEP_EVERYTHING_PINNED
121
+ vector<BufferHandle> pinned_heap_handles;
122
+ };
123
+
124
+ } // namespace duckdb