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
@@ -49,9 +49,9 @@ void Binder::BindSchemaOrCatalog(ClientContext &context, string &catalog, string
49
49
  if (database) {
50
50
  // we have a database with this name
51
51
  // check if there is a schema
52
- auto schema_obj = Catalog::GetSchema(context, INVALID_CATALOG, schema, true);
52
+ auto schema_obj = Catalog::GetSchema(context, INVALID_CATALOG, schema, OnEntryNotFound::RETURN_NULL);
53
53
  if (schema_obj) {
54
- auto &attached = schema_obj->catalog->GetAttached();
54
+ auto &attached = schema_obj->catalog.GetAttached();
55
55
  throw BinderException(
56
56
  "Ambiguous reference to catalog or schema \"%s\" - use a fully qualified path like \"%s.%s\"",
57
57
  schema, attached.GetName(), schema);
@@ -95,18 +95,18 @@ SchemaCatalogEntry &Binder::BindSchema(CreateInfo &info) {
95
95
  }
96
96
  }
97
97
  // fetch the schema in which we want to create the object
98
- auto schema_obj = Catalog::GetSchema(context, info.catalog, info.schema);
99
- D_ASSERT(schema_obj->type == CatalogType::SCHEMA_ENTRY);
100
- info.schema = schema_obj->name;
98
+ auto &schema_obj = Catalog::GetSchema(context, info.catalog, info.schema);
99
+ D_ASSERT(schema_obj.type == CatalogType::SCHEMA_ENTRY);
100
+ info.schema = schema_obj.name;
101
101
  if (!info.temporary) {
102
- properties.modified_databases.insert(schema_obj->catalog->GetName());
102
+ properties.modified_databases.insert(schema_obj.catalog.GetName());
103
103
  }
104
- return *schema_obj;
104
+ return schema_obj;
105
105
  }
106
106
 
107
107
  SchemaCatalogEntry &Binder::BindCreateSchema(CreateInfo &info) {
108
108
  auto &schema = BindSchema(info);
109
- if (schema.catalog->IsSystemCatalog()) {
109
+ if (schema.catalog.IsSystemCatalog()) {
110
110
  throw BinderException("Cannot create entry in system catalog");
111
111
  }
112
112
  return schema;
@@ -136,11 +136,11 @@ static void QualifyFunctionNames(ClientContext &context, unique_ptr<ParsedExpres
136
136
  switch (expr->GetExpressionClass()) {
137
137
  case ExpressionClass::FUNCTION: {
138
138
  auto &func = expr->Cast<FunctionExpression>();
139
- auto function = (StandardEntry *)Catalog::GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, func.catalog,
140
- func.schema, func.function_name, true);
139
+ auto function = Catalog::GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, func.catalog, func.schema,
140
+ func.function_name, OnEntryNotFound::RETURN_NULL);
141
141
  if (function) {
142
- func.catalog = function->catalog->GetName();
143
- func.schema = function->schema->name;
142
+ func.catalog = function->ParentCatalog().GetName();
143
+ func.schema = function->ParentSchema().name;
144
144
  }
145
145
  break;
146
146
  }
@@ -160,7 +160,7 @@ static void QualifyFunctionNames(ClientContext &context, unique_ptr<ParsedExpres
160
160
  }
161
161
 
162
162
  SchemaCatalogEntry &Binder::BindCreateFunctionInfo(CreateInfo &info) {
163
- auto &base = (CreateMacroInfo &)info;
163
+ auto &base = info.Cast<CreateMacroInfo>();
164
164
  auto &scalar_function = base.function->Cast<ScalarMacroFunction>();
165
165
 
166
166
  if (scalar_function.expression->HasParameter()) {
@@ -207,7 +207,8 @@ SchemaCatalogEntry &Binder::BindCreateFunctionInfo(CreateInfo &info) {
207
207
  return BindCreateSchema(info);
208
208
  }
209
209
 
210
- void Binder::BindLogicalType(ClientContext &context, LogicalType &type, Catalog *catalog, const string &schema) {
210
+ void Binder::BindLogicalType(ClientContext &context, LogicalType &type, optional_ptr<Catalog> catalog,
211
+ const string &schema) {
211
212
  if (type.id() == LogicalTypeId::LIST || type.id() == LogicalTypeId::MAP) {
212
213
  auto child_type = ListType::GetChildType(type);
213
214
  BindLogicalType(context, child_type, catalog, schema);
@@ -241,7 +242,7 @@ void Binder::BindLogicalType(ClientContext &context, LogicalType &type, Catalog
241
242
  } else if (type.id() == LogicalTypeId::USER) {
242
243
  auto &user_type_name = UserType::GetTypeName(type);
243
244
  if (catalog) {
244
- type = catalog->GetType(context, schema, user_type_name, true);
245
+ type = catalog->GetType(context, schema, user_type_name, OnEntryNotFound::RETURN_NULL);
245
246
  if (type.id() == LogicalTypeId::INVALID) {
246
247
  // look in the system catalog if the type was not found
247
248
  type = Catalog::GetType(context, SYSTEM_CATALOG, schema, user_type_name);
@@ -251,20 +252,21 @@ void Binder::BindLogicalType(ClientContext &context, LogicalType &type, Catalog
251
252
  }
252
253
  } else if (type.id() == LogicalTypeId::ENUM) {
253
254
  auto &enum_type_name = EnumType::GetTypeName(type);
254
- TypeCatalogEntry *enum_type_catalog;
255
+ optional_ptr<TypeCatalogEntry> enum_type_catalog;
255
256
  if (catalog) {
256
- enum_type_catalog = catalog->GetEntry<TypeCatalogEntry>(context, schema, enum_type_name, true);
257
+ enum_type_catalog =
258
+ catalog->GetEntry<TypeCatalogEntry>(context, schema, enum_type_name, OnEntryNotFound::RETURN_NULL);
257
259
  if (!enum_type_catalog) {
258
260
  // look in the system catalog if the type was not found
259
- enum_type_catalog =
260
- Catalog::GetEntry<TypeCatalogEntry>(context, SYSTEM_CATALOG, schema, enum_type_name, true);
261
+ enum_type_catalog = Catalog::GetEntry<TypeCatalogEntry>(context, SYSTEM_CATALOG, schema, enum_type_name,
262
+ OnEntryNotFound::RETURN_NULL);
261
263
  }
262
264
  } else {
263
- enum_type_catalog =
264
- Catalog::GetEntry<TypeCatalogEntry>(context, INVALID_CATALOG, schema, enum_type_name, true);
265
+ enum_type_catalog = Catalog::GetEntry<TypeCatalogEntry>(context, INVALID_CATALOG, schema, enum_type_name,
266
+ OnEntryNotFound::RETURN_NULL);
265
267
  }
266
268
 
267
- LogicalType::SetCatalog(type, enum_type_catalog);
269
+ EnumType::SetCatalog(type, enum_type_catalog.get());
268
270
  }
269
271
  }
270
272
 
@@ -290,17 +292,30 @@ static void FindMatchingPrimaryKeyColumns(const ColumnList &columns, const vecto
290
292
  } else {
291
293
  pk_names = unique.columns;
292
294
  }
293
- if (pk_names.size() != fk.fk_columns.size()) {
294
- // the number of referencing and referenced columns for foreign keys must be the same
295
- continue;
296
- }
297
295
  if (find_primary_key) {
298
296
  // found matching primary key
297
+ if (pk_names.size() != fk.fk_columns.size()) {
298
+ auto pk_name_str = StringUtil::Join(pk_names, ",");
299
+ auto fk_name_str = StringUtil::Join(fk.fk_columns, ",");
300
+ throw BinderException(
301
+ "Failed to create foreign key: number of referencing (%s) and referenced columns (%s) differ",
302
+ fk_name_str, pk_name_str);
303
+ }
299
304
  fk.pk_columns = pk_names;
300
305
  return;
301
306
  }
302
- if (fk.pk_columns != pk_names) {
303
- // Name mismatch
307
+ if (pk_names.size() != fk.fk_columns.size()) {
308
+ // the number of referencing and referenced columns for foreign keys must be the same
309
+ continue;
310
+ }
311
+ bool equals = true;
312
+ for (idx_t i = 0; i < fk.pk_columns.size(); i++) {
313
+ if (!StringUtil::CIEquals(fk.pk_columns[i], pk_names[i])) {
314
+ equals = false;
315
+ break;
316
+ }
317
+ }
318
+ if (!equals) {
304
319
  continue;
305
320
  }
306
321
  // found match
@@ -501,7 +516,7 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
501
516
  break;
502
517
  }
503
518
  case CatalogType::INDEX_ENTRY: {
504
- auto &base = (CreateIndexInfo &)*stmt.info;
519
+ auto &base = stmt.info->Cast<CreateIndexInfo>();
505
520
 
506
521
  // visit the table reference
507
522
  auto bound_table = Bind(*base.table);
@@ -519,11 +534,11 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
519
534
  throw BinderException("Cannot create index on a view!");
520
535
  }
521
536
 
522
- result.plan = table.catalog->BindCreateIndex(*this, stmt, table, std::move(plan));
537
+ result.plan = table.catalog.BindCreateIndex(*this, stmt, table, std::move(plan));
523
538
  break;
524
539
  }
525
540
  case CatalogType::TABLE_ENTRY: {
526
- auto &create_info = (CreateTableInfo &)*stmt.info;
541
+ auto &create_info = stmt.info->Cast<CreateTableInfo>();
527
542
  // If there is a foreign key constraint, resolve primary key column's index from primary key column's name
528
543
  reference_set_t<SchemaCatalogEntry> fk_schemas;
529
544
  for (idx_t i = 0; i < create_info.constraints.size(); i++) {
@@ -538,7 +553,7 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
538
553
  D_ASSERT(fk.info.pk_keys.empty());
539
554
  D_ASSERT(fk.info.fk_keys.empty());
540
555
  FindForeignKeyIndexes(create_info.columns, fk.fk_columns, fk.info.fk_keys);
541
- if (create_info.table == fk.info.table) {
556
+ if (StringUtil::CIEquals(create_info.table, fk.info.table)) {
542
557
  // self-referential foreign key constraint
543
558
  fk.info.type = ForeignKeyType::FK_TYPE_SELF_REFERENCE_TABLE;
544
559
  FindMatchingPrimaryKeyColumns(create_info.columns, create_info.constraints, fk);
@@ -546,21 +561,20 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
546
561
  CheckForeignKeyTypes(create_info.columns, create_info.columns, fk);
547
562
  } else {
548
563
  // have to resolve referenced table
549
- auto pk_table_entry_ptr =
564
+ auto &pk_table_entry_ptr =
550
565
  Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, fk.info.schema, fk.info.table);
551
- fk_schemas.insert(*pk_table_entry_ptr->schema);
552
- FindMatchingPrimaryKeyColumns(pk_table_entry_ptr->GetColumns(), pk_table_entry_ptr->GetConstraints(),
553
- fk);
554
- FindForeignKeyIndexes(pk_table_entry_ptr->GetColumns(), fk.pk_columns, fk.info.pk_keys);
555
- CheckForeignKeyTypes(pk_table_entry_ptr->GetColumns(), create_info.columns, fk);
556
- auto &storage = pk_table_entry_ptr->GetStorage();
566
+ fk_schemas.insert(pk_table_entry_ptr.schema);
567
+ FindMatchingPrimaryKeyColumns(pk_table_entry_ptr.GetColumns(), pk_table_entry_ptr.GetConstraints(), fk);
568
+ FindForeignKeyIndexes(pk_table_entry_ptr.GetColumns(), fk.pk_columns, fk.info.pk_keys);
569
+ CheckForeignKeyTypes(pk_table_entry_ptr.GetColumns(), create_info.columns, fk);
570
+ auto &storage = pk_table_entry_ptr.GetStorage();
557
571
  auto index = storage.info->indexes.FindForeignKeyIndex(fk.info.pk_keys,
558
572
  ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE);
559
573
  if (!index) {
560
574
  auto fk_column_names = StringUtil::Join(fk.pk_columns, ",");
561
575
  throw BinderException("Failed to create foreign key on %s(%s): no UNIQUE or PRIMARY KEY constraint "
562
576
  "present on these columns",
563
- pk_table_entry_ptr->name, fk_column_names);
577
+ pk_table_entry_ptr.name, fk_column_names);
564
578
  }
565
579
  }
566
580
  D_ASSERT(fk.info.pk_keys.size() == fk.info.fk_keys.size());
@@ -635,10 +649,10 @@ BoundStatement Binder::Bind(CreateStatement &stmt) {
635
649
  // 2: create a type alias with a custom type.
636
650
  // eg. CREATE TYPE a AS INT; CREATE TYPE b AS a;
637
651
  // We set b to be an alias for the underlying type of a
638
- auto inner_type = Catalog::GetType(context, schema.catalog->GetName(), schema.name,
652
+ auto inner_type = Catalog::GetType(context, schema.catalog.GetName(), schema.name,
639
653
  UserType::GetTypeName(create_type_info.type));
640
654
  // clear to nullptr, we don't need this
641
- LogicalType::SetCatalog(inner_type, nullptr);
655
+ EnumType::SetCatalog(inner_type, nullptr);
642
656
  inner_type.SetAlias(create_type_info.name);
643
657
  create_type_info.type = inner_type;
644
658
  }
@@ -291,15 +291,15 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
291
291
  if (column.Type().id() == LogicalTypeId::VARCHAR) {
292
292
  ExpressionBinder::TestCollation(context, StringType::GetCollation(column.Type()));
293
293
  }
294
- BindLogicalType(context, column.TypeMutable(), result->schema.catalog);
294
+ BindLogicalType(context, column.TypeMutable(), &result->schema.catalog);
295
295
  // We add a catalog dependency
296
- auto type_dependency = LogicalType::GetCatalog(column.Type());
296
+ auto type_dependency = EnumType::GetCatalog(column.Type());
297
297
  if (type_dependency) {
298
298
  // Only if the USER comes from a create type
299
299
  result->dependencies.AddDependency(*type_dependency);
300
300
  }
301
301
  }
302
- result->dependencies.VerifyDependencies(*schema.catalog, result->Base().table);
302
+ result->dependencies.VerifyDependencies(schema.catalog, result->Base().table);
303
303
  properties.allow_stream_result = false;
304
304
  return result;
305
305
  }
@@ -29,7 +29,7 @@ BoundStatement Binder::Bind(DeleteStatement &stmt) {
29
29
 
30
30
  if (!table.temporary) {
31
31
  // delete from persistent table: not read only!
32
- properties.modified_databases.insert(table.catalog->GetName());
32
+ properties.modified_databases.insert(table.catalog.GetName());
33
33
  }
34
34
 
35
35
  // Add CTEs as bindable
@@ -34,17 +34,17 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
34
34
  case CatalogType::TABLE_ENTRY:
35
35
  case CatalogType::TYPE_ENTRY: {
36
36
  BindSchemaOrCatalog(stmt.info->catalog, stmt.info->schema);
37
- auto entry = (StandardEntry *)Catalog::GetEntry(context, stmt.info->type, stmt.info->catalog, stmt.info->schema,
38
- stmt.info->name, true);
37
+ auto entry = Catalog::GetEntry(context, stmt.info->type, stmt.info->catalog, stmt.info->schema, stmt.info->name,
38
+ OnEntryNotFound::RETURN_NULL);
39
39
  if (!entry) {
40
40
  break;
41
41
  }
42
- stmt.info->catalog = entry->catalog->GetName();
42
+ stmt.info->catalog = entry->ParentCatalog().GetName();
43
43
  if (!entry->temporary) {
44
44
  // we can only drop temporary tables in read-only mode
45
45
  properties.modified_databases.insert(stmt.info->catalog);
46
46
  }
47
- stmt.info->schema = entry->schema->name;
47
+ stmt.info->schema = entry->ParentSchema().name;
48
48
  break;
49
49
  }
50
50
  case CatalogType::DATABASE_ENTRY: {
@@ -89,10 +89,10 @@ void ReorderTableEntries(vector<reference<TableCatalogEntry>> &tables) {
89
89
 
90
90
  string CreateFileName(const string &id_suffix, TableCatalogEntry &table, const string &extension) {
91
91
  auto name = SanitizeExportIdentifier(table.name);
92
- if (table.schema->name == DEFAULT_SCHEMA) {
92
+ if (table.schema.name == DEFAULT_SCHEMA) {
93
93
  return StringUtil::Format("%s%s.%s", name, id_suffix, extension);
94
94
  }
95
- auto schema = SanitizeExportIdentifier(table.schema->name);
95
+ auto schema = SanitizeExportIdentifier(table.schema.name);
96
96
  return StringUtil::Format("%s_%s%s.%s", schema, name, id_suffix, extension);
97
97
  }
98
98
 
@@ -107,9 +107,9 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
107
107
  result.names = {"Success"};
108
108
 
109
109
  // lookup the format in the catalog
110
- auto copy_function =
110
+ auto &copy_function =
111
111
  Catalog::GetEntry<CopyFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->format);
112
- if (!copy_function->function.copy_to_bind && !copy_function->function.plan) {
112
+ if (!copy_function.function.copy_to_bind && !copy_function.function.plan) {
113
113
  throw NotImplementedException("COPY TO is not supported for FORMAT \"%s\"", stmt.info->format);
114
114
  }
115
115
 
@@ -118,9 +118,9 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
118
118
  vector<reference<TableCatalogEntry>> tables;
119
119
  auto schemas = Catalog::GetSchemas(context, catalog);
120
120
  for (auto &schema : schemas) {
121
- schema->Scan(context, CatalogType::TABLE_ENTRY, [&](CatalogEntry *entry) {
122
- if (entry->type == CatalogType::TABLE_ENTRY) {
123
- tables.push_back(entry->Cast<TableCatalogEntry>());
121
+ schema.get().Scan(context, CatalogType::TABLE_ENTRY, [&](CatalogEntry &entry) {
122
+ if (entry.type == CatalogType::TABLE_ENTRY) {
123
+ tables.push_back(entry.Cast<TableCatalogEntry>());
124
124
  }
125
125
  });
126
126
  }
@@ -146,7 +146,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
146
146
  idx_t id = 0;
147
147
  while (true) {
148
148
  string id_suffix = id == 0 ? string() : "_" + to_string(id);
149
- auto name = CreateFileName(id_suffix, table, copy_function->function.extension);
149
+ auto name = CreateFileName(id_suffix, table, copy_function.function.extension);
150
150
  auto directory = stmt.info->file_path;
151
151
  auto full_path = fs.JoinPath(directory, name);
152
152
  info->file_path = full_path;
@@ -159,7 +159,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
159
159
  }
160
160
  info->is_from = false;
161
161
  info->catalog = catalog;
162
- info->schema = table.schema->name;
162
+ info->schema = table.schema.name;
163
163
  info->table = table.name;
164
164
 
165
165
  // We can not export generated columns
@@ -202,7 +202,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
202
202
  }
203
203
 
204
204
  // create the export node
205
- auto export_node = make_uniq<LogicalExport>(copy_function->function, std::move(stmt.info), exported_tables);
205
+ auto export_node = make_uniq<LogicalExport>(copy_function.function, std::move(stmt.info), exported_tables);
206
206
 
207
207
  if (child_operator) {
208
208
  export_node->children.push_back(std::move(child_operator));
@@ -9,6 +9,7 @@
9
9
  #include "duckdb/planner/operator/logical_get.hpp"
10
10
  #include "duckdb/common/string_util.hpp"
11
11
  #include "duckdb/function/table/table_scan.hpp"
12
+ #include "duckdb/planner/operator/logical_dummy_scan.hpp"
12
13
  #include "duckdb/planner/operator/logical_projection.hpp"
13
14
  #include "duckdb/planner/expression_iterator.hpp"
14
15
  #include "duckdb/planner/expression_binder/returning_binder.hpp"
@@ -398,10 +399,10 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
398
399
  result.types = {LogicalType::BIGINT};
399
400
 
400
401
  BindSchemaOrCatalog(stmt.catalog, stmt.schema);
401
- auto &table = *Catalog::GetEntry<TableCatalogEntry>(context, stmt.catalog, stmt.schema, stmt.table);
402
+ auto &table = Catalog::GetEntry<TableCatalogEntry>(context, stmt.catalog, stmt.schema, stmt.table);
402
403
  if (!table.temporary) {
403
404
  // inserting into a non-temporary table: alters underlying database
404
- properties.modified_databases.insert(table.catalog->GetName());
405
+ properties.modified_databases.insert(table.catalog.GetName());
405
406
  }
406
407
 
407
408
  auto insert = make_uniq<LogicalInsert>(table, GenerateTableIndex());
@@ -409,7 +410,7 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
409
410
  AddCTEMap(stmt.cte_map);
410
411
 
411
412
  vector<LogicalIndex> named_column_map;
412
- if (!stmt.columns.empty()) {
413
+ if (!stmt.columns.empty() || stmt.default_values) {
413
414
  // insertion statement specifies column list
414
415
 
415
416
  // create a mapping of (list index) -> (column index)
@@ -448,11 +449,10 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
448
449
 
449
450
  // bind the default values
450
451
  BindDefaultValues(table.GetColumns(), insert->bound_defaults);
451
- if (!stmt.select_statement) {
452
+ if (!stmt.select_statement && !stmt.default_values) {
452
453
  result.plan = std::move(insert);
453
454
  return result;
454
455
  }
455
-
456
456
  // Exclude the generated columns from this amount
457
457
  idx_t expected_columns = stmt.columns.empty() ? table.GetColumns().PhysicalColumnCount() : stmt.columns.size();
458
458
 
@@ -488,14 +488,19 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
488
488
  }
489
489
 
490
490
  // parse select statement and add to logical plan
491
- auto select_binder = Binder::CreateBinder(context, this);
492
- auto root_select = select_binder->Bind(*stmt.select_statement);
493
- MoveCorrelatedExpressions(*select_binder);
491
+ unique_ptr<LogicalOperator> root;
492
+ if (stmt.select_statement) {
493
+ auto select_binder = Binder::CreateBinder(context, this);
494
+ auto root_select = select_binder->Bind(*stmt.select_statement);
495
+ MoveCorrelatedExpressions(*select_binder);
494
496
 
495
- CheckInsertColumnCountMismatch(expected_columns, root_select.types.size(), !stmt.columns.empty(),
496
- table.name.c_str());
497
+ CheckInsertColumnCountMismatch(expected_columns, root_select.types.size(), !stmt.columns.empty(),
498
+ table.name.c_str());
497
499
 
498
- auto root = CastLogicalOperatorToTypes(root_select.types, insert->expected_types, std::move(root_select.plan));
500
+ root = CastLogicalOperatorToTypes(root_select.types, insert->expected_types, std::move(root_select.plan));
501
+ } else {
502
+ root = make_uniq<LogicalDummyScan>(GenerateTableIndex());
503
+ }
499
504
  insert->AddChild(std::move(root));
500
505
 
501
506
  BindOnConflictClause(*insert, table, stmt);
@@ -9,15 +9,15 @@ namespace duckdb {
9
9
 
10
10
  BoundStatement Binder::Bind(PragmaStatement &stmt) {
11
11
  // bind the pragma function
12
- auto entry =
13
- Catalog::GetEntry<PragmaFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->name, false);
12
+ auto &entry =
13
+ Catalog::GetEntry<PragmaFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->name);
14
14
  string error;
15
15
  FunctionBinder function_binder(context);
16
- idx_t bound_idx = function_binder.BindFunction(entry->name, entry->functions, *stmt.info, error);
16
+ idx_t bound_idx = function_binder.BindFunction(entry.name, entry.functions, *stmt.info, error);
17
17
  if (bound_idx == DConstants::INVALID_INDEX) {
18
18
  throw BinderException(FormatError(stmt.stmt_location, error));
19
19
  }
20
- auto bound_function = entry->functions.GetFunctionByOffset(bound_idx);
20
+ auto bound_function = entry.functions.GetFunctionByOffset(bound_idx);
21
21
  if (!bound_function.function) {
22
22
  throw BinderException("PRAGMA function does not have a function specified");
23
23
  }
@@ -18,14 +18,15 @@ BoundStatement Binder::Bind(AlterStatement &stmt) {
18
18
  result.types = {LogicalType::BOOLEAN};
19
19
  BindSchemaOrCatalog(stmt.info->catalog, stmt.info->schema);
20
20
  auto entry = Catalog::GetEntry(context, stmt.info->GetCatalogType(), stmt.info->catalog, stmt.info->schema,
21
- stmt.info->name, stmt.info->if_exists);
21
+ stmt.info->name, stmt.info->if_not_found);
22
22
  if (entry) {
23
+ auto &catalog = entry->ParentCatalog();
23
24
  if (!entry->temporary) {
24
25
  // we can only alter temporary tables/views in read-only mode
25
- properties.modified_databases.insert(entry->catalog->GetName());
26
+ properties.modified_databases.insert(catalog.GetName());
26
27
  }
27
- stmt.info->catalog = entry->catalog->GetName();
28
- stmt.info->schema = ((StandardEntry *)entry)->schema->name;
28
+ stmt.info->catalog = catalog.GetName();
29
+ stmt.info->schema = entry->ParentSchema().name;
29
30
  }
30
31
  result.plan = make_uniq<LogicalSimple>(LogicalOperatorType::LOGICAL_ALTER, std::move(stmt.info));
31
32
  properties.return_type = StatementReturnType::NOTHING;
@@ -209,7 +209,7 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) {
209
209
 
210
210
  if (!table.temporary) {
211
211
  // update of persistent table: not read only!
212
- properties.modified_databases.insert(table.catalog->GetName());
212
+ properties.modified_databases.insert(table.catalog.GetName());
213
213
  }
214
214
  auto update = make_uniq<LogicalUpdate>(table);
215
215
 
@@ -66,7 +66,7 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
66
66
  // extract a table or view from the catalog
67
67
  BindSchemaOrCatalog(ref.catalog_name, ref.schema_name);
68
68
  auto table_or_view = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name,
69
- ref.table_name, true, error_context);
69
+ ref.table_name, OnEntryNotFound::RETURN_NULL, error_context);
70
70
  // we still didn't find the table
71
71
  if (GetBindingMode() == BindingMode::EXTRACT_NAMES) {
72
72
  if (!table_or_view || table_or_view->type == CatalogType::TABLE_ENTRY) {
@@ -111,7 +111,7 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
111
111
 
112
112
  // could not find an alternative: bind again to get the error
113
113
  table_or_view = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name,
114
- ref.table_name, false, error_context);
114
+ ref.table_name, OnEntryNotFound::THROW_EXCEPTION, error_context);
115
115
  }
116
116
  switch (table_or_view->type) {
117
117
  case CatalogType::TABLE_ENTRY: {
@@ -140,7 +140,7 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
140
140
  auto logical_get = make_uniq<LogicalGet>(table_index, scan_function, std::move(bind_data),
141
141
  std::move(return_types), std::move(return_names));
142
142
  bind_context.AddBaseTable(table_index, alias, table_names, table_types, logical_get->column_ids,
143
- logical_get->GetTable());
143
+ logical_get->GetTable().get());
144
144
  return make_uniq_base<BoundTableRef, BoundBaseTableRef>(table, std::move(logical_get));
145
145
  }
146
146
  case CatalogType::VIEW_ENTRY: {
@@ -185,7 +185,7 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
185
185
  }
186
186
  // now add the table function to the bind context so its columns can be bound
187
187
  bind_context.AddTableFunction(bind_index, function_name, return_names, return_types, get->column_ids,
188
- get->GetTable());
188
+ get->GetTable().get());
189
189
  return std::move(get);
190
190
  }
191
191
 
@@ -205,16 +205,12 @@ unique_ptr<BoundTableRef> Binder::Bind(TableFunctionRef &ref) {
205
205
  D_ASSERT(ref.function->type == ExpressionType::FUNCTION);
206
206
  auto &fexpr = ref.function->Cast<FunctionExpression>();
207
207
 
208
- TableFunctionCatalogEntry *function = nullptr;
209
-
210
208
  // fetch the function from the catalog
211
- auto func_catalog = Catalog::GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, fexpr.catalog, fexpr.schema,
212
- fexpr.function_name, false, error_context);
209
+ auto &func_catalog = Catalog::GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, fexpr.catalog, fexpr.schema,
210
+ fexpr.function_name, error_context);
213
211
 
214
- if (func_catalog->type == CatalogType::TABLE_FUNCTION_ENTRY) {
215
- function = (TableFunctionCatalogEntry *)func_catalog;
216
- } else if (func_catalog->type == CatalogType::TABLE_MACRO_ENTRY) {
217
- auto macro_func = (TableMacroCatalogEntry *)func_catalog;
212
+ if (func_catalog.type == CatalogType::TABLE_MACRO_ENTRY) {
213
+ auto &macro_func = func_catalog.Cast<TableMacroCatalogEntry>();
218
214
  auto query_node = BindTableMacro(fexpr, macro_func, 0);
219
215
  D_ASSERT(query_node);
220
216
 
@@ -234,6 +230,8 @@ unique_ptr<BoundTableRef> Binder::Bind(TableFunctionRef &ref) {
234
230
  MoveCorrelatedExpressions(*result->binder);
235
231
  return std::move(result);
236
232
  }
233
+ D_ASSERT(func_catalog.type == CatalogType::TABLE_FUNCTION_ENTRY);
234
+ auto &function = func_catalog.Cast<TableFunctionCatalogEntry>();
237
235
 
238
236
  // evaluate the input parameters to the function
239
237
  vector<LogicalType> arguments;
@@ -241,18 +239,18 @@ unique_ptr<BoundTableRef> Binder::Bind(TableFunctionRef &ref) {
241
239
  named_parameter_map_t named_parameters;
242
240
  unique_ptr<BoundSubqueryRef> subquery;
243
241
  string error;
244
- if (!BindTableFunctionParameters(*function, fexpr.children, arguments, parameters, named_parameters, subquery,
242
+ if (!BindTableFunctionParameters(function, fexpr.children, arguments, parameters, named_parameters, subquery,
245
243
  error)) {
246
244
  throw BinderException(FormatError(ref, error));
247
245
  }
248
246
 
249
247
  // select the function based on the input parameters
250
248
  FunctionBinder function_binder(context);
251
- idx_t best_function_idx = function_binder.BindFunction(function->name, function->functions, arguments, error);
249
+ idx_t best_function_idx = function_binder.BindFunction(function.name, function.functions, arguments, error);
252
250
  if (best_function_idx == DConstants::INVALID_INDEX) {
253
251
  throw BinderException(FormatError(ref, error));
254
252
  }
255
- auto table_function = function->functions.GetFunctionByOffset(best_function_idx);
253
+ auto table_function = function.functions.GetFunctionByOffset(best_function_idx);
256
254
 
257
255
  // now check the named parameters
258
256
  BindNamedParameters(table_function.named_parameters, named_parameters, error_context, table_function.name);
@@ -357,10 +357,10 @@ bool Binder::HasMatchingBinding(const string &catalog_name, const string &schema
357
357
  if (!catalog_entry) {
358
358
  return false;
359
359
  }
360
- if (!catalog_name.empty() && catalog_entry->catalog->GetName() != catalog_name) {
360
+ if (!catalog_name.empty() && catalog_entry->catalog.GetName() != catalog_name) {
361
361
  return false;
362
362
  }
363
- if (!schema_name.empty() && catalog_entry->schema->name != schema_name) {
363
+ if (!schema_name.empty() && catalog_entry->schema.name != schema_name) {
364
364
  return false;
365
365
  }
366
366
  if (catalog_entry->name != table_name) {
@@ -2,8 +2,17 @@
2
2
 
3
3
  namespace duckdb {
4
4
 
5
- BoundExpression::BoundExpression(unique_ptr<Expression> expr)
6
- : ParsedExpression(ExpressionType::INVALID, ExpressionClass::BOUND_EXPRESSION), expr(std::move(expr)) {
5
+ BoundExpression::BoundExpression(unique_ptr<Expression> expr_p)
6
+ : ParsedExpression(ExpressionType::INVALID, ExpressionClass::BOUND_EXPRESSION), expr(std::move(expr_p)) {
7
+ this->alias = expr->alias;
8
+ }
9
+
10
+ unique_ptr<Expression> &BoundExpression::GetExpression(ParsedExpression &expr) {
11
+ auto &bound_expr = expr.Cast<BoundExpression>();
12
+ if (!bound_expr.expr) {
13
+ throw InternalException("BoundExpression::GetExpression called on empty bound expression");
14
+ }
15
+ return bound_expr.expr;
7
16
  }
8
17
 
9
18
  string BoundExpression::ToString() const {
@@ -38,12 +38,9 @@ unique_ptr<LogicalOperator> LogicalCopyToFile::Deserialize(LogicalDeserializatio
38
38
  auto has_bind_data = reader.ReadRequired<bool>();
39
39
 
40
40
  auto &context = state.gstate.context;
41
- auto copy_func_catalog_entry =
41
+ auto &copy_func_catalog_entry =
42
42
  Catalog::GetEntry<CopyFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, copy_func_name);
43
- if (!copy_func_catalog_entry) {
44
- throw InternalException("Cant find catalog entry for function %s", copy_func_name);
45
- }
46
- CopyFunction copy_func = copy_func_catalog_entry->function;
43
+ auto &copy_func = copy_func_catalog_entry.function;
47
44
 
48
45
  unique_ptr<FunctionData> bind_data;
49
46
  if (has_bind_data) {
@@ -10,7 +10,8 @@ unique_ptr<LogicalOperator> LogicalCreate::Deserialize(LogicalDeserializationSta
10
10
  auto &context = state.gstate.context;
11
11
  auto info = CreateInfo::Deserialize(reader.GetSource());
12
12
 
13
- auto schema_catalog_entry = Catalog::GetSchema(context, INVALID_CATALOG, info->schema, true);
13
+ auto schema_catalog_entry =
14
+ Catalog::GetSchema(context, INVALID_CATALOG, info->schema, OnEntryNotFound::RETURN_NULL);
14
15
  return make_uniq<LogicalCreate>(state.type, std::move(info), schema_catalog_entry);
15
16
  }
16
17
 
@@ -21,7 +21,7 @@ unique_ptr<LogicalOperator> LogicalCreateIndex::Deserialize(LogicalDeserializati
21
21
  auto &context = state.gstate.context;
22
22
  auto catalog_info = TableCatalogEntry::Deserialize(reader.GetSource(), context);
23
23
 
24
- auto table =
24
+ auto &table =
25
25
  Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, catalog_info->schema, catalog_info->table);
26
26
  auto unbound_expressions = reader.ReadRequiredSerializableList<Expression>(state.gstate);
27
27
 
@@ -42,7 +42,7 @@ unique_ptr<LogicalOperator> LogicalCreateIndex::Deserialize(LogicalDeserializati
42
42
  reader, state.gstate, CatalogType::TABLE_FUNCTION_ENTRY, bind_data, has_deserialize);
43
43
 
44
44
  reader.Finalize();
45
- return make_uniq<LogicalCreateIndex>(std::move(bind_data), std::move(info), std::move(unbound_expressions), *table,
45
+ return make_uniq<LogicalCreateIndex>(std::move(bind_data), std::move(info), std::move(unbound_expressions), table,
46
46
  std::move(function));
47
47
  }
48
48
 
@@ -19,11 +19,11 @@ unique_ptr<LogicalOperator> LogicalDelete::Deserialize(LogicalDeserializationSta
19
19
  auto &context = state.gstate.context;
20
20
  auto info = TableCatalogEntry::Deserialize(reader.GetSource(), context);
21
21
 
22
- auto table_catalog_entry =
22
+ auto &table_catalog_entry =
23
23
  Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, info->schema, info->table);
24
24
 
25
25
  auto table_index = reader.ReadRequired<idx_t>();
26
- auto result = make_uniq<LogicalDelete>(*table_catalog_entry, table_index);
26
+ auto result = make_uniq<LogicalDelete>(table_catalog_entry, table_index);
27
27
  result->return_chunk = reader.ReadRequired<bool>();
28
28
  return std::move(result);
29
29
  }