duckdb 0.7.1-dev2.0 → 0.7.1-dev284.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 (140) hide show
  1. package/binding.gyp +7 -7
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/json/buffered_json_reader.cpp +50 -9
  4. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +7 -2
  5. package/src/duckdb/extension/json/include/json_common.hpp +2 -2
  6. package/src/duckdb/extension/json/include/json_scan.hpp +29 -10
  7. package/src/duckdb/extension/json/json_functions/copy_json.cpp +35 -22
  8. package/src/duckdb/extension/json/json_functions/json_create.cpp +8 -8
  9. package/src/duckdb/extension/json/json_functions/json_transform.cpp +47 -8
  10. package/src/duckdb/extension/json/json_functions/read_json.cpp +104 -49
  11. package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +5 -3
  12. package/src/duckdb/extension/json/json_functions.cpp +6 -0
  13. package/src/duckdb/extension/json/json_scan.cpp +144 -34
  14. package/src/duckdb/extension/parquet/parquet-extension.cpp +3 -2
  15. package/src/duckdb/src/catalog/catalog.cpp +15 -0
  16. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +8 -7
  17. package/src/duckdb/src/common/enums/logical_operator_type.cpp +2 -0
  18. package/src/duckdb/src/common/enums/physical_operator_type.cpp +2 -0
  19. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  20. package/src/duckdb/src/common/file_system.cpp +14 -0
  21. package/src/duckdb/src/common/hive_partitioning.cpp +1 -0
  22. package/src/duckdb/src/common/operator/cast_operators.cpp +14 -8
  23. package/src/duckdb/src/common/printer.cpp +1 -1
  24. package/src/duckdb/src/common/types/time.cpp +1 -1
  25. package/src/duckdb/src/common/types/timestamp.cpp +35 -4
  26. package/src/duckdb/src/common/types.cpp +36 -10
  27. package/src/duckdb/src/execution/column_binding_resolver.cpp +5 -2
  28. package/src/duckdb/src/execution/index/art/art.cpp +117 -67
  29. package/src/duckdb/src/execution/index/art/art_key.cpp +24 -12
  30. package/src/duckdb/src/execution/index/art/leaf.cpp +7 -8
  31. package/src/duckdb/src/execution/index/art/node.cpp +13 -27
  32. package/src/duckdb/src/execution/index/art/node16.cpp +5 -8
  33. package/src/duckdb/src/execution/index/art/node256.cpp +3 -5
  34. package/src/duckdb/src/execution/index/art/node4.cpp +4 -7
  35. package/src/duckdb/src/execution/index/art/node48.cpp +5 -8
  36. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -3
  37. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +7 -9
  38. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +6 -11
  39. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +13 -13
  40. package/src/duckdb/src/execution/operator/persistent/parallel_csv_reader.cpp +1 -1
  41. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +37 -0
  42. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +0 -5
  43. package/src/duckdb/src/execution/physical_plan/plan_simple.cpp +4 -0
  44. package/src/duckdb/src/execution/physical_plan_generator.cpp +1 -0
  45. package/src/duckdb/src/function/pragma/pragma_queries.cpp +38 -11
  46. package/src/duckdb/src/function/table/read_csv.cpp +17 -5
  47. package/src/duckdb/src/function/table/table_scan.cpp +3 -0
  48. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  49. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +5 -1
  50. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  51. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  52. package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +1 -0
  53. package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +1 -0
  54. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +3 -2
  55. package/src/duckdb/src/include/duckdb/common/enums/wal_type.hpp +3 -0
  56. package/src/duckdb/src/include/duckdb/common/exception.hpp +10 -0
  57. package/src/duckdb/src/include/duckdb/common/file_system.hpp +1 -0
  58. package/src/duckdb/src/include/duckdb/common/hive_partitioning.hpp +9 -1
  59. package/src/duckdb/src/include/duckdb/common/radix_partitioning.hpp +4 -4
  60. package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +5 -1
  61. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +37 -41
  62. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +8 -11
  63. package/src/duckdb/src/include/duckdb/execution/operator/persistent/base_csv_reader.hpp +1 -3
  64. package/src/duckdb/src/include/duckdb/execution/operator/persistent/buffered_csv_reader.hpp +0 -2
  65. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -0
  66. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_detach.hpp +32 -0
  67. package/src/duckdb/src/include/duckdb/main/client_data.hpp +2 -2
  68. package/src/duckdb/src/include/duckdb/main/config.hpp +0 -3
  69. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -4
  70. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +32 -0
  71. package/src/duckdb/src/include/duckdb/parser/query_node/select_node.hpp +1 -1
  72. package/src/duckdb/src/include/duckdb/parser/sql_statement.hpp +2 -2
  73. package/src/duckdb/src/include/duckdb/parser/statement/copy_statement.hpp +1 -1
  74. package/src/duckdb/src/include/duckdb/parser/statement/detach_statement.hpp +29 -0
  75. package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -0
  76. package/src/duckdb/src/include/duckdb/parser/statement/select_statement.hpp +3 -3
  77. package/src/duckdb/src/include/duckdb/parser/tableref/subqueryref.hpp +1 -1
  78. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +1 -0
  79. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +1 -0
  80. package/src/duckdb/src/include/duckdb/planner/binder.hpp +4 -0
  81. package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +10 -3
  82. package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +1 -5
  83. package/src/duckdb/src/include/duckdb/planner/operator/logical_show.hpp +1 -2
  84. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +7 -1
  85. package/src/duckdb/src/include/duckdb/storage/index.hpp +47 -38
  86. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +7 -0
  87. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +2 -0
  88. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +7 -0
  89. package/src/duckdb/src/main/client_context.cpp +2 -0
  90. package/src/duckdb/src/main/extension/extension_alias.cpp +2 -1
  91. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +2 -6
  92. package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +3 -0
  93. package/src/duckdb/src/parser/statement/copy_statement.cpp +2 -13
  94. package/src/duckdb/src/parser/statement/delete_statement.cpp +3 -0
  95. package/src/duckdb/src/parser/statement/detach_statement.cpp +15 -0
  96. package/src/duckdb/src/parser/statement/insert_statement.cpp +9 -0
  97. package/src/duckdb/src/parser/statement/update_statement.cpp +3 -0
  98. package/src/duckdb/src/parser/transform/expression/transform_case.cpp +3 -3
  99. package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -1
  100. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +19 -0
  101. package/src/duckdb/src/parser/transformer.cpp +2 -0
  102. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +3 -0
  103. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +6 -3
  104. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +16 -14
  105. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +13 -0
  106. package/src/duckdb/src/planner/binder/statement/bind_detach.cpp +19 -0
  107. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +29 -4
  108. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +22 -1
  109. package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +2 -1
  110. package/src/duckdb/src/planner/binder.cpp +2 -0
  111. package/src/duckdb/src/planner/expression_binder/index_binder.cpp +32 -1
  112. package/src/duckdb/src/planner/expression_binder/lateral_binder.cpp +21 -5
  113. package/src/duckdb/src/planner/logical_operator.cpp +4 -0
  114. package/src/duckdb/src/planner/planner.cpp +1 -0
  115. package/src/duckdb/src/storage/compression/bitpacking.cpp +16 -7
  116. package/src/duckdb/src/storage/data_table.cpp +66 -3
  117. package/src/duckdb/src/storage/index.cpp +1 -1
  118. package/src/duckdb/src/storage/local_storage.cpp +1 -1
  119. package/src/duckdb/src/storage/storage_info.cpp +2 -1
  120. package/src/duckdb/src/storage/table/column_data.cpp +4 -2
  121. package/src/duckdb/src/storage/table/update_segment.cpp +15 -0
  122. package/src/duckdb/src/storage/table_index_list.cpp +1 -2
  123. package/src/duckdb/src/storage/wal_replay.cpp +68 -0
  124. package/src/duckdb/src/storage/write_ahead_log.cpp +21 -1
  125. package/src/duckdb/src/transaction/commit_state.cpp +5 -2
  126. package/src/duckdb/third_party/fmt/include/fmt/core.h +1 -2
  127. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +1 -0
  128. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +14 -0
  129. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +530 -1006
  130. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +17659 -17626
  131. package/src/duckdb/third_party/thrift/thrift/Thrift.h +8 -2
  132. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  133. package/src/duckdb/ub_src_execution_operator_schema.cpp +2 -0
  134. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  135. package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
  136. package/src/duckdb/ub_src_planner_binder_statement.cpp +2 -0
  137. package/src/statement.cpp +46 -12
  138. package/test/prepare.test.ts +39 -1
  139. package/test/typescript_decls.test.ts +1 -1
  140. package/src/duckdb/src/include/duckdb/function/create_database_extension.hpp +0 -37
@@ -28,7 +28,7 @@ protected:
28
28
  CopyStatement(const CopyStatement &other);
29
29
 
30
30
  public:
31
- unique_ptr<SQLStatement> Copy() const override;
31
+ DUCKDB_API unique_ptr<SQLStatement> Copy() const override;
32
32
 
33
33
  private:
34
34
  };
@@ -0,0 +1,29 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/parser/statement/detach_statement.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/parser/parsed_data/detach_info.hpp"
12
+ #include "duckdb/parser/sql_statement.hpp"
13
+
14
+ namespace duckdb {
15
+
16
+ class DetachStatement : public SQLStatement {
17
+ public:
18
+ DetachStatement();
19
+
20
+ unique_ptr<DetachInfo> info;
21
+
22
+ protected:
23
+ DetachStatement(const DetachStatement &other);
24
+
25
+ public:
26
+ unique_ptr<SQLStatement> Copy() const override;
27
+ };
28
+
29
+ } // namespace duckdb
@@ -4,6 +4,7 @@
4
4
  #include "duckdb/parser/statement/copy_statement.hpp"
5
5
  #include "duckdb/parser/statement/create_statement.hpp"
6
6
  #include "duckdb/parser/statement/delete_statement.hpp"
7
+ #include "duckdb/parser/statement/detach_statement.hpp"
7
8
  #include "duckdb/parser/statement/drop_statement.hpp"
8
9
  #include "duckdb/parser/statement/execute_statement.hpp"
9
10
  #include "duckdb/parser/statement/explain_statement.hpp"
@@ -21,7 +21,7 @@ class QueryNode;
21
21
  //! SelectStatement is a typical SELECT clause
22
22
  class SelectStatement : public SQLStatement {
23
23
  public:
24
- SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
24
+ DUCKDB_API SelectStatement() : SQLStatement(StatementType::SELECT_STATEMENT) {
25
25
  }
26
26
 
27
27
  //! The main query node
@@ -32,9 +32,9 @@ protected:
32
32
 
33
33
  public:
34
34
  //! Convert the SELECT statement to a string
35
- string ToString() const override;
35
+ DUCKDB_API string ToString() const override;
36
36
  //! Create a copy of this SelectStatement
37
- unique_ptr<SQLStatement> Copy() const override;
37
+ DUCKDB_API unique_ptr<SQLStatement> Copy() const override;
38
38
  //! Serializes a SelectStatement to a stand-alone binary blob
39
39
  void Serialize(Serializer &serializer) const;
40
40
  //! Deserializes a blob back into a SelectStatement, returns nullptr if
@@ -15,7 +15,7 @@ namespace duckdb {
15
15
  //! Represents a subquery
16
16
  class SubqueryRef : public TableRef {
17
17
  public:
18
- explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
18
+ DUCKDB_API explicit SubqueryRef(unique_ptr<SelectStatement> subquery, string alias = string());
19
19
 
20
20
  //! The subquery
21
21
  unique_ptr<SelectStatement> subquery;
@@ -20,6 +20,7 @@ class AttachStatement;
20
20
  class CallStatement;
21
21
  class CopyStatement;
22
22
  class CreateStatement;
23
+ class DetachStatement;
23
24
  class DeleteStatement;
24
25
  class DropStatement;
25
26
  class ExtensionStatement;
@@ -156,6 +156,7 @@ private:
156
156
  unique_ptr<SQLStatement> TransformShow(duckdb_libpgquery::PGNode *node);
157
157
  unique_ptr<ShowStatement> TransformShowSelect(duckdb_libpgquery::PGNode *node);
158
158
  unique_ptr<AttachStatement> TransformAttach(duckdb_libpgquery::PGNode *node);
159
+ unique_ptr<DetachStatement> TransformDetach(duckdb_libpgquery::PGNode *node);
159
160
  unique_ptr<SetStatement> TransformUse(duckdb_libpgquery::PGNode *node);
160
161
 
161
162
  unique_ptr<PrepareStatement> TransformPrepare(duckdb_libpgquery::PGNode *node);
@@ -108,6 +108,9 @@ public:
108
108
 
109
109
  unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info);
110
110
  unique_ptr<BoundCreateTableInfo> BindCreateTableInfo(unique_ptr<CreateInfo> info, SchemaCatalogEntry *schema);
111
+
112
+ vector<unique_ptr<Expression>> BindCreateIndexExpressions(TableCatalogEntry *table, CreateIndexInfo *info);
113
+
111
114
  void BindCreateViewInfo(CreateViewInfo &base);
112
115
  SchemaCatalogEntry *BindSchema(CreateInfo &info);
113
116
  SchemaCatalogEntry *BindCreateFunctionInfo(CreateInfo &info);
@@ -247,6 +250,7 @@ private:
247
250
  BoundStatement Bind(LoadStatement &stmt);
248
251
  BoundStatement Bind(LogicalPlanStatement &stmt);
249
252
  BoundStatement Bind(AttachStatement &stmt);
253
+ BoundStatement Bind(DetachStatement &stmt);
250
254
 
251
255
  BoundStatement BindReturning(vector<unique_ptr<ParsedExpression>> returning_list, TableCatalogEntry *table,
252
256
  idx_t update_table_index, unique_ptr<LogicalOperator> child_operator,
@@ -10,20 +10,27 @@
10
10
 
11
11
  #include "duckdb/planner/expression_binder.hpp"
12
12
  #include "duckdb/common/unordered_map.hpp"
13
+ #include "duckdb/parser/parsed_data/create_index_info.hpp"
14
+ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
13
15
 
14
16
  namespace duckdb {
15
17
  class BoundColumnRefExpression;
16
18
 
17
- //! The INDEX binder is responsible for binding an expression within an Index statement
19
+ //! The IndexBinder is responsible for binding an expression within an index statement
18
20
  class IndexBinder : public ExpressionBinder {
19
21
  public:
20
- IndexBinder(Binder &binder, ClientContext &context);
22
+ IndexBinder(Binder &binder, ClientContext &context, TableCatalogEntry *table = nullptr,
23
+ CreateIndexInfo *info = nullptr);
21
24
 
22
25
  protected:
23
26
  BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth,
24
27
  bool root_expression = false) override;
25
-
26
28
  string UnsupportedAggregateMessage() override;
29
+
30
+ private:
31
+ // only for WAL replay
32
+ TableCatalogEntry *table;
33
+ CreateIndexInfo *info;
27
34
  };
28
35
 
29
36
  } // namespace duckdb
@@ -32,11 +32,7 @@ protected:
32
32
  // already resolved
33
33
  }
34
34
  vector<ColumnBinding> GetColumnBindings() override {
35
- vector<ColumnBinding> bindings;
36
- for (idx_t i = 0; i < types.size(); i++) {
37
- bindings.push_back(ColumnBinding(0, i));
38
- }
39
- return bindings;
35
+ return GenerateColumnBindings(0, types.size());
40
36
  }
41
37
  };
42
38
  } // namespace duckdb
@@ -33,8 +33,7 @@ protected:
33
33
  LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR};
34
34
  }
35
35
  vector<ColumnBinding> GetColumnBindings() override {
36
- return {ColumnBinding(0, 0), ColumnBinding(0, 1), ColumnBinding(0, 2),
37
- ColumnBinding(0, 3), ColumnBinding(0, 4), ColumnBinding(0, 5)};
36
+ return GenerateColumnBindings(0, types.size());
38
37
  }
39
38
  };
40
39
  } // namespace duckdb
@@ -122,6 +122,12 @@ public:
122
122
  void UpdateColumn(TableCatalogEntry &table, ClientContext &context, Vector &row_ids,
123
123
  const vector<column_t> &column_path, DataChunk &updates);
124
124
 
125
+ //! Add an index to the DataTable. NOTE: for CREATE (UNIQUE) INDEX statements, we use the PhysicalCreateIndex
126
+ //! operator. This function is only used during the WAL replay, and is a much less performant index creation
127
+ //! approach.
128
+ void WALAddIndex(ClientContext &context, unique_ptr<Index> index,
129
+ const vector<unique_ptr<Expression>> &expressions);
130
+
125
131
  //! Fetches an append lock
126
132
  void AppendLock(TableAppendState &state);
127
133
  //! Begin appending structs to this table, obtaining necessary locks, etc
@@ -176,7 +182,7 @@ public:
176
182
  static bool IsForeignKeyIndex(const vector<PhysicalIndex> &fk_keys, Index &index, ForeignKeyType fk_type);
177
183
 
178
184
  //! Initializes a special scan that is used to create an index on the table, it keeps locks on the table
179
- void InitializeCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
185
+ void InitializeWALCreateIndexScan(CreateIndexScanState &state, const vector<column_t> &column_ids);
180
186
  //! Scans the next chunk for the CREATE INDEX operator
181
187
  bool CreateIndexScan(TableScanState &state, DataChunk &result, TableScanType type);
182
188
 
@@ -40,11 +40,11 @@ public:
40
40
  IndexType type;
41
41
  //! Associated table io manager
42
42
  TableIOManager &table_io_manager;
43
- //! Column identifiers to extract from the base table
43
+ //! Column identifiers to extract key columns from the base table
44
44
  vector<column_t> column_ids;
45
- //! Unordered_set of column_ids used by the index
45
+ //! Unordered set of column_ids used by the index
46
46
  unordered_set<column_t> column_id_set;
47
- //! Unbound expressions used by the index
47
+ //! Unbound expressions used by the index during optimizations
48
48
  vector<unique_ptr<Expression>> unbound_expressions;
49
49
  //! The physical types stored in the index
50
50
  vector<PhysicalType> types;
@@ -64,94 +64,103 @@ public:
64
64
  bool track_memory;
65
65
 
66
66
  public:
67
- //! Initialize a scan on the index with the given expression and column ids
68
- //! to fetch from the base table when we only have one query predicate
67
+ //! Initialize a single predicate scan on the index with the given expression and column IDs
69
68
  virtual unique_ptr<IndexScanState> InitializeScanSinglePredicate(const Transaction &transaction, const Value &value,
70
69
  ExpressionType expressionType) = 0;
71
- //! Initialize a scan on the index with the given expression and column ids
72
- //! to fetch from the base table for two query predicates
70
+ //! Initialize a two predicate scan on the index with the given expression and column IDs
73
71
  virtual unique_ptr<IndexScanState> InitializeScanTwoPredicates(Transaction &transaction, const Value &low_value,
74
72
  ExpressionType low_expression_type,
75
73
  const Value &high_value,
76
74
  ExpressionType high_expression_type) = 0;
77
- //! Perform a lookup on the index, fetching up to max_count result ids. Returns true if all row ids were fetched,
78
- //! and false otherwise.
75
+ //! Performs a lookup on the index, fetching up to max_count result IDs. Returns true if all row IDs were fetched,
76
+ //! and false otherwise
79
77
  virtual bool Scan(Transaction &transaction, DataTable &table, IndexScanState &state, idx_t max_count,
80
78
  vector<row_t> &result_ids) = 0;
81
79
 
82
80
  //! Obtain a lock on the index
83
81
  virtual void InitializeLock(IndexLock &state);
84
- //! Called when data is appended to the index. The lock obtained from InitializeAppend must be held
82
+ //! Called when data is appended to the index. The lock obtained from InitializeLock must be held
85
83
  virtual bool Append(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
84
+ //! Obtains a lock and calls Append while holding that lock
86
85
  bool Append(DataChunk &entries, Vector &row_identifiers);
87
- //! Verify that data can be appended to the index
86
+ //! Verify that data can be appended to the index without a constraint violation
88
87
  virtual void VerifyAppend(DataChunk &chunk) = 0;
89
- //! Verify that data can be appended to the index
88
+ //! Verify that data can be appended to the index without a constraint violation using the conflict manager
90
89
  virtual void VerifyAppend(DataChunk &chunk, ConflictManager &conflict_manager) = 0;
91
- //! Verify that data can be appended to the index for foreign key constraint
92
- virtual void VerifyAppendForeignKey(DataChunk &chunk) = 0;
93
- //! Verify that data can be delete from the index for foreign key constraint
94
- virtual void VerifyDeleteForeignKey(DataChunk &chunk) = 0;
90
+ //! Performs constraint checking for a chunk of input data
91
+ virtual void CheckConstraintsForChunk(DataChunk &input, ConflictManager &conflict_manager) = 0;
95
92
 
96
- //! Called when data inside the index is Deleted
93
+ //! Delete a chunk of entries from the index. The lock obtained from InitializeLock must be held
97
94
  virtual void Delete(IndexLock &state, DataChunk &entries, Vector &row_identifiers) = 0;
95
+ //! Obtains a lock and calls Delete while holding that lock
98
96
  void Delete(DataChunk &entries, Vector &row_identifiers);
99
97
 
100
- //! Insert data into the index. Does not lock the index.
98
+ //! Insert a chunk of entries into the index
101
99
  virtual bool Insert(IndexLock &lock, DataChunk &input, Vector &row_identifiers) = 0;
102
100
 
103
- //! Merge other_index into this index.
101
+ //! Merge another index into this index. The lock obtained from InitializeLock must be held, and the other
102
+ //! index must also be locked during the merge
104
103
  virtual bool MergeIndexes(IndexLock &state, Index *other_index) = 0;
104
+ //! Obtains a lock and calls MergeIndexes while holding that lock
105
105
  bool MergeIndexes(Index *other_index);
106
106
 
107
107
  //! Returns the string representation of an index
108
108
  virtual string ToString() = 0;
109
- //! Verifies that the memory_size value of the index matches its actual size
109
+ //! Verifies that the in-memory size value of the index matches its actual size
110
110
  virtual void Verify() = 0;
111
-
112
- //! Returns true if the index is affected by updates on the specified column ids, and false otherwise
111
+ //! Increases the memory size by the difference between the old size and the current size
112
+ //! and performs verifications
113
+ virtual void IncreaseAndVerifyMemorySize(idx_t old_memory_size) = 0;
114
+
115
+ //! Increases the in-memory size value
116
+ inline void IncreaseMemorySize(idx_t size) {
117
+ memory_size += size;
118
+ };
119
+ //! Decreases the in-memory size value
120
+ inline void DecreaseMemorySize(idx_t size) {
121
+ D_ASSERT(memory_size >= size);
122
+ memory_size -= size;
123
+ };
124
+
125
+ //! Returns true if the index is affected by updates on the specified column IDs, and false otherwise
113
126
  bool IndexIsUpdated(const vector<PhysicalIndex> &column_ids) const;
114
127
 
115
- //! Returns how many of the input values were found in the 'input' chunk, with the option to also record what those
116
- //! matches were. For this purpose, nulls count as a match, and are returned in 'null_count'
117
- virtual void LookupValues(DataChunk &input, ConflictManager &conflict_manager) = 0;
118
-
119
128
  //! Returns unique flag
120
129
  bool IsUnique() {
121
130
  return (constraint_type == IndexConstraintType::UNIQUE || constraint_type == IndexConstraintType::PRIMARY);
122
131
  }
123
- //! Returns primary flag
132
+ //! Returns primary key flag
124
133
  bool IsPrimary() {
125
134
  return (constraint_type == IndexConstraintType::PRIMARY);
126
135
  }
127
- //! Returns foreign flag
136
+ //! Returns foreign key flag
128
137
  bool IsForeign() {
129
138
  return (constraint_type == IndexConstraintType::FOREIGN);
130
139
  }
131
- //! Serializes the index and returns the pair of block_id offset positions
132
- virtual BlockPointer Serialize(duckdb::MetaBlockWriter &writer);
133
- BlockPointer GetBlockPointer();
134
140
 
135
- //! Returns block/offset of where index was most recently serialized.
141
+ //! Serializes the index and returns the pair of block_id offset positions
142
+ virtual BlockPointer Serialize(MetaBlockWriter &writer);
143
+ //! Returns the serialized data pointer to the block and offset of the serialized index
136
144
  BlockPointer GetSerializedDataPointer() const {
137
145
  return serialized_data_pointer;
138
146
  }
139
147
 
140
- protected:
148
+ //! Execute the index expressions on an input chunk
141
149
  void ExecuteExpressions(DataChunk &input, DataChunk &result);
142
150
 
143
- //! Lock used for updating the index
151
+ protected:
152
+ //! Lock used for any changes to the index
144
153
  mutex lock;
145
-
146
- //! Pointer to most recently checkpointed index data.
154
+ //! Pointer to serialized index data
147
155
  BlockPointer serialized_data_pointer;
148
156
 
149
157
  private:
150
- //! Bound expressions used by the index
158
+ //! Bound expressions used during expression execution
151
159
  vector<unique_ptr<Expression>> bound_expressions;
152
- //! Expression executor for the index expressions
160
+ //! Expression executor to execute the index expressions
153
161
  ExpressionExecutor executor;
154
162
 
163
+ //! Bind the unbound expressions of the index
155
164
  unique_ptr<Expression> BindExpression(unique_ptr<Expression> expr);
156
165
  };
157
166
 
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "duckdb/common/common.hpp"
12
12
  #include "duckdb/common/enums/access_mode.hpp"
13
+ #include "duckdb/parser/tableref/table_function_ref.hpp"
13
14
 
14
15
  namespace duckdb {
15
16
  class AttachedDatabase;
@@ -27,11 +28,17 @@ typedef unique_ptr<Catalog> (*attach_function_t)(StorageExtensionInfo *storage_i
27
28
  const string &name, AttachInfo &info, AccessMode access_mode);
28
29
  typedef unique_ptr<TransactionManager> (*create_transaction_manager_t)(StorageExtensionInfo *storage_info,
29
30
  AttachedDatabase &db, Catalog &catalog);
31
+ typedef unique_ptr<TableFunctionRef> (*create_database_t)(StorageExtensionInfo *info, ClientContext &context,
32
+ const string &database_name, const string &source_path);
33
+ typedef unique_ptr<TableFunctionRef> (*drop_database_t)(StorageExtensionInfo *storage_info, ClientContext &context,
34
+ const string &database_name);
30
35
 
31
36
  class StorageExtension {
32
37
  public:
33
38
  attach_function_t attach;
34
39
  create_transaction_manager_t create_transaction_manager;
40
+ create_database_t create_database;
41
+ drop_database_t drop_database;
35
42
 
36
43
  //! Additional info passed to the various storage functions
37
44
  shared_ptr<StorageExtensionInfo> storage_info;
@@ -23,6 +23,8 @@ struct UpdateNode;
23
23
  class UpdateSegment {
24
24
  public:
25
25
  UpdateSegment(ColumnData &column_data);
26
+ // Construct a duplicate of 'other' with 'new_owner' as it's column data
27
+ UpdateSegment(UpdateSegment &other, ColumnData &new_owner);
26
28
  ~UpdateSegment();
27
29
 
28
30
  ColumnData &column_data;
@@ -15,6 +15,7 @@
15
15
  #include "duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp"
16
16
  #include "duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp"
17
17
  #include "duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp"
18
+ #include "duckdb/catalog/catalog_entry/index_catalog_entry.hpp"
18
19
  #include "duckdb/main/attached_database.hpp"
19
20
  #include "duckdb/storage/storage_info.hpp"
20
21
 
@@ -77,6 +78,9 @@ protected:
77
78
  void ReplayCreateTableMacro();
78
79
  void ReplayDropTableMacro();
79
80
 
81
+ void ReplayCreateIndex();
82
+ void ReplayDropIndex();
83
+
80
84
  void ReplayUseTable();
81
85
  void ReplayInsert();
82
86
  void ReplayDelete();
@@ -125,6 +129,9 @@ public:
125
129
  void WriteCreateTableMacro(TableMacroCatalogEntry *entry);
126
130
  void WriteDropTableMacro(TableMacroCatalogEntry *entry);
127
131
 
132
+ void WriteCreateIndex(IndexCatalogEntry *entry);
133
+ void WriteDropIndex(IndexCatalogEntry *entry);
134
+
128
135
  void WriteCreateType(TypeCatalogEntry *entry);
129
136
  void WriteDropType(TypeCatalogEntry *entry);
130
137
  //! Sets the table used for subsequent insert/delete/update commands
@@ -665,6 +665,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
665
665
  statement = std::move(copied_statement);
666
666
  break;
667
667
  }
668
+ #ifndef DUCKDB_ALTERNATIVE_VERIFY
668
669
  case StatementType::COPY_STATEMENT:
669
670
  case StatementType::INSERT_STATEMENT:
670
671
  case StatementType::DELETE_STATEMENT:
@@ -685,6 +686,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
685
686
  statement = std::move(parser.statements[0]);
686
687
  break;
687
688
  }
689
+ #endif
688
690
  default:
689
691
  statement = std::move(copied_statement);
690
692
  break;
@@ -24,8 +24,9 @@ ExtensionAlias ExtensionHelper::GetExtensionAlias(idx_t index) {
24
24
  }
25
25
 
26
26
  string ExtensionHelper::ApplyExtensionAlias(string extension_name) {
27
+ auto lname = StringUtil::Lower(extension_name);
27
28
  for (idx_t index = 0; internal_aliases[index].alias; index++) {
28
- if (extension_name == internal_aliases[index].alias) {
29
+ if (lname == internal_aliases[index].alias) {
29
30
  return internal_aliases[index].extension;
30
31
  }
31
32
  }
@@ -83,12 +83,8 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
83
83
  *node_ptr = std::move(cross_product);
84
84
  return;
85
85
  }
86
- case JoinType::INNER:
87
- case JoinType::LEFT:
88
- case JoinType::RIGHT:
89
- case JoinType::OUTER: {
90
- // inner/left/right/full outer join, replace with cross product
91
- // since the condition is always true, left/right/outer join are equivalent to inner join here
86
+ case JoinType::INNER: {
87
+ // inner, replace with cross product
92
88
  auto cross_product =
93
89
  LogicalCrossProduct::Create(std::move(join.children[0]), std::move(join.children[1]));
94
90
  *node_ptr = std::move(cross_product);
@@ -16,6 +16,9 @@ unique_ptr<CreateInfo> CreateIndexInfo::Copy() const {
16
16
  for (auto &expr : expressions) {
17
17
  result->expressions.push_back(expr->Copy());
18
18
  }
19
+ for (auto &expr : parsed_expressions) {
20
+ result->parsed_expressions.push_back(expr->Copy());
21
+ }
19
22
 
20
23
  result->scan_types = scan_types;
21
24
  result->names = names;
@@ -11,16 +11,6 @@ CopyStatement::CopyStatement(const CopyStatement &other) : SQLStatement(other),
11
11
  }
12
12
  }
13
13
 
14
- string ConvertOptionValueToString(const Value &val) {
15
- auto type = val.type().id();
16
- switch (type) {
17
- case LogicalTypeId::VARCHAR:
18
- return KeywordHelper::WriteOptionallyQuoted(val.ToString());
19
- default:
20
- return val.ToString();
21
- }
22
- }
23
-
24
14
  string CopyStatement::CopyOptionsToString(const string &format,
25
15
  const case_insensitive_map_t<vector<Value>> &options) const {
26
16
  if (format.empty() && options.empty()) {
@@ -45,15 +35,14 @@ string CopyStatement::CopyOptionsToString(const string &format,
45
35
  // Options like HEADER don't need an explicit value
46
36
  // just providing the name already sets it to true
47
37
  } else if (values.size() == 1) {
48
- result += ConvertOptionValueToString(values[0]);
38
+ result += values[0].ToSQLString();
49
39
  } else {
50
40
  result += "( ";
51
41
  for (idx_t i = 0; i < values.size(); i++) {
52
- auto &value = values[i];
53
42
  if (i) {
54
43
  result += ", ";
55
44
  }
56
- result += KeywordHelper::WriteOptionallyQuoted(value.ToString());
45
+ result += values[i].ToSQLString();
57
46
  }
58
47
  result += " )";
59
48
  }
@@ -13,6 +13,9 @@ DeleteStatement::DeleteStatement(const DeleteStatement &other) : SQLStatement(ot
13
13
  for (const auto &using_clause : other.using_clauses) {
14
14
  using_clauses.push_back(using_clause->Copy());
15
15
  }
16
+ for (auto &expr : other.returning_list) {
17
+ returning_list.emplace_back(expr->Copy());
18
+ }
16
19
  cte_map = other.cte_map.Copy();
17
20
  }
18
21
 
@@ -0,0 +1,15 @@
1
+ #include "duckdb/parser/statement/detach_statement.hpp"
2
+
3
+ namespace duckdb {
4
+
5
+ DetachStatement::DetachStatement() : SQLStatement(StatementType::DETACH_STATEMENT) {
6
+ }
7
+
8
+ DetachStatement::DetachStatement(const DetachStatement &other) : SQLStatement(other), info(other.info->Copy()) {
9
+ }
10
+
11
+ unique_ptr<SQLStatement> DetachStatement::Copy() const {
12
+ return unique_ptr<DetachStatement>(new DetachStatement(*this));
13
+ }
14
+
15
+ } // namespace duckdb
@@ -13,6 +13,9 @@ OnConflictInfo::OnConflictInfo(const OnConflictInfo &other)
13
13
  if (other.set_info) {
14
14
  set_info = other.set_info->Copy();
15
15
  }
16
+ if (other.condition) {
17
+ condition = other.condition->Copy();
18
+ }
16
19
  }
17
20
 
18
21
  unique_ptr<OnConflictInfo> OnConflictInfo::Copy() const {
@@ -28,6 +31,12 @@ InsertStatement::InsertStatement(const InsertStatement &other)
28
31
  select_statement(unique_ptr_cast<SQLStatement, SelectStatement>(other.select_statement->Copy())),
29
32
  columns(other.columns), table(other.table), schema(other.schema), catalog(other.catalog) {
30
33
  cte_map = other.cte_map.Copy();
34
+ for (auto &expr : other.returning_list) {
35
+ returning_list.emplace_back(expr->Copy());
36
+ }
37
+ if (other.table_ref) {
38
+ table_ref = other.table_ref->Copy();
39
+ }
31
40
  if (other.on_conflict_info) {
32
41
  on_conflict_info = other.on_conflict_info->Copy();
33
42
  }
@@ -27,6 +27,9 @@ UpdateStatement::UpdateStatement(const UpdateStatement &other)
27
27
  if (other.from_table) {
28
28
  from_table = other.from_table->Copy();
29
29
  }
30
+ for (auto &expr : other.returning_list) {
31
+ returning_list.emplace_back(expr->Copy());
32
+ }
30
33
  cte_map = other.cte_map.Copy();
31
34
  }
32
35
 
@@ -9,16 +9,16 @@ unique_ptr<ParsedExpression> Transformer::TransformCase(duckdb_libpgquery::PGCas
9
9
  D_ASSERT(root);
10
10
 
11
11
  auto case_node = make_unique<CaseExpression>();
12
+ auto root_arg = TransformExpression(reinterpret_cast<duckdb_libpgquery::PGNode *>(root->arg));
12
13
  for (auto cell = root->args->head; cell != nullptr; cell = cell->next) {
13
14
  CaseCheck case_check;
14
15
 
15
16
  auto w = reinterpret_cast<duckdb_libpgquery::PGCaseWhen *>(cell->data.ptr_value);
16
17
  auto test_raw = TransformExpression(reinterpret_cast<duckdb_libpgquery::PGNode *>(w->expr));
17
18
  unique_ptr<ParsedExpression> test;
18
- auto arg = TransformExpression(reinterpret_cast<duckdb_libpgquery::PGNode *>(root->arg));
19
- if (arg) {
19
+ if (root_arg) {
20
20
  case_check.when_expr =
21
- make_unique<ComparisonExpression>(ExpressionType::COMPARE_EQUAL, std::move(arg), std::move(test_raw));
21
+ make_unique<ComparisonExpression>(ExpressionType::COMPARE_EQUAL, root_arg->Copy(), std::move(test_raw));
22
22
  } else {
23
23
  case_check.when_expr = std::move(test_raw);
24
24
  }
@@ -11,7 +11,6 @@ unique_ptr<CreateStatement> Transformer::TransformCreateDatabase(duckdb_libpgque
11
11
  auto result = make_unique<CreateStatement>();
12
12
  auto info = make_unique<CreateDatabaseInfo>();
13
13
 
14
- info->extension_name = stmt->extension ? stmt->extension : string();
15
14
  info->path = stmt->path ? stmt->path : string();
16
15
 
17
16
  auto qualified_name = TransformQualifiedName(stmt->name);
@@ -0,0 +1,19 @@
1
+ #include "duckdb/parser/transformer.hpp"
2
+ #include "duckdb/parser/statement/detach_statement.hpp"
3
+ #include "duckdb/parser/expression/constant_expression.hpp"
4
+ #include "duckdb/common/string_util.hpp"
5
+
6
+ namespace duckdb {
7
+
8
+ unique_ptr<DetachStatement> Transformer::TransformDetach(duckdb_libpgquery::PGNode *node) {
9
+ auto stmt = reinterpret_cast<duckdb_libpgquery::PGDetachStmt *>(node);
10
+ auto result = make_unique<DetachStatement>();
11
+ auto info = make_unique<DetachInfo>();
12
+ info->name = stmt->db_name;
13
+ info->if_exists = stmt->missing_ok;
14
+
15
+ result->info = std::move(info);
16
+ return result;
17
+ }
18
+
19
+ } // namespace duckdb
@@ -145,6 +145,8 @@ unique_ptr<SQLStatement> Transformer::TransformStatementInternal(duckdb_libpgque
145
145
  return TransformAlterSequence(stmt);
146
146
  case duckdb_libpgquery::T_PGAttachStmt:
147
147
  return TransformAttach(stmt);
148
+ case duckdb_libpgquery::T_PGDetachStmt:
149
+ return TransformDetach(stmt);
148
150
  case duckdb_libpgquery::T_PGUseStmt:
149
151
  return TransformUse(stmt);
150
152
  case duckdb_libpgquery::T_PGCreateDatabaseStmt:
@@ -72,6 +72,9 @@ static void NegatePercentileFractions(ClientContext &context, unique_ptr<ParsedE
72
72
  for (const auto &element_val : ListValue::GetChildren(value)) {
73
73
  values.push_back(NegatePercentileValue(element_val, desc));
74
74
  }
75
+ if (values.empty()) {
76
+ throw BinderException("Empty list in percentile not allowed");
77
+ }
75
78
  bound.expr = make_unique<BoundConstantExpression>(Value::LIST(values));
76
79
  } else {
77
80
  bound.expr = make_unique<BoundConstantExpression>(NegatePercentileValue(value, desc));