duckdb 0.6.2-dev772.0 → 0.6.2-dev889.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 (320) hide show
  1. package/binding.gyp +1 -1
  2. package/package.json +1 -1
  3. package/src/connection.cpp +2 -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 +1 -1
  9. package/src/duckdb/extension/icu/icu-makedate.cpp +1 -1
  10. package/src/duckdb/extension/icu/icu-strptime.cpp +2 -2
  11. package/src/duckdb/extension/icu/icu-timezone.cpp +6 -5
  12. package/src/duckdb/extension/json/json-extension.cpp +1 -1
  13. package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -1
  14. package/src/duckdb/src/catalog/catalog.cpp +516 -177
  15. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +1 -0
  16. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +66 -49
  17. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +15 -16
  18. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +1 -1
  19. package/src/duckdb/src/catalog/catalog_entry.cpp +6 -2
  20. package/src/duckdb/src/catalog/catalog_search_path.cpp +177 -22
  21. package/src/duckdb/src/catalog/catalog_set.cpp +134 -72
  22. package/src/duckdb/src/catalog/catalog_transaction.cpp +28 -0
  23. package/src/duckdb/src/catalog/default/default_views.cpp +4 -4
  24. package/src/duckdb/src/catalog/dependency_list.cpp +13 -0
  25. package/src/duckdb/src/catalog/dependency_manager.cpp +19 -13
  26. package/src/duckdb/src/common/constants.cpp +8 -0
  27. package/src/duckdb/src/common/enums/catalog_type.cpp +2 -0
  28. package/src/duckdb/src/common/enums/logical_operator_type.cpp +2 -0
  29. package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
  30. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  31. package/src/duckdb/src/common/file_system.cpp +1 -1
  32. package/src/duckdb/src/common/string_util.cpp +5 -1
  33. package/src/duckdb/src/execution/index/art/art.cpp +1 -1
  34. package/src/duckdb/src/execution/operator/helper/physical_transaction.cpp +1 -0
  35. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +1 -1
  36. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +3 -2
  37. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +1 -1
  38. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +1 -1
  39. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +4 -3
  40. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  41. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +72 -0
  42. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +2 -1
  43. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +3 -3
  44. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +5 -1
  45. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +2 -1
  46. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  47. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +1 -1
  48. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +2 -1
  49. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +10 -2
  50. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  51. package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +1 -1
  52. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +2 -3
  53. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  54. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  55. package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +4 -0
  56. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  57. package/src/duckdb/src/execution/physical_plan_generator.cpp +3 -2
  58. package/src/duckdb/src/function/built_in_functions.cpp +88 -0
  59. package/src/duckdb/src/function/function.cpp +0 -79
  60. package/src/duckdb/src/function/function_binder.cpp +2 -1
  61. package/src/duckdb/src/function/pragma/pragma_queries.cpp +10 -1
  62. package/src/duckdb/src/function/scalar/date/current.cpp +2 -2
  63. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +3 -2
  64. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +14 -17
  65. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
  66. package/src/duckdb/src/function/scalar/system/system_functions.cpp +7 -4
  67. package/src/duckdb/src/function/table/checkpoint.cpp +37 -4
  68. package/src/duckdb/src/function/table/read_csv.cpp +1 -1
  69. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +32 -25
  70. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +26 -22
  71. package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +1 -1
  72. package/src/duckdb/src/function/table/system/duckdb_extensions.cpp +1 -1
  73. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +22 -15
  74. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +25 -18
  75. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +16 -8
  76. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +26 -19
  77. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +24 -17
  78. package/src/duckdb/src/function/table/system/duckdb_types.cpp +22 -16
  79. package/src/duckdb/src/function/table/system/duckdb_views.cpp +20 -13
  80. package/src/duckdb/src/function/table/system/pragma_collations.cpp +3 -4
  81. package/src/duckdb/src/function/table/system/pragma_database_list.cpp +20 -12
  82. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +39 -24
  83. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +1 -7
  84. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +3 -2
  85. package/src/duckdb/src/function/table/system_functions.cpp +0 -1
  86. package/src/duckdb/src/function/table/table_scan.cpp +13 -10
  87. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  88. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +102 -81
  89. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +4 -0
  90. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +4 -0
  91. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +4 -0
  92. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +4 -0
  93. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +4 -0
  94. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +4 -0
  95. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +4 -0
  96. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +21 -14
  97. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +4 -0
  98. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +4 -0
  99. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +4 -0
  100. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +4 -0
  101. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +4 -0
  102. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +4 -0
  103. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +2 -0
  104. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +30 -11
  105. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +35 -20
  106. package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +32 -0
  107. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +27 -0
  108. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +6 -4
  109. package/src/duckdb/src/include/duckdb/common/allocator.hpp +3 -0
  110. package/src/duckdb/src/include/duckdb/common/constants.hpp +8 -3
  111. package/src/duckdb/src/include/duckdb/common/enums/catalog_type.hpp +1 -0
  112. package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +1 -0
  113. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +1 -0
  114. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +10 -4
  115. package/src/duckdb/src/include/duckdb/common/file_system.hpp +2 -0
  116. package/src/duckdb/src/include/duckdb/common/string_util.hpp +3 -0
  117. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +2 -2
  118. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_attach.hpp +33 -0
  119. package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +2 -1
  120. package/src/duckdb/src/include/duckdb/function/aggregate/algebraic_functions.hpp +1 -0
  121. package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +1 -0
  122. package/src/duckdb/src/include/duckdb/function/aggregate/holistic_functions.hpp +1 -0
  123. package/src/duckdb/src/include/duckdb/function/aggregate/nested_functions.hpp +1 -0
  124. package/src/duckdb/src/include/duckdb/function/aggregate/regression_functions.hpp +1 -0
  125. package/src/duckdb/src/include/duckdb/function/built_in_functions.hpp +78 -0
  126. package/src/duckdb/src/include/duckdb/function/function.hpp +0 -61
  127. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +1 -2
  128. package/src/duckdb/src/include/duckdb/function/pragma/pragma_functions.hpp +1 -0
  129. package/src/duckdb/src/include/duckdb/function/scalar/blob_functions.hpp +1 -0
  130. package/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp +1 -0
  131. package/src/duckdb/src/include/duckdb/function/scalar/enum_functions.hpp +1 -0
  132. package/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp +1 -0
  133. package/src/duckdb/src/include/duckdb/function/scalar/math_functions.hpp +1 -0
  134. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -0
  135. package/src/duckdb/src/include/duckdb/function/scalar/operators.hpp +1 -0
  136. package/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp +1 -0
  137. package/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp +1 -0
  138. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +1 -0
  139. package/src/duckdb/src/include/duckdb/function/scalar/trigonometric_functions.hpp +1 -0
  140. package/src/duckdb/src/include/duckdb/function/scalar/uuid_functions.hpp +1 -0
  141. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
  142. package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +1 -0
  143. package/src/duckdb/src/include/duckdb/function/table/range.hpp +1 -0
  144. package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +1 -0
  145. package/src/duckdb/src/include/duckdb/function/table/summary.hpp +1 -0
  146. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +1 -4
  147. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +1 -0
  148. package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -1
  149. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +64 -0
  150. package/src/duckdb/src/include/duckdb/main/client_context.hpp +3 -3
  151. package/src/duckdb/src/include/duckdb/main/client_data.hpp +2 -1
  152. package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
  153. package/src/duckdb/src/include/duckdb/main/database.hpp +6 -6
  154. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +69 -0
  155. package/src/duckdb/src/include/duckdb/main/settings.hpp +10 -0
  156. package/src/duckdb/src/include/duckdb/main/valid_checker.hpp +2 -2
  157. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +3 -1
  158. package/src/duckdb/src/include/duckdb/parser/expression/window_expression.hpp +3 -1
  159. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_function_info.hpp +2 -2
  160. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +18 -1
  161. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +53 -56
  162. package/src/duckdb/src/include/duckdb/parser/parsed_data/attach_info.hpp +39 -0
  163. package/src/duckdb/src/include/duckdb/parser/parsed_data/copy_info.hpp +4 -1
  164. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_aggregate_function_info.hpp +3 -18
  165. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_collation_info.hpp +4 -13
  166. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_copy_function_info.hpp +3 -12
  167. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_index_info.hpp +1 -1
  168. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_info.hpp +5 -3
  169. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_pragma_function_info.hpp +3 -14
  170. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +3 -19
  171. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +3 -1
  172. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +7 -34
  173. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +7 -1
  174. package/src/duckdb/src/include/duckdb/parser/parsed_data/exported_table_data.hpp +3 -0
  175. package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +2 -2
  176. package/src/duckdb/src/include/duckdb/parser/qualified_name.hpp +10 -2
  177. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +2 -2
  178. package/src/duckdb/src/include/duckdb/parser/statement/attach_statement.hpp +29 -0
  179. package/src/duckdb/src/include/duckdb/parser/statement/export_statement.hpp +1 -0
  180. package/src/duckdb/src/include/duckdb/parser/statement/insert_statement.hpp +2 -0
  181. package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -0
  182. package/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp +4 -1
  183. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
  184. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  185. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
  186. package/src/duckdb/src/include/duckdb/planner/binder.hpp +11 -1
  187. package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +2 -1
  188. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +1 -0
  189. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +13 -6
  190. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +10 -2
  191. package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +2 -2
  192. package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +2 -2
  193. package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +9 -12
  194. package/src/duckdb/src/include/duckdb/storage/table/data_table_info.hpp +3 -7
  195. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +5 -6
  196. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +9 -7
  197. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +3 -1
  198. package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +64 -0
  199. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +14 -23
  200. package/src/duckdb/src/include/duckdb/transaction/transaction_context.hpp +12 -8
  201. package/src/duckdb/src/include/duckdb/transaction/transaction_manager.hpp +5 -10
  202. package/src/duckdb/src/include/duckdb/transaction/undo_buffer.hpp +1 -1
  203. package/src/duckdb/src/main/attached_database.cpp +97 -0
  204. package/src/duckdb/src/main/capi/table_function-c.cpp +1 -1
  205. package/src/duckdb/src/main/client_context.cpp +28 -22
  206. package/src/duckdb/src/main/client_data.cpp +5 -2
  207. package/src/duckdb/src/main/config.cpp +1 -0
  208. package/src/duckdb/src/main/connection.cpp +1 -1
  209. package/src/duckdb/src/main/database.cpp +54 -40
  210. package/src/duckdb/src/main/database_manager.cpp +95 -0
  211. package/src/duckdb/src/main/materialized_query_result.cpp +1 -1
  212. package/src/duckdb/src/main/prepared_statement_data.cpp +1 -2
  213. package/src/duckdb/src/main/query_result.cpp +4 -4
  214. package/src/duckdb/src/main/settings/settings.cpp +22 -6
  215. package/src/duckdb/src/main/stream_query_result.cpp +1 -1
  216. package/src/duckdb/src/parser/expression/columnref_expression.cpp +9 -3
  217. package/src/duckdb/src/parser/expression/function_expression.cpp +15 -13
  218. package/src/duckdb/src/parser/expression/window_expression.cpp +6 -4
  219. package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +7 -7
  220. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +12 -2
  221. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +96 -98
  222. package/src/duckdb/src/parser/parsed_data/create_aggregate_function_info.cpp +27 -0
  223. package/src/duckdb/src/parser/parsed_data/create_collation_info.cpp +23 -0
  224. package/src/duckdb/src/parser/parsed_data/create_copy_function_info.cpp +21 -0
  225. package/src/duckdb/src/parser/parsed_data/create_info.cpp +3 -0
  226. package/src/duckdb/src/parser/parsed_data/create_pragma_function_info.cpp +23 -0
  227. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -1
  228. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +28 -0
  229. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +9 -3
  230. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +49 -0
  231. package/src/duckdb/src/parser/statement/attach_statement.cpp +15 -0
  232. package/src/duckdb/src/parser/statement/insert_statement.cpp +6 -2
  233. package/src/duckdb/src/parser/tableref/basetableref.cpp +9 -4
  234. package/src/duckdb/src/parser/transform/constraint/transform_constraint.cpp +15 -13
  235. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +17 -7
  236. package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +4 -9
  237. package/src/duckdb/src/parser/transform/helpers/nodetype_to_string.cpp +4 -0
  238. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +5 -4
  239. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +8 -10
  240. package/src/duckdb/src/parser/transform/statement/transform_attach.cpp +32 -0
  241. package/src/duckdb/src/parser/transform/statement/transform_checkpoint.cpp +7 -2
  242. package/src/duckdb/src/parser/transform/statement/transform_copy.cpp +1 -0
  243. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +1 -0
  244. package/src/duckdb/src/parser/transform/statement/transform_create_schema.cpp +1 -0
  245. package/src/duckdb/src/parser/transform/statement/transform_create_sequence.cpp +1 -0
  246. package/src/duckdb/src/parser/transform/statement/transform_create_table.cpp +5 -5
  247. package/src/duckdb/src/parser/transform/statement/transform_create_table_as.cpp +1 -0
  248. package/src/duckdb/src/parser/transform/statement/transform_create_type.cpp +6 -13
  249. package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +6 -6
  250. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +11 -2
  251. package/src/duckdb/src/parser/transform/statement/transform_export.cpp +5 -1
  252. package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +1 -0
  253. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +12 -36
  254. package/src/duckdb/src/parser/transform/statement/transform_show.cpp +3 -1
  255. package/src/duckdb/src/parser/transform/statement/transform_use.cpp +21 -0
  256. package/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp +11 -3
  257. package/src/duckdb/src/parser/transformer.cpp +4 -0
  258. package/src/duckdb/src/planner/bind_context.cpp +11 -2
  259. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +1 -1
  260. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +43 -13
  261. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +1 -1
  262. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +2 -3
  263. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +2 -3
  264. package/src/duckdb/src/planner/binder/statement/bind_attach.cpp +20 -0
  265. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +7 -4
  266. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +79 -27
  267. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +11 -7
  268. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  269. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +13 -5
  270. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +6 -3
  271. package/src/duckdb/src/planner/binder/statement/bind_extension.cpp +1 -1
  272. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +3 -2
  273. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +2 -2
  274. package/src/duckdb/src/planner/binder/statement/bind_prepare.cpp +0 -2
  275. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +11 -6
  276. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  277. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +10 -6
  278. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +2 -4
  279. package/src/duckdb/src/planner/binder.cpp +17 -2
  280. package/src/duckdb/src/planner/logical_operator.cpp +5 -12
  281. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +3 -4
  282. package/src/duckdb/src/planner/operator/logical_create.cpp +1 -4
  283. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  284. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -3
  285. package/src/duckdb/src/planner/operator/logical_insert.cpp +1 -1
  286. package/src/duckdb/src/planner/operator/logical_update.cpp +1 -1
  287. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +1 -1
  288. package/src/duckdb/src/planner/planner.cpp +3 -2
  289. package/src/duckdb/src/planner/pragma_handler.cpp +1 -1
  290. package/src/duckdb/src/storage/buffer_manager.cpp +5 -0
  291. package/src/duckdb/src/storage/checkpoint_manager.cpp +10 -17
  292. package/src/duckdb/src/storage/data_table.cpp +34 -24
  293. package/src/duckdb/src/storage/local_storage.cpp +7 -3
  294. package/src/duckdb/src/storage/single_file_block_manager.cpp +3 -3
  295. package/src/duckdb/src/storage/storage_manager.cpp +25 -42
  296. package/src/duckdb/src/storage/table/column_data.cpp +2 -1
  297. package/src/duckdb/src/storage/table/row_group.cpp +7 -2
  298. package/src/duckdb/src/storage/wal_replay.cpp +6 -22
  299. package/src/duckdb/src/storage/write_ahead_log.cpp +3 -3
  300. package/src/duckdb/src/transaction/meta_transaction.cpp +106 -0
  301. package/src/duckdb/src/transaction/transaction.cpp +21 -21
  302. package/src/duckdb/src/transaction/transaction_context.cpp +44 -8
  303. package/src/duckdb/src/transaction/transaction_manager.cpp +20 -20
  304. package/src/duckdb/src/transaction/undo_buffer.cpp +1 -3
  305. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +2 -0
  306. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +27 -1
  307. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +99 -97
  308. package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +1 -0
  309. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +15206 -14793
  310. package/src/duckdb/ub_src_catalog.cpp +4 -0
  311. package/src/duckdb/ub_src_execution_operator_schema.cpp +2 -0
  312. package/src/duckdb/ub_src_function.cpp +2 -0
  313. package/src/duckdb/ub_src_function_table_system.cpp +0 -2
  314. package/src/duckdb/ub_src_main.cpp +4 -0
  315. package/src/duckdb/ub_src_parser_parsed_data.cpp +12 -0
  316. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  317. package/src/duckdb/ub_src_parser_transform_statement.cpp +4 -0
  318. package/src/duckdb/ub_src_planner_binder_statement.cpp +2 -0
  319. package/src/duckdb/ub_src_transaction.cpp +2 -0
  320. package/src/duckdb/src/function/table/system/pragma_functions.cpp +0 -120
@@ -28,30 +28,120 @@
28
28
  #include "duckdb/planner/binder.hpp"
29
29
  #include "duckdb/catalog/default/default_types.hpp"
30
30
  #include "duckdb/main/extension_functions.hpp"
31
+ #include "duckdb/main/connection.hpp"
32
+ #include "duckdb/main/attached_database.hpp"
33
+ #include "duckdb/main/database_manager.hpp"
34
+ #include "duckdb/function/built_in_functions.hpp"
31
35
  #include <algorithm>
36
+
32
37
  namespace duckdb {
33
38
 
34
- string SimilarCatalogEntry::GetQualifiedName() const {
35
- D_ASSERT(Found());
39
+ Catalog::Catalog(AttachedDatabase &db)
40
+ : schemas(make_unique<CatalogSet>(*this, make_unique<DefaultSchemaGenerator>(*this))),
41
+ dependency_manager(make_unique<DependencyManager>(*this)), db(db) {
42
+ }
43
+ Catalog::~Catalog() {
44
+ }
45
+
46
+ void Catalog::Initialize(bool load_builtin) {
47
+ // first initialize the base system catalogs
48
+ // these are never written to the WAL
49
+ // we start these at 1 because deleted entries default to 0
50
+ CatalogTransaction data(GetDatabase(), 1, 1);
36
51
 
37
- return schema->name + "." + name;
52
+ // create the default schema
53
+ CreateSchemaInfo info;
54
+ info.schema = DEFAULT_SCHEMA;
55
+ info.internal = true;
56
+ CreateSchema(data, &info);
57
+
58
+ if (load_builtin) {
59
+ // initialize default functions
60
+ BuiltinFunctions builtin(data, *this);
61
+ builtin.Initialize();
62
+ }
63
+
64
+ Verify();
38
65
  }
39
66
 
40
- Catalog::Catalog(DatabaseInstance &db)
41
- : db(db), schemas(make_unique<CatalogSet>(*this, make_unique<DefaultSchemaGenerator>(*this))),
42
- dependency_manager(make_unique<DependencyManager>(*this)) {
43
- catalog_version = 0;
67
+ DatabaseInstance &Catalog::GetDatabase() {
68
+ return db.GetDatabase();
44
69
  }
45
- Catalog::~Catalog() {
70
+
71
+ AttachedDatabase &Catalog::GetAttached() {
72
+ return db;
73
+ }
74
+
75
+ const string &Catalog::GetName() {
76
+ return GetAttached().GetName();
77
+ }
78
+
79
+ idx_t Catalog::GetOid() {
80
+ return GetAttached().oid;
81
+ }
82
+
83
+ Catalog &Catalog::GetSystemCatalog(ClientContext &context) {
84
+ return Catalog::GetSystemCatalog(*context.db);
85
+ }
86
+
87
+ Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name) {
88
+ auto &db_manager = DatabaseManager::Get(context);
89
+ if (catalog_name == TEMP_CATALOG) {
90
+ return ClientData::Get(context).temporary_objects->GetCatalog();
91
+ }
92
+ if (catalog_name == SYSTEM_CATALOG) {
93
+ return GetSystemCatalog(context);
94
+ }
95
+ auto entry = db_manager.GetDatabase(
96
+ context, IsInvalidCatalog(catalog_name) ? DatabaseManager::GetDefaultDatabase(context) : catalog_name);
97
+ if (!entry) {
98
+ throw BinderException("Catalog \"%s\" does not exist!", catalog_name);
99
+ }
100
+ return entry->GetCatalog();
46
101
  }
47
102
 
48
- Catalog &Catalog::GetCatalog(ClientContext &context) {
49
- return context.db->GetCatalog();
103
+ //===--------------------------------------------------------------------===//
104
+ // Schema
105
+ //===--------------------------------------------------------------------===//
106
+ CatalogEntry *Catalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo *info) {
107
+ D_ASSERT(!info->schema.empty());
108
+ DependencyList dependencies;
109
+ auto entry = make_unique<SchemaCatalogEntry>(this, info->schema, info->internal);
110
+ auto result = entry.get();
111
+ if (!schemas->CreateEntry(transaction, info->schema, move(entry), dependencies)) {
112
+ if (info->on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
113
+ throw CatalogException("Schema with name %s already exists!", info->schema);
114
+ } else {
115
+ D_ASSERT(info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT);
116
+ }
117
+ return nullptr;
118
+ }
119
+ return result;
120
+ }
121
+
122
+ CatalogEntry *Catalog::CreateSchema(ClientContext &context, CreateSchemaInfo *info) {
123
+ return CreateSchema(GetCatalogTransaction(context), info);
124
+ }
125
+
126
+ CatalogTransaction Catalog::GetCatalogTransaction(ClientContext &context) {
127
+ return CatalogTransaction(*this, context);
128
+ }
129
+
130
+ void Catalog::DropSchema(ClientContext &context, DropInfo *info) {
131
+ D_ASSERT(!info->name.empty());
132
+ ModifyCatalog();
133
+ if (!schemas->DropEntry(GetCatalogTransaction(context), info->name, info->cascade)) {
134
+ if (!info->if_exists) {
135
+ throw CatalogException("Schema with name \"%s\" does not exist!", info->name);
136
+ }
137
+ }
50
138
  }
51
139
 
140
+ //===--------------------------------------------------------------------===//
141
+ // Table
142
+ //===--------------------------------------------------------------------===//
52
143
  CatalogEntry *Catalog::CreateTable(ClientContext &context, BoundCreateTableInfo *info) {
53
- auto schema = GetSchema(context, info->base->schema);
54
- return CreateTable(context, schema, info);
144
+ return CreateTable(GetCatalogTransaction(context), info);
55
145
  }
56
146
 
57
147
  CatalogEntry *Catalog::CreateTable(ClientContext &context, unique_ptr<CreateTableInfo> info) {
@@ -60,115 +150,214 @@ CatalogEntry *Catalog::CreateTable(ClientContext &context, unique_ptr<CreateTabl
60
150
  return CreateTable(context, bound_info.get());
61
151
  }
62
152
 
63
- CatalogEntry *Catalog::CreateTable(ClientContext &context, SchemaCatalogEntry *schema, BoundCreateTableInfo *info) {
64
- return schema->CreateTable(context, info);
153
+ CatalogEntry *Catalog::CreateTable(CatalogTransaction transaction, SchemaCatalogEntry *schema,
154
+ BoundCreateTableInfo *info) {
155
+ return schema->CreateTable(transaction, info);
156
+ }
157
+
158
+ CatalogEntry *Catalog::CreateTable(CatalogTransaction transaction, BoundCreateTableInfo *info) {
159
+ auto schema = GetSchema(transaction, info->base->schema);
160
+ return CreateTable(transaction, schema, info);
161
+ }
162
+
163
+ //===--------------------------------------------------------------------===//
164
+ // View
165
+ //===--------------------------------------------------------------------===//
166
+ CatalogEntry *Catalog::CreateView(CatalogTransaction transaction, CreateViewInfo *info) {
167
+ auto schema = GetSchema(transaction, info->schema);
168
+ return CreateView(transaction, schema, info);
65
169
  }
66
170
 
67
171
  CatalogEntry *Catalog::CreateView(ClientContext &context, CreateViewInfo *info) {
68
- auto schema = GetSchema(context, info->schema);
69
- return CreateView(context, schema, info);
172
+ return CreateView(GetCatalogTransaction(context), info);
173
+ }
174
+
175
+ CatalogEntry *Catalog::CreateView(CatalogTransaction transaction, SchemaCatalogEntry *schema, CreateViewInfo *info) {
176
+ return schema->CreateView(transaction, info);
70
177
  }
71
178
 
72
- CatalogEntry *Catalog::CreateView(ClientContext &context, SchemaCatalogEntry *schema, CreateViewInfo *info) {
73
- return schema->CreateView(context, info);
179
+ //===--------------------------------------------------------------------===//
180
+ // Sequence
181
+ //===--------------------------------------------------------------------===//
182
+ CatalogEntry *Catalog::CreateSequence(CatalogTransaction transaction, CreateSequenceInfo *info) {
183
+ auto schema = GetSchema(transaction, info->schema);
184
+ return CreateSequence(transaction, schema, info);
74
185
  }
75
186
 
76
187
  CatalogEntry *Catalog::CreateSequence(ClientContext &context, CreateSequenceInfo *info) {
77
- auto schema = GetSchema(context, info->schema);
78
- return CreateSequence(context, schema, info);
188
+ return CreateSequence(GetCatalogTransaction(context), info);
189
+ }
190
+
191
+ CatalogEntry *Catalog::CreateSequence(CatalogTransaction transaction, SchemaCatalogEntry *schema,
192
+ CreateSequenceInfo *info) {
193
+ return schema->CreateSequence(transaction, info);
194
+ }
195
+
196
+ //===--------------------------------------------------------------------===//
197
+ // Type
198
+ //===--------------------------------------------------------------------===//
199
+ CatalogEntry *Catalog::CreateType(CatalogTransaction transaction, CreateTypeInfo *info) {
200
+ auto schema = GetSchema(transaction, info->schema);
201
+ return CreateType(transaction, schema, info);
79
202
  }
80
203
 
81
204
  CatalogEntry *Catalog::CreateType(ClientContext &context, CreateTypeInfo *info) {
82
- auto schema = GetSchema(context, info->schema);
83
- return CreateType(context, schema, info);
205
+ return CreateType(GetCatalogTransaction(context), info);
84
206
  }
85
207
 
86
- CatalogEntry *Catalog::CreateSequence(ClientContext &context, SchemaCatalogEntry *schema, CreateSequenceInfo *info) {
87
- return schema->CreateSequence(context, info);
208
+ CatalogEntry *Catalog::CreateType(CatalogTransaction transaction, SchemaCatalogEntry *schema, CreateTypeInfo *info) {
209
+ return schema->CreateType(transaction, info);
88
210
  }
89
211
 
90
- CatalogEntry *Catalog::CreateType(ClientContext &context, SchemaCatalogEntry *schema, CreateTypeInfo *info) {
91
- return schema->CreateType(context, info);
212
+ //===--------------------------------------------------------------------===//
213
+ // Table Function
214
+ //===--------------------------------------------------------------------===//
215
+ CatalogEntry *Catalog::CreateTableFunction(CatalogTransaction transaction, CreateTableFunctionInfo *info) {
216
+ auto schema = GetSchema(transaction, info->schema);
217
+ return CreateTableFunction(transaction, schema, info);
92
218
  }
93
219
 
94
220
  CatalogEntry *Catalog::CreateTableFunction(ClientContext &context, CreateTableFunctionInfo *info) {
95
- auto schema = GetSchema(context, info->schema);
96
- return CreateTableFunction(context, schema, info);
221
+ return CreateTableFunction(GetCatalogTransaction(context), info);
97
222
  }
98
223
 
99
- CatalogEntry *Catalog::CreateTableFunction(ClientContext &context, SchemaCatalogEntry *schema,
224
+ CatalogEntry *Catalog::CreateTableFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
100
225
  CreateTableFunctionInfo *info) {
101
- return schema->CreateTableFunction(context, info);
226
+ return schema->CreateTableFunction(transaction, info);
227
+ }
228
+
229
+ //===--------------------------------------------------------------------===//
230
+ // Copy Function
231
+ //===--------------------------------------------------------------------===//
232
+ CatalogEntry *Catalog::CreateCopyFunction(CatalogTransaction transaction, CreateCopyFunctionInfo *info) {
233
+ auto schema = GetSchema(transaction, info->schema);
234
+ return CreateCopyFunction(transaction, schema, info);
102
235
  }
103
236
 
104
237
  CatalogEntry *Catalog::CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo *info) {
105
- auto schema = GetSchema(context, info->schema);
106
- return CreateCopyFunction(context, schema, info);
238
+ return CreateCopyFunction(GetCatalogTransaction(context), info);
107
239
  }
108
240
 
109
- CatalogEntry *Catalog::CreateCopyFunction(ClientContext &context, SchemaCatalogEntry *schema,
241
+ CatalogEntry *Catalog::CreateCopyFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
110
242
  CreateCopyFunctionInfo *info) {
111
- return schema->CreateCopyFunction(context, info);
243
+ return schema->CreateCopyFunction(transaction, info);
244
+ }
245
+
246
+ //===--------------------------------------------------------------------===//
247
+ // Pragma Function
248
+ //===--------------------------------------------------------------------===//
249
+ CatalogEntry *Catalog::CreatePragmaFunction(CatalogTransaction transaction, CreatePragmaFunctionInfo *info) {
250
+ auto schema = GetSchema(transaction, info->schema);
251
+ return CreatePragmaFunction(transaction, schema, info);
112
252
  }
113
253
 
114
254
  CatalogEntry *Catalog::CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info) {
115
- auto schema = GetSchema(context, info->schema);
116
- return CreatePragmaFunction(context, schema, info);
255
+ return CreatePragmaFunction(GetCatalogTransaction(context), info);
117
256
  }
118
257
 
119
- CatalogEntry *Catalog::CreatePragmaFunction(ClientContext &context, SchemaCatalogEntry *schema,
258
+ CatalogEntry *Catalog::CreatePragmaFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
120
259
  CreatePragmaFunctionInfo *info) {
121
- return schema->CreatePragmaFunction(context, info);
260
+ return schema->CreatePragmaFunction(transaction, info);
261
+ }
262
+
263
+ //===--------------------------------------------------------------------===//
264
+ // Function
265
+ //===--------------------------------------------------------------------===//
266
+ CatalogEntry *Catalog::CreateFunction(CatalogTransaction transaction, CreateFunctionInfo *info) {
267
+ auto schema = GetSchema(transaction, info->schema);
268
+ return CreateFunction(transaction, schema, info);
122
269
  }
123
270
 
124
271
  CatalogEntry *Catalog::CreateFunction(ClientContext &context, CreateFunctionInfo *info) {
125
- auto schema = GetSchema(context, info->schema);
126
- return CreateFunction(context, schema, info);
272
+ return CreateFunction(GetCatalogTransaction(context), info);
127
273
  }
128
274
 
129
- CatalogEntry *Catalog::CreateFunction(ClientContext &context, SchemaCatalogEntry *schema, CreateFunctionInfo *info) {
130
- return schema->CreateFunction(context, info);
275
+ CatalogEntry *Catalog::CreateFunction(CatalogTransaction transaction, SchemaCatalogEntry *schema,
276
+ CreateFunctionInfo *info) {
277
+ return schema->CreateFunction(transaction, info);
278
+ }
279
+
280
+ CatalogEntry *Catalog::AddFunction(ClientContext &context, CreateFunctionInfo *info) {
281
+ info->on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
282
+ return CreateFunction(context, info);
283
+ }
284
+
285
+ //===--------------------------------------------------------------------===//
286
+ // Collation
287
+ //===--------------------------------------------------------------------===//
288
+ CatalogEntry *Catalog::CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info) {
289
+ auto schema = GetSchema(transaction, info->schema);
290
+ return CreateCollation(transaction, schema, info);
131
291
  }
132
292
 
133
293
  CatalogEntry *Catalog::CreateCollation(ClientContext &context, CreateCollationInfo *info) {
134
- auto schema = GetSchema(context, info->schema);
135
- return CreateCollation(context, schema, info);
294
+ return CreateCollation(GetCatalogTransaction(context), info);
136
295
  }
137
296
 
138
- CatalogEntry *Catalog::CreateCollation(ClientContext &context, SchemaCatalogEntry *schema, CreateCollationInfo *info) {
139
- return schema->CreateCollation(context, info);
297
+ CatalogEntry *Catalog::CreateCollation(CatalogTransaction transaction, SchemaCatalogEntry *schema,
298
+ CreateCollationInfo *info) {
299
+ return schema->CreateCollation(transaction, info);
140
300
  }
141
301
 
142
- CatalogEntry *Catalog::CreateSchema(ClientContext &context, CreateSchemaInfo *info) {
143
- D_ASSERT(!info->schema.empty());
144
- if (info->schema == TEMP_SCHEMA) {
145
- throw CatalogException("Cannot create built-in schema \"%s\"", info->schema);
302
+ //===--------------------------------------------------------------------===//
303
+ // Lookup Structures
304
+ //===--------------------------------------------------------------------===//
305
+ struct CatalogLookup {
306
+ CatalogLookup(Catalog &catalog, string schema_p) : catalog(catalog), schema(move(schema_p)) {
146
307
  }
147
308
 
148
- unordered_set<CatalogEntry *> dependencies;
149
- auto entry = make_unique<SchemaCatalogEntry>(this, info->schema, info->internal);
150
- auto result = entry.get();
151
- if (!schemas->CreateEntry(context, info->schema, move(entry), dependencies)) {
152
- if (info->on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
153
- throw CatalogException("Schema with name %s already exists!", info->schema);
154
- } else {
155
- D_ASSERT(info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT);
156
- }
157
- return nullptr;
309
+ Catalog &catalog;
310
+ string schema;
311
+ };
312
+
313
+ //! Return value of Catalog::LookupEntry
314
+ struct CatalogEntryLookup {
315
+ SchemaCatalogEntry *schema;
316
+ CatalogEntry *entry;
317
+
318
+ DUCKDB_API bool Found() const {
319
+ return entry;
320
+ }
321
+ };
322
+
323
+ //! Return value of SimilarEntryInSchemas
324
+ struct SimilarCatalogEntry {
325
+ //! The entry name. Empty if absent
326
+ string name;
327
+ //! The distance to the given name.
328
+ idx_t distance;
329
+ //! The schema of the entry.
330
+ SchemaCatalogEntry *schema;
331
+
332
+ DUCKDB_API bool Found() const {
333
+ return !name.empty();
158
334
  }
159
- return result;
160
- }
161
335
 
162
- void Catalog::DropSchema(ClientContext &context, DropInfo *info) {
163
- D_ASSERT(!info->name.empty());
164
- ModifyCatalog();
165
- if (!schemas->DropEntry(context, info->name, info->cascade)) {
166
- if (!info->if_exists) {
167
- throw CatalogException("Schema with name \"%s\" does not exist!", info->name);
336
+ DUCKDB_API string GetQualifiedName(bool qualify_catalog, bool qualify_schema) const;
337
+ };
338
+
339
+ string SimilarCatalogEntry::GetQualifiedName(bool qualify_catalog, bool qualify_schema) const {
340
+ D_ASSERT(Found());
341
+ string result;
342
+ if (qualify_catalog) {
343
+ result += schema->catalog->GetName();
344
+ }
345
+ if (qualify_schema) {
346
+ if (!result.empty()) {
347
+ result += ".";
168
348
  }
349
+ result += schema->name;
350
+ }
351
+ if (!result.empty()) {
352
+ result += ".";
169
353
  }
354
+ result += name;
355
+ return result;
170
356
  }
171
357
 
358
+ //===--------------------------------------------------------------------===//
359
+ // Generic
360
+ //===--------------------------------------------------------------------===//
172
361
  void Catalog::DropEntry(ClientContext &context, DropInfo *info) {
173
362
  ModifyCatalog();
174
363
  if (info->type == CatalogType::SCHEMA_ENTRY) {
@@ -185,31 +374,31 @@ void Catalog::DropEntry(ClientContext &context, DropInfo *info) {
185
374
  lookup.schema->DropEntry(context, info);
186
375
  }
187
376
 
188
- CatalogEntry *Catalog::AddFunction(ClientContext &context, CreateFunctionInfo *info) {
189
- info->on_conflict = OnCreateConflict::ALTER_ON_CONFLICT;
190
- return CreateFunction(context, info);
191
- }
192
-
193
- SchemaCatalogEntry *Catalog::GetSchema(ClientContext &context, const string &schema_name, bool if_exists,
377
+ SchemaCatalogEntry *Catalog::GetSchema(CatalogTransaction transaction, const string &schema_name, bool if_exists,
194
378
  QueryErrorContext error_context) {
195
379
  D_ASSERT(!schema_name.empty());
196
- if (schema_name == TEMP_SCHEMA) {
197
- return SchemaCatalogEntry::GetTemporaryObjects(context);
198
- }
199
- auto entry = schemas->GetEntry(context, schema_name);
380
+ auto entry = schemas->GetEntry(transaction, schema_name);
200
381
  if (!entry && !if_exists) {
201
382
  throw CatalogException(error_context.FormatError("Schema with name %s does not exist!", schema_name));
202
383
  }
203
384
  return (SchemaCatalogEntry *)entry;
204
385
  }
205
386
 
387
+ SchemaCatalogEntry *Catalog::GetSchema(ClientContext &context, const string &schema_name, bool if_exists,
388
+ QueryErrorContext error_context) {
389
+ return GetSchema(GetCatalogTransaction(context), schema_name, if_exists, error_context);
390
+ }
391
+
206
392
  void Catalog::ScanSchemas(ClientContext &context, std::function<void(CatalogEntry *)> callback) {
207
393
  // create all default schemas first
208
- schemas->Scan(context, [&](CatalogEntry *entry) { callback(entry); });
394
+ schemas->Scan(GetCatalogTransaction(context), [&](CatalogEntry *entry) { callback(entry); });
209
395
  }
210
396
 
397
+ //===--------------------------------------------------------------------===//
398
+ // Lookup
399
+ //===--------------------------------------------------------------------===//
211
400
  SimilarCatalogEntry Catalog::SimilarEntryInSchemas(ClientContext &context, const string &entry_name, CatalogType type,
212
- const vector<SchemaCatalogEntry *> &schemas) {
401
+ const unordered_set<SchemaCatalogEntry *> &schemas) {
213
402
 
214
403
  vector<CatalogSet *> sets;
215
404
  std::transform(schemas.begin(), schemas.end(), std::back_inserter(sets),
@@ -217,7 +406,8 @@ SimilarCatalogEntry Catalog::SimilarEntryInSchemas(ClientContext &context, const
217
406
  pair<string, idx_t> most_similar {"", (idx_t)-1};
218
407
  SchemaCatalogEntry *schema_of_most_similar = nullptr;
219
408
  for (auto schema : schemas) {
220
- auto entry = schema->GetCatalogSet(type).SimilarEntry(context, entry_name);
409
+ auto transaction = schema->catalog->GetCatalogTransaction(context);
410
+ auto entry = schema->GetCatalogSet(type).SimilarEntry(transaction, entry_name);
221
411
  if (!entry.first.empty() && (most_similar.first.empty() || most_similar.second > entry.second)) {
222
412
  most_similar = entry;
223
413
  schema_of_most_similar = schema;
@@ -237,18 +427,87 @@ string FindExtension(const string &function_name) {
237
427
  }
238
428
  return "";
239
429
  }
430
+
431
+ vector<CatalogSearchEntry> GetCatalogEntries(ClientContext &context, const string &catalog, const string &schema) {
432
+ vector<CatalogSearchEntry> entries;
433
+ auto &search_path = *context.client_data->catalog_search_path;
434
+ if (IsInvalidCatalog(catalog) && IsInvalidSchema(schema)) {
435
+ // no catalog or schema provided - scan the entire search path
436
+ entries = search_path.Get();
437
+ } else if (IsInvalidCatalog(catalog)) {
438
+ auto catalogs = search_path.GetCatalogsForSchema(schema);
439
+ for (auto &catalog_name : catalogs) {
440
+ entries.emplace_back(catalog_name, schema);
441
+ }
442
+ if (entries.empty()) {
443
+ entries.emplace_back(DatabaseManager::GetDefaultDatabase(context), schema);
444
+ }
445
+ } else if (IsInvalidSchema(schema)) {
446
+ auto schemas = search_path.GetSchemasForCatalog(catalog);
447
+ for (auto &schema_name : schemas) {
448
+ entries.emplace_back(catalog, schema_name);
449
+ }
450
+ if (entries.empty()) {
451
+ entries.emplace_back(catalog, DEFAULT_SCHEMA);
452
+ }
453
+ } else {
454
+ // specific catalog and schema provided
455
+ entries.emplace_back(catalog, schema);
456
+ }
457
+ return entries;
458
+ }
459
+
460
+ void FindMinimalQualification(ClientContext &context, const string &catalog_name, const string &schema_name,
461
+ bool &qualify_database, bool &qualify_schema) {
462
+ // check if we can we qualify ONLY the schema
463
+ bool found = false;
464
+ auto entries = GetCatalogEntries(context, INVALID_CATALOG, schema_name);
465
+ for (auto &entry : entries) {
466
+ if (entry.catalog == catalog_name && entry.schema == schema_name) {
467
+ found = true;
468
+ break;
469
+ }
470
+ }
471
+ if (found) {
472
+ qualify_database = false;
473
+ qualify_schema = true;
474
+ return;
475
+ }
476
+ // check if we can qualify ONLY the catalog
477
+ found = false;
478
+ entries = GetCatalogEntries(context, catalog_name, INVALID_SCHEMA);
479
+ for (auto &entry : entries) {
480
+ if (entry.catalog == catalog_name && entry.schema == schema_name) {
481
+ found = true;
482
+ break;
483
+ }
484
+ }
485
+ if (found) {
486
+ qualify_database = true;
487
+ qualify_schema = false;
488
+ return;
489
+ }
490
+ // need to qualify both catalog and schema
491
+ qualify_database = true;
492
+ qualify_schema = true;
493
+ }
494
+
240
495
  CatalogException Catalog::CreateMissingEntryException(ClientContext &context, const string &entry_name,
241
- CatalogType type, const vector<SchemaCatalogEntry *> &schemas,
496
+ CatalogType type,
497
+ const unordered_set<SchemaCatalogEntry *> &schemas,
242
498
  QueryErrorContext error_context) {
243
499
  auto entry = SimilarEntryInSchemas(context, entry_name, type, schemas);
244
500
 
245
- vector<SchemaCatalogEntry *> unseen_schemas;
246
- this->schemas->Scan([&schemas, &unseen_schemas](CatalogEntry *entry) {
247
- auto schema_entry = (SchemaCatalogEntry *)entry;
248
- if (std::find(schemas.begin(), schemas.end(), schema_entry) == schemas.end()) {
249
- unseen_schemas.emplace_back(schema_entry);
501
+ unordered_set<SchemaCatalogEntry *> unseen_schemas;
502
+ auto &db_manager = DatabaseManager::Get(context);
503
+ auto databases = db_manager.GetDatabases(context);
504
+ for (auto database : databases) {
505
+ auto &catalog = database->GetCatalog();
506
+ auto current_schemas = catalog.GetAllSchemas(context);
507
+ for (auto &current_schema : current_schemas) {
508
+ unseen_schemas.insert(current_schema);
250
509
  }
251
- });
510
+ }
252
511
  auto unseen_entry = SimilarEntryInSchemas(context, entry_name, type, unseen_schemas);
253
512
  auto extension_name = FindExtension(entry_name);
254
513
  if (!extension_name.empty()) {
@@ -258,7 +517,14 @@ CatalogException Catalog::CreateMissingEntryException(ClientContext &context, co
258
517
  }
259
518
  string did_you_mean;
260
519
  if (unseen_entry.Found() && unseen_entry.distance < entry.distance) {
261
- did_you_mean = "\nDid you mean \"" + unseen_entry.GetQualifiedName() + "\"?";
520
+ // the closest matching entry requires qualification as it is not in the default search path
521
+ // check how to minimally qualify this entry
522
+ auto catalog_name = unseen_entry.schema->catalog->GetName();
523
+ auto schema_name = unseen_entry.schema->name;
524
+ bool qualify_database;
525
+ bool qualify_schema;
526
+ FindMinimalQualification(context, catalog_name, schema_name, qualify_database, qualify_schema);
527
+ did_you_mean = "\nDid you mean \"" + unseen_entry.GetQualifiedName(qualify_database, qualify_schema) + "\"?";
262
528
  } else if (entry.Found()) {
263
529
  did_you_mean = "\nDid you mean \"" + entry.name + "\"?";
264
530
  }
@@ -267,44 +533,74 @@ CatalogException Catalog::CreateMissingEntryException(ClientContext &context, co
267
533
  entry_name, did_you_mean));
268
534
  }
269
535
 
270
- CatalogEntryLookup Catalog::LookupEntry(ClientContext &context, CatalogType type, const string &schema_name,
271
- const string &name, bool if_exists, QueryErrorContext error_context) {
272
- if (!schema_name.empty()) {
273
- auto schema = GetSchema(context, schema_name, if_exists, error_context);
274
- if (!schema) {
275
- D_ASSERT(if_exists);
276
- return {nullptr, nullptr};
277
- }
278
-
279
- auto entry = schema->GetCatalogSet(type).GetEntry(context, name);
280
- if (!entry && !if_exists) {
281
- throw CreateMissingEntryException(context, name, type, {schema}, error_context);
282
- }
536
+ CatalogEntryLookup Catalog::LookupEntryInternal(CatalogTransaction transaction, CatalogType type, const string &schema,
537
+ const string &name) {
283
538
 
284
- return {schema, entry};
539
+ auto schema_entry = (SchemaCatalogEntry *)GetSchema(transaction, schema, true);
540
+ if (!schema_entry) {
541
+ return {nullptr, nullptr};
285
542
  }
286
-
287
- const auto &paths = ClientData::Get(context).catalog_search_path->Get();
288
- for (const auto &path : paths) {
289
- auto lookup = LookupEntry(context, type, path, name, true, error_context);
290
- if (lookup.Found()) {
291
- return lookup;
292
- }
543
+ auto entry = schema_entry->GetCatalogSet(type).GetEntry(transaction, name);
544
+ if (!entry) {
545
+ return {schema_entry, nullptr};
293
546
  }
547
+ return {schema_entry, entry};
548
+ }
294
549
 
295
- if (!if_exists) {
296
- vector<SchemaCatalogEntry *> schemas;
297
- for (const auto &path : paths) {
298
- auto schema = GetSchema(context, path, true);
299
- if (schema) {
300
- schemas.emplace_back(schema);
550
+ CatalogEntryLookup Catalog::LookupEntry(ClientContext &context, CatalogType type, const string &schema,
551
+ const string &name, bool if_exists, QueryErrorContext error_context) {
552
+ unordered_set<SchemaCatalogEntry *> schemas;
553
+ if (IsInvalidSchema(schema)) {
554
+ // try all schemas for this catalog
555
+ auto catalog_name = GetName();
556
+ if (catalog_name == DatabaseManager::GetDefaultDatabase(context)) {
557
+ catalog_name = INVALID_CATALOG;
558
+ }
559
+ auto entries = GetCatalogEntries(context, GetName(), INVALID_SCHEMA);
560
+ for (auto &entry : entries) {
561
+ auto &candidate_schema = entry.schema;
562
+ auto transaction = GetCatalogTransaction(context);
563
+ auto result = LookupEntryInternal(transaction, type, candidate_schema, name);
564
+ if (result.Found()) {
565
+ return result;
566
+ }
567
+ if (result.schema) {
568
+ schemas.insert(result.schema);
301
569
  }
302
570
  }
303
-
304
- throw CreateMissingEntryException(context, name, type, schemas, error_context);
571
+ } else {
572
+ auto transaction = GetCatalogTransaction(context);
573
+ auto result = LookupEntryInternal(transaction, type, schema, name);
574
+ if (result.Found()) {
575
+ return result;
576
+ }
577
+ if (result.schema) {
578
+ schemas.insert(result.schema);
579
+ }
580
+ }
581
+ if (if_exists) {
582
+ return {nullptr, nullptr};
305
583
  }
584
+ throw CreateMissingEntryException(context, name, type, schemas, error_context);
585
+ }
306
586
 
307
- return {nullptr, nullptr};
587
+ CatalogEntryLookup Catalog::LookupEntry(ClientContext &context, vector<CatalogLookup> &lookups, CatalogType type,
588
+ const string &name, bool if_exists, QueryErrorContext error_context) {
589
+ unordered_set<SchemaCatalogEntry *> schemas;
590
+ for (auto &lookup : lookups) {
591
+ auto transaction = lookup.catalog.GetCatalogTransaction(context);
592
+ auto result = lookup.catalog.LookupEntryInternal(transaction, type, lookup.schema, name);
593
+ if (result.Found()) {
594
+ return result;
595
+ }
596
+ if (result.schema) {
597
+ schemas.insert(result.schema);
598
+ }
599
+ }
600
+ if (if_exists) {
601
+ return {nullptr, nullptr};
602
+ }
603
+ throw CreateMissingEntryException(context, name, type, schemas, error_context);
308
604
  }
309
605
 
310
606
  CatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema, const string &name) {
@@ -325,75 +621,101 @@ CatalogEntry *Catalog::GetEntry(ClientContext &context, CatalogType type, const
325
621
  return LookupEntry(context, type, schema_name, name, if_exists, error_context).entry;
326
622
  }
327
623
 
328
- template <>
329
- TableCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
330
- bool if_exists, QueryErrorContext error_context) {
331
- auto entry = GetEntry(context, CatalogType::TABLE_ENTRY, schema_name, name, if_exists);
332
- if (!entry) {
624
+ CatalogEntry *Catalog::GetEntry(ClientContext &context, CatalogType type, const string &catalog, const string &schema,
625
+ const string &name, bool if_exists_p, QueryErrorContext error_context) {
626
+ auto entries = GetCatalogEntries(context, catalog, schema);
627
+ vector<CatalogLookup> lookups;
628
+ lookups.reserve(entries.size());
629
+ for (auto &entry : entries) {
630
+ lookups.emplace_back(Catalog::GetCatalog(context, entry.catalog), entry.schema);
631
+ }
632
+ auto result = LookupEntry(context, lookups, type, name, if_exists_p, error_context);
633
+ if (!result.Found()) {
634
+ D_ASSERT(if_exists_p);
333
635
  return nullptr;
334
636
  }
335
- if (entry->type != CatalogType::TABLE_ENTRY) {
336
- throw CatalogException(error_context.FormatError("%s is not a table", name));
637
+ return result.entry;
638
+ }
639
+
640
+ SchemaCatalogEntry *Catalog::GetSchema(ClientContext &context, const string &catalog_name, const string &schema_name,
641
+ bool if_exists_p, QueryErrorContext error_context) {
642
+ auto entries = GetCatalogEntries(context, catalog_name, schema_name);
643
+ SchemaCatalogEntry *result = nullptr;
644
+ for (idx_t i = 0; i < entries.size(); i++) {
645
+ auto if_exists = i + 1 == entries.size() ? if_exists_p : true;
646
+ auto &catalog = Catalog::GetCatalog(context, entries[i].catalog);
647
+ auto result = catalog.GetSchema(context, schema_name, if_exists, error_context);
648
+ if (result) {
649
+ return result;
650
+ }
337
651
  }
338
- return (TableCatalogEntry *)entry;
339
- }
340
-
341
- template <>
342
- SequenceCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
343
- bool if_exists, QueryErrorContext error_context) {
344
- return (SequenceCatalogEntry *)GetEntry(context, CatalogType::SEQUENCE_ENTRY, schema_name, name, if_exists,
345
- error_context);
346
- }
347
-
348
- template <>
349
- TableFunctionCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
350
- bool if_exists, QueryErrorContext error_context) {
351
- return (TableFunctionCatalogEntry *)GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, schema_name, name,
352
- if_exists, error_context);
652
+ return result;
353
653
  }
354
654
 
355
- template <>
356
- CopyFunctionCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
357
- bool if_exists, QueryErrorContext error_context) {
358
- return (CopyFunctionCatalogEntry *)GetEntry(context, CatalogType::COPY_FUNCTION_ENTRY, schema_name, name, if_exists,
359
- error_context);
655
+ LogicalType Catalog::GetType(ClientContext &context, const string &catalog_name, const string &schema,
656
+ const string &name) {
657
+ CatalogEntry *entry;
658
+ entry = GetEntry(context, CatalogType::TYPE_ENTRY, catalog_name, schema, name, true);
659
+ if (!entry) {
660
+ // look in the system catalog
661
+ entry = GetEntry(context, CatalogType::TYPE_ENTRY, SYSTEM_CATALOG, schema, name, true);
662
+ if (!entry) {
663
+ // repeat the search to get the error
664
+ GetEntry(context, CatalogType::TYPE_ENTRY, catalog_name, schema, name);
665
+ throw InternalException("Catalog::GetType - second type lookup somehow succeeded!?");
666
+ }
667
+ }
668
+ auto type_entry = (TypeCatalogEntry *)entry;
669
+ auto result_type = type_entry->user_type;
670
+ LogicalType::SetCatalog(result_type, type_entry);
671
+ return result_type;
360
672
  }
361
673
 
362
- template <>
363
- PragmaFunctionCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
364
- bool if_exists, QueryErrorContext error_context) {
365
- return (PragmaFunctionCatalogEntry *)GetEntry(context, CatalogType::PRAGMA_FUNCTION_ENTRY, schema_name, name,
366
- if_exists, error_context);
367
- }
674
+ vector<SchemaCatalogEntry *> Catalog::GetSchemas(ClientContext &context, const string &catalog_name) {
675
+ vector<Catalog *> catalogs;
676
+ if (IsInvalidCatalog(catalog_name)) {
677
+ unordered_set<string> name;
368
678
 
369
- template <>
370
- AggregateFunctionCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
371
- bool if_exists, QueryErrorContext error_context) {
372
- auto entry = GetEntry(context, CatalogType::AGGREGATE_FUNCTION_ENTRY, schema_name, name, if_exists, error_context);
373
- if (entry->type != CatalogType::AGGREGATE_FUNCTION_ENTRY) {
374
- throw CatalogException(error_context.FormatError("%s is not an aggregate function", name));
679
+ auto &search_path = *context.client_data->catalog_search_path;
680
+ for (auto &entry : search_path.Get()) {
681
+ if (name.find(entry.catalog) != name.end()) {
682
+ continue;
683
+ }
684
+ name.insert(entry.catalog);
685
+ catalogs.push_back(&Catalog::GetCatalog(context, entry.catalog));
686
+ }
687
+ } else {
688
+ catalogs.push_back(&Catalog::GetCatalog(context, catalog_name));
375
689
  }
376
- return (AggregateFunctionCatalogEntry *)entry;
690
+ vector<SchemaCatalogEntry *> result;
691
+ for (auto catalog : catalogs) {
692
+ auto schemas = catalog->schemas->GetEntries<SchemaCatalogEntry>(catalog->GetCatalogTransaction(context));
693
+ result.insert(result.end(), schemas.begin(), schemas.end());
694
+ }
695
+ return result;
377
696
  }
378
697
 
379
- template <>
380
- CollateCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
381
- bool if_exists, QueryErrorContext error_context) {
382
- return (CollateCatalogEntry *)GetEntry(context, CatalogType::COLLATION_ENTRY, schema_name, name, if_exists,
383
- error_context);
384
- }
698
+ vector<SchemaCatalogEntry *> Catalog::GetAllSchemas(ClientContext &context) {
699
+ vector<SchemaCatalogEntry *> result;
385
700
 
386
- template <>
387
- TypeCatalogEntry *Catalog::GetEntry(ClientContext &context, const string &schema_name, const string &name,
388
- bool if_exists, QueryErrorContext error_context) {
389
- return (TypeCatalogEntry *)GetEntry(context, CatalogType::TYPE_ENTRY, schema_name, name, if_exists, error_context);
390
- }
701
+ auto &db_manager = DatabaseManager::Get(context);
702
+ auto databases = db_manager.GetDatabases(context);
703
+ for (auto database : databases) {
704
+ auto &catalog = database->GetCatalog();
705
+ auto new_schemas = catalog.schemas->GetEntries<SchemaCatalogEntry>(catalog.GetCatalogTransaction(context));
706
+ result.insert(result.end(), new_schemas.begin(), new_schemas.end());
707
+ }
708
+ sort(result.begin(), result.end(), [&](SchemaCatalogEntry *x, SchemaCatalogEntry *y) {
709
+ if (x->catalog->GetName() < y->catalog->GetName()) {
710
+ return true;
711
+ }
712
+ if (x->catalog->GetName() == y->catalog->GetName()) {
713
+ return x->name < y->name;
714
+ }
715
+ return false;
716
+ });
391
717
 
392
- LogicalType Catalog::GetType(ClientContext &context, const string &schema, const string &name) {
393
- auto user_type_catalog = GetEntry<TypeCatalogEntry>(context, schema, name);
394
- auto result_type = user_type_catalog->user_type;
395
- LogicalType::SetCatalog(result_type, user_type_catalog);
396
- return result_type;
718
+ return result;
397
719
  }
398
720
 
399
721
  void Catalog::Alter(ClientContext &context, AlterInfo *info) {
@@ -405,12 +727,29 @@ void Catalog::Alter(ClientContext &context, AlterInfo *info) {
405
727
  return lookup.schema->Alter(context, info);
406
728
  }
407
729
 
730
+ void Catalog::Verify() {
731
+ #ifdef DEBUG
732
+ schemas->Verify(*this);
733
+ #endif
734
+ }
735
+
736
+ //===--------------------------------------------------------------------===//
737
+ // Catalog Version
738
+ //===--------------------------------------------------------------------===//
408
739
  idx_t Catalog::GetCatalogVersion() {
409
- return catalog_version;
740
+ return GetDatabase().GetDatabaseManager().catalog_version;
410
741
  }
411
742
 
412
743
  idx_t Catalog::ModifyCatalog() {
413
- return catalog_version++;
744
+ return GetDatabase().GetDatabaseManager().catalog_version++;
745
+ }
746
+
747
+ bool Catalog::IsSystemCatalog() const {
748
+ return db.IsSystem();
749
+ }
750
+
751
+ bool Catalog::IsTemporaryCatalog() const {
752
+ return db.IsTemporary();
414
753
  }
415
754
 
416
755
  } // namespace duckdb