duckdb 0.6.2-dev781.0 → 0.6.2-dev891.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/column_reader.cpp +7 -0
  14. package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -1
  15. package/src/duckdb/src/catalog/catalog.cpp +516 -177
  16. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +1 -0
  17. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +66 -49
  18. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +15 -16
  19. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +1 -1
  20. package/src/duckdb/src/catalog/catalog_entry.cpp +6 -2
  21. package/src/duckdb/src/catalog/catalog_search_path.cpp +177 -22
  22. package/src/duckdb/src/catalog/catalog_set.cpp +134 -72
  23. package/src/duckdb/src/catalog/catalog_transaction.cpp +28 -0
  24. package/src/duckdb/src/catalog/default/default_views.cpp +4 -4
  25. package/src/duckdb/src/catalog/dependency_list.cpp +13 -0
  26. package/src/duckdb/src/catalog/dependency_manager.cpp +19 -13
  27. package/src/duckdb/src/common/constants.cpp +8 -0
  28. package/src/duckdb/src/common/enums/catalog_type.cpp +2 -0
  29. package/src/duckdb/src/common/enums/logical_operator_type.cpp +2 -0
  30. package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
  31. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  32. package/src/duckdb/src/common/file_system.cpp +1 -1
  33. package/src/duckdb/src/common/string_util.cpp +5 -1
  34. package/src/duckdb/src/execution/index/art/art.cpp +1 -1
  35. package/src/duckdb/src/execution/operator/helper/physical_transaction.cpp +1 -0
  36. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +1 -1
  37. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +3 -2
  38. package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +1 -1
  39. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +1 -1
  40. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +4 -3
  41. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  42. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +72 -0
  43. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +2 -1
  44. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +3 -3
  45. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +5 -1
  46. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +2 -1
  47. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  48. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +1 -1
  49. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +2 -1
  50. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +10 -2
  51. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  52. package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +1 -1
  53. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +2 -3
  54. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  55. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  56. package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +4 -0
  57. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  58. package/src/duckdb/src/execution/physical_plan_generator.cpp +3 -2
  59. package/src/duckdb/src/function/built_in_functions.cpp +88 -0
  60. package/src/duckdb/src/function/function.cpp +0 -79
  61. package/src/duckdb/src/function/function_binder.cpp +2 -1
  62. package/src/duckdb/src/function/pragma/pragma_queries.cpp +10 -1
  63. package/src/duckdb/src/function/scalar/date/current.cpp +2 -2
  64. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +3 -2
  65. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +14 -17
  66. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
  67. package/src/duckdb/src/function/scalar/system/system_functions.cpp +7 -4
  68. package/src/duckdb/src/function/table/checkpoint.cpp +37 -4
  69. package/src/duckdb/src/function/table/read_csv.cpp +1 -1
  70. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +32 -25
  71. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +26 -22
  72. package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +1 -1
  73. package/src/duckdb/src/function/table/system/duckdb_extensions.cpp +1 -1
  74. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +22 -15
  75. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +25 -18
  76. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +16 -8
  77. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +26 -19
  78. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +24 -17
  79. package/src/duckdb/src/function/table/system/duckdb_types.cpp +22 -16
  80. package/src/duckdb/src/function/table/system/duckdb_views.cpp +20 -13
  81. package/src/duckdb/src/function/table/system/pragma_collations.cpp +3 -4
  82. package/src/duckdb/src/function/table/system/pragma_database_list.cpp +20 -12
  83. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +39 -24
  84. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +1 -7
  85. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +3 -2
  86. package/src/duckdb/src/function/table/system_functions.cpp +0 -1
  87. package/src/duckdb/src/function/table/table_scan.cpp +13 -10
  88. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  89. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +102 -81
  90. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +4 -0
  91. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +4 -0
  92. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +4 -0
  93. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +4 -0
  94. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +4 -0
  95. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +4 -0
  96. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +4 -0
  97. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +21 -14
  98. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +4 -0
  99. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +4 -0
  100. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +4 -0
  101. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +4 -0
  102. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +4 -0
  103. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +4 -0
  104. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +2 -0
  105. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +30 -11
  106. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +35 -20
  107. package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +32 -0
  108. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +27 -0
  109. package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +6 -4
  110. package/src/duckdb/src/include/duckdb/common/allocator.hpp +3 -0
  111. package/src/duckdb/src/include/duckdb/common/constants.hpp +8 -3
  112. package/src/duckdb/src/include/duckdb/common/enums/catalog_type.hpp +1 -0
  113. package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +1 -0
  114. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +1 -0
  115. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +10 -4
  116. package/src/duckdb/src/include/duckdb/common/file_system.hpp +2 -0
  117. package/src/duckdb/src/include/duckdb/common/string_util.hpp +3 -0
  118. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +2 -2
  119. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_attach.hpp +33 -0
  120. package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +2 -1
  121. package/src/duckdb/src/include/duckdb/function/aggregate/algebraic_functions.hpp +1 -0
  122. package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +1 -0
  123. package/src/duckdb/src/include/duckdb/function/aggregate/holistic_functions.hpp +1 -0
  124. package/src/duckdb/src/include/duckdb/function/aggregate/nested_functions.hpp +1 -0
  125. package/src/duckdb/src/include/duckdb/function/aggregate/regression_functions.hpp +1 -0
  126. package/src/duckdb/src/include/duckdb/function/built_in_functions.hpp +78 -0
  127. package/src/duckdb/src/include/duckdb/function/function.hpp +0 -61
  128. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +1 -2
  129. package/src/duckdb/src/include/duckdb/function/pragma/pragma_functions.hpp +1 -0
  130. package/src/duckdb/src/include/duckdb/function/scalar/blob_functions.hpp +1 -0
  131. package/src/duckdb/src/include/duckdb/function/scalar/date_functions.hpp +1 -0
  132. package/src/duckdb/src/include/duckdb/function/scalar/enum_functions.hpp +1 -0
  133. package/src/duckdb/src/include/duckdb/function/scalar/generic_functions.hpp +1 -0
  134. package/src/duckdb/src/include/duckdb/function/scalar/math_functions.hpp +1 -0
  135. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -0
  136. package/src/duckdb/src/include/duckdb/function/scalar/operators.hpp +1 -0
  137. package/src/duckdb/src/include/duckdb/function/scalar/regexp.hpp +1 -0
  138. package/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp +1 -0
  139. package/src/duckdb/src/include/duckdb/function/scalar/string_functions.hpp +1 -0
  140. package/src/duckdb/src/include/duckdb/function/scalar/trigonometric_functions.hpp +1 -0
  141. package/src/duckdb/src/include/duckdb/function/scalar/uuid_functions.hpp +1 -0
  142. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
  143. package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +1 -0
  144. package/src/duckdb/src/include/duckdb/function/table/range.hpp +1 -0
  145. package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +1 -0
  146. package/src/duckdb/src/include/duckdb/function/table/summary.hpp +1 -0
  147. package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +1 -4
  148. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +1 -0
  149. package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -1
  150. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +64 -0
  151. package/src/duckdb/src/include/duckdb/main/client_context.hpp +3 -3
  152. package/src/duckdb/src/include/duckdb/main/client_data.hpp +2 -1
  153. package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
  154. package/src/duckdb/src/include/duckdb/main/database.hpp +6 -6
  155. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +69 -0
  156. package/src/duckdb/src/include/duckdb/main/settings.hpp +10 -0
  157. package/src/duckdb/src/include/duckdb/main/valid_checker.hpp +2 -2
  158. package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +3 -1
  159. package/src/duckdb/src/include/duckdb/parser/expression/window_expression.hpp +3 -1
  160. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_function_info.hpp +2 -2
  161. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +18 -1
  162. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +53 -56
  163. package/src/duckdb/src/include/duckdb/parser/parsed_data/attach_info.hpp +39 -0
  164. package/src/duckdb/src/include/duckdb/parser/parsed_data/copy_info.hpp +4 -1
  165. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_aggregate_function_info.hpp +3 -18
  166. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_collation_info.hpp +4 -13
  167. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_copy_function_info.hpp +3 -12
  168. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_index_info.hpp +1 -1
  169. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_info.hpp +5 -3
  170. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_pragma_function_info.hpp +3 -14
  171. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +3 -19
  172. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +3 -1
  173. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +7 -34
  174. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +7 -1
  175. package/src/duckdb/src/include/duckdb/parser/parsed_data/exported_table_data.hpp +3 -0
  176. package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +2 -2
  177. package/src/duckdb/src/include/duckdb/parser/qualified_name.hpp +10 -2
  178. package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +2 -2
  179. package/src/duckdb/src/include/duckdb/parser/statement/attach_statement.hpp +29 -0
  180. package/src/duckdb/src/include/duckdb/parser/statement/export_statement.hpp +1 -0
  181. package/src/duckdb/src/include/duckdb/parser/statement/insert_statement.hpp +2 -0
  182. package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -0
  183. package/src/duckdb/src/include/duckdb/parser/tableref/basetableref.hpp +4 -1
  184. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
  185. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  186. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
  187. package/src/duckdb/src/include/duckdb/planner/binder.hpp +11 -1
  188. package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +2 -1
  189. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +1 -0
  190. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +13 -6
  191. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +10 -2
  192. package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +2 -2
  193. package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +2 -2
  194. package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +9 -12
  195. package/src/duckdb/src/include/duckdb/storage/table/data_table_info.hpp +3 -7
  196. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +5 -6
  197. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +9 -7
  198. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +3 -1
  199. package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +64 -0
  200. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +14 -23
  201. package/src/duckdb/src/include/duckdb/transaction/transaction_context.hpp +12 -8
  202. package/src/duckdb/src/include/duckdb/transaction/transaction_manager.hpp +5 -10
  203. package/src/duckdb/src/include/duckdb/transaction/undo_buffer.hpp +1 -1
  204. package/src/duckdb/src/main/attached_database.cpp +97 -0
  205. package/src/duckdb/src/main/capi/table_function-c.cpp +1 -1
  206. package/src/duckdb/src/main/client_context.cpp +28 -22
  207. package/src/duckdb/src/main/client_data.cpp +5 -2
  208. package/src/duckdb/src/main/config.cpp +1 -0
  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
@@ -7,6 +7,7 @@ namespace duckdb {
7
7
 
8
8
  IndexCatalogEntry::IndexCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schema, CreateIndexInfo *info)
9
9
  : StandardEntry(CatalogType::INDEX_ENTRY, schema, catalog, info->index_name), index(nullptr), sql(info->sql) {
10
+ this->temporary = info->temporary;
10
11
  }
11
12
 
12
13
  IndexCatalogEntry::~IndexCatalogEntry() {
@@ -36,6 +36,7 @@
36
36
  #include "duckdb/planner/constraints/bound_foreign_key_constraint.hpp"
37
37
  #include "duckdb/planner/parsed_data/bound_create_table_info.hpp"
38
38
  #include "duckdb/storage/data_table.hpp"
39
+ #include "duckdb/catalog/dependency_list.hpp"
39
40
 
40
41
  #include <sstream>
41
42
 
@@ -54,9 +55,10 @@ void FindForeignKeyInformation(CatalogEntry *entry, AlterForeignKeyType alter_fk
54
55
  }
55
56
  auto &fk = (ForeignKeyConstraint &)*cond;
56
57
  if (fk.info.type == ForeignKeyType::FK_TYPE_FOREIGN_KEY_TABLE) {
57
- fk_arrays.push_back(make_unique<AlterForeignKeyInfo>(fk.info.schema, fk.info.table, false, entry->name,
58
- fk.pk_columns, fk.fk_columns, fk.info.pk_keys,
59
- fk.info.fk_keys, alter_fk_type));
58
+ AlterEntryData alter_data(entry->catalog->GetName(), fk.info.schema, fk.info.table, false);
59
+ fk_arrays.push_back(make_unique<AlterForeignKeyInfo>(move(alter_data), entry->name, fk.pk_columns,
60
+ fk.fk_columns, fk.info.pk_keys, fk.info.fk_keys,
61
+ alter_fk_type));
60
62
  } else if (fk.info.type == ForeignKeyType::FK_TYPE_PRIMARY_KEY_TABLE &&
61
63
  alter_fk_type == AlterForeignKeyType::AFT_DELETE) {
62
64
  throw CatalogException("Could not drop the table because this table is main key table of the table \"%s\"",
@@ -74,33 +76,32 @@ SchemaCatalogEntry::SchemaCatalogEntry(Catalog *catalog, string name_p, bool int
74
76
  this->internal = internal;
75
77
  }
76
78
 
77
- CatalogEntry *SchemaCatalogEntry::AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry,
78
- OnCreateConflict on_conflict, unordered_set<CatalogEntry *> dependencies) {
79
+ CatalogTransaction SchemaCatalogEntry::GetCatalogTransaction(ClientContext &context) {
80
+ return CatalogTransaction(*catalog, context);
81
+ }
82
+
83
+ CatalogEntry *SchemaCatalogEntry::AddEntry(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
84
+ OnCreateConflict on_conflict, DependencyList dependencies) {
79
85
  auto entry_name = entry->name;
80
86
  auto entry_type = entry->type;
81
87
  auto result = entry.get();
82
88
 
83
89
  // first find the set for this entry
84
90
  auto &set = GetCatalogSet(entry_type);
85
-
86
- if (name != TEMP_SCHEMA) {
87
- dependencies.insert(this);
88
- } else {
89
- entry->temporary = true;
90
- }
91
+ dependencies.AddDependency(this);
91
92
  if (on_conflict == OnCreateConflict::REPLACE_ON_CONFLICT) {
92
93
  // CREATE OR REPLACE: first try to drop the entry
93
- auto old_entry = set.GetEntry(context, entry_name);
94
+ auto old_entry = set.GetEntry(transaction, entry_name);
94
95
  if (old_entry) {
95
96
  if (old_entry->type != entry_type) {
96
97
  throw CatalogException("Existing object %s is of type %s, trying to replace with type %s", entry_name,
97
98
  CatalogTypeToString(old_entry->type), CatalogTypeToString(entry_type));
98
99
  }
99
- (void)set.DropEntry(context, entry_name, false);
100
+ (void)set.DropEntry(transaction, entry_name, false, entry->internal);
100
101
  }
101
102
  }
102
103
  // now try to add the entry
103
- if (!set.CreateEntry(context, entry_name, move(entry), dependencies)) {
104
+ if (!set.CreateEntry(transaction, entry_name, move(entry), dependencies)) {
104
105
  // entry already exists!
105
106
  if (on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
106
107
  throw CatalogException("%s with name \"%s\" already exists!", CatalogTypeToString(entry_type), entry_name);
@@ -111,27 +112,27 @@ CatalogEntry *SchemaCatalogEntry::AddEntry(ClientContext &context, unique_ptr<St
111
112
  return result;
112
113
  }
113
114
 
114
- CatalogEntry *SchemaCatalogEntry::AddEntry(ClientContext &context, unique_ptr<StandardEntry> entry,
115
+ CatalogEntry *SchemaCatalogEntry::AddEntry(CatalogTransaction transaction, unique_ptr<StandardEntry> entry,
115
116
  OnCreateConflict on_conflict) {
116
- unordered_set<CatalogEntry *> dependencies;
117
- return AddEntry(context, move(entry), on_conflict, dependencies);
117
+ DependencyList dependencies;
118
+ return AddEntry(transaction, move(entry), on_conflict, dependencies);
118
119
  }
119
120
 
120
- CatalogEntry *SchemaCatalogEntry::CreateSequence(ClientContext &context, CreateSequenceInfo *info) {
121
+ CatalogEntry *SchemaCatalogEntry::CreateSequence(CatalogTransaction transaction, CreateSequenceInfo *info) {
121
122
  auto sequence = make_unique<SequenceCatalogEntry>(catalog, this, info);
122
- return AddEntry(context, move(sequence), info->on_conflict);
123
+ return AddEntry(transaction, move(sequence), info->on_conflict);
123
124
  }
124
125
 
125
- CatalogEntry *SchemaCatalogEntry::CreateType(ClientContext &context, CreateTypeInfo *info) {
126
+ CatalogEntry *SchemaCatalogEntry::CreateType(CatalogTransaction transaction, CreateTypeInfo *info) {
126
127
  auto type_entry = make_unique<TypeCatalogEntry>(catalog, this, info);
127
- return AddEntry(context, move(type_entry), info->on_conflict);
128
+ return AddEntry(transaction, move(type_entry), info->on_conflict);
128
129
  }
129
130
 
130
- CatalogEntry *SchemaCatalogEntry::CreateTable(ClientContext &context, BoundCreateTableInfo *info) {
131
+ CatalogEntry *SchemaCatalogEntry::CreateTable(CatalogTransaction transaction, BoundCreateTableInfo *info) {
131
132
  auto table = make_unique<TableCatalogEntry>(catalog, this, info);
132
133
  table->storage->info->cardinality = table->storage->GetTotalRows();
133
134
 
134
- CatalogEntry *entry = AddEntry(context, move(table), info->Base().on_conflict, info->dependencies);
135
+ CatalogEntry *entry = AddEntry(transaction, move(table), info->Base().on_conflict, info->dependencies);
135
136
  if (!entry) {
136
137
  return nullptr;
137
138
  }
@@ -142,60 +143,60 @@ CatalogEntry *SchemaCatalogEntry::CreateTable(ClientContext &context, BoundCreat
142
143
  for (idx_t i = 0; i < fk_arrays.size(); i++) {
143
144
  // alter primary key table
144
145
  AlterForeignKeyInfo *fk_info = fk_arrays[i].get();
145
- catalog->Alter(context, fk_info);
146
+ catalog->Alter(transaction.GetContext(), fk_info);
146
147
 
147
148
  // make a dependency between this table and referenced table
148
149
  auto &set = GetCatalogSet(CatalogType::TABLE_ENTRY);
149
- info->dependencies.insert(set.GetEntry(context, fk_info->name));
150
+ info->dependencies.AddDependency(set.GetEntry(transaction, fk_info->name));
150
151
  }
151
152
  return entry;
152
153
  }
153
154
 
154
- CatalogEntry *SchemaCatalogEntry::CreateView(ClientContext &context, CreateViewInfo *info) {
155
+ CatalogEntry *SchemaCatalogEntry::CreateView(CatalogTransaction transaction, CreateViewInfo *info) {
155
156
  auto view = make_unique<ViewCatalogEntry>(catalog, this, info);
156
- return AddEntry(context, move(view), info->on_conflict);
157
+ return AddEntry(transaction, move(view), info->on_conflict);
157
158
  }
158
159
 
159
160
  CatalogEntry *SchemaCatalogEntry::CreateIndex(ClientContext &context, CreateIndexInfo *info, TableCatalogEntry *table) {
160
- unordered_set<CatalogEntry *> dependencies;
161
- dependencies.insert(table);
161
+ DependencyList dependencies;
162
+ dependencies.AddDependency(table);
162
163
  auto index = make_unique<IndexCatalogEntry>(catalog, this, info);
163
- return AddEntry(context, move(index), info->on_conflict, dependencies);
164
+ return AddEntry(GetCatalogTransaction(context), move(index), info->on_conflict, dependencies);
164
165
  }
165
166
 
166
- CatalogEntry *SchemaCatalogEntry::CreateCollation(ClientContext &context, CreateCollationInfo *info) {
167
+ CatalogEntry *SchemaCatalogEntry::CreateCollation(CatalogTransaction transaction, CreateCollationInfo *info) {
167
168
  auto collation = make_unique<CollateCatalogEntry>(catalog, this, info);
168
169
  collation->internal = info->internal;
169
- return AddEntry(context, move(collation), info->on_conflict);
170
+ return AddEntry(transaction, move(collation), info->on_conflict);
170
171
  }
171
172
 
172
- CatalogEntry *SchemaCatalogEntry::CreateTableFunction(ClientContext &context, CreateTableFunctionInfo *info) {
173
+ CatalogEntry *SchemaCatalogEntry::CreateTableFunction(CatalogTransaction transaction, CreateTableFunctionInfo *info) {
173
174
  auto table_function = make_unique<TableFunctionCatalogEntry>(catalog, this, info);
174
175
  table_function->internal = info->internal;
175
- return AddEntry(context, move(table_function), info->on_conflict);
176
+ return AddEntry(transaction, move(table_function), info->on_conflict);
176
177
  }
177
178
 
178
- CatalogEntry *SchemaCatalogEntry::CreateCopyFunction(ClientContext &context, CreateCopyFunctionInfo *info) {
179
+ CatalogEntry *SchemaCatalogEntry::CreateCopyFunction(CatalogTransaction transaction, CreateCopyFunctionInfo *info) {
179
180
  auto copy_function = make_unique<CopyFunctionCatalogEntry>(catalog, this, info);
180
181
  copy_function->internal = info->internal;
181
- return AddEntry(context, move(copy_function), info->on_conflict);
182
+ return AddEntry(transaction, move(copy_function), info->on_conflict);
182
183
  }
183
184
 
184
- CatalogEntry *SchemaCatalogEntry::CreatePragmaFunction(ClientContext &context, CreatePragmaFunctionInfo *info) {
185
+ CatalogEntry *SchemaCatalogEntry::CreatePragmaFunction(CatalogTransaction transaction, CreatePragmaFunctionInfo *info) {
185
186
  auto pragma_function = make_unique<PragmaFunctionCatalogEntry>(catalog, this, info);
186
187
  pragma_function->internal = info->internal;
187
- return AddEntry(context, move(pragma_function), info->on_conflict);
188
+ return AddEntry(transaction, move(pragma_function), info->on_conflict);
188
189
  }
189
190
 
190
- CatalogEntry *SchemaCatalogEntry::CreateFunction(ClientContext &context, CreateFunctionInfo *info) {
191
+ CatalogEntry *SchemaCatalogEntry::CreateFunction(CatalogTransaction transaction, CreateFunctionInfo *info) {
191
192
  if (info->on_conflict == OnCreateConflict::ALTER_ON_CONFLICT) {
192
193
  // check if the original entry exists
193
194
  auto &catalog_set = GetCatalogSet(info->type);
194
- auto current_entry = catalog_set.GetEntry(context, info->name);
195
+ auto current_entry = catalog_set.GetEntry(transaction, info->name);
195
196
  if (current_entry) {
196
197
  // the current entry exists - alter it instead
197
198
  auto alter_info = info->GetAlterInfo();
198
- Alter(context, alter_info.get());
199
+ Alter(transaction.GetContext(), alter_info.get());
199
200
  return nullptr;
200
201
  }
201
202
  }
@@ -224,14 +225,15 @@ CatalogEntry *SchemaCatalogEntry::CreateFunction(ClientContext &context, CreateF
224
225
  throw InternalException("Unknown function type \"%s\"", CatalogTypeToString(info->type));
225
226
  }
226
227
  function->internal = info->internal;
227
- return AddEntry(context, move(function), info->on_conflict);
228
+ return AddEntry(transaction, move(function), info->on_conflict);
228
229
  }
229
230
 
230
231
  void SchemaCatalogEntry::DropEntry(ClientContext &context, DropInfo *info) {
231
232
  auto &set = GetCatalogSet(info->type);
232
233
 
233
234
  // first find the entry
234
- auto existing_entry = set.GetEntry(context, info->name);
235
+ auto transaction = GetCatalogTransaction(context);
236
+ auto existing_entry = set.GetEntry(transaction, info->name);
235
237
  if (!existing_entry) {
236
238
  if (!info->if_exists) {
237
239
  throw CatalogException("%s with name \"%s\" does not exist!", CatalogTypeToString(info->type), info->name);
@@ -247,27 +249,28 @@ void SchemaCatalogEntry::DropEntry(ClientContext &context, DropInfo *info) {
247
249
  vector<unique_ptr<AlterForeignKeyInfo>> fk_arrays;
248
250
  FindForeignKeyInformation(existing_entry, AlterForeignKeyType::AFT_DELETE, fk_arrays);
249
251
 
250
- if (!set.DropEntry(context, info->name, info->cascade)) {
252
+ if (!set.DropEntry(transaction, info->name, info->cascade, info->allow_drop_internal)) {
251
253
  throw InternalException("Could not drop element because of an internal error");
252
254
  }
253
255
 
254
256
  // remove the foreign key constraint in main key table if main key table's name is valid
255
257
  for (idx_t i = 0; i < fk_arrays.size(); i++) {
256
- // alter primary key tablee
257
- Catalog::GetCatalog(context).Alter(context, fk_arrays[i].get());
258
+ // alter primary key table
259
+ catalog->Alter(context, fk_arrays[i].get());
258
260
  }
259
261
  }
260
262
 
261
263
  void SchemaCatalogEntry::Alter(ClientContext &context, AlterInfo *info) {
262
264
  CatalogType type = info->GetCatalogType();
263
265
  auto &set = GetCatalogSet(type);
266
+ auto transaction = GetCatalogTransaction(context);
264
267
  if (info->type == AlterType::CHANGE_OWNERSHIP) {
265
- if (!set.AlterOwnership(context, (ChangeOwnershipInfo *)info)) {
268
+ if (!set.AlterOwnership(transaction, (ChangeOwnershipInfo *)info)) {
266
269
  throw CatalogException("Couldn't change ownership!");
267
270
  }
268
271
  } else {
269
272
  string name = info->name;
270
- if (!set.AlterEntry(context, name, info)) {
273
+ if (!set.AlterEntry(transaction, name, info)) {
271
274
  throw CatalogException("Entry with name \"%s\" does not exist!", name);
272
275
  }
273
276
  }
@@ -276,7 +279,7 @@ void SchemaCatalogEntry::Alter(ClientContext &context, AlterInfo *info) {
276
279
  void SchemaCatalogEntry::Scan(ClientContext &context, CatalogType type,
277
280
  const std::function<void(CatalogEntry *)> &callback) {
278
281
  auto &set = GetCatalogSet(type);
279
- set.Scan(context, callback);
282
+ set.Scan(GetCatalogTransaction(context), callback);
280
283
  }
281
284
 
282
285
  void SchemaCatalogEntry::Scan(CatalogType type, const std::function<void(CatalogEntry *)> &callback) {
@@ -335,4 +338,18 @@ CatalogSet &SchemaCatalogEntry::GetCatalogSet(CatalogType type) {
335
338
  }
336
339
  }
337
340
 
341
+ void SchemaCatalogEntry::Verify(Catalog &catalog) {
342
+ CatalogEntry::Verify(catalog);
343
+
344
+ tables.Verify(catalog);
345
+ indexes.Verify(catalog);
346
+ table_functions.Verify(catalog);
347
+ copy_functions.Verify(catalog);
348
+ pragma_functions.Verify(catalog);
349
+ functions.Verify(catalog);
350
+ sequences.Verify(catalog);
351
+ collations.Verify(catalog);
352
+ types.Verify(catalog);
353
+ }
354
+
338
355
  } // namespace duckdb
@@ -99,9 +99,8 @@ TableCatalogEntry::TableCatalogEntry(Catalog *catalog, SchemaCatalogEntry *schem
99
99
  for (auto &col_def : columns.Physical()) {
100
100
  storage_columns.push_back(col_def.Copy());
101
101
  }
102
- storage =
103
- make_shared<DataTable>(catalog->db, StorageManager::GetStorageManager(catalog->db).GetTableIOManager(info),
104
- schema->name, name, move(storage_columns), move(info->data));
102
+ storage = make_shared<DataTable>(catalog->GetAttached(), StorageManager::Get(*catalog).GetTableIOManager(info),
103
+ schema->name, name, move(storage_columns), move(info->data));
105
104
 
106
105
  // create the unique indexes for the UNIQUE and PRIMARY KEY and FOREIGN KEY constraints
107
106
  idx_t indexes_idx = 0;
@@ -237,7 +236,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::RenameColumn(ClientContext &context,
237
236
  if (rename_idx.index == COLUMN_IDENTIFIER_ROW_ID) {
238
237
  throw CatalogException("Cannot rename rowid column");
239
238
  }
240
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
239
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
241
240
  create_info->temporary = temporary;
242
241
  for (auto &col : columns.Logical()) {
243
242
  auto copy = col.Copy();
@@ -309,7 +308,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::AddColumn(ClientContext &context, Ad
309
308
  return nullptr;
310
309
  }
311
310
 
312
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
311
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
313
312
  create_info->temporary = temporary;
314
313
 
315
314
  for (auto &col : columns.Logical()) {
@@ -318,7 +317,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::AddColumn(ClientContext &context, Ad
318
317
  for (auto &constraint : constraints) {
319
318
  create_info->constraints.push_back(constraint->Copy());
320
319
  }
321
- Binder::BindLogicalType(context, info.new_column.TypeMutable(), schema->name);
320
+ Binder::BindLogicalType(context, info.new_column.TypeMutable(), catalog->GetName(), schema->name);
322
321
  info.new_column.SetOid(columns.LogicalColumnCount());
323
322
  info.new_column.SetStorageOid(columns.PhysicalColumnCount());
324
323
  auto col = info.new_column.Copy();
@@ -342,7 +341,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::RemoveColumn(ClientContext &context,
342
341
  return nullptr;
343
342
  }
344
343
 
345
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
344
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
346
345
  create_info->temporary = temporary;
347
346
 
348
347
  logical_index_set_t removed_columns;
@@ -452,7 +451,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::RemoveColumn(ClientContext &context,
452
451
  }
453
452
 
454
453
  unique_ptr<CatalogEntry> TableCatalogEntry::SetDefault(ClientContext &context, SetDefaultInfo &info) {
455
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
454
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
456
455
  auto default_idx = GetColumnIndex(info.column_name);
457
456
  if (default_idx.index == COLUMN_IDENTIFIER_ROW_ID) {
458
457
  throw CatalogException("Cannot SET DEFAULT for rowid column");
@@ -483,7 +482,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::SetDefault(ClientContext &context, S
483
482
 
484
483
  unique_ptr<CatalogEntry> TableCatalogEntry::SetNotNull(ClientContext &context, SetNotNullInfo &info) {
485
484
 
486
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
485
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
487
486
  create_info->columns = columns.Copy();
488
487
 
489
488
  auto not_null_idx = GetColumnIndex(info.column_name);
@@ -521,7 +520,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::SetNotNull(ClientContext &context, S
521
520
  }
522
521
 
523
522
  unique_ptr<CatalogEntry> TableCatalogEntry::DropNotNull(ClientContext &context, DropNotNullInfo &info) {
524
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
523
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
525
524
  create_info->columns = columns.Copy();
526
525
 
527
526
  auto not_null_idx = GetColumnIndex(info.column_name);
@@ -544,11 +543,11 @@ unique_ptr<CatalogEntry> TableCatalogEntry::DropNotNull(ClientContext &context,
544
543
 
545
544
  unique_ptr<CatalogEntry> TableCatalogEntry::ChangeColumnType(ClientContext &context, ChangeColumnTypeInfo &info) {
546
545
  if (info.target_type.id() == LogicalTypeId::USER) {
547
- auto &catalog = Catalog::GetCatalog(context);
548
- info.target_type = catalog.GetType(context, schema->name, UserType::GetTypeName(info.target_type));
546
+ info.target_type =
547
+ Catalog::GetType(context, catalog->GetName(), schema->name, UserType::GetTypeName(info.target_type));
549
548
  }
550
549
  auto change_idx = GetColumnIndex(info.column_name);
551
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
550
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
552
551
  create_info->temporary = temporary;
553
552
 
554
553
  for (auto &col : columns.Logical()) {
@@ -636,7 +635,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::ChangeColumnType(ClientContext &cont
636
635
 
637
636
  unique_ptr<CatalogEntry> TableCatalogEntry::AddForeignKeyConstraint(ClientContext &context, AlterForeignKeyInfo &info) {
638
637
  D_ASSERT(info.type == AlterForeignKeyType::AFT_ADD);
639
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
638
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
640
639
  create_info->temporary = temporary;
641
640
 
642
641
  create_info->columns = columns.Copy();
@@ -661,7 +660,7 @@ unique_ptr<CatalogEntry> TableCatalogEntry::AddForeignKeyConstraint(ClientContex
661
660
  unique_ptr<CatalogEntry> TableCatalogEntry::DropForeignKeyConstraint(ClientContext &context,
662
661
  AlterForeignKeyInfo &info) {
663
662
  D_ASSERT(info.type == AlterForeignKeyType::AFT_DELETE);
664
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
663
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
665
664
  create_info->temporary = temporary;
666
665
 
667
666
  create_info->columns = columns.Copy();
@@ -810,7 +809,7 @@ string TableCatalogEntry::ToSQL() {
810
809
  }
811
810
 
812
811
  unique_ptr<CatalogEntry> TableCatalogEntry::Copy(ClientContext &context) {
813
- auto create_info = make_unique<CreateTableInfo>(schema->name, name);
812
+ auto create_info = make_unique<CreateTableInfo>(schema, name);
814
813
  create_info->columns = columns.Copy();
815
814
 
816
815
  for (idx_t i = 0; i < constraints.size(); i++) {
@@ -80,7 +80,7 @@ string ViewCatalogEntry::ToSQL() {
80
80
 
81
81
  unique_ptr<CatalogEntry> ViewCatalogEntry::Copy(ClientContext &context) {
82
82
  D_ASSERT(!internal);
83
- auto create_info = make_unique<CreateViewInfo>(schema->name, name);
83
+ auto create_info = make_unique<CreateViewInfo>(schema, name);
84
84
  create_info->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
85
85
  for (idx_t i = 0; i < aliases.size(); i++) {
86
86
  create_info->aliases.push_back(aliases[i]);
@@ -5,8 +5,8 @@
5
5
  namespace duckdb {
6
6
 
7
7
  CatalogEntry::CatalogEntry(CatalogType type, Catalog *catalog_p, string name_p)
8
- : oid(catalog_p->ModifyCatalog()), type(type), catalog(catalog_p), set(nullptr), name(move(name_p)), deleted(false),
9
- temporary(false), internal(false), parent(nullptr) {
8
+ : oid(catalog_p ? catalog_p->ModifyCatalog() : 0), type(type), catalog(catalog_p), set(nullptr), name(move(name_p)),
9
+ deleted(false), temporary(false), internal(false), parent(nullptr) {
10
10
  }
11
11
 
12
12
  CatalogEntry::~CatalogEntry() {
@@ -32,4 +32,8 @@ string CatalogEntry::ToSQL() {
32
32
  }
33
33
  // LCOV_EXCL_STOP
34
34
 
35
+ void CatalogEntry::Verify(Catalog &catalog_p) {
36
+ D_ASSERT(&catalog_p == catalog);
37
+ }
38
+
35
39
  } // namespace duckdb
@@ -8,61 +8,216 @@
8
8
 
9
9
  namespace duckdb {
10
10
 
11
+ CatalogSearchEntry::CatalogSearchEntry(string catalog_p, string schema_p)
12
+ : catalog(move(catalog_p)), schema(move(schema_p)) {
13
+ }
14
+
15
+ string CatalogSearchEntry::ToString() const {
16
+ if (catalog.empty()) {
17
+ return WriteOptionallyQuoted(schema);
18
+ } else {
19
+ return WriteOptionallyQuoted(catalog) + "." + WriteOptionallyQuoted(schema);
20
+ }
21
+ }
22
+
23
+ string CatalogSearchEntry::WriteOptionallyQuoted(const string &input) {
24
+ for (idx_t i = 0; i < input.size(); i++) {
25
+ if (input[i] == '.' || input[i] == ',') {
26
+ return "\"" + input + "\"";
27
+ }
28
+ }
29
+ return input;
30
+ }
31
+
32
+ string CatalogSearchEntry::ListToString(const vector<CatalogSearchEntry> &input) {
33
+ string result;
34
+ for (auto &entry : input) {
35
+ if (!result.empty()) {
36
+ result += ",";
37
+ }
38
+ result += entry.ToString();
39
+ }
40
+ return result;
41
+ }
42
+
43
+ CatalogSearchEntry CatalogSearchEntry::ParseInternal(const string &input, idx_t &idx) {
44
+ string catalog;
45
+ string schema;
46
+ string entry;
47
+ bool finished = false;
48
+ normal:
49
+ for (; idx < input.size(); idx++) {
50
+ if (input[idx] == '"') {
51
+ idx++;
52
+ goto quoted;
53
+ } else if (input[idx] == '.') {
54
+ goto separator;
55
+ } else if (input[idx] == ',') {
56
+ finished = true;
57
+ goto separator;
58
+ }
59
+ entry += input[idx];
60
+ }
61
+ finished = true;
62
+ goto separator;
63
+ quoted:
64
+ //! look for another quote
65
+ for (; idx < input.size(); idx++) {
66
+ if (input[idx] == '"') {
67
+ //! unquote
68
+ idx++;
69
+ goto normal;
70
+ }
71
+ entry += input[idx];
72
+ }
73
+ throw ParserException("Unterminated quote in qualified name!");
74
+ separator:
75
+ if (entry.empty()) {
76
+ throw ParserException("Unexpected dot - empty CatalogSearchEntry");
77
+ }
78
+ if (schema.empty()) {
79
+ // if we parse one entry it is the schema
80
+ schema = move(entry);
81
+ } else if (catalog.empty()) {
82
+ // if we parse two entries it is [catalog.schema]
83
+ catalog = move(schema);
84
+ schema = move(entry);
85
+ } else {
86
+ throw ParserException("Too many dots - expected [schema] or [catalog.schema] for CatalogSearchEntry");
87
+ }
88
+ entry = "";
89
+ idx++;
90
+ if (finished) {
91
+ goto final;
92
+ }
93
+ goto normal;
94
+ final:
95
+ if (schema.empty()) {
96
+ throw ParserException("Unexpected end of entry - empty CatalogSearchEntry");
97
+ }
98
+ return CatalogSearchEntry(move(catalog), move(schema));
99
+ }
100
+
101
+ CatalogSearchEntry CatalogSearchEntry::Parse(const string &input) {
102
+ idx_t pos = 0;
103
+ auto result = ParseInternal(input, pos);
104
+ if (pos < input.size()) {
105
+ throw ParserException("Failed to convert entry \"%s\" to CatalogSearchEntry - expected a single entry", input);
106
+ }
107
+ return result;
108
+ }
109
+
110
+ vector<CatalogSearchEntry> CatalogSearchEntry::ParseList(const string &input) {
111
+ idx_t pos = 0;
112
+ vector<CatalogSearchEntry> result;
113
+ while (pos < input.size()) {
114
+ auto entry = ParseInternal(input, pos);
115
+ result.push_back(entry);
116
+ }
117
+ return result;
118
+ }
119
+
11
120
  CatalogSearchPath::CatalogSearchPath(ClientContext &context_p) : context(context_p) {
12
121
  Reset();
13
122
  }
14
123
 
15
124
  void CatalogSearchPath::Reset() {
16
- SetPaths(ParsePaths(""));
125
+ vector<CatalogSearchEntry> empty;
126
+ SetPaths(empty);
17
127
  }
18
128
 
19
- void CatalogSearchPath::Set(vector<string> &new_paths, bool is_set_schema) {
129
+ void CatalogSearchPath::Set(vector<CatalogSearchEntry> new_paths, bool is_set_schema) {
20
130
  if (is_set_schema && new_paths.size() != 1) {
21
131
  throw CatalogException("SET schema can set only 1 schema. This has %d", new_paths.size());
22
132
  }
23
- auto &catalog = Catalog::GetCatalog(context);
24
- for (const auto &path : new_paths) {
25
- if (!catalog.GetSchema(context, StringUtil::Lower(path), true)) {
26
- throw CatalogException("SET %s: No schema named %s found.", is_set_schema ? "schema" : "search_path", path);
133
+ for (auto &path : new_paths) {
134
+ if (!Catalog::GetSchema(context, path.catalog, path.schema, true)) {
135
+ if (path.catalog.empty()) {
136
+ // only schema supplied - check if this is a database instead
137
+ auto schema = Catalog::GetSchema(context, path.schema, DEFAULT_SCHEMA, true);
138
+ if (schema) {
139
+ path.catalog = move(path.schema);
140
+ path.schema = schema->name;
141
+ continue;
142
+ }
143
+ }
144
+ throw CatalogException("SET %s: No catalog + schema named %s found.",
145
+ is_set_schema ? "schema" : "search_path", path.ToString());
27
146
  }
28
147
  }
29
148
  this->set_paths = move(new_paths);
30
149
  SetPaths(set_paths);
31
150
  }
32
151
 
33
- void CatalogSearchPath::Set(const string &new_value, bool is_set_schema) {
34
- auto new_paths = ParsePaths(new_value);
35
- Set(new_paths, is_set_schema);
152
+ void CatalogSearchPath::Set(CatalogSearchEntry new_value, bool is_set_schema) {
153
+ vector<CatalogSearchEntry> new_paths {move(new_value)};
154
+ Set(move(new_paths), is_set_schema);
36
155
  }
37
156
 
38
- const vector<string> &CatalogSearchPath::Get() {
157
+ const vector<CatalogSearchEntry> &CatalogSearchPath::Get() {
39
158
  return paths;
40
159
  }
41
160
 
42
- const string &CatalogSearchPath::GetOrDefault(const string &name) {
43
- return name == INVALID_SCHEMA ? GetDefault() : name; // NOLINT
161
+ string CatalogSearchPath::GetDefaultSchema(const string &catalog) {
162
+ for (auto &path : paths) {
163
+ if (path.catalog == TEMP_CATALOG) {
164
+ continue;
165
+ }
166
+ if (StringUtil::CIEquals(path.catalog, catalog)) {
167
+ return path.schema;
168
+ }
169
+ }
170
+ return DEFAULT_SCHEMA;
171
+ }
172
+
173
+ string CatalogSearchPath::GetDefaultCatalog(const string &schema) {
174
+ for (auto &path : paths) {
175
+ if (path.catalog == TEMP_CATALOG) {
176
+ continue;
177
+ }
178
+ if (StringUtil::CIEquals(path.schema, schema)) {
179
+ return path.catalog;
180
+ }
181
+ }
182
+ return INVALID_CATALOG;
183
+ }
184
+
185
+ vector<string> CatalogSearchPath::GetCatalogsForSchema(const string &schema) {
186
+ vector<string> schemas;
187
+ for (auto &path : paths) {
188
+ if (StringUtil::CIEquals(path.schema, schema)) {
189
+ schemas.push_back(path.catalog);
190
+ }
191
+ }
192
+ return schemas;
193
+ }
194
+
195
+ vector<string> CatalogSearchPath::GetSchemasForCatalog(const string &catalog) {
196
+ vector<string> schemas;
197
+ for (auto &path : paths) {
198
+ if (StringUtil::CIEquals(path.catalog, catalog)) {
199
+ schemas.push_back(path.schema);
200
+ }
201
+ }
202
+ return schemas;
44
203
  }
45
204
 
46
- const string &CatalogSearchPath::GetDefault() {
205
+ const CatalogSearchEntry &CatalogSearchPath::GetDefault() {
47
206
  const auto &paths = Get();
48
207
  D_ASSERT(paths.size() >= 2);
49
- D_ASSERT(paths[0] == TEMP_SCHEMA);
50
208
  return paths[1];
51
209
  }
52
210
 
53
- void CatalogSearchPath::SetPaths(vector<string> new_paths) {
211
+ void CatalogSearchPath::SetPaths(vector<CatalogSearchEntry> new_paths) {
54
212
  paths.clear();
55
213
  paths.reserve(new_paths.size() + 3);
56
- paths.emplace_back(TEMP_SCHEMA);
214
+ paths.emplace_back(TEMP_CATALOG, DEFAULT_SCHEMA);
57
215
  for (auto &path : new_paths) {
58
216
  paths.push_back(move(path));
59
217
  }
60
- paths.emplace_back(DEFAULT_SCHEMA);
61
- paths.emplace_back("pg_catalog");
62
- }
63
-
64
- vector<string> CatalogSearchPath::ParsePaths(const string &value) {
65
- return StringUtil::SplitWithQuote(StringUtil::Lower(value));
218
+ paths.emplace_back(INVALID_CATALOG, DEFAULT_SCHEMA);
219
+ paths.emplace_back(SYSTEM_CATALOG, DEFAULT_SCHEMA);
220
+ paths.emplace_back(SYSTEM_CATALOG, "pg_catalog");
66
221
  }
67
222
 
68
223
  } // namespace duckdb