duckdb 0.7.2-dev2507.0 → 0.7.2-dev2675.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 (254) hide show
  1. package/binding.gyp +7 -7
  2. package/package.json +2 -2
  3. package/src/connection.cpp +1 -1
  4. package/src/duckdb/extension/icu/icu-dateadd.cpp +3 -3
  5. package/src/duckdb/extension/icu/icu-datepart.cpp +3 -3
  6. package/src/duckdb/extension/icu/icu-datesub.cpp +2 -2
  7. package/src/duckdb/extension/icu/icu-datetrunc.cpp +1 -1
  8. package/src/duckdb/extension/icu/icu-extension.cpp +3 -3
  9. package/src/duckdb/extension/icu/icu-list-range.cpp +2 -2
  10. package/src/duckdb/extension/icu/icu-makedate.cpp +1 -1
  11. package/src/duckdb/extension/icu/icu-strptime.cpp +4 -4
  12. package/src/duckdb/extension/icu/icu-table-range.cpp +2 -2
  13. package/src/duckdb/extension/icu/icu-timebucket.cpp +1 -1
  14. package/src/duckdb/extension/icu/icu-timezone.cpp +4 -4
  15. package/src/duckdb/extension/json/json-extension.cpp +6 -6
  16. package/src/duckdb/extension/parquet/parquet-extension.cpp +9 -8
  17. package/src/duckdb/extension/parquet/parquet_statistics.cpp +3 -0
  18. package/src/duckdb/src/catalog/catalog.cpp +166 -127
  19. package/src/duckdb/src/catalog/catalog_entry/copy_function_catalog_entry.cpp +3 -3
  20. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  21. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +90 -82
  22. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +65 -67
  23. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +3 -3
  24. package/src/duckdb/src/catalog/catalog_entry/pragma_function_catalog_entry.cpp +4 -4
  25. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +8 -8
  26. package/src/duckdb/src/catalog/catalog_entry/scalar_macro_catalog_entry.cpp +10 -10
  27. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +6 -6
  28. package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +6 -6
  29. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +4 -4
  30. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +9 -9
  31. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +5 -5
  32. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +23 -23
  33. package/src/duckdb/src/catalog/catalog_entry.cpp +27 -6
  34. package/src/duckdb/src/catalog/catalog_search_path.cpp +2 -2
  35. package/src/duckdb/src/catalog/catalog_set.cpp +84 -87
  36. package/src/duckdb/src/catalog/catalog_transaction.cpp +1 -1
  37. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -1
  38. package/src/duckdb/src/catalog/default/default_schemas.cpp +1 -1
  39. package/src/duckdb/src/catalog/default/default_types.cpp +1 -1
  40. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  41. package/src/duckdb/src/catalog/dependency_list.cpp +2 -2
  42. package/src/duckdb/src/catalog/dependency_manager.cpp +9 -10
  43. package/src/duckdb/src/catalog/duck_catalog.cpp +30 -26
  44. package/src/duckdb/src/catalog/similar_catalog_entry.cpp +1 -1
  45. package/src/duckdb/src/common/radix_partitioning.cpp +1 -1
  46. package/src/duckdb/src/common/types.cpp +15 -27
  47. package/src/duckdb/src/execution/index/art/art.cpp +286 -269
  48. package/src/duckdb/src/execution/index/art/art_key.cpp +22 -32
  49. package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +224 -0
  50. package/src/duckdb/src/execution/index/art/iterator.cpp +142 -123
  51. package/src/duckdb/src/execution/index/art/leaf.cpp +319 -170
  52. package/src/duckdb/src/execution/index/art/leaf_segment.cpp +42 -0
  53. package/src/duckdb/src/execution/index/art/node.cpp +444 -379
  54. package/src/duckdb/src/execution/index/art/node16.cpp +178 -114
  55. package/src/duckdb/src/execution/index/art/node256.cpp +117 -79
  56. package/src/duckdb/src/execution/index/art/node4.cpp +169 -114
  57. package/src/duckdb/src/execution/index/art/node48.cpp +175 -105
  58. package/src/duckdb/src/execution/index/art/prefix.cpp +405 -127
  59. package/src/duckdb/src/execution/index/art/prefix_segment.cpp +42 -0
  60. package/src/duckdb/src/execution/index/art/swizzleable_pointer.cpp +10 -85
  61. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +4 -3
  62. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +2 -2
  63. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +2 -0
  64. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +4 -3
  65. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +19 -18
  66. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +5 -5
  67. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  68. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +1 -1
  69. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +17 -17
  70. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +1 -1
  71. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +1 -1
  72. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  73. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +4 -3
  74. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +1 -1
  75. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +1 -1
  76. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +2 -2
  77. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +1 -1
  78. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  79. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +4 -3
  80. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  81. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  82. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  83. package/src/duckdb/src/function/built_in_functions.cpp +10 -10
  84. package/src/duckdb/src/function/function_binder.cpp +3 -3
  85. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +5 -6
  86. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +2 -2
  87. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +9 -8
  88. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +6 -6
  89. package/src/duckdb/src/function/table/arrow.cpp +5 -5
  90. package/src/duckdb/src/function/table/read_csv.cpp +5 -1
  91. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +8 -7
  92. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +14 -14
  93. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +2 -2
  94. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +26 -25
  95. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +13 -12
  96. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +7 -7
  97. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +8 -9
  98. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +10 -9
  99. package/src/duckdb/src/function/table/system/duckdb_types.cpp +13 -13
  100. package/src/duckdb/src/function/table/system/duckdb_views.cpp +11 -10
  101. package/src/duckdb/src/function/table/system/pragma_collations.cpp +2 -2
  102. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +5 -5
  103. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +3 -3
  104. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +2 -2
  105. package/src/duckdb/src/function/table/table_scan.cpp +39 -37
  106. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  107. package/src/duckdb/src/function/udf_function.cpp +2 -2
  108. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +122 -81
  109. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +2 -3
  110. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +3 -3
  111. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +1 -1
  112. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  113. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +24 -20
  114. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +3 -3
  115. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  116. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/macro_catalog_entry.hpp +2 -2
  117. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +1 -1
  118. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +2 -2
  119. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +22 -17
  121. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -1
  123. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +2 -2
  124. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +3 -3
  127. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +28 -7
  128. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +20 -19
  129. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +9 -9
  130. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +2 -1
  131. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +10 -4
  132. package/src/duckdb/src/include/duckdb/common/enums/on_entry_not_found.hpp +17 -0
  133. package/src/duckdb/src/include/duckdb/common/queue.hpp +1 -1
  134. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -4
  135. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +53 -45
  136. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +29 -24
  137. package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +114 -0
  138. package/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp +26 -20
  139. package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +63 -39
  140. package/src/duckdb/src/include/duckdb/execution/index/art/leaf_segment.hpp +36 -0
  141. package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +98 -116
  142. package/src/duckdb/src/include/duckdb/execution/index/art/node16.hpp +48 -36
  143. package/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +52 -35
  144. package/src/duckdb/src/include/duckdb/execution/index/art/node4.hpp +46 -36
  145. package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +57 -35
  146. package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +57 -50
  147. package/src/duckdb/src/include/duckdb/execution/index/art/prefix_segment.hpp +40 -0
  148. package/src/duckdb/src/include/duckdb/execution/index/art/swizzleable_pointer.hpp +38 -31
  149. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +2 -1
  150. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -0
  151. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -4
  152. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -2
  153. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +5 -4
  154. package/src/duckdb/src/include/duckdb/function/table_function.hpp +28 -15
  155. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +2 -0
  156. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  157. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -2
  158. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  159. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +2 -2
  160. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +7 -5
  161. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  162. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +1 -1
  163. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +1 -1
  164. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +3 -2
  165. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +5 -5
  166. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +13 -0
  167. package/src/duckdb/src/include/duckdb/parser/statement/insert_statement.hpp +4 -1
  168. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +5 -2
  169. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +4 -1
  170. package/src/duckdb/src/include/duckdb/planner/binder.hpp +2 -2
  171. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -2
  172. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +4 -7
  173. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +1 -1
  174. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +0 -5
  175. package/src/duckdb/src/include/duckdb/storage/index.hpp +13 -28
  176. package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +0 -2
  177. package/src/duckdb/src/include/duckdb/transaction/cleanup_state.hpp +5 -0
  178. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +12 -0
  179. package/src/duckdb/src/include/duckdb.h +26 -0
  180. package/src/duckdb/src/main/attached_database.cpp +12 -6
  181. package/src/duckdb/src/main/capi/helper-c.cpp +7 -0
  182. package/src/duckdb/src/main/capi/table_function-c.cpp +17 -16
  183. package/src/duckdb/src/main/client_context.cpp +12 -11
  184. package/src/duckdb/src/main/database_manager.cpp +13 -12
  185. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -2
  186. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +3 -3
  187. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +2 -2
  188. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +2 -2
  189. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +9 -9
  190. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +2 -2
  191. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +2 -2
  192. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +2 -2
  193. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +2 -2
  194. package/src/duckdb/src/parser/statement/insert_statement.cpp +15 -6
  195. package/src/duckdb/src/parser/transform/constraint/transform_constraint.cpp +1 -1
  196. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +18 -5
  197. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +3 -2
  198. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +5 -1
  199. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +1 -1
  200. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +1 -1
  201. package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +5 -7
  202. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +1 -1
  203. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +26 -27
  204. package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +17 -17
  205. package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +9 -9
  206. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +6 -6
  207. package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +6 -6
  208. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +2 -2
  209. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +21 -21
  210. package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +2 -3
  211. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +33 -36
  212. package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +5 -5
  213. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +23 -23
  214. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -4
  215. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +7 -7
  216. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +23 -23
  217. package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +4 -4
  218. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +14 -13
  219. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +56 -42
  220. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +3 -3
  221. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  222. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +4 -4
  223. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +10 -10
  224. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +16 -11
  225. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +4 -4
  226. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +5 -4
  227. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  228. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +3 -3
  229. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +10 -12
  230. package/src/duckdb/src/planner/binder.cpp +2 -2
  231. package/src/duckdb/src/planner/expression/bound_expression.cpp +11 -2
  232. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +2 -5
  233. package/src/duckdb/src/planner/operator/logical_create.cpp +2 -1
  234. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  235. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -2
  236. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  237. package/src/duckdb/src/planner/operator/logical_insert.cpp +2 -7
  238. package/src/duckdb/src/planner/operator/logical_update.cpp +2 -6
  239. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +2 -2
  240. package/src/duckdb/src/planner/pragma_handler.cpp +3 -4
  241. package/src/duckdb/src/storage/checkpoint_manager.cpp +57 -55
  242. package/src/duckdb/src/storage/data_table.cpp +9 -9
  243. package/src/duckdb/src/storage/index.cpp +18 -6
  244. package/src/duckdb/src/storage/local_storage.cpp +8 -2
  245. package/src/duckdb/src/storage/standard_buffer_manager.cpp +0 -9
  246. package/src/duckdb/src/storage/table/update_segment.cpp +1 -1
  247. package/src/duckdb/src/storage/wal_replay.cpp +29 -31
  248. package/src/duckdb/src/storage/write_ahead_log.cpp +8 -8
  249. package/src/duckdb/src/transaction/cleanup_state.cpp +7 -1
  250. package/src/duckdb/src/transaction/commit_state.cpp +3 -4
  251. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
  252. package/src/duckdb/src/transaction/undo_buffer.cpp +8 -0
  253. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  254. package/src/duckdb/ub_src_execution_index_art.cpp +7 -1
@@ -1,31 +1,34 @@
1
1
  #include "duckdb/execution/index/art/iterator.hpp"
2
2
 
3
+ #include "duckdb/common/limits.hpp"
3
4
  #include "duckdb/execution/index/art/art.hpp"
5
+ #include "duckdb/execution/index/art/node.hpp"
6
+ #include "duckdb/execution/index/art/prefix.hpp"
4
7
 
5
8
  namespace duckdb {
6
- uint8_t &IteratorCurrentKey::operator[](idx_t idx) {
7
- if (idx >= key.size()) {
8
- key.push_back(0);
9
- }
10
- D_ASSERT(idx < key.size());
11
- return key[idx];
12
- }
13
9
 
14
- //! Push Byte
15
- void IteratorCurrentKey::Push(uint8_t byte) {
10
+ void IteratorCurrentKey::Push(const uint8_t byte) {
16
11
  if (cur_key_pos == key.size()) {
17
12
  key.push_back(byte);
18
13
  }
19
14
  D_ASSERT(cur_key_pos < key.size());
20
15
  key[cur_key_pos++] = byte;
21
16
  }
22
- //! Pops n elements
23
- void IteratorCurrentKey::Pop(idx_t n) {
17
+
18
+ void IteratorCurrentKey::Pop(const idx_t n) {
24
19
  cur_key_pos -= n;
25
20
  D_ASSERT(cur_key_pos <= key.size());
26
21
  }
27
22
 
28
- bool IteratorCurrentKey::operator>(const Key &k) const {
23
+ uint8_t &IteratorCurrentKey::operator[](idx_t idx) {
24
+ if (idx >= key.size()) {
25
+ key.push_back(0);
26
+ }
27
+ D_ASSERT(idx < key.size());
28
+ return key[idx];
29
+ }
30
+
31
+ bool IteratorCurrentKey::operator>(const ARTKey &k) const {
29
32
  for (idx_t i = 0; i < MinValue<idx_t>(cur_key_pos, k.len); i++) {
30
33
  if (key[i] > k.data[i]) {
31
34
  return true;
@@ -36,7 +39,7 @@ bool IteratorCurrentKey::operator>(const Key &k) const {
36
39
  return cur_key_pos > k.len;
37
40
  }
38
41
 
39
- bool IteratorCurrentKey::operator>=(const Key &k) const {
42
+ bool IteratorCurrentKey::operator>=(const ARTKey &k) const {
40
43
  for (idx_t i = 0; i < MinValue<idx_t>(cur_key_pos, k.len); i++) {
41
44
  if (key[i] > k.data[i]) {
42
45
  return true;
@@ -47,7 +50,7 @@ bool IteratorCurrentKey::operator>=(const Key &k) const {
47
50
  return cur_key_pos >= k.len;
48
51
  }
49
52
 
50
- bool IteratorCurrentKey::operator==(const Key &k) const {
53
+ bool IteratorCurrentKey::operator==(const ARTKey &k) const {
51
54
  if (cur_key_pos != k.len) {
52
55
  return false;
53
56
  }
@@ -60,96 +63,76 @@ bool IteratorCurrentKey::operator==(const Key &k) const {
60
63
  }
61
64
 
62
65
  void Iterator::FindMinimum(Node &node) {
63
- Node *next = nullptr;
64
- idx_t pos = 0;
66
+
65
67
  // reconstruct the prefix
66
- for (idx_t i = 0; i < node.prefix.Size(); i++) {
67
- cur_key.Push(node.prefix[i]);
68
+ // FIXME: get all bytes at once to increase performance
69
+ auto &node_prefix = node.GetPrefix(*art);
70
+ for (idx_t i = 0; i < node_prefix.count; i++) {
71
+ cur_key.Push(node_prefix.GetByte(*art, i));
68
72
  }
69
- switch (node.type) {
70
- case NodeType::NLeaf:
71
- last_leaf = (Leaf *)&node;
73
+
74
+ // found the minimum
75
+ if (node.DecodeARTNodeType() == NType::LEAF) {
76
+ last_leaf = Node::GetAllocator(*art, NType::LEAF).Get<Leaf>(node);
72
77
  return;
73
- case NodeType::N4: {
74
- next = ((Node4 &)node).children[0].Unswizzle(*art);
75
- cur_key.Push(((Node4 &)node).key[0]);
76
- break;
77
- }
78
- case NodeType::N16: {
79
- next = ((Node16 &)node).children[0].Unswizzle(*art);
80
- cur_key.Push(((Node16 &)node).key[0]);
81
- break;
82
- }
83
- case NodeType::N48: {
84
- auto &n48 = (Node48 &)node;
85
- while (n48.child_index[pos] == Node::EMPTY_MARKER) {
86
- pos++;
87
- }
88
- cur_key.Push(pos);
89
- next = n48.children[n48.child_index[pos]].Unswizzle(*art);
90
- break;
91
- }
92
- case NodeType::N256: {
93
- auto &n256 = (Node256 &)node;
94
- while (!n256.children[pos]) {
95
- pos++;
96
- }
97
- cur_key.Push(pos);
98
- next = (Node *)n256.children[pos].Unswizzle(*art);
99
- break;
100
- }
101
78
  }
102
- nodes.push(IteratorEntry(&node, pos));
79
+
80
+ // go to the leftmost entry in the current node
81
+ uint8_t byte = 0;
82
+ auto next = node.GetNextChild(*art, byte);
83
+ D_ASSERT(next);
84
+ cur_key.Push(byte);
85
+
86
+ // recurse
87
+ nodes.emplace(node, byte);
103
88
  FindMinimum(*next);
104
89
  }
105
90
 
106
- void Iterator::PushKey(Node *cur_node, uint16_t pos) {
107
- switch (cur_node->type) {
108
- case NodeType::N4:
109
- cur_key.Push(((Node4 *)cur_node)->key[pos]);
110
- break;
111
- case NodeType::N16:
112
- cur_key.Push(((Node16 *)cur_node)->key[pos]);
113
- break;
114
- case NodeType::N48:
115
- case NodeType::N256:
116
- cur_key.Push(pos);
117
- break;
118
- case NodeType::NLeaf:
119
- break;
91
+ void Iterator::PushKey(const Node &node, const uint8_t byte) {
92
+ if (node.DecodeARTNodeType() != NType::LEAF) {
93
+ cur_key.Push(byte);
120
94
  }
121
95
  }
122
96
 
123
- bool Iterator::Scan(Key &bound, idx_t max_count, vector<row_t> &result_ids, bool is_inclusive) {
97
+ bool Iterator::Scan(const ARTKey &key, const idx_t &max_count, vector<row_t> &result_ids, const bool &is_inclusive) {
98
+
124
99
  bool has_next;
125
100
  do {
126
- if (!bound.Empty()) {
101
+ if (!key.Empty()) {
102
+ // no more row IDs within the key bounds
127
103
  if (is_inclusive) {
128
- if (cur_key > bound) {
129
- break;
104
+ if (cur_key > key) {
105
+ return true;
130
106
  }
131
107
  } else {
132
- if (cur_key >= bound) {
133
- break;
108
+ if (cur_key >= key) {
109
+ return true;
134
110
  }
135
111
  }
136
112
  }
113
+
114
+ // adding more elements would exceed the max count
137
115
  if (result_ids.size() + last_leaf->count > max_count) {
138
- // adding these elements would exceed the max count
139
116
  return false;
140
117
  }
118
+
119
+ // FIXME: copy all at once to improve performance
141
120
  for (idx_t i = 0; i < last_leaf->count; i++) {
142
- row_t row_id = last_leaf->GetRowId(i);
121
+ row_t row_id = last_leaf->GetRowId(*art, i);
143
122
  result_ids.push_back(row_id);
144
123
  }
124
+
125
+ // get the next leaf
145
126
  has_next = Next();
127
+
146
128
  } while (has_next);
129
+
147
130
  return true;
148
131
  }
149
132
 
150
133
  void Iterator::PopNode() {
151
134
  auto cur_node = nodes.top();
152
- idx_t elements_to_pop = cur_node.node->prefix.Size() + (nodes.size() != 1);
135
+ idx_t elements_to_pop = cur_node.node.GetPrefix(*art).count + (nodes.size() != 1);
153
136
  cur_key.Pop(elements_to_pop);
154
137
  nodes.pop();
155
138
  }
@@ -157,79 +140,110 @@ void Iterator::PopNode() {
157
140
  bool Iterator::Next() {
158
141
  if (!nodes.empty()) {
159
142
  auto cur_node = nodes.top().node;
160
- if (cur_node->type == NodeType::NLeaf) {
161
- // Pop Leaf (We must pop the prefix size + the key to the node (unless we are popping the root)
143
+ if (cur_node.DecodeARTNodeType() == NType::LEAF) {
144
+ // pop leaf
145
+ // we must pop the prefix size + the key to the node, unless we are popping the root
162
146
  PopNode();
163
147
  }
164
148
  }
165
149
 
166
- // Look for the next leaf
150
+ // look for the next leaf
167
151
  while (!nodes.empty()) {
152
+
168
153
  // cur_node
169
154
  auto &top = nodes.top();
170
- Node *node = top.node;
171
- if (node->type == NodeType::NLeaf) {
172
- // found a leaf: move to next node
173
- last_leaf = (Leaf *)node;
155
+ Node node = top.node;
156
+
157
+ // found a leaf: move to next node
158
+ if (node.DecodeARTNodeType() == NType::LEAF) {
159
+ last_leaf = Node::GetAllocator(*art, NType::LEAF).Get<Leaf>(node);
174
160
  return true;
175
161
  }
176
- // Find next node
177
- top.pos = node->GetNextPos(top.pos);
178
- if (top.pos != DConstants::INVALID_INDEX) {
179
- // add key-byte of the new node
180
- PushKey(node, top.pos);
181
- auto next_node = node->GetChild(*art, top.pos);
162
+
163
+ // find next node
164
+ if (top.byte == NumericLimits<uint8_t>::Maximum()) {
165
+ // no node found: move up the tree, pop prefix and key of current node
166
+ PopNode();
167
+ continue;
168
+ }
169
+
170
+ top.byte == 0 ? top.byte : top.byte++;
171
+ auto next_node = node.GetNextChild(*art, top.byte);
172
+
173
+ if (next_node) {
174
+ // add the next node's key byte
175
+ PushKey(node, top.byte);
176
+
182
177
  // add prefix of new node
183
- for (idx_t i = 0; i < next_node->prefix.Size(); i++) {
184
- cur_key.Push(next_node->prefix[i]);
178
+ // FIXME: get all bytes at once to increase performance
179
+ auto &next_node_prefix = next_node->GetPrefix(*art);
180
+ for (idx_t i = 0; i < next_node_prefix.count; i++) {
181
+ cur_key.Push(next_node_prefix.GetByte(*art, i));
185
182
  }
183
+
186
184
  // next node found: push it
187
- nodes.push(IteratorEntry(next_node, DConstants::INVALID_INDEX));
185
+ nodes.emplace(*next_node, 0);
188
186
  } else {
189
- // no node found: move up the tree and Pop prefix and key of current node
187
+
188
+ // no node found: move up the tree, pop prefix and key of current node
190
189
  PopNode();
191
190
  }
192
191
  }
193
192
  return false;
194
193
  }
195
194
 
196
- bool Iterator::LowerBound(Node *node, Key &key, bool inclusive) {
197
- bool equal = true;
198
- if (!node) {
195
+ bool Iterator::LowerBound(Node node, const ARTKey &key, const bool &is_inclusive) {
196
+
197
+ if (!node.IsSet()) {
199
198
  return false;
200
199
  }
200
+
201
201
  idx_t depth = 0;
202
+ bool equal = true;
202
203
  while (true) {
203
- nodes.push(IteratorEntry(node, 0));
204
+
205
+ nodes.emplace(node, 0);
204
206
  auto &top = nodes.top();
207
+
205
208
  // reconstruct the prefix
206
- for (idx_t i = 0; i < top.node->prefix.Size(); i++) {
207
- cur_key.Push(top.node->prefix[i]);
209
+ // FIXME: get all bytes at once to increase performance
210
+ reference<Prefix> node_prefix(top.node.GetPrefix(*art));
211
+ for (idx_t i = 0; i < node_prefix.get().count; i++) {
212
+ cur_key.Push(node_prefix.get().GetByte(*art, i));
208
213
  }
214
+
209
215
  // greater case: find leftmost leaf node directly
210
216
  if (!equal) {
211
- while (node->type != NodeType::NLeaf) {
212
- auto min_pos = node->GetMin();
213
- PushKey(node, min_pos);
214
- nodes.push(IteratorEntry(node, min_pos));
215
- node = node->GetChild(*art, min_pos);
217
+ while (node.DecodeARTNodeType() != NType::LEAF) {
218
+
219
+ uint8_t byte = 0;
220
+ auto next_node = *node.GetNextChild(*art, byte);
221
+ D_ASSERT(next_node.IsSet());
222
+
223
+ PushKey(node, byte);
224
+ nodes.emplace(node, byte);
225
+ node = next_node;
226
+
216
227
  // reconstruct the prefix
217
- for (idx_t i = 0; i < node->prefix.Size(); i++) {
218
- cur_key.Push(node->prefix[i]);
228
+ node_prefix = node.GetPrefix(*art);
229
+ for (idx_t i = 0; i < node_prefix.get().count; i++) {
230
+ cur_key.Push(node_prefix.get().GetByte(*art, i));
219
231
  }
232
+
220
233
  auto &c_top = nodes.top();
221
234
  c_top.node = node;
222
235
  }
223
236
  }
224
- if (node->type == NodeType::NLeaf) {
237
+
238
+ if (node.DecodeARTNodeType() == NType::LEAF) {
225
239
  // found a leaf node: check if it is bigger or equal than the current key
226
- auto leaf = static_cast<Leaf *>(node);
227
- last_leaf = leaf;
240
+ last_leaf = Node::GetAllocator(*art, NType::LEAF).Get<Leaf>(node);
241
+
228
242
  // if the search is not inclusive the leaf node could still be equal to the current value
229
243
  // check if leaf is equal to the current key
230
244
  if (cur_key == key) {
231
245
  // if it's not inclusive check if there is a next leaf
232
- if (!inclusive && !Next()) {
246
+ if (!is_inclusive && !Next()) {
233
247
  return false;
234
248
  } else {
235
249
  return true;
@@ -248,33 +262,38 @@ bool Iterator::LowerBound(Node *node, Key &key, bool inclusive) {
248
262
 
249
263
  return Next();
250
264
  }
265
+
251
266
  // equal case:
252
- uint32_t mismatch_pos = node->prefix.KeyMismatchPosition(key, depth);
253
- if (mismatch_pos != node->prefix.Size()) {
254
- if (node->prefix[mismatch_pos] < key[depth + mismatch_pos]) {
255
- // Less
267
+ node_prefix = node.GetPrefix(*art);
268
+ auto mismatch_pos = node_prefix.get().KeyMismatchPosition(*art, key, depth);
269
+ if (mismatch_pos != node_prefix.get().count) {
270
+ if (node_prefix.get().GetByte(*art, mismatch_pos) < key[depth + mismatch_pos]) {
271
+ // less
256
272
  PopNode();
257
273
  return Next();
258
- } else {
259
- // Greater
260
- top.pos = DConstants::INVALID_INDEX;
261
- return Next();
262
274
  }
275
+ // greater
276
+ top.byte = 0;
277
+ return Next();
263
278
  }
264
279
 
265
280
  // prefix matches, search inside the child for the key
266
- depth += node->prefix.Size();
281
+ depth += node_prefix.get().count;
282
+ top.byte = key[depth];
283
+ auto child = node.GetNextChild(*art, top.byte);
284
+ equal = key[depth] == top.byte;
267
285
 
268
- top.pos = node->GetChildGreaterEqual(key[depth], equal);
269
- // The maximum key byte of the current node is less than the key
270
- // So fall back to the previous node
271
- if (top.pos == DConstants::INVALID_INDEX) {
286
+ // the maximum key byte of the current node is less than the key
287
+ // fall back to the previous node
288
+ if (!child) {
272
289
  PopNode();
273
290
  return Next();
274
291
  }
275
- PushKey(node, top.pos);
276
- node = node->GetChild(*art, top.pos);
277
- // This means all children of this node qualify as geq
292
+
293
+ PushKey(node, top.byte);
294
+ node = *child;
295
+
296
+ // all children of this node qualify as greater or equal
278
297
  depth++;
279
298
  }
280
299
  }