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
@@ -63,9 +63,27 @@ void CatalogSet::PutEntry(EntryIndex index, unique_ptr<CatalogEntry> catalog_ent
63
63
  entry->second.entry = move(catalog_entry);
64
64
  }
65
65
 
66
- bool CatalogSet::CreateEntry(ClientContext &context, const string &name, unique_ptr<CatalogEntry> value,
67
- unordered_set<CatalogEntry *> &dependencies) {
68
- auto &transaction = Transaction::GetTransaction(context);
66
+ bool CatalogSet::CreateEntry(CatalogTransaction transaction, const string &name, unique_ptr<CatalogEntry> value,
67
+ DependencyList &dependencies) {
68
+ if (value->internal && !catalog.IsSystemCatalog() && name != DEFAULT_SCHEMA) {
69
+ throw InternalException("Attempting to create internal entry \"%s\" in non-system catalog - internal entries "
70
+ "can only be created in the system catalog",
71
+ name);
72
+ }
73
+ if (!value->internal) {
74
+ if (!value->temporary && catalog.IsSystemCatalog()) {
75
+ throw InternalException(
76
+ "Attempting to create non-internal entry \"%s\" in system catalog - the system catalog "
77
+ "can only contain internal entries",
78
+ name);
79
+ }
80
+ if (value->temporary && !catalog.IsTemporaryCatalog()) {
81
+ throw InternalException("Attempting to create temporary entry \"%s\" in non-temporary catalog", name);
82
+ }
83
+ if (!value->temporary && catalog.IsTemporaryCatalog() && name != DEFAULT_SCHEMA) {
84
+ throw InternalException("Attempting to create non-temporary entry \"%s\" in temporary catalog", name);
85
+ }
86
+ }
69
87
  // lock the catalog for writing
70
88
  lock_guard<mutex> write_lock(catalog.write_lock);
71
89
  // lock this catalog set to disallow reading
@@ -73,12 +91,12 @@ bool CatalogSet::CreateEntry(ClientContext &context, const string &name, unique_
73
91
 
74
92
  // first check if the entry exists in the unordered set
75
93
  idx_t index;
76
- auto mapping_value = GetMapping(context, name);
94
+ auto mapping_value = GetMapping(transaction, name);
77
95
  if (mapping_value == nullptr || mapping_value->deleted) {
78
96
  // if it does not: entry has never been created
79
97
 
80
98
  // check if there is a default entry
81
- auto entry = CreateDefaultEntry(context, name, read_lock);
99
+ auto entry = CreateDefaultEntry(transaction, name, read_lock);
82
100
  if (entry) {
83
101
  return false;
84
102
  }
@@ -93,12 +111,12 @@ bool CatalogSet::CreateEntry(ClientContext &context, const string &name, unique_
93
111
 
94
112
  auto entry_index = PutEntry(current_entry++, move(dummy_node));
95
113
  index = entry_index.GetIndex();
96
- PutMapping(context, name, move(entry_index));
114
+ PutMapping(transaction, name, move(entry_index));
97
115
  } else {
98
116
  index = mapping_value->index.GetIndex();
99
117
  auto &current = *mapping_value->index.GetEntry();
100
118
  // if it does, we have to check version numbers
101
- if (HasConflict(context, current.timestamp)) {
119
+ if (HasConflict(transaction, current.timestamp)) {
102
120
  // current version has been written to by a currently active
103
121
  // transaction
104
122
  throw TransactionException("Catalog write-write conflict on create with \"%s\"", current.name);
@@ -116,20 +134,28 @@ bool CatalogSet::CreateEntry(ClientContext &context, const string &name, unique_
116
134
  value->set = this;
117
135
 
118
136
  // now add the dependency set of this object to the dependency manager
119
- catalog.dependency_manager->AddObject(context, value.get(), dependencies);
137
+ catalog.dependency_manager->AddObject(transaction, value.get(), dependencies);
120
138
 
121
139
  auto value_ptr = value.get();
122
140
  EntryIndex entry_index(*this, index);
123
141
  PutEntry(move(entry_index), move(value));
124
142
  // push the old entry in the undo buffer for this transaction
125
- transaction.PushCatalogEntry(value_ptr->child.get());
143
+ if (transaction.transaction) {
144
+ transaction.transaction->PushCatalogEntry(value_ptr->child.get());
145
+ }
126
146
  return true;
127
147
  }
128
148
 
129
- bool CatalogSet::GetEntryInternal(ClientContext &context, EntryIndex &entry_index, CatalogEntry *&catalog_entry) {
149
+ bool CatalogSet::CreateEntry(ClientContext &context, const string &name, unique_ptr<CatalogEntry> value,
150
+ DependencyList &dependencies) {
151
+ return CreateEntry(catalog.GetCatalogTransaction(context), name, move(value), dependencies);
152
+ }
153
+
154
+ bool CatalogSet::GetEntryInternal(CatalogTransaction transaction, EntryIndex &entry_index,
155
+ CatalogEntry *&catalog_entry) {
130
156
  catalog_entry = entry_index.GetEntry().get();
131
157
  // if it does: we have to retrieve the entry and to check version numbers
132
- if (HasConflict(context, catalog_entry->timestamp)) {
158
+ if (HasConflict(transaction, catalog_entry->timestamp)) {
133
159
  // current version has been written to by a currently active
134
160
  // transaction
135
161
  throw TransactionException("Catalog write-write conflict on alter with \"%s\"", catalog_entry->name);
@@ -143,9 +169,9 @@ bool CatalogSet::GetEntryInternal(ClientContext &context, EntryIndex &entry_inde
143
169
  return true;
144
170
  }
145
171
 
146
- bool CatalogSet::GetEntryInternal(ClientContext &context, const string &name, EntryIndex *entry_index,
172
+ bool CatalogSet::GetEntryInternal(CatalogTransaction transaction, const string &name, EntryIndex *entry_index,
147
173
  CatalogEntry *&catalog_entry) {
148
- auto mapping_value = GetMapping(context, name);
174
+ auto mapping_value = GetMapping(transaction, name);
149
175
  if (mapping_value == nullptr || mapping_value->deleted) {
150
176
  // the entry does not exist, check if we can create a default entry
151
177
  return false;
@@ -153,34 +179,33 @@ bool CatalogSet::GetEntryInternal(ClientContext &context, const string &name, En
153
179
  if (entry_index) {
154
180
  *entry_index = mapping_value->index.Copy();
155
181
  }
156
- return GetEntryInternal(context, mapping_value->index, catalog_entry);
182
+ return GetEntryInternal(transaction, mapping_value->index, catalog_entry);
157
183
  }
158
184
 
159
- bool CatalogSet::AlterOwnership(ClientContext &context, ChangeOwnershipInfo *info) {
185
+ bool CatalogSet::AlterOwnership(CatalogTransaction transaction, ChangeOwnershipInfo *info) {
160
186
  CatalogEntry *entry;
161
- if (!GetEntryInternal(context, info->name, nullptr, entry)) {
187
+ if (!GetEntryInternal(transaction, info->name, nullptr, entry)) {
162
188
  return false;
163
189
  }
164
190
 
165
- auto owner_entry = catalog.GetEntry(context, info->owner_schema, info->owner_name);
191
+ auto owner_entry = catalog.GetEntry(transaction.GetContext(), info->owner_schema, info->owner_name);
166
192
  if (!owner_entry) {
167
193
  return false;
168
194
  }
169
195
 
170
- catalog.dependency_manager->AddOwnership(context, owner_entry, entry);
196
+ catalog.dependency_manager->AddOwnership(transaction, owner_entry, entry);
171
197
 
172
198
  return true;
173
199
  }
174
200
 
175
- bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInfo *alter_info) {
176
- auto &transaction = Transaction::GetTransaction(context);
201
+ bool CatalogSet::AlterEntry(CatalogTransaction transaction, const string &name, AlterInfo *alter_info) {
177
202
  // lock the catalog for writing
178
203
  lock_guard<mutex> write_lock(catalog.write_lock);
179
204
 
180
205
  // first check if the entry exists in the unordered set
181
206
  EntryIndex entry_index;
182
207
  CatalogEntry *entry;
183
- if (!GetEntryInternal(context, name, &entry_index, entry)) {
208
+ if (!GetEntryInternal(transaction, name, &entry_index, entry)) {
184
209
  return false;
185
210
  }
186
211
  if (!alter_info->allow_internal && entry->internal) {
@@ -194,6 +219,10 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
194
219
  // set the timestamp to the timestamp of the current transaction
195
220
  // and point it to the updated table node
196
221
  string original_name = entry->name;
222
+ if (!transaction.context) {
223
+ throw InternalException("Cannot AlterEntry without client context");
224
+ }
225
+ auto &context = *transaction.context;
197
226
  auto value = entry->AlterEntry(context, alter_info);
198
227
  if (!value) {
199
228
  // alter failed, but did not result in an error
@@ -201,9 +230,9 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
201
230
  }
202
231
 
203
232
  if (value->name != original_name) {
204
- auto mapping_value = GetMapping(context, value->name);
233
+ auto mapping_value = GetMapping(transaction, value->name);
205
234
  if (mapping_value && !mapping_value->deleted) {
206
- auto original_entry = GetEntryForTransaction(context, mapping_value->index.GetEntry().get());
235
+ auto original_entry = GetEntryForTransaction(transaction, mapping_value->index.GetEntry().get());
207
236
  if (!original_entry->deleted) {
208
237
  entry->UndoAlter(context, alter_info);
209
238
  string rename_err_msg =
@@ -215,8 +244,8 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
215
244
 
216
245
  if (value->name != original_name) {
217
246
  // Do PutMapping and DeleteMapping after dependency check
218
- PutMapping(context, value->name, entry_index.Copy());
219
- DeleteMapping(context, original_name);
247
+ PutMapping(transaction, value->name, entry_index.Copy());
248
+ DeleteMapping(transaction, original_name);
220
249
  }
221
250
 
222
251
  value->timestamp = transaction.transaction_id;
@@ -230,18 +259,21 @@ bool CatalogSet::AlterEntry(ClientContext &context, const string &name, AlterInf
230
259
  BinaryData serialized_alter = serializer.GetData();
231
260
 
232
261
  // push the old entry in the undo buffer for this transaction
233
- transaction.PushCatalogEntry(new_entry->child.get(), serialized_alter.data.get(), serialized_alter.size);
262
+ if (transaction.transaction) {
263
+ transaction.transaction->PushCatalogEntry(new_entry->child.get(), serialized_alter.data.get(),
264
+ serialized_alter.size);
265
+ }
234
266
 
235
267
  // Check the dependency manager to verify that there are no conflicting dependencies with this alter
236
268
  // Note that we do this AFTER the new entry has been entirely set up in the catalog set
237
269
  // that is because in case the alter fails because of a dependency conflict, we need to be able to cleanly roll back
238
270
  // to the old entry.
239
- catalog.dependency_manager->AlterObject(context, entry, new_entry);
271
+ catalog.dependency_manager->AlterObject(transaction, entry, new_entry);
240
272
 
241
273
  return true;
242
274
  }
243
275
 
244
- void CatalogSet::DropEntryDependencies(ClientContext &context, EntryIndex &entry_index, CatalogEntry &entry,
276
+ void CatalogSet::DropEntryDependencies(CatalogTransaction transaction, EntryIndex &entry_index, CatalogEntry &entry,
245
277
  bool cascade) {
246
278
  // Stores the deleted value of the entry before starting the process
247
279
  EntryDropper dropper(entry_index);
@@ -250,17 +282,16 @@ void CatalogSet::DropEntryDependencies(ClientContext &context, EntryIndex &entry
250
282
  entry_index.GetEntry()->deleted = true;
251
283
 
252
284
  // check any dependencies of this object
253
- entry.catalog->dependency_manager->DropObject(context, &entry, cascade);
285
+ entry.catalog->dependency_manager->DropObject(transaction, &entry, cascade);
254
286
 
255
287
  // dropper destructor is called here
256
288
  // the destructor makes sure to return the value to the previous state
257
289
  // dropper.~EntryDropper()
258
290
  }
259
291
 
260
- void CatalogSet::DropEntryInternal(ClientContext &context, EntryIndex entry_index, CatalogEntry &entry, bool cascade) {
261
- auto &transaction = Transaction::GetTransaction(context);
262
-
263
- DropEntryDependencies(context, entry_index, entry, cascade);
292
+ void CatalogSet::DropEntryInternal(CatalogTransaction transaction, EntryIndex entry_index, CatalogEntry &entry,
293
+ bool cascade) {
294
+ DropEntryDependencies(transaction, entry_index, entry, cascade);
264
295
 
265
296
  // create a new entry and replace the currently stored one
266
297
  // set the timestamp to the timestamp of the current transaction
@@ -273,27 +304,37 @@ void CatalogSet::DropEntryInternal(ClientContext &context, EntryIndex entry_inde
273
304
  PutEntry(move(entry_index), move(value));
274
305
 
275
306
  // push the old entry in the undo buffer for this transaction
276
- transaction.PushCatalogEntry(value_ptr->child.get());
307
+ if (transaction.transaction) {
308
+ transaction.transaction->PushCatalogEntry(value_ptr->child.get());
309
+ }
277
310
  }
278
311
 
279
- bool CatalogSet::DropEntry(ClientContext &context, const string &name, bool cascade) {
312
+ bool CatalogSet::DropEntry(CatalogTransaction transaction, const string &name, bool cascade, bool allow_drop_internal) {
280
313
  // lock the catalog for writing
281
314
  lock_guard<mutex> write_lock(catalog.write_lock);
282
315
  // we can only delete an entry that exists
283
316
  EntryIndex entry_index;
284
317
  CatalogEntry *entry;
285
- if (!GetEntryInternal(context, name, &entry_index, entry)) {
318
+ if (!GetEntryInternal(transaction, name, &entry_index, entry)) {
286
319
  return false;
287
320
  }
288
- if (entry->internal) {
321
+ if (entry->internal && !allow_drop_internal) {
289
322
  throw CatalogException("Cannot drop entry \"%s\" because it is an internal system entry", entry->name);
290
323
  }
291
324
 
292
325
  lock_guard<mutex> read_lock(catalog_lock);
293
- DropEntryInternal(context, move(entry_index), *entry, cascade);
326
+ DropEntryInternal(transaction, move(entry_index), *entry, cascade);
294
327
  return true;
295
328
  }
296
329
 
330
+ bool CatalogSet::DropEntry(ClientContext &context, const string &name, bool cascade, bool allow_drop_internal) {
331
+ return DropEntry(catalog.GetCatalogTransaction(context), name, cascade, allow_drop_internal);
332
+ }
333
+
334
+ Catalog &CatalogSet::GetCatalog() {
335
+ return catalog;
336
+ }
337
+
297
338
  void CatalogSet::CleanupEntry(CatalogEntry *catalog_entry) {
298
339
  // destroy the backed up entry: it is no longer required
299
340
  D_ASSERT(catalog_entry->parent);
@@ -318,13 +359,12 @@ void CatalogSet::CleanupEntry(CatalogEntry *catalog_entry) {
318
359
  }
319
360
  }
320
361
 
321
- bool CatalogSet::HasConflict(ClientContext &context, transaction_t timestamp) {
322
- auto &transaction = Transaction::GetTransaction(context);
362
+ bool CatalogSet::HasConflict(CatalogTransaction transaction, transaction_t timestamp) {
323
363
  return (timestamp >= TRANSACTION_ID_START && timestamp != transaction.transaction_id) ||
324
364
  (timestamp < TRANSACTION_ID_START && timestamp > transaction.start_time);
325
365
  }
326
366
 
327
- MappingValue *CatalogSet::GetMapping(ClientContext &context, const string &name, bool get_latest) {
367
+ MappingValue *CatalogSet::GetMapping(CatalogTransaction transaction, const string &name, bool get_latest) {
328
368
  MappingValue *mapping_value;
329
369
  auto entry = mapping.find(name);
330
370
  if (entry != mapping.end()) {
@@ -337,7 +377,7 @@ MappingValue *CatalogSet::GetMapping(ClientContext &context, const string &name,
337
377
  return mapping_value;
338
378
  }
339
379
  while (mapping_value->child) {
340
- if (UseTimestamp(context, mapping_value->timestamp)) {
380
+ if (UseTimestamp(transaction, mapping_value->timestamp)) {
341
381
  break;
342
382
  }
343
383
  mapping_value = mapping_value->child.get();
@@ -346,12 +386,12 @@ MappingValue *CatalogSet::GetMapping(ClientContext &context, const string &name,
346
386
  return mapping_value;
347
387
  }
348
388
 
349
- void CatalogSet::PutMapping(ClientContext &context, const string &name, EntryIndex entry_index) {
389
+ void CatalogSet::PutMapping(CatalogTransaction transaction, const string &name, EntryIndex entry_index) {
350
390
  auto entry = mapping.find(name);
351
391
  auto new_value = make_unique<MappingValue>(move(entry_index));
352
- new_value->timestamp = Transaction::GetTransaction(context).transaction_id;
392
+ new_value->timestamp = transaction.transaction_id;
353
393
  if (entry != mapping.end()) {
354
- if (HasConflict(context, entry->second->timestamp)) {
394
+ if (HasConflict(transaction, entry->second->timestamp)) {
355
395
  throw TransactionException("Catalog write-write conflict on name \"%s\"", name);
356
396
  }
357
397
  new_value->child = move(entry->second);
@@ -360,19 +400,18 @@ void CatalogSet::PutMapping(ClientContext &context, const string &name, EntryInd
360
400
  mapping[name] = move(new_value);
361
401
  }
362
402
 
363
- void CatalogSet::DeleteMapping(ClientContext &context, const string &name) {
403
+ void CatalogSet::DeleteMapping(CatalogTransaction transaction, const string &name) {
364
404
  auto entry = mapping.find(name);
365
405
  D_ASSERT(entry != mapping.end());
366
406
  auto delete_marker = make_unique<MappingValue>(entry->second->index.Copy());
367
407
  delete_marker->deleted = true;
368
- delete_marker->timestamp = Transaction::GetTransaction(context).transaction_id;
408
+ delete_marker->timestamp = transaction.transaction_id;
369
409
  delete_marker->child = move(entry->second);
370
410
  delete_marker->child->parent = delete_marker.get();
371
411
  mapping[name] = move(delete_marker);
372
412
  }
373
413
 
374
- bool CatalogSet::UseTimestamp(ClientContext &context, transaction_t timestamp) {
375
- auto &transaction = Transaction::GetTransaction(context);
414
+ bool CatalogSet::UseTimestamp(CatalogTransaction transaction, transaction_t timestamp) {
376
415
  if (timestamp == transaction.transaction_id) {
377
416
  // we created this version
378
417
  return true;
@@ -384,9 +423,9 @@ bool CatalogSet::UseTimestamp(ClientContext &context, transaction_t timestamp) {
384
423
  return false;
385
424
  }
386
425
 
387
- CatalogEntry *CatalogSet::GetEntryForTransaction(ClientContext &context, CatalogEntry *current) {
426
+ CatalogEntry *CatalogSet::GetEntryForTransaction(CatalogTransaction transaction, CatalogEntry *current) {
388
427
  while (current->child) {
389
- if (UseTimestamp(context, current->timestamp)) {
428
+ if (UseTimestamp(transaction, current->timestamp)) {
390
429
  break;
391
430
  }
392
431
  current = current->child.get();
@@ -407,14 +446,14 @@ CatalogEntry *CatalogSet::GetCommittedEntry(CatalogEntry *current) {
407
446
  return current;
408
447
  }
409
448
 
410
- pair<string, idx_t> CatalogSet::SimilarEntry(ClientContext &context, const string &name) {
449
+ pair<string, idx_t> CatalogSet::SimilarEntry(CatalogTransaction transaction, const string &name) {
411
450
  unique_lock<mutex> lock(catalog_lock);
412
- CreateDefaultEntries(context, lock);
451
+ CreateDefaultEntries(transaction, lock);
413
452
 
414
453
  string result;
415
454
  idx_t current_score = (idx_t)-1;
416
455
  for (auto &kv : mapping) {
417
- auto mapping_value = GetMapping(context, kv.first);
456
+ auto mapping_value = GetMapping(transaction, kv.first);
418
457
  if (mapping_value && !mapping_value->deleted) {
419
458
  auto ldist = StringUtil::LevenshteinDistance(kv.first, name);
420
459
  if (ldist < current_score) {
@@ -426,7 +465,7 @@ pair<string, idx_t> CatalogSet::SimilarEntry(ClientContext &context, const strin
426
465
  return {result, current_score};
427
466
  }
428
467
 
429
- CatalogEntry *CatalogSet::CreateEntryInternal(ClientContext &context, unique_ptr<CatalogEntry> entry) {
468
+ CatalogEntry *CatalogSet::CreateEntryInternal(CatalogTransaction transaction, unique_ptr<CatalogEntry> entry) {
430
469
  if (mapping.find(entry->name) != mapping.end()) {
431
470
  return nullptr;
432
471
  }
@@ -437,12 +476,13 @@ CatalogEntry *CatalogSet::CreateEntryInternal(ClientContext &context, unique_ptr
437
476
  entry->timestamp = 0;
438
477
 
439
478
  auto entry_index = PutEntry(current_entry++, move(entry));
440
- PutMapping(context, name, move(entry_index));
479
+ PutMapping(transaction, name, move(entry_index));
441
480
  mapping[name]->timestamp = 0;
442
481
  return catalog_entry;
443
482
  }
444
483
 
445
- CatalogEntry *CatalogSet::CreateDefaultEntry(ClientContext &context, const string &name, unique_lock<mutex> &lock) {
484
+ CatalogEntry *CatalogSet::CreateDefaultEntry(CatalogTransaction transaction, const string &name,
485
+ unique_lock<mutex> &lock) {
446
486
  // no entry found with this name, check for defaults
447
487
  if (!defaults || defaults->created_all_entries) {
448
488
  // no defaults either: return null
@@ -450,8 +490,12 @@ CatalogEntry *CatalogSet::CreateDefaultEntry(ClientContext &context, const strin
450
490
  }
451
491
  // this catalog set has a default map defined
452
492
  // check if there is a default entry that we can create with this name
493
+ if (!transaction.context) {
494
+ // no context - cannot create default entry
495
+ return nullptr;
496
+ }
453
497
  lock.unlock();
454
- auto entry = defaults->CreateDefaultEntry(context, name);
498
+ auto entry = defaults->CreateDefaultEntry(*transaction.context, name);
455
499
 
456
500
  lock.lock();
457
501
  if (!entry) {
@@ -459,7 +503,7 @@ CatalogEntry *CatalogSet::CreateDefaultEntry(ClientContext &context, const strin
459
503
  return nullptr;
460
504
  }
461
505
  // there is a default entry! create it
462
- auto result = CreateEntryInternal(context, move(entry));
506
+ auto result = CreateEntryInternal(transaction, move(entry));
463
507
  if (result) {
464
508
  return result;
465
509
  }
@@ -467,24 +511,28 @@ CatalogEntry *CatalogSet::CreateDefaultEntry(ClientContext &context, const strin
467
511
  // this means somebody else created the entry first
468
512
  // just retry?
469
513
  lock.unlock();
470
- return GetEntry(context, name);
514
+ return GetEntry(transaction, name);
471
515
  }
472
516
 
473
- CatalogEntry *CatalogSet::GetEntry(ClientContext &context, const string &name) {
517
+ CatalogEntry *CatalogSet::GetEntry(CatalogTransaction transaction, const string &name) {
474
518
  unique_lock<mutex> lock(catalog_lock);
475
- auto mapping_value = GetMapping(context, name);
519
+ auto mapping_value = GetMapping(transaction, name);
476
520
  if (mapping_value != nullptr && !mapping_value->deleted) {
477
521
  // we found an entry for this name
478
522
  // check the version numbers
479
523
 
480
524
  auto catalog_entry = mapping_value->index.GetEntry().get();
481
- CatalogEntry *current = GetEntryForTransaction(context, catalog_entry);
482
- if (current->deleted || (current->name != name && !UseTimestamp(context, mapping_value->timestamp))) {
525
+ CatalogEntry *current = GetEntryForTransaction(transaction, catalog_entry);
526
+ if (current->deleted || (current->name != name && !UseTimestamp(transaction, mapping_value->timestamp))) {
483
527
  return nullptr;
484
528
  }
485
529
  return current;
486
530
  }
487
- return CreateDefaultEntry(context, name, lock);
531
+ return CreateDefaultEntry(transaction, name, lock);
532
+ }
533
+
534
+ CatalogEntry *CatalogSet::GetEntry(ClientContext &context, const string &name) {
535
+ return GetEntry(catalog.GetCatalogTransaction(context), name);
488
536
  }
489
537
 
490
538
  void CatalogSet::UpdateTimestamp(CatalogEntry *entry, transaction_t timestamp) {
@@ -604,8 +652,8 @@ void CatalogSet::Undo(CatalogEntry *entry) {
604
652
  catalog.ModifyCatalog();
605
653
  }
606
654
 
607
- void CatalogSet::CreateDefaultEntries(ClientContext &context, unique_lock<mutex> &lock) {
608
- if (!defaults || defaults->created_all_entries) {
655
+ void CatalogSet::CreateDefaultEntries(CatalogTransaction transaction, unique_lock<mutex> &lock) {
656
+ if (!defaults || defaults->created_all_entries || !transaction.context) {
609
657
  return;
610
658
  }
611
659
  // this catalog set has a default set defined:
@@ -616,32 +664,36 @@ void CatalogSet::CreateDefaultEntries(ClientContext &context, unique_lock<mutex>
616
664
  // we unlock during the CreateEntry, since it might reference other catalog sets...
617
665
  // specifically for views this can happen since the view will be bound
618
666
  lock.unlock();
619
- auto entry = defaults->CreateDefaultEntry(context, default_entry);
667
+ auto entry = defaults->CreateDefaultEntry(*transaction.context, default_entry);
620
668
  if (!entry) {
621
669
  throw InternalException("Failed to create default entry for %s", default_entry);
622
670
  }
623
671
 
624
672
  lock.lock();
625
- CreateEntryInternal(context, move(entry));
673
+ CreateEntryInternal(transaction, move(entry));
626
674
  }
627
675
  }
628
676
  defaults->created_all_entries = true;
629
677
  }
630
678
 
631
- void CatalogSet::Scan(ClientContext &context, const std::function<void(CatalogEntry *)> &callback) {
679
+ void CatalogSet::Scan(CatalogTransaction transaction, const std::function<void(CatalogEntry *)> &callback) {
632
680
  // lock the catalog set
633
681
  unique_lock<mutex> lock(catalog_lock);
634
- CreateDefaultEntries(context, lock);
682
+ CreateDefaultEntries(transaction, lock);
635
683
 
636
684
  for (auto &kv : entries) {
637
685
  auto entry = kv.second.entry.get();
638
- entry = GetEntryForTransaction(context, entry);
686
+ entry = GetEntryForTransaction(transaction, entry);
639
687
  if (!entry->deleted) {
640
688
  callback(entry);
641
689
  }
642
690
  }
643
691
  }
644
692
 
693
+ void CatalogSet::Scan(ClientContext &context, const std::function<void(CatalogEntry *)> &callback) {
694
+ Scan(catalog.GetCatalogTransaction(context), callback);
695
+ }
696
+
645
697
  void CatalogSet::Scan(const std::function<void(CatalogEntry *)> &callback) {
646
698
  // lock the catalog set
647
699
  lock_guard<mutex> lock(catalog_lock);
@@ -653,4 +705,14 @@ void CatalogSet::Scan(const std::function<void(CatalogEntry *)> &callback) {
653
705
  }
654
706
  }
655
707
  }
708
+
709
+ void CatalogSet::Verify(Catalog &catalog_p) {
710
+ D_ASSERT(&catalog_p == &catalog);
711
+ vector<CatalogEntry *> entries;
712
+ Scan([&](CatalogEntry *entry) { entries.push_back(entry); });
713
+ for (auto &entry : entries) {
714
+ entry->Verify(catalog_p);
715
+ }
716
+ }
717
+
656
718
  } // namespace duckdb
@@ -0,0 +1,28 @@
1
+ #include "duckdb/catalog/catalog_transaction.hpp"
2
+ #include "duckdb/catalog/catalog.hpp"
3
+ #include "duckdb/transaction/transaction.hpp"
4
+ #include "duckdb/main/database.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ CatalogTransaction::CatalogTransaction(Catalog &catalog, ClientContext &context) {
9
+ auto &transaction = Transaction::Get(context, catalog);
10
+ this->db = &DatabaseInstance::GetDatabase(context);
11
+ this->transaction_id = transaction.transaction_id;
12
+ this->start_time = transaction.start_time;
13
+ this->transaction = &transaction;
14
+ this->context = &context;
15
+ }
16
+
17
+ CatalogTransaction::CatalogTransaction(DatabaseInstance &db, transaction_t transaction_id_p, transaction_t start_time_p)
18
+ : db(&db), context(nullptr), transaction(nullptr), transaction_id(transaction_id_p), start_time(start_time_p) {
19
+ }
20
+
21
+ ClientContext &CatalogTransaction::GetContext() {
22
+ if (!context) {
23
+ throw InternalException("Attempting to get a context in a CatalogTransaction without a context");
24
+ }
25
+ return *context;
26
+ }
27
+
28
+ } // namespace duckdb
@@ -39,7 +39,7 @@ static DefaultView internal_views[] = {
39
39
  {"pg_catalog", "pg_index", "SELECT index_oid indexrelid, table_oid indrelid, 0 indnatts, 0 indnkeyatts, is_unique indisunique, is_primary indisprimary, false indisexclusion, true indimmediate, false indisclustered, true indisvalid, false indcheckxmin, true indisready, true indislive, false indisreplident, NULL::INT[] indkey, NULL::OID[] indcollation, NULL::OID[] indclass, NULL::INT[] indoption, expressions indexprs, NULL indpred FROM duckdb_indexes()"},
40
40
  {"pg_catalog", "pg_indexes", "SELECT schema_name schemaname, table_name tablename, index_name indexname, NULL \"tablespace\", sql indexdef FROM duckdb_indexes()"},
41
41
  {"pg_catalog", "pg_namespace", "SELECT oid, schema_name nspname, 0 nspowner, NULL nspacl FROM duckdb_schemas()"},
42
- {"pg_catalog", "pg_proc", "SELECT f.function_oid oid, function_name proname, s.oid pronamespace, varargs provariadic, function_type = 'aggregate' proisagg, function_type = 'table' proretset, return_type prorettype, parameter_types proargtypes, parameters proargnames FROM duckdb_functions() f LEFT JOIN duckdb_schemas() s USING (schema_name)"},
42
+ {"pg_catalog", "pg_proc", "SELECT f.function_oid oid, function_name proname, s.oid pronamespace, varargs provariadic, function_type = 'aggregate' proisagg, function_type = 'table' proretset, return_type prorettype, parameter_types proargtypes, parameters proargnames FROM duckdb_functions() f LEFT JOIN duckdb_schemas() s USING (database_name, schema_name)"},
43
43
  {"pg_catalog", "pg_sequence", "SELECT sequence_oid seqrelid, 0 seqtypid, start_value seqstart, increment_by seqincrement, max_value seqmax, min_value seqmin, 0 seqcache, cycle seqcycle FROM duckdb_sequences()"},
44
44
  {"pg_catalog", "pg_sequences", "SELECT schema_name schemaname, sequence_name sequencename, 'duckdb' sequenceowner, 0 data_type, start_value, min_value, max_value, increment_by, cycle, 0 cache_size, last_value FROM duckdb_sequences()"},
45
45
  {"pg_catalog", "pg_settings", "SELECT name, value setting, description short_desc, CASE WHEN input_type = 'VARCHAR' THEN 'string' WHEN input_type = 'BOOLEAN' THEN 'bool' WHEN input_type IN ('BIGINT', 'UBIGINT') THEN 'integer' ELSE input_type END vartype FROM duckdb_settings()"},
@@ -47,9 +47,9 @@ static DefaultView internal_views[] = {
47
47
  {"pg_catalog", "pg_tablespace", "SELECT 0 oid, 'pg_default' spcname, 0 spcowner, NULL spcacl, NULL spcoptions"},
48
48
  {"pg_catalog", "pg_type", "SELECT type_oid oid, format_pg_type(type_name) typname, schema_oid typnamespace, 0 typowner, type_size typlen, false typbyval, CASE WHEN logical_type='ENUM' THEN 'e' else 'b' end typtype, CASE WHEN type_category='NUMERIC' THEN 'N' WHEN type_category='STRING' THEN 'S' WHEN type_category='DATETIME' THEN 'D' WHEN type_category='BOOLEAN' THEN 'B' WHEN type_category='COMPOSITE' THEN 'C' WHEN type_category='USER' THEN 'U' ELSE 'X' END typcategory, false typispreferred, true typisdefined, NULL typdelim, NULL typrelid, NULL typsubscript, NULL typelem, NULL typarray, NULL typinput, NULL typoutput, NULL typreceive, NULL typsend, NULL typmodin, NULL typmodout, NULL typanalyze, 'd' typalign, 'p' typstorage, NULL typnotnull, NULL typbasetype, NULL typtypmod, NULL typndims, NULL typcollation, NULL typdefaultbin, NULL typdefault, NULL typacl FROM duckdb_types() WHERE type_size IS NOT NULL;"},
49
49
  {"pg_catalog", "pg_views", "SELECT schema_name schemaname, view_name viewname, 'duckdb' viewowner, sql definition FROM duckdb_views()"},
50
- {"information_schema", "columns", "SELECT NULL table_catalog, schema_name table_schema, table_name, column_name, column_index ordinal_position, column_default, CASE WHEN is_nullable THEN 'YES' ELSE 'NO' END is_nullable, data_type, character_maximum_length, NULL character_octet_length, numeric_precision, numeric_precision_radix, numeric_scale, NULL datetime_precision, NULL interval_type, NULL interval_precision, NULL character_set_catalog, NULL character_set_schema, NULL character_set_name, NULL collation_catalog, NULL collation_schema, NULL collation_name, NULL domain_catalog, NULL domain_schema, NULL domain_name, NULL udt_catalog, NULL udt_schema, NULL udt_name, NULL scope_catalog, NULL scope_schema, NULL scope_name, NULL maximum_cardinality, NULL dtd_identifier, NULL is_self_referencing, NULL is_identity, NULL identity_generation, NULL identity_start, NULL identity_increment, NULL identity_maximum, NULL identity_minimum, NULL identity_cycle, NULL is_generated, NULL generation_expression, NULL is_updatable FROM duckdb_columns;"},
51
- {"information_schema", "schemata", "SELECT NULL catalog_name, schema_name, 'duckdb' schema_owner, NULL default_character_set_catalog, NULL default_character_set_schema, NULL default_character_set_name, sql sql_path FROM duckdb_schemas()"},
52
- {"information_schema", "tables", "SELECT NULL table_catalog, schema_name table_schema, table_name, CASE WHEN temporary THEN 'LOCAL TEMPORARY' ELSE 'BASE TABLE' END table_type, NULL self_referencing_column_name, NULL reference_generation, NULL user_defined_type_catalog, NULL user_defined_type_schema, NULL user_defined_type_name, 'YES' is_insertable_into, 'NO' is_typed, CASE WHEN temporary THEN 'PRESERVE' ELSE NULL END commit_action FROM duckdb_tables() UNION ALL SELECT NULL table_catalog, schema_name table_schema, view_name table_name, 'VIEW' table_type, NULL self_referencing_column_name, NULL reference_generation, NULL user_defined_type_catalog, NULL user_defined_type_schema, NULL user_defined_type_name, 'NO' is_insertable_into, 'NO' is_typed, NULL commit_action FROM duckdb_views;"},
50
+ {"information_schema", "columns", "SELECT database_name table_catalog, schema_name table_schema, table_name, column_name, column_index ordinal_position, column_default, CASE WHEN is_nullable THEN 'YES' ELSE 'NO' END is_nullable, data_type, character_maximum_length, NULL character_octet_length, numeric_precision, numeric_precision_radix, numeric_scale, NULL datetime_precision, NULL interval_type, NULL interval_precision, NULL character_set_catalog, NULL character_set_schema, NULL character_set_name, NULL collation_catalog, NULL collation_schema, NULL collation_name, NULL domain_catalog, NULL domain_schema, NULL domain_name, NULL udt_catalog, NULL udt_schema, NULL udt_name, NULL scope_catalog, NULL scope_schema, NULL scope_name, NULL maximum_cardinality, NULL dtd_identifier, NULL is_self_referencing, NULL is_identity, NULL identity_generation, NULL identity_start, NULL identity_increment, NULL identity_maximum, NULL identity_minimum, NULL identity_cycle, NULL is_generated, NULL generation_expression, NULL is_updatable FROM duckdb_columns;"},
51
+ {"information_schema", "schemata", "SELECT database_name catalog_name, schema_name, 'duckdb' schema_owner, NULL default_character_set_catalog, NULL default_character_set_schema, NULL default_character_set_name, sql sql_path FROM duckdb_schemas()"},
52
+ {"information_schema", "tables", "SELECT database_name table_catalog, schema_name table_schema, table_name, CASE WHEN temporary THEN 'LOCAL TEMPORARY' ELSE 'BASE TABLE' END table_type, NULL self_referencing_column_name, NULL reference_generation, NULL user_defined_type_catalog, NULL user_defined_type_schema, NULL user_defined_type_name, 'YES' is_insertable_into, 'NO' is_typed, CASE WHEN temporary THEN 'PRESERVE' ELSE NULL END commit_action FROM duckdb_tables() UNION ALL SELECT NULL table_catalog, schema_name table_schema, view_name table_name, 'VIEW' table_type, NULL self_referencing_column_name, NULL reference_generation, NULL user_defined_type_catalog, NULL user_defined_type_schema, NULL user_defined_type_name, 'NO' is_insertable_into, 'NO' is_typed, NULL commit_action FROM duckdb_views;"},
53
53
  {nullptr, nullptr, nullptr}};
54
54
 
55
55
  static unique_ptr<CreateViewInfo> GetDefaultView(const string &input_schema, const string &input_name) {
@@ -0,0 +1,13 @@
1
+ #include "duckdb/catalog/dependency_list.hpp"
2
+ #include "duckdb/catalog/catalog_entry.hpp"
3
+
4
+ namespace duckdb {
5
+
6
+ void DependencyList::AddDependency(CatalogEntry *entry) {
7
+ if (entry->internal) {
8
+ return;
9
+ }
10
+ set.insert(entry);
11
+ }
12
+
13
+ } // namespace duckdb