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
@@ -217,7 +217,7 @@ void Binder::BindDefaultValues(ColumnList &columns, vector<unique_ptr<Expression
217
217
  }
218
218
  }
219
219
 
220
- static void ExtractExpressionDependencies(Expression &expr, unordered_set<CatalogEntry *> &dependencies) {
220
+ static void ExtractExpressionDependencies(Expression &expr, DependencyList &dependencies) {
221
221
  if (expr.type == ExpressionType::BOUND_FUNCTION) {
222
222
  auto &function = (BoundFunctionExpression &)expr;
223
223
  if (function.function.dependency) {
@@ -241,12 +241,10 @@ static void ExtractDependencies(BoundCreateTableInfo &info) {
241
241
  }
242
242
  }
243
243
  }
244
-
245
- unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info) {
244
+ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry *schema) {
246
245
  auto &base = (CreateTableInfo &)*info;
247
-
248
246
  auto result = make_unique<BoundCreateTableInfo>(move(info));
249
- result->schema = BindSchema(*result->base);
247
+ result->schema = schema;
250
248
  if (base.query) {
251
249
  // construct the result object
252
250
  auto query_obj = Bind(*base.query);
@@ -284,16 +282,22 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
284
282
  if (column.Type().id() == LogicalTypeId::VARCHAR) {
285
283
  ExpressionBinder::TestCollation(context, StringType::GetCollation(column.Type()));
286
284
  }
287
- BindLogicalType(context, column.TypeMutable());
285
+ BindLogicalType(context, column.TypeMutable(), result->schema->catalog->GetName());
288
286
  // We add a catalog dependency
289
287
  auto type_dependency = LogicalType::GetCatalog(column.Type());
290
288
  if (type_dependency) {
291
289
  // Only if the USER comes from a create type
292
- result->dependencies.insert(type_dependency);
290
+ result->dependencies.AddDependency(type_dependency);
293
291
  }
294
292
  }
295
293
  properties.allow_stream_result = false;
296
294
  return result;
297
295
  }
298
296
 
297
+ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateInfo> info) {
298
+ auto &base = (CreateTableInfo &)*info;
299
+ auto schema = BindCreateSchema(base);
300
+ return BindCreateTableInfo(move(info), schema);
301
+ }
302
+
299
303
  } // namespace duckdb
@@ -28,7 +28,7 @@ BoundStatement Binder::Bind(DeleteStatement &stmt) {
28
28
 
29
29
  if (!table->temporary) {
30
30
  // delete from persistent table: not read only!
31
- properties.read_only = false;
31
+ properties.modified_databases.insert(table->catalog->GetName());
32
32
  }
33
33
 
34
34
  // Add CTEs as bindable
@@ -16,10 +16,12 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
16
16
  // it also does not require a valid transaction
17
17
  properties.requires_valid_transaction = false;
18
18
  break;
19
- case CatalogType::SCHEMA_ENTRY:
19
+ case CatalogType::SCHEMA_ENTRY: {
20
20
  // dropping a schema is never read-only because there are no temporary schemas
21
- properties.read_only = false;
21
+ auto &catalog = Catalog::GetCatalog(context, stmt.info->catalog);
22
+ properties.modified_databases.insert(catalog.GetName());
22
23
  break;
24
+ }
23
25
  case CatalogType::VIEW_ENTRY:
24
26
  case CatalogType::SEQUENCE_ENTRY:
25
27
  case CatalogType::MACRO_ENTRY:
@@ -27,18 +29,24 @@ BoundStatement Binder::Bind(DropStatement &stmt) {
27
29
  case CatalogType::INDEX_ENTRY:
28
30
  case CatalogType::TABLE_ENTRY:
29
31
  case CatalogType::TYPE_ENTRY: {
30
- auto entry = (StandardEntry *)Catalog::GetCatalog(context).GetEntry(context, stmt.info->type, stmt.info->schema,
31
- stmt.info->name, true);
32
+ BindSchemaOrCatalog(stmt.info->catalog, stmt.info->schema);
33
+ auto entry = (StandardEntry *)Catalog::GetEntry(context, stmt.info->type, stmt.info->catalog, stmt.info->schema,
34
+ stmt.info->name, true);
32
35
  if (!entry) {
33
36
  break;
34
37
  }
38
+ stmt.info->catalog = entry->catalog->GetName();
35
39
  if (!entry->temporary) {
36
40
  // we can only drop temporary tables in read-only mode
37
- properties.read_only = false;
41
+ properties.modified_databases.insert(stmt.info->catalog);
38
42
  }
39
43
  stmt.info->schema = entry->schema->name;
40
44
  break;
41
45
  }
46
+ case CatalogType::DATABASE_ENTRY:
47
+ // attaching and detaching is read-only
48
+ stmt.info->catalog = SYSTEM_CATALOG;
49
+ break;
42
50
  default:
43
51
  throw BinderException("Unknown catalog type for drop statement!");
44
52
  }
@@ -96,15 +96,16 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
96
96
  result.names = {"Success"};
97
97
 
98
98
  // lookup the format in the catalog
99
- auto &catalog = Catalog::GetCatalog(context);
100
- auto copy_function = catalog.GetEntry<CopyFunctionCatalogEntry>(context, DEFAULT_SCHEMA, stmt.info->format);
99
+ auto copy_function =
100
+ Catalog::GetEntry<CopyFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->format);
101
101
  if (!copy_function->function.copy_to_bind) {
102
102
  throw NotImplementedException("COPY TO is not supported for FORMAT \"%s\"", stmt.info->format);
103
103
  }
104
104
 
105
105
  // gather a list of all the tables
106
+ string catalog = stmt.database.empty() ? INVALID_CATALOG : stmt.database;
106
107
  vector<TableCatalogEntry *> tables;
107
- auto schemas = catalog.schemas->GetEntries<SchemaCatalogEntry>(context);
108
+ auto schemas = Catalog::GetSchemas(context, catalog);
108
109
  for (auto &schema : schemas) {
109
110
  schema->Scan(context, CatalogType::TABLE_ENTRY, [&](CatalogEntry *entry) {
110
111
  if (entry->type == CatalogType::TABLE_ENTRY) {
@@ -153,6 +154,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
153
154
  id++;
154
155
  }
155
156
  info->is_from = false;
157
+ info->catalog = catalog;
156
158
  info->schema = table->schema->name;
157
159
  info->table = table->name;
158
160
 
@@ -161,6 +163,7 @@ BoundStatement Binder::Bind(ExportStatement &stmt) {
161
163
  info->select_list.push_back(col.GetName());
162
164
  }
163
165
 
166
+ exported_data.database_name = catalog;
164
167
  exported_data.table_name = info->table;
165
168
  exported_data.schema_name = info->schema;
166
169
  exported_data.file_path = info->file_path;
@@ -11,7 +11,7 @@ BoundStatement Binder::Bind(ExtensionStatement &stmt) {
11
11
  D_ASSERT(stmt.extension.plan_function);
12
12
  auto parse_result = stmt.extension.plan_function(stmt.extension.parser_info.get(), context, move(stmt.parse_data));
13
13
 
14
- properties.read_only = parse_result.read_only;
14
+ properties.modified_databases = parse_result.modified_databases;
15
15
  properties.requires_valid_transaction = parse_result.requires_valid_transaction;
16
16
  properties.return_type = parse_result.return_type;
17
17
 
@@ -30,11 +30,12 @@ BoundStatement Binder::Bind(InsertStatement &stmt) {
30
30
  result.names = {"Count"};
31
31
  result.types = {LogicalType::BIGINT};
32
32
 
33
- auto table = Catalog::GetCatalog(context).GetEntry<TableCatalogEntry>(context, stmt.schema, stmt.table);
33
+ BindSchemaOrCatalog(stmt.catalog, stmt.schema);
34
+ auto table = Catalog::GetEntry<TableCatalogEntry>(context, stmt.catalog, stmt.schema, stmt.table);
34
35
  D_ASSERT(table);
35
36
  if (!table->temporary) {
36
37
  // inserting into a non-temporary table: alters underlying database
37
- properties.read_only = false;
38
+ properties.modified_databases.insert(table->catalog->GetName());
38
39
  }
39
40
 
40
41
  auto insert = make_unique<LogicalInsert>(table, GenerateTableIndex());
@@ -8,9 +8,9 @@
8
8
  namespace duckdb {
9
9
 
10
10
  BoundStatement Binder::Bind(PragmaStatement &stmt) {
11
- auto &catalog = Catalog::GetCatalog(context);
12
11
  // bind the pragma function
13
- auto entry = catalog.GetEntry<PragmaFunctionCatalogEntry>(context, DEFAULT_SCHEMA, stmt.info->name, false);
12
+ auto entry =
13
+ Catalog::GetEntry<PragmaFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->name, false);
14
14
  string error;
15
15
  FunctionBinder function_binder(context);
16
16
  idx_t bound_idx = function_binder.BindFunction(entry->name, entry->functions, *stmt.info, error);
@@ -11,8 +11,6 @@ BoundStatement Binder::Bind(PrepareStatement &stmt) {
11
11
  this->bound_tables = prepared_planner.binder->bound_tables;
12
12
 
13
13
  auto prepare = make_unique<LogicalPrepare>(stmt.name, move(prepared_data), move(prepared_planner.plan));
14
- // we can prepare in read-only mode: prepared statements are not written to the catalog
15
- properties.read_only = true;
16
14
  // we can always prepare, even if the transaction has been invalidated
17
15
  // this is required because most clients ALWAYS invoke prepared statements
18
16
  properties.requires_valid_transaction = false;
@@ -2,6 +2,7 @@
2
2
  #include "duckdb/parser/statement/transaction_statement.hpp"
3
3
  #include "duckdb/planner/operator/logical_simple.hpp"
4
4
  #include "duckdb/catalog/catalog.hpp"
5
+ #include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
5
6
  #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
6
7
  #include "duckdb/catalog/catalog_entry/view_catalog_entry.hpp"
7
8
  #include "duckdb/planner/binder.hpp"
@@ -15,12 +16,16 @@ BoundStatement Binder::Bind(AlterStatement &stmt) {
15
16
  BoundStatement result;
16
17
  result.names = {"Success"};
17
18
  result.types = {LogicalType::BOOLEAN};
18
- Catalog &catalog = Catalog::GetCatalog(context);
19
- auto entry = catalog.GetEntry(context, stmt.info->GetCatalogType(), stmt.info->schema, stmt.info->name,
20
- stmt.info->if_exists);
21
- if (entry && !entry->temporary) {
22
- // we can only alter temporary tables/views in read-only mode
23
- properties.read_only = false;
19
+ BindSchemaOrCatalog(stmt.info->catalog, stmt.info->schema);
20
+ auto entry = Catalog::GetEntry(context, stmt.info->GetCatalogType(), stmt.info->catalog, stmt.info->schema,
21
+ stmt.info->name, stmt.info->if_exists);
22
+ if (entry) {
23
+ if (!entry->temporary) {
24
+ // we can only alter temporary tables/views in read-only mode
25
+ properties.modified_databases.insert(entry->catalog->GetName());
26
+ }
27
+ stmt.info->catalog = entry->catalog->GetName();
28
+ stmt.info->schema = ((StandardEntry *)entry)->schema->name;
24
29
  }
25
30
  result.plan = make_unique<LogicalSimple>(LogicalOperatorType::LOGICAL_ALTER, move(stmt.info));
26
31
  properties.return_type = StatementReturnType::NOTHING;
@@ -157,7 +157,7 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) {
157
157
 
158
158
  if (!table->temporary) {
159
159
  // update of persistent table: not read only!
160
- properties.read_only = false;
160
+ properties.modified_databases.insert(table->catalog->GetName());
161
161
  }
162
162
  auto update = make_unique<LogicalUpdate>(table);
163
163
 
@@ -63,11 +63,15 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
63
63
  }
64
64
  // not a CTE
65
65
  // extract a table or view from the catalog
66
- auto &catalog = Catalog::GetCatalog(context);
67
- auto table_or_view =
68
- catalog.GetEntry(context, CatalogType::TABLE_ENTRY, ref.schema_name, ref.table_name, true, error_context);
66
+ BindSchemaOrCatalog(ref.catalog_name, ref.schema_name);
67
+ auto table_or_view = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name,
68
+ ref.table_name, true, error_context);
69
69
  if (!table_or_view) {
70
- auto table_name = ref.schema_name.empty() ? ref.table_name : (ref.schema_name + "." + ref.table_name);
70
+ string table_name = ref.catalog_name;
71
+ if (!ref.schema_name.empty()) {
72
+ table_name += (!table_name.empty() ? "." : "") + ref.schema_name;
73
+ }
74
+ table_name += (!table_name.empty() ? "." : "") + ref.table_name;
71
75
  // table could not be found: try to bind a replacement scan
72
76
  auto &config = DBConfig::GetConfig(context);
73
77
  if (context.config.use_replacement_scans) {
@@ -95,8 +99,8 @@ unique_ptr<BoundTableRef> Binder::Bind(BaseTableRef &ref) {
95
99
  return make_unique_base<BoundTableRef, BoundEmptyTableRef>(table_index);
96
100
  }
97
101
  // could not find an alternative: bind again to get the error
98
- table_or_view = Catalog::GetCatalog(context).GetEntry(context, CatalogType::TABLE_ENTRY, ref.schema_name,
99
- ref.table_name, false, error_context);
102
+ table_or_view = Catalog::GetEntry(context, CatalogType::TABLE_ENTRY, ref.catalog_name, ref.schema_name,
103
+ ref.table_name, false, error_context);
100
104
  }
101
105
  switch (table_or_view->type) {
102
106
  case CatalogType::TABLE_ENTRY: {
@@ -186,10 +186,8 @@ unique_ptr<BoundTableRef> Binder::Bind(TableFunctionRef &ref) {
186
186
  TableFunctionCatalogEntry *function = nullptr;
187
187
 
188
188
  // fetch the function from the catalog
189
- auto &catalog = Catalog::GetCatalog(context);
190
-
191
- auto func_catalog = catalog.GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, fexpr->schema,
192
- fexpr->function_name, false, error_context);
189
+ auto func_catalog = Catalog::GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, fexpr->catalog, fexpr->schema,
190
+ fexpr->function_name, false, error_context);
193
191
 
194
192
  if (func_catalog->type == CatalogType::TABLE_FUNCTION_ENTRY) {
195
193
  function = (TableFunctionCatalogEntry *)func_catalog;
@@ -87,6 +87,8 @@ BoundStatement Binder::Bind(SQLStatement &statement) {
87
87
  return Bind((ExecuteStatement &)statement);
88
88
  case StatementType::LOGICAL_PLAN_STATEMENT:
89
89
  return Bind((LogicalPlanStatement &)statement);
90
+ case StatementType::ATTACH_STATEMENT:
91
+ return Bind((AttachStatement &)statement);
90
92
  default: // LCOV_EXCL_START
91
93
  throw NotImplementedException("Unimplemented statement type \"%s\" for Bind",
92
94
  StatementTypeToString(statement.type));
@@ -259,6 +261,7 @@ void Binder::AddBoundView(ViewCatalogEntry *view) {
259
261
  }
260
262
 
261
263
  idx_t Binder::GenerateTableIndex() {
264
+ D_ASSERT(parent.get() != this);
262
265
  if (parent) {
263
266
  return parent->GenerateTableIndex();
264
267
  }
@@ -327,6 +330,12 @@ bool Binder::HasMatchingBinding(const string &table_name, const string &column_n
327
330
 
328
331
  bool Binder::HasMatchingBinding(const string &schema_name, const string &table_name, const string &column_name,
329
332
  string &error_message) {
333
+ string empty_catalog;
334
+ return HasMatchingBinding(empty_catalog, schema_name, table_name, column_name, error_message);
335
+ }
336
+
337
+ bool Binder::HasMatchingBinding(const string &catalog_name, const string &schema_name, const string &table_name,
338
+ const string &column_name, string &error_message) {
330
339
  Binding *binding = nullptr;
331
340
  D_ASSERT(!lambda_bindings);
332
341
  if (macro_binding && table_name == macro_binding->alias) {
@@ -338,12 +347,18 @@ bool Binder::HasMatchingBinding(const string &schema_name, const string &table_n
338
347
  if (!binding) {
339
348
  return false;
340
349
  }
341
- if (!schema_name.empty()) {
350
+ if (!catalog_name.empty() || !schema_name.empty()) {
342
351
  auto catalog_entry = binding->GetStandardEntry();
343
352
  if (!catalog_entry) {
344
353
  return false;
345
354
  }
346
- if (catalog_entry->schema->name != schema_name || catalog_entry->name != table_name) {
355
+ if (!catalog_name.empty() && catalog_entry->catalog->GetName() != catalog_name) {
356
+ return false;
357
+ }
358
+ if (!schema_name.empty() && catalog_entry->schema->name != schema_name) {
359
+ return false;
360
+ }
361
+ if (catalog_entry->name != table_name) {
347
362
  return false;
348
363
  }
349
364
  }
@@ -282,9 +282,6 @@ unique_ptr<LogicalOperator> LogicalOperator::Deserialize(Deserializer &deseriali
282
282
  case LogicalOperatorType::LOGICAL_UPDATE:
283
283
  result = LogicalUpdate::Deserialize(state, reader);
284
284
  break;
285
- case LogicalOperatorType::LOGICAL_ALTER:
286
- result = LogicalSimple::Deserialize(state, reader);
287
- break;
288
285
  case LogicalOperatorType::LOGICAL_CREATE_TABLE:
289
286
  result = LogicalCreateTable::Deserialize(state, reader);
290
287
  break;
@@ -303,15 +300,9 @@ unique_ptr<LogicalOperator> LogicalOperator::Deserialize(Deserializer &deseriali
303
300
  case LogicalOperatorType::LOGICAL_CREATE_MACRO:
304
301
  result = LogicalCreate::Deserialize(state, reader);
305
302
  break;
306
- case LogicalOperatorType::LOGICAL_DROP:
307
- result = LogicalSimple::Deserialize(state, reader);
308
- break;
309
303
  case LogicalOperatorType::LOGICAL_PRAGMA:
310
304
  result = LogicalPragma::Deserialize(state, reader);
311
305
  break;
312
- case LogicalOperatorType::LOGICAL_TRANSACTION:
313
- result = LogicalSimple::Deserialize(state, reader);
314
- break;
315
306
  case LogicalOperatorType::LOGICAL_CREATE_TYPE:
316
307
  result = LogicalCreate::Deserialize(state, reader);
317
308
  break;
@@ -330,16 +321,18 @@ unique_ptr<LogicalOperator> LogicalOperator::Deserialize(Deserializer &deseriali
330
321
  case LogicalOperatorType::LOGICAL_EXPORT:
331
322
  result = LogicalExport::Deserialize(state, reader);
332
323
  break;
333
- case LogicalOperatorType::LOGICAL_VACUUM:
334
- result = LogicalSimple::Deserialize(state, reader);
335
- break;
336
324
  case LogicalOperatorType::LOGICAL_SET:
337
325
  result = LogicalSet::Deserialize(state, reader);
338
326
  break;
339
327
  case LogicalOperatorType::LOGICAL_RESET:
340
328
  result = LogicalReset::Deserialize(state, reader);
341
329
  break;
330
+ case LogicalOperatorType::LOGICAL_ALTER:
331
+ case LogicalOperatorType::LOGICAL_VACUUM:
342
332
  case LogicalOperatorType::LOGICAL_LOAD:
333
+ case LogicalOperatorType::LOGICAL_ATTACH:
334
+ case LogicalOperatorType::LOGICAL_TRANSACTION:
335
+ case LogicalOperatorType::LOGICAL_DROP:
343
336
  result = LogicalSimple::Deserialize(state, reader);
344
337
  break;
345
338
  case LogicalOperatorType::LOGICAL_EXTENSION_OPERATOR:
@@ -34,12 +34,11 @@ unique_ptr<LogicalOperator> LogicalCopyToFile::Deserialize(LogicalDeserializatio
34
34
  auto has_bind_data = reader.ReadRequired<bool>();
35
35
 
36
36
  auto &context = state.gstate.context;
37
- auto &catalog = Catalog::GetCatalog(context);
38
- auto func_catalog = catalog.GetEntry(context, CatalogType::COPY_FUNCTION_ENTRY, DEFAULT_SCHEMA, copy_func_name);
39
- if (!func_catalog || func_catalog->type != CatalogType::COPY_FUNCTION_ENTRY) {
37
+ auto copy_func_catalog_entry =
38
+ Catalog::GetEntry<CopyFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, copy_func_name);
39
+ if (!copy_func_catalog_entry) {
40
40
  throw InternalException("Cant find catalog entry for function %s", copy_func_name);
41
41
  }
42
- auto copy_func_catalog_entry = (CopyFunctionCatalogEntry *)func_catalog;
43
42
  CopyFunction copy_func = copy_func_catalog_entry->function;
44
43
 
45
44
  unique_ptr<FunctionData> bind_data;
@@ -10,10 +10,7 @@ unique_ptr<LogicalOperator> LogicalCreate::Deserialize(LogicalDeserializationSta
10
10
  auto &context = state.gstate.context;
11
11
  auto info = CreateInfo::Deserialize(reader.GetSource());
12
12
 
13
- auto &catalog = Catalog::GetCatalog(context);
14
- // TODO(stephwang): review if below is necessary or just not pass schema_catalog_entry
15
- SchemaCatalogEntry *schema_catalog_entry = catalog.GetSchema(context, info->schema, true);
16
-
13
+ auto schema_catalog_entry = Catalog::GetSchema(context, INVALID_CATALOG, info->schema, true);
17
14
  return make_unique<LogicalCreate>(state.type, move(info), schema_catalog_entry);
18
15
  }
19
16
 
@@ -20,9 +20,9 @@ unique_ptr<LogicalOperator> LogicalCreateIndex::Deserialize(LogicalDeserializati
20
20
 
21
21
  auto &context = state.gstate.context;
22
22
  auto catalog_info = TableCatalogEntry::Deserialize(reader.GetSource(), context);
23
- auto &catalog = Catalog::GetCatalog(context);
24
- TableCatalogEntry *table = catalog.GetEntry<TableCatalogEntry>(context, catalog_info->schema, catalog_info->table);
25
23
 
24
+ auto table =
25
+ Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, catalog_info->schema, catalog_info->table);
26
26
  auto unbound_expressions = reader.ReadRequiredSerializableList<Expression>(state.gstate);
27
27
 
28
28
  auto create_info = reader.ReadOptional<CreateInfo>(nullptr);
@@ -13,9 +13,8 @@ unique_ptr<LogicalOperator> LogicalDelete::Deserialize(LogicalDeserializationSta
13
13
  auto &context = state.gstate.context;
14
14
  auto info = TableCatalogEntry::Deserialize(reader.GetSource(), context);
15
15
 
16
- auto &catalog = Catalog::GetCatalog(context);
17
-
18
- TableCatalogEntry *table_catalog_entry = catalog.GetEntry<TableCatalogEntry>(context, info->schema, info->table);
16
+ auto table_catalog_entry =
17
+ Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, info->schema, info->table);
19
18
 
20
19
  auto table_index = reader.ReadRequired<idx_t>();
21
20
  auto result = make_unique<LogicalDelete>(table_catalog_entry, table_index);
@@ -34,7 +34,7 @@ unique_ptr<LogicalOperator> LogicalInsert::Deserialize(LogicalDeserializationSta
34
34
  auto return_chunk = reader.ReadRequired<bool>();
35
35
  auto bound_defaults = reader.ReadRequiredSerializableList<Expression>(state.gstate);
36
36
 
37
- auto &catalog = Catalog::GetCatalog(context);
37
+ auto &catalog = Catalog::GetCatalog(context, INVALID_CATALOG);
38
38
 
39
39
  TableCatalogEntry *table_catalog_entry = catalog.GetEntry<TableCatalogEntry>(context, info->schema, info->table);
40
40
 
@@ -17,7 +17,7 @@ void LogicalUpdate::Serialize(FieldWriter &writer) const {
17
17
  unique_ptr<LogicalOperator> LogicalUpdate::Deserialize(LogicalDeserializationState &state, FieldReader &reader) {
18
18
  auto &context = state.gstate.context;
19
19
  auto info = TableCatalogEntry::Deserialize(reader.GetSource(), context);
20
- auto &catalog = Catalog::GetCatalog(context);
20
+ auto &catalog = Catalog::GetCatalog(context, INVALID_CATALOG);
21
21
 
22
22
  TableCatalogEntry *table_catalog_entry = catalog.GetEntry<TableCatalogEntry>(context, info->schema, info->table);
23
23
 
@@ -39,7 +39,7 @@ unique_ptr<BoundCreateTableInfo> BoundCreateTableInfo::Deserialize(Deserializer
39
39
  auto schema_name = create_info->schema;
40
40
  auto result = make_unique<BoundCreateTableInfo>(move(create_info));
41
41
  auto &context = state.context;
42
- result->schema = Catalog::GetCatalog(context).GetSchema(context, schema_name);
42
+ result->schema = Catalog::GetSchema(context, INVALID_CATALOG, schema_name);
43
43
  result->base = source.ReadOptional<CreateInfo>();
44
44
 
45
45
  source.ReadList<Constraint>(result->constraints);
@@ -8,8 +8,8 @@
8
8
  #include "duckdb/planner/binder.hpp"
9
9
  #include "duckdb/planner/expression/bound_parameter_expression.hpp"
10
10
  #include "duckdb/execution/expression_executor.hpp"
11
- #include "duckdb/transaction/transaction.hpp"
12
11
  #include "duckdb/common/serializer/buffered_deserializer.hpp"
12
+ #include "duckdb/transaction/meta_transaction.hpp"
13
13
 
14
14
  namespace duckdb {
15
15
 
@@ -103,7 +103,7 @@ shared_ptr<PreparedStatementData> Planner::PrepareSQLStatement(unique_ptr<SQLSta
103
103
  prepared_data->types = types;
104
104
  prepared_data->value_map = move(value_map);
105
105
  prepared_data->properties = properties;
106
- prepared_data->catalog_version = Transaction::GetTransaction(context).catalog_version;
106
+ prepared_data->catalog_version = MetaTransaction::Get(context).catalog_version;
107
107
  return prepared_data;
108
108
  }
109
109
 
@@ -132,6 +132,7 @@ void Planner::CreatePlan(unique_ptr<SQLStatement> statement) {
132
132
  case StatementType::PREPARE_STATEMENT:
133
133
  case StatementType::EXECUTE_STATEMENT:
134
134
  case StatementType::LOGICAL_PLAN_STATEMENT:
135
+ case StatementType::ATTACH_STATEMENT:
135
136
  CreatePlan(*statement);
136
137
  break;
137
138
  default:
@@ -62,7 +62,7 @@ void PragmaHandler::HandlePragmaStatements(ClientContextLock &lock, vector<uniqu
62
62
  string PragmaHandler::HandlePragma(SQLStatement *statement) { // PragmaInfo &info
63
63
  auto info = *((PragmaStatement &)*statement).info;
64
64
  auto entry =
65
- Catalog::GetCatalog(context).GetEntry<PragmaFunctionCatalogEntry>(context, DEFAULT_SCHEMA, info.name, false);
65
+ Catalog::GetEntry<PragmaFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, info.name, false);
66
66
  string error;
67
67
 
68
68
  FunctionBinder function_binder(context);
@@ -6,6 +6,7 @@
6
6
  #include "duckdb/parallel/concurrentqueue.hpp"
7
7
  #include "duckdb/storage/in_memory_block_manager.hpp"
8
8
  #include "duckdb/storage/storage_manager.hpp"
9
+ #include "duckdb/main/attached_database.hpp"
9
10
 
10
11
  namespace duckdb {
11
12
 
@@ -1017,6 +1018,10 @@ Allocator &BufferAllocator::Get(DatabaseInstance &db) {
1017
1018
  return BufferManager::GetBufferManager(db).GetBufferAllocator();
1018
1019
  }
1019
1020
 
1021
+ Allocator &BufferAllocator::Get(AttachedDatabase &db) {
1022
+ return BufferAllocator::Get(db.GetDatabase());
1023
+ }
1024
+
1020
1025
  Allocator &BufferManager::GetBufferAllocator() {
1021
1026
  return buffer_allocator;
1022
1027
  }
@@ -30,11 +30,16 @@
30
30
  #include "duckdb/storage/meta_block_reader.hpp"
31
31
  #include "duckdb/storage/table/column_checkpoint_state.hpp"
32
32
  #include "duckdb/transaction/transaction_manager.hpp"
33
+ #include "duckdb/main/attached_database.hpp"
33
34
 
34
35
  namespace duckdb {
35
36
 
36
37
  void ReorderTableEntries(vector<TableCatalogEntry *> &tables);
37
38
 
39
+ SingleFileCheckpointWriter::SingleFileCheckpointWriter(AttachedDatabase &db, BlockManager &block_manager)
40
+ : CheckpointWriter(db), partial_block_manager(block_manager) {
41
+ }
42
+
38
43
  BlockManager &SingleFileCheckpointWriter::GetBlockManager() {
39
44
  auto &storage_manager = (SingleFileStorageManager &)db.GetStorageManager();
40
45
  return *storage_manager.block_manager;
@@ -49,7 +54,7 @@ unique_ptr<TableDataWriter> SingleFileCheckpointWriter::GetTableDataWriter(Table
49
54
  }
50
55
 
51
56
  void SingleFileCheckpointWriter::CreateCheckpoint() {
52
- auto &config = DBConfig::GetConfig(db);
57
+ auto &config = DBConfig::Get(db);
53
58
  auto &storage_manager = (SingleFileStorageManager &)db.GetStorageManager();
54
59
  if (storage_manager.InMemory()) {
55
60
  return;
@@ -68,7 +73,6 @@ void SingleFileCheckpointWriter::CreateCheckpoint() {
68
73
 
69
74
  vector<SchemaCatalogEntry *> schemas;
70
75
  // we scan the set of committed schemas
71
- auto &catalog = Catalog::GetCatalog(db);
72
76
  catalog.schemas->Scan([&](CatalogEntry *entry) { schemas.push_back((SchemaCatalogEntry *)entry); });
73
77
  // write the actual data into the database
74
78
  // write the amount of schemas
@@ -119,7 +123,7 @@ void SingleFileCheckpointReader::LoadFromStorage() {
119
123
  return;
120
124
  }
121
125
 
122
- Connection con(storage.db);
126
+ Connection con(storage.GetDatabase());
123
127
  con.BeginTransaction();
124
128
  // create the MetaBlockReader to read from the storage
125
129
  MetaBlockReader reader(block_manager, meta_block);
@@ -243,8 +247,6 @@ void CheckpointWriter::WriteSchema(SchemaCatalogEntry &schema) {
243
247
  }
244
248
 
245
249
  void CheckpointReader::ReadSchema(ClientContext &context, MetaBlockReader &reader) {
246
- auto &catalog = Catalog::GetCatalog(context);
247
-
248
250
  // read the schema and create it in the catalog
249
251
  auto info = SchemaCatalogEntry::Deserialize(reader);
250
252
  // we set create conflict to ignore to ignore the failure of recreating the main schema
@@ -302,8 +304,6 @@ void CheckpointWriter::WriteView(ViewCatalogEntry &view) {
302
304
 
303
305
  void CheckpointReader::ReadView(ClientContext &context, MetaBlockReader &reader) {
304
306
  auto info = ViewCatalogEntry::Deserialize(reader, context);
305
-
306
- auto &catalog = Catalog::GetCatalog(context);
307
307
  catalog.CreateView(context, info.get());
308
308
  }
309
309
 
@@ -316,8 +316,6 @@ void CheckpointWriter::WriteSequence(SequenceCatalogEntry &seq) {
316
316
 
317
317
  void CheckpointReader::ReadSequence(ClientContext &context, MetaBlockReader &reader) {
318
318
  auto info = SequenceCatalogEntry::Deserialize(reader);
319
-
320
- auto &catalog = Catalog::GetCatalog(context);
321
319
  catalog.CreateSequence(context, info.get());
322
320
  }
323
321
 
@@ -341,7 +339,6 @@ void CheckpointReader::ReadIndex(ClientContext &context, MetaBlockReader &reader
341
339
  auto info = IndexCatalogEntry::Deserialize(reader, context);
342
340
 
343
341
  // Create index in the catalog
344
- auto &catalog = Catalog::GetCatalog(context);
345
342
  auto schema_catalog = catalog.GetSchema(context, info->schema);
346
343
  auto table_catalog =
347
344
  (TableCatalogEntry *)catalog.GetEntry(context, CatalogType::TABLE_ENTRY, info->schema, info->table->table_name);
@@ -384,7 +381,7 @@ void CheckpointReader::ReadIndex(ClientContext &context, MetaBlockReader &reader
384
381
  case IndexType::ART: {
385
382
  auto art =
386
383
  make_unique<ART>(info->column_ids, TableIOManager::Get(*table_catalog->storage), move(unbound_expressions),
387
- info->constraint_type, *context.db, root_block_id, root_offset);
384
+ info->constraint_type, table_catalog->storage->db, root_block_id, root_offset);
388
385
  index_catalog->index = art.get();
389
386
  table_catalog->storage->info->indexes.AddIndex(move(art));
390
387
  break;
@@ -403,8 +400,6 @@ void CheckpointWriter::WriteType(TypeCatalogEntry &table) {
403
400
 
404
401
  void CheckpointReader::ReadType(ClientContext &context, MetaBlockReader &reader) {
405
402
  auto info = TypeCatalogEntry::Deserialize(reader);
406
-
407
- auto &catalog = Catalog::GetCatalog(context);
408
403
  catalog.CreateType(context, info.get());
409
404
  }
410
405
 
@@ -417,7 +412,6 @@ void CheckpointWriter::WriteMacro(ScalarMacroCatalogEntry &macro) {
417
412
 
418
413
  void CheckpointReader::ReadMacro(ClientContext &context, MetaBlockReader &reader) {
419
414
  auto info = ScalarMacroCatalogEntry::Deserialize(reader, context);
420
- auto &catalog = Catalog::GetCatalog(context);
421
415
  catalog.CreateFunction(context, info.get());
422
416
  }
423
417
 
@@ -427,7 +421,6 @@ void CheckpointWriter::WriteTableMacro(TableMacroCatalogEntry &macro) {
427
421
 
428
422
  void CheckpointReader::ReadTableMacro(ClientContext &context, MetaBlockReader &reader) {
429
423
  auto info = TableMacroCatalogEntry::Deserialize(reader, context);
430
- auto &catalog = Catalog::GetCatalog(context);
431
424
  catalog.CreateFunction(context, info.get());
432
425
  }
433
426
 
@@ -448,13 +441,13 @@ void CheckpointReader::ReadTable(ClientContext &context, MetaBlockReader &reader
448
441
  auto info = TableCatalogEntry::Deserialize(reader, context);
449
442
  // bind the info
450
443
  auto binder = Binder::CreateBinder(context);
451
- auto bound_info = binder->BindCreateTableInfo(move(info));
444
+ auto schema = catalog.GetSchema(context, info->schema);
445
+ auto bound_info = binder->BindCreateTableInfo(move(info), schema);
452
446
 
453
447
  // now read the actual table data and place it into the create table info
454
448
  ReadTableData(context, reader, *bound_info);
455
449
 
456
450
  // finally create the table in the catalog
457
- auto &catalog = Catalog::GetCatalog(context);
458
451
  catalog.CreateTable(context, bound_info.get());
459
452
  }
460
453