duckdb 0.7.2-dev457.0 → 0.7.2-dev614.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 (95) hide show
  1. package/binding.gyp +9 -9
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/icu/icu-table-range.cpp +7 -7
  4. package/src/duckdb/extension/parquet/parquet-extension.cpp +1 -0
  5. package/src/duckdb/extension/parquet/parquet_reader.cpp +1 -1
  6. package/src/duckdb/src/catalog/catalog.cpp +13 -0
  7. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +2 -21
  8. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +8 -2
  9. package/src/duckdb/src/catalog/catalog_set.cpp +1 -0
  10. package/src/duckdb/src/common/arrow/arrow_appender.cpp +48 -4
  11. package/src/duckdb/src/common/arrow/arrow_converter.cpp +1 -1
  12. package/src/duckdb/src/common/field_writer.cpp +1 -0
  13. package/src/duckdb/src/common/serializer/buffered_deserializer.cpp +4 -0
  14. package/src/duckdb/src/common/serializer/buffered_file_reader.cpp +15 -2
  15. package/src/duckdb/src/common/types/blob.cpp +1 -1
  16. package/src/duckdb/src/common/types/chunk_collection.cpp +2 -2
  17. package/src/duckdb/src/common/types/data_chunk.cpp +1 -1
  18. package/src/duckdb/src/common/types/value.cpp +8 -8
  19. package/src/duckdb/src/common/types.cpp +147 -64
  20. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +12 -3
  21. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +2 -2
  22. package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +6 -11
  23. package/src/duckdb/src/execution/operator/join/physical_range_join.cpp +1 -1
  24. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +2 -2
  25. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +20 -40
  26. package/src/duckdb/src/function/aggregate/holistic/quantile.cpp +1 -1
  27. package/src/duckdb/src/function/aggregate/nested/list.cpp +8 -8
  28. package/src/duckdb/src/function/cast/struct_cast.cpp +1 -1
  29. package/src/duckdb/src/function/scalar/date/date_part.cpp +1 -1
  30. package/src/duckdb/src/function/scalar/list/list_concat.cpp +5 -4
  31. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +3 -3
  32. package/src/duckdb/src/function/scalar/list/list_value.cpp +1 -1
  33. package/src/duckdb/src/function/scalar/map/map_entries.cpp +1 -1
  34. package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +1 -1
  35. package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +1 -1
  36. package/src/duckdb/src/function/table/arrow.cpp +5 -2
  37. package/src/duckdb/src/function/table/arrow_conversion.cpp +18 -0
  38. package/src/duckdb/src/function/table/system/test_all_types.cpp +2 -2
  39. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  40. package/src/duckdb/src/function/table_function.cpp +11 -11
  41. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
  42. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +1 -1
  43. package/src/duckdb/src/include/duckdb/common/field_writer.hpp +12 -4
  44. package/src/duckdb/src/include/duckdb/common/{http_stats.hpp → http_state.hpp} +18 -4
  45. package/src/duckdb/src/include/duckdb/common/serializer/buffered_deserializer.hpp +4 -2
  46. package/src/duckdb/src/include/duckdb/common/serializer/buffered_file_reader.hpp +8 -2
  47. package/src/duckdb/src/include/duckdb/common/serializer.hpp +13 -0
  48. package/src/duckdb/src/include/duckdb/common/types/value.hpp +3 -3
  49. package/src/duckdb/src/include/duckdb/common/types.hpp +30 -4
  50. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +1 -0
  51. package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +12 -1
  52. package/src/duckdb/src/include/duckdb/function/table_function.hpp +8 -0
  53. package/src/duckdb/src/include/duckdb/main/client_data.hpp +3 -3
  54. package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +2 -0
  55. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +1 -0
  56. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +3 -0
  57. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +6 -0
  58. package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +1 -1
  59. package/src/duckdb/src/include/duckdb/storage/meta_block_reader.hpp +7 -0
  60. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +0 -1
  61. package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +1 -1
  62. package/src/duckdb/src/main/client_context.cpp +30 -32
  63. package/src/duckdb/src/main/client_data.cpp +7 -6
  64. package/src/duckdb/src/main/config.cpp +4 -0
  65. package/src/duckdb/src/main/database.cpp +9 -0
  66. package/src/duckdb/src/main/query_profiler.cpp +17 -15
  67. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +3 -4
  68. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +5 -3
  69. package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +9 -2
  70. package/src/duckdb/src/optimizer/unnest_rewriter.cpp +2 -2
  71. package/src/duckdb/src/parser/expression/conjunction_expression.cpp +2 -0
  72. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +1 -1
  73. package/src/duckdb/src/parser/transform/helpers/transform_typename.cpp +3 -2
  74. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +3 -4
  75. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +1 -1
  76. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +4 -3
  77. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +2 -1
  78. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +2 -1
  79. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +1 -0
  80. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +11 -1
  81. package/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +1 -0
  82. package/src/duckdb/src/planner/expression_binder.cpp +1 -1
  83. package/src/duckdb/src/planner/logical_operator.cpp +4 -2
  84. package/src/duckdb/src/planner/planner.cpp +2 -1
  85. package/src/duckdb/src/storage/checkpoint_manager.cpp +8 -3
  86. package/src/duckdb/src/storage/meta_block_reader.cpp +22 -0
  87. package/src/duckdb/src/storage/statistics/list_stats.cpp +6 -2
  88. package/src/duckdb/src/storage/statistics/struct_stats.cpp +3 -1
  89. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  90. package/src/duckdb/src/storage/table/update_segment.cpp +11 -7
  91. package/src/duckdb/src/storage/wal_replay.cpp +8 -5
  92. package/src/duckdb/src/storage/write_ahead_log.cpp +2 -2
  93. package/src/duckdb/src/transaction/commit_state.cpp +11 -7
  94. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +1152 -1152
  95. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
@@ -137,6 +137,9 @@ public:
137
137
  unique_ptr<AlterInfo> Copy() const override;
138
138
  void SerializeAlterTable(FieldWriter &writer) const override;
139
139
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, AlterEntryData data);
140
+ string GetColumnName() const override {
141
+ return removed_column;
142
+ };
140
143
  };
141
144
 
142
145
  //===--------------------------------------------------------------------===//
@@ -158,6 +161,9 @@ public:
158
161
  unique_ptr<AlterInfo> Copy() const override;
159
162
  void SerializeAlterTable(FieldWriter &writer) const override;
160
163
  static unique_ptr<AlterInfo> Deserialize(FieldReader &reader, AlterEntryData data);
164
+ string GetColumnName() const override {
165
+ return column_name;
166
+ };
161
167
  };
162
168
 
163
169
  //===--------------------------------------------------------------------===//
@@ -44,7 +44,7 @@ protected:
44
44
  virtual void WriteMacro(ScalarMacroCatalogEntry &table);
45
45
  virtual void WriteTableMacro(TableMacroCatalogEntry &table);
46
46
  virtual void WriteIndex(IndexCatalogEntry &index_catalog);
47
- virtual void WriteType(TypeCatalogEntry &table);
47
+ virtual void WriteType(TypeCatalogEntry &type);
48
48
  };
49
49
 
50
50
  class CheckpointReader {
@@ -36,7 +36,14 @@ public:
36
36
  //! Read content of size read_size into the buffer
37
37
  void ReadData(data_ptr_t buffer, idx_t read_size) override;
38
38
 
39
+ ClientContext &GetContext() override;
40
+ Catalog *GetCatalog() override;
41
+ void SetCatalog(Catalog *catalog_p);
42
+ void SetContext(ClientContext *context_p);
43
+
39
44
  private:
40
45
  void ReadNewBlock(block_id_t id);
46
+ Catalog *catalog = nullptr;
47
+ ClientContext *context = nullptr;
41
48
  };
42
49
  } // namespace duckdb
@@ -34,7 +34,6 @@ public:
34
34
  bool HasUncommittedUpdates(idx_t vector_index);
35
35
  bool HasUpdates(idx_t vector_index) const;
36
36
  bool HasUpdates(idx_t start_row_idx, idx_t end_row_idx);
37
- void ClearUpdates();
38
37
 
39
38
  void FetchUpdates(TransactionData transaction, idx_t vector_index, Vector &result);
40
39
  void FetchCommitted(idx_t vector_index, Vector &result);
@@ -137,7 +137,7 @@ public:
137
137
  //! Sets the table used for subsequent insert/delete/update commands
138
138
  void WriteSetTable(string &schema, string &table);
139
139
 
140
- void WriteAlter(AlterInfo &info);
140
+ void WriteAlter(data_ptr_t ptr, idx_t data_size);
141
141
 
142
142
  void WriteInsert(DataChunk &chunk);
143
143
  void WriteDelete(DataChunk &chunk);
@@ -1,52 +1,52 @@
1
1
  #include "duckdb/main/client_context.hpp"
2
2
 
3
- #include "duckdb/main/client_context_file_opener.hpp"
4
- #include "duckdb/main/query_profiler.hpp"
5
- #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
6
3
  #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
4
+ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
7
5
  #include "duckdb/catalog/catalog_search_path.hpp"
6
+ #include "duckdb/common/file_system.hpp"
7
+ #include "duckdb/common/http_state.hpp"
8
+ #include "duckdb/common/preserved_error.hpp"
9
+ #include "duckdb/common/progress_bar/progress_bar.hpp"
8
10
  #include "duckdb/common/serializer/buffered_deserializer.hpp"
11
+ #include "duckdb/common/serializer/buffered_file_writer.hpp"
9
12
  #include "duckdb/common/serializer/buffered_serializer.hpp"
13
+ #include "duckdb/common/types/column_data_collection.hpp"
14
+ #include "duckdb/execution/column_binding_resolver.hpp"
15
+ #include "duckdb/execution/operator/helper/physical_result_collector.hpp"
10
16
  #include "duckdb/execution/physical_plan_generator.hpp"
17
+ #include "duckdb/main/appender.hpp"
18
+ #include "duckdb/main/attached_database.hpp"
19
+ #include "duckdb/main/client_context_file_opener.hpp"
20
+ #include "duckdb/main/client_data.hpp"
11
21
  #include "duckdb/main/database.hpp"
22
+ #include "duckdb/main/database_manager.hpp"
23
+ #include "duckdb/main/error_manager.hpp"
12
24
  #include "duckdb/main/materialized_query_result.hpp"
13
- #include "duckdb/main/client_data.hpp"
25
+ #include "duckdb/main/query_profiler.hpp"
14
26
  #include "duckdb/main/query_result.hpp"
27
+ #include "duckdb/main/relation.hpp"
15
28
  #include "duckdb/main/stream_query_result.hpp"
16
29
  #include "duckdb/optimizer/optimizer.hpp"
17
- #include "duckdb/parser/parser.hpp"
30
+ #include "duckdb/parallel/task_scheduler.hpp"
18
31
  #include "duckdb/parser/expression/constant_expression.hpp"
19
32
  #include "duckdb/parser/expression/parameter_expression.hpp"
20
33
  #include "duckdb/parser/parsed_data/create_function_info.hpp"
34
+ #include "duckdb/parser/parsed_expression_iterator.hpp"
35
+ #include "duckdb/parser/parser.hpp"
36
+ #include "duckdb/parser/query_node/select_node.hpp"
21
37
  #include "duckdb/parser/statement/drop_statement.hpp"
38
+ #include "duckdb/parser/statement/execute_statement.hpp"
22
39
  #include "duckdb/parser/statement/explain_statement.hpp"
40
+ #include "duckdb/parser/statement/prepare_statement.hpp"
41
+ #include "duckdb/parser/statement/relation_statement.hpp"
23
42
  #include "duckdb/parser/statement/select_statement.hpp"
24
43
  #include "duckdb/planner/operator/logical_execute.hpp"
25
44
  #include "duckdb/planner/planner.hpp"
26
- #include "duckdb/transaction/transaction_manager.hpp"
27
- #include "duckdb/transaction/transaction.hpp"
28
- #include "duckdb/storage/data_table.hpp"
29
- #include "duckdb/main/appender.hpp"
30
- #include "duckdb/main/relation.hpp"
31
- #include "duckdb/parser/statement/relation_statement.hpp"
32
- #include "duckdb/parallel/task_scheduler.hpp"
33
- #include "duckdb/common/serializer/buffered_file_writer.hpp"
34
45
  #include "duckdb/planner/pragma_handler.hpp"
35
- #include "duckdb/common/file_system.hpp"
36
- #include "duckdb/execution/column_binding_resolver.hpp"
37
- #include "duckdb/execution/operator/helper/physical_result_collector.hpp"
38
- #include "duckdb/parser/query_node/select_node.hpp"
39
- #include "duckdb/parser/parsed_expression_iterator.hpp"
40
- #include "duckdb/parser/statement/prepare_statement.hpp"
41
- #include "duckdb/parser/statement/execute_statement.hpp"
42
- #include "duckdb/common/types/column_data_collection.hpp"
43
- #include "duckdb/common/preserved_error.hpp"
44
- #include "duckdb/common/progress_bar/progress_bar.hpp"
45
- #include "duckdb/main/error_manager.hpp"
46
- #include "duckdb/main/database_manager.hpp"
46
+ #include "duckdb/storage/data_table.hpp"
47
47
  #include "duckdb/transaction/meta_transaction.hpp"
48
- #include "duckdb/common/http_stats.hpp"
49
- #include "duckdb/main/attached_database.hpp"
48
+ #include "duckdb/transaction/transaction.hpp"
49
+ #include "duckdb/transaction/transaction_manager.hpp"
50
50
 
51
51
  namespace duckdb {
52
52
 
@@ -156,8 +156,8 @@ void ClientContext::BeginQueryInternal(ClientContextLock &lock, const string &qu
156
156
  PreservedError ClientContext::EndQueryInternal(ClientContextLock &lock, bool success, bool invalidate_transaction) {
157
157
  client_data->profiler->EndQuery();
158
158
 
159
- if (client_data->http_stats) {
160
- client_data->http_stats->Reset();
159
+ if (client_data->http_state) {
160
+ client_data->http_state->Reset();
161
161
  }
162
162
 
163
163
  // Notify any registered state of query end
@@ -717,9 +717,7 @@ unique_ptr<PendingQueryResult> ClientContext::PendingStatementOrPreparedStatemen
717
717
  auto &profiler = QueryProfiler::Get(*this);
718
718
  profiler.StartQuery(query, IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get()));
719
719
 
720
- if (IsExplainAnalyze(statement ? statement.get() : prepared->unbound_statement.get())) {
721
- client_data->http_stats = make_unique<HTTPStats>();
722
- }
720
+ client_data->http_state = make_unique<HTTPState>();
723
721
 
724
722
  bool invalidate_query = true;
725
723
  try {
@@ -1,15 +1,16 @@
1
1
  #include "duckdb/main/client_data.hpp"
2
- #include "duckdb/main/client_context.hpp"
3
- #include "duckdb/main/client_context_file_opener.hpp"
4
- #include "duckdb/main/query_profiler.hpp"
5
- #include "duckdb/common/http_stats.hpp"
6
- #include "duckdb/common/random_engine.hpp"
7
- #include "duckdb/catalog/catalog_search_path.hpp"
2
+
8
3
  #include "duckdb/catalog/catalog.hpp"
4
+ #include "duckdb/catalog/catalog_search_path.hpp"
5
+ #include "duckdb/common/http_state.hpp"
6
+ #include "duckdb/common/random_engine.hpp"
9
7
  #include "duckdb/common/serializer/buffered_file_writer.hpp"
10
8
  #include "duckdb/main/attached_database.hpp"
9
+ #include "duckdb/main/client_context.hpp"
10
+ #include "duckdb/main/client_context_file_opener.hpp"
11
11
  #include "duckdb/main/database.hpp"
12
12
  #include "duckdb/main/database_manager.hpp"
13
+ #include "duckdb/main/query_profiler.hpp"
13
14
 
14
15
  namespace duckdb {
15
16
 
@@ -270,6 +270,7 @@ idx_t CGroupBandwidthQuota(idx_t physical_cores, FileSystem &fs) {
270
270
  }
271
271
 
272
272
  idx_t GetSystemMaxThreadsInternal(FileSystem &fs) {
273
+ #ifndef DUCKDB_NO_THREADS
273
274
  idx_t physical_cores = std::thread::hardware_concurrency();
274
275
  #ifdef __linux__
275
276
  auto cores_available_per_period = CGroupBandwidthQuota(physical_cores, fs);
@@ -277,6 +278,9 @@ idx_t GetSystemMaxThreadsInternal(FileSystem &fs) {
277
278
  #else
278
279
  return physical_cores;
279
280
  #endif
281
+ #else
282
+ return 1;
283
+ #endif
280
284
  }
281
285
 
282
286
  void DBConfig::SetDefaultMaxThreads() {
@@ -115,6 +115,15 @@ ConnectionManager &ConnectionManager::Get(DatabaseInstance &db) {
115
115
  return db.GetConnectionManager();
116
116
  }
117
117
 
118
+ ClientContext *ConnectionManager::GetConnection(DatabaseInstance *db) {
119
+ for (auto &conn : connections) {
120
+ if (conn.first->db.get() == db) {
121
+ return conn.first;
122
+ }
123
+ }
124
+ return nullptr;
125
+ }
126
+
118
127
  ConnectionManager &ConnectionManager::Get(ClientContext &context) {
119
128
  return ConnectionManager::Get(DatabaseInstance::GetDatabase(context));
120
129
  }
@@ -1,21 +1,23 @@
1
1
  #include "duckdb/main/query_profiler.hpp"
2
- #include "duckdb/common/to_string.hpp"
2
+
3
3
  #include "duckdb/common/fstream.hpp"
4
+ #include "duckdb/common/http_state.hpp"
5
+ #include "duckdb/common/limits.hpp"
4
6
  #include "duckdb/common/printer.hpp"
5
7
  #include "duckdb/common/string_util.hpp"
6
- #include "duckdb/execution/physical_operator.hpp"
7
- #include "duckdb/execution/operator/join/physical_delim_join.hpp"
8
- #include "duckdb/execution/operator/helper/physical_execute.hpp"
9
- #include "duckdb/common/http_stats.hpp"
8
+ #include "duckdb/common/to_string.hpp"
10
9
  #include "duckdb/common/tree_renderer.hpp"
11
- #include "duckdb/common/limits.hpp"
12
10
  #include "duckdb/execution/expression_executor.hpp"
13
- #include "duckdb/planner/expression/bound_function_expression.hpp"
11
+ #include "duckdb/execution/operator/helper/physical_execute.hpp"
12
+ #include "duckdb/execution/operator/join/physical_delim_join.hpp"
13
+ #include "duckdb/execution/physical_operator.hpp"
14
14
  #include "duckdb/main/client_config.hpp"
15
15
  #include "duckdb/main/client_context.hpp"
16
16
  #include "duckdb/main/client_data.hpp"
17
- #include <utility>
17
+ #include "duckdb/planner/expression/bound_function_expression.hpp"
18
+
18
19
  #include <algorithm>
20
+ #include <utility>
19
21
 
20
22
  namespace duckdb {
21
23
 
@@ -377,15 +379,15 @@ void QueryProfiler::QueryTreeToStream(std::ostream &ss) const {
377
379
  return;
378
380
  }
379
381
 
380
- if (context.client_data->http_stats && !context.client_data->http_stats->IsEmpty()) {
382
+ if (context.client_data->http_state && !context.client_data->http_state->IsEmpty()) {
381
383
  string read =
382
- "in: " + StringUtil::BytesToHumanReadableString(context.client_data->http_stats->total_bytes_received);
384
+ "in: " + StringUtil::BytesToHumanReadableString(context.client_data->http_state->total_bytes_received);
383
385
  string written =
384
- "out: " + StringUtil::BytesToHumanReadableString(context.client_data->http_stats->total_bytes_sent);
385
- string head = "#HEAD: " + to_string(context.client_data->http_stats->head_count);
386
- string get = "#GET: " + to_string(context.client_data->http_stats->get_count);
387
- string put = "#PUT: " + to_string(context.client_data->http_stats->put_count);
388
- string post = "#POST: " + to_string(context.client_data->http_stats->post_count);
386
+ "out: " + StringUtil::BytesToHumanReadableString(context.client_data->http_state->total_bytes_sent);
387
+ string head = "#HEAD: " + to_string(context.client_data->http_state->head_count);
388
+ string get = "#GET: " + to_string(context.client_data->http_state->get_count);
389
+ string put = "#PUT: " + to_string(context.client_data->http_state->put_count);
390
+ string post = "#POST: " + to_string(context.client_data->http_state->post_count);
389
391
 
390
392
  constexpr idx_t TOTAL_BOX_WIDTH = 39;
391
393
  ss << "┌─────────────────────────────────────┐\n";
@@ -39,8 +39,7 @@ void CardinalityEstimator::AddRelationTdom(FilterInfo *filter_info) {
39
39
  }
40
40
  }
41
41
  auto key = ColumnBinding(filter_info->left_binding.table_index, filter_info->left_binding.column_index);
42
- column_binding_set_t tmp({key});
43
- relations_to_tdoms.emplace_back(RelationsToTDom(tmp));
42
+ relations_to_tdoms.emplace_back(column_binding_set_t({key}));
44
43
  }
45
44
 
46
45
  bool CardinalityEstimator::SingleColumnFilter(FilterInfo *filter_info) {
@@ -93,7 +92,7 @@ void CardinalityEstimator::AddToEquivalenceSets(FilterInfo *filter_info, vector<
93
92
  column_binding_set_t tmp;
94
93
  tmp.insert(filter_info->left_binding);
95
94
  tmp.insert(filter_info->right_binding);
96
- relations_to_tdoms.emplace_back(RelationsToTDom(tmp));
95
+ relations_to_tdoms.emplace_back(tmp);
97
96
  relations_to_tdoms.back().filters.push_back(filter_info);
98
97
  }
99
98
  }
@@ -259,7 +258,7 @@ double CardinalityEstimator::EstimateCardinalityWithSet(JoinRelationSet *new_set
259
258
  // connection to any subgraph in subgraphs. Add a new subgraph, and maybe later there will be
260
259
  // a connection.
261
260
  if (!found_match) {
262
- subgraphs.emplace_back(Subgraph2Denominator());
261
+ subgraphs.emplace_back();
263
262
  auto subgraph = &subgraphs.back();
264
263
  subgraph->relations.insert(filter->left_binding.table_index);
265
264
  subgraph->relations.insert(filter->right_binding.table_index);
@@ -156,7 +156,7 @@ bool JoinOrderOptimizer::ExtractJoinRelations(LogicalOperator &input_op, vector<
156
156
  vector<column_binding_map_t<ColumnBinding>> child_binding_maps;
157
157
  idx_t child_bindings_it = 0;
158
158
  for (auto &child : op->children) {
159
- child_binding_maps.emplace_back(column_binding_map_t<ColumnBinding>());
159
+ child_binding_maps.emplace_back();
160
160
  JoinOrderOptimizer optimizer(context);
161
161
  child = optimizer.Optimize(std::move(child));
162
162
  // save the relation bindings from the optimized child. These later all get added to the
@@ -230,7 +230,7 @@ bool JoinOrderOptimizer::ExtractJoinRelations(LogicalOperator &input_op, vector<
230
230
  auto relation_id = relations.size();
231
231
  // push one child column binding map back.
232
232
  vector<column_binding_map_t<ColumnBinding>> child_binding_maps;
233
- child_binding_maps.emplace_back(column_binding_map_t<ColumnBinding>());
233
+ child_binding_maps.emplace_back();
234
234
  optimizer.cardinality_estimator.CopyRelationMap(child_binding_maps.at(0));
235
235
  // This logical projection may sit on top of a logical comparison join that has been pushed down
236
236
  // we want to copy the binding info of both tables
@@ -882,9 +882,11 @@ unique_ptr<LogicalOperator> JoinOrderOptimizer::RewritePlan(unique_ptr<LogicalOp
882
882
 
883
883
  // first we will extract all relations from the main plan
884
884
  vector<unique_ptr<LogicalOperator>> extracted_relations;
885
+ extracted_relations.reserve(relations.size());
885
886
  for (auto &relation : relations) {
886
887
  extracted_relations.push_back(ExtractJoinRelation(*relation));
887
888
  }
889
+
888
890
  // now we generate the actual joins
889
891
  auto join_tree = GenerateJoins(extracted_relations, node);
890
892
  // perform the final pushdown of remaining filters
@@ -1012,7 +1014,7 @@ unique_ptr<LogicalOperator> JoinOrderOptimizer::Optimize(unique_ptr<LogicalOpera
1012
1014
  for (idx_t i = 0; i < relations.size(); i++) {
1013
1015
  auto &rel = *relations[i];
1014
1016
  auto node = set_manager.GetJoinRelation(i);
1015
- nodes_ops.emplace_back(NodeOp(make_unique<JoinNode>(node, 0), rel.op));
1017
+ nodes_ops.emplace_back(make_unique<JoinNode>(node, 0), rel.op);
1016
1018
  }
1017
1019
 
1018
1020
  cardinality_estimator.InitCardinalityEstimatorProps(&nodes_ops, &filter_infos);
@@ -35,7 +35,7 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<
35
35
 
36
36
  auto constant_value = ExpressionExecutor::EvaluateScalar(GetContext(), *constant_expr);
37
37
  D_ASSERT(constant_value.type() == constant_expr->return_type);
38
- auto &patt_str = StringValue::Get(constant_value);
38
+ auto patt_str = StringValue::Get(constant_value);
39
39
 
40
40
  duckdb_re2::RE2 pattern(patt_str);
41
41
  if (!pattern.ok()) {
@@ -47,7 +47,14 @@ unique_ptr<Expression> RegexOptimizationRule::Apply(LogicalOperator &op, vector<
47
47
  auto contains = make_unique<BoundFunctionExpression>(root->return_type, ContainsFun::GetFunction(),
48
48
  std::move(root->children), nullptr);
49
49
 
50
- contains->children[1] = make_unique<BoundConstantExpression>(Value(patt_str));
50
+ string min;
51
+ string max;
52
+ pattern.PossibleMatchRange(&min, &max, patt_str.size());
53
+ if (min == max) {
54
+ contains->children[1] = make_unique<BoundConstantExpression>(Value(std::move(min)));
55
+ } else {
56
+ contains->children[1] = make_unique<BoundConstantExpression>(Value(std::move(patt_str)));
57
+ }
51
58
  return std::move(contains);
52
59
  }
53
60
  return nullptr;
@@ -261,7 +261,7 @@ void UnnestRewriter::UpdateBoundUnnestBindings(UnnestRewriterPlanUpdater &update
261
261
  for (idx_t child_col_idx = 0; child_col_idx < unnest_child_cols.size(); child_col_idx++) {
262
262
  if (delim_columns[delim_col_idx].table_index == unnest_child_cols[child_col_idx].table_index) {
263
263
  ColumnBinding old_binding(overwritten_tbl_idx, DConstants::INVALID_INDEX);
264
- updater.replace_bindings.emplace_back(ReplaceBinding(old_binding, delim_columns[delim_col_idx]));
264
+ updater.replace_bindings.emplace_back(old_binding, delim_columns[delim_col_idx]);
265
265
  break;
266
266
  }
267
267
  }
@@ -301,7 +301,7 @@ void UnnestRewriter::GetLHSExpressions(LogicalOperator &op) {
301
301
  }
302
302
 
303
303
  for (idx_t i = 0; i < op.types.size(); i++) {
304
- lhs_bindings.emplace_back(LHSBinding(col_bindings[i], op.types[i]));
304
+ lhs_bindings.emplace_back(col_bindings[i], op.types[i]);
305
305
  if (set_alias) {
306
306
  auto &proj = (LogicalProjection &)op;
307
307
  lhs_bindings.back().alias = proj.expressions[i]->alias;
@@ -45,9 +45,11 @@ bool ConjunctionExpression::Equal(const ConjunctionExpression *a, const Conjunct
45
45
 
46
46
  unique_ptr<ParsedExpression> ConjunctionExpression::Copy() const {
47
47
  vector<unique_ptr<ParsedExpression>> copy_children;
48
+ copy_children.reserve(children.size());
48
49
  for (auto &expr : children) {
49
50
  copy_children.push_back(expr->Copy());
50
51
  }
52
+
51
53
  auto copy = make_unique<ConjunctionExpression>(type, std::move(copy_children));
52
54
  copy->CopyProperties(*this);
53
55
  return std::move(copy);
@@ -24,7 +24,7 @@ static ExpressionType WindowToExpressionType(string &fun_name) {
24
24
  return ExpressionType::WINDOW_FIRST_VALUE;
25
25
  } else if (fun_name == "last_value" || fun_name == "last") {
26
26
  return ExpressionType::WINDOW_LAST_VALUE;
27
- } else if (fun_name == "nth_value" || fun_name == "last") {
27
+ } else if (fun_name == "nth_value") {
28
28
  return ExpressionType::WINDOW_NTH_VALUE;
29
29
  } else if (fun_name == "cume_dist") {
30
30
  return ExpressionType::WINDOW_CUME_DIST;
@@ -52,7 +52,8 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName *type_n
52
52
  children.push_back(make_pair(entry_name, entry_type));
53
53
  }
54
54
  D_ASSERT(!children.empty());
55
- result_type = LogicalType::STRUCT(std::move(children));
55
+ result_type = LogicalType::STRUCT(children);
56
+
56
57
  } else if (base_type == LogicalTypeId::MAP) {
57
58
 
58
59
  if (!type_name->typmods || type_name->typmods->length != 2) {
@@ -207,7 +208,7 @@ LogicalType Transformer::TransformTypeName(duckdb_libpgquery::PGTypeName *type_n
207
208
  // array bounds: turn the type into a list
208
209
  idx_t extra_stack = 0;
209
210
  for (auto cell = type_name->arrayBounds->head; cell != nullptr; cell = cell->next) {
210
- result_type = LogicalType::LIST(std::move(result_type));
211
+ result_type = LogicalType::LIST(result_type);
211
212
  StackCheck(extra_stack++);
212
213
  }
213
214
  }
@@ -6,7 +6,9 @@ namespace duckdb {
6
6
  unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNode *node) {
7
7
  auto stmt = reinterpret_cast<duckdb_libpgquery::PGRenameStmt *>(node);
8
8
  D_ASSERT(stmt);
9
- D_ASSERT(stmt->relation);
9
+ if (!stmt->relation) {
10
+ throw NotImplementedException("Altering schemas is not yet supported");
11
+ }
10
12
 
11
13
  unique_ptr<AlterInfo> info;
12
14
 
@@ -17,8 +19,6 @@ unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNod
17
19
  if (stmt->relation->relname) {
18
20
  data.name = stmt->relation->relname;
19
21
  }
20
- if (stmt->relation->schemaname) {
21
- }
22
22
  // first we check the type of ALTER
23
23
  switch (stmt->renameType) {
24
24
  case duckdb_libpgquery::PG_OBJECT_COLUMN: {
@@ -36,7 +36,6 @@ unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNod
36
36
  info = make_unique<RenameTableInfo>(std::move(data), new_name);
37
37
  break;
38
38
  }
39
-
40
39
  case duckdb_libpgquery::PG_OBJECT_VIEW: {
41
40
  // change view name
42
41
  string new_name = stmt->newname;
@@ -219,7 +219,7 @@ BindResult SelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFuncti
219
219
  const auto null_order = (order.null_order == OrderByNullType::ORDER_DEFAULT)
220
220
  ? config.options.default_null_order
221
221
  : order.null_order;
222
- order_bys->orders.emplace_back(BoundOrderByNode(sense, null_order, std::move(order_expr.expr)));
222
+ order_bys->orders.emplace_back(sense, null_order, std::move(order_expr.expr));
223
223
  }
224
224
  }
225
225
 
@@ -175,11 +175,12 @@ unique_ptr<ParsedExpression> ExpressionBinder::CreateStructPack(ColumnRefExpress
175
175
  }
176
176
  }
177
177
  // We found the table, now create the struct_pack expression
178
- vector<unique_ptr<ParsedExpression>> child_exprs;
178
+ vector<unique_ptr<ParsedExpression>> child_expressions;
179
+ child_expressions.reserve(binding->names.size());
179
180
  for (const auto &column_name : binding->names) {
180
- child_exprs.push_back(make_unique<ColumnRefExpression>(column_name, table_name));
181
+ child_expressions.push_back(make_unique<ColumnRefExpression>(column_name, table_name));
181
182
  }
182
- return make_unique<FunctionExpression>("struct_pack", std::move(child_exprs));
183
+ return make_unique<FunctionExpression>("struct_pack", std::move(child_expressions));
183
184
  }
184
185
 
185
186
  unique_ptr<ParsedExpression> ExpressionBinder::QualifyColumnName(ColumnRefExpression &colref, string &error_message) {
@@ -441,8 +441,9 @@ unique_ptr<LogicalOperator> DuckCatalog::BindCreateIndex(Binder &binder, CreateS
441
441
 
442
442
  auto &get = (LogicalGet &)*plan;
443
443
  // bind the index expressions
444
- vector<unique_ptr<Expression>> expressions;
445
444
  IndexBinder index_binder(binder, binder.context);
445
+ vector<unique_ptr<Expression>> expressions;
446
+ expressions.reserve(base.expressions.size());
446
447
  for (auto &expr : base.expressions) {
447
448
  expressions.push_back(index_binder.Bind(expr));
448
449
  }
@@ -303,9 +303,10 @@ unique_ptr<BoundCreateTableInfo> Binder::BindCreateTableInfo(unique_ptr<CreateIn
303
303
  }
304
304
 
305
305
  vector<unique_ptr<Expression>> Binder::BindCreateIndexExpressions(TableCatalogEntry *table, CreateIndexInfo *info) {
306
- vector<unique_ptr<Expression>> expressions;
307
306
 
308
307
  auto index_binder = IndexBinder(*this, this->context, table, info);
308
+ vector<unique_ptr<Expression>> expressions;
309
+ expressions.reserve(info->expressions.size());
309
310
  for (auto &expr : info->expressions) {
310
311
  expressions.push_back(index_binder.Bind(expr));
311
312
  }
@@ -271,6 +271,7 @@ unique_ptr<SelectNode> Binder::BindUnpivot(Binder &child_binder, PivotRef &ref,
271
271
  vector<vector<unique_ptr<ParsedExpression>>> unpivot_expressions;
272
272
  for (idx_t v_idx = 0; v_idx < unpivot.entries[0].values.size(); v_idx++) {
273
273
  vector<unique_ptr<ParsedExpression>> expressions;
274
+ expressions.reserve(unpivot.entries.size());
274
275
  for (auto &entry : unpivot.entries) {
275
276
  expressions.push_back(make_unique<ColumnRefExpression>(entry.values[v_idx].ToString()));
276
277
  }
@@ -126,9 +126,18 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
126
126
  unique_ptr<FunctionData> bind_data;
127
127
  vector<LogicalType> return_types;
128
128
  vector<string> return_names;
129
- if (table_function.bind) {
129
+ if (table_function.bind || table_function.bind_replace) {
130
130
  TableFunctionBindInput bind_input(parameters, named_parameters, input_table_types, input_table_names,
131
131
  table_function.function_info.get());
132
+ if (table_function.bind_replace) {
133
+ auto new_plan = table_function.bind_replace(context, bind_input);
134
+ if (new_plan != nullptr) {
135
+ return CreatePlan(*Bind(*new_plan));
136
+ } else if (!table_function.bind) {
137
+ throw BinderException("Failed to bind \"%s\": nullptr returned from bind_replace without bind function",
138
+ table_function.name);
139
+ }
140
+ }
132
141
  bind_data = table_function.bind(context, bind_input, return_types, return_names);
133
142
  if (table_function.name == "pandas_scan" || table_function.name == "arrow_scan") {
134
143
  auto arrow_bind = (PyTableFunctionData *)bind_data.get();
@@ -153,6 +162,7 @@ Binder::BindTableFunctionInternal(TableFunction &table_function, const string &f
153
162
  return_names[i] = "C" + to_string(i);
154
163
  }
155
164
  }
165
+
156
166
  auto get = make_unique<LogicalGet>(bind_index, table_function, std::move(bind_data), return_types, return_names);
157
167
  get->parameters = parameters;
158
168
  get->named_parameters = named_parameters;
@@ -8,6 +8,7 @@ unique_ptr<LogicalOperator> Binder::CreatePlan(BoundCTERef &ref) {
8
8
  auto index = ref.bind_index;
9
9
 
10
10
  vector<LogicalType> types;
11
+ types.reserve(ref.types.size());
11
12
  for (auto &type : ref.types) {
12
13
  types.push_back(type);
13
14
  }
@@ -157,7 +157,7 @@ LogicalType ExpressionBinder::ExchangeType(const LogicalType &type, LogicalTypeI
157
157
  for (auto &child_type : child_types) {
158
158
  child_type.second = ExchangeType(child_type.second, target, new_type);
159
159
  }
160
- return LogicalType::STRUCT(std::move(child_types));
160
+ return LogicalType::STRUCT(child_types);
161
161
  }
162
162
  case LogicalTypeId::UNION: {
163
163
  auto member_types = UnionType::CopyMemberTypes(type);
@@ -128,6 +128,8 @@ void LogicalOperator::Verify(ClientContext &context) {
128
128
  continue;
129
129
  }
130
130
  BufferedSerializer serializer;
131
+ // We are serializing a query plan
132
+ serializer.is_query_plan = true;
131
133
  try {
132
134
  expressions[expr_idx]->Serialize(serializer);
133
135
  } catch (NotImplementedException &ex) {
@@ -136,7 +138,7 @@ void LogicalOperator::Verify(ClientContext &context) {
136
138
  }
137
139
 
138
140
  auto data = serializer.GetData();
139
- auto deserializer = BufferedDeserializer(data.data.get(), data.size);
141
+ auto deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
140
142
 
141
143
  PlanDeserializationState state(context);
142
144
  auto deserialized_expression = Expression::Deserialize(deserializer, state);
@@ -371,7 +373,7 @@ unique_ptr<LogicalOperator> LogicalOperator::Copy(ClientContext &context) const
371
373
  std::string(ex.what()));
372
374
  }
373
375
  auto data = logical_op_serializer.GetData();
374
- auto logical_op_deserializer = BufferedDeserializer(data.data.get(), data.size);
376
+ auto logical_op_deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
375
377
  PlanDeserializationState state(context);
376
378
  auto op_copy = LogicalOperator::Deserialize(logical_op_deserializer, state);
377
379
  return op_copy;
@@ -184,6 +184,7 @@ void Planner::VerifyPlan(ClientContext &context, unique_ptr<LogicalOperator> &op
184
184
  }
185
185
 
186
186
  BufferedSerializer serializer;
187
+ serializer.is_query_plan = true;
187
188
  try {
188
189
  op->Serialize(serializer);
189
190
  } catch (NotImplementedException &ex) {
@@ -191,7 +192,7 @@ void Planner::VerifyPlan(ClientContext &context, unique_ptr<LogicalOperator> &op
191
192
  return;
192
193
  }
193
194
  auto data = serializer.GetData();
194
- auto deserializer = BufferedDeserializer(data.data.get(), data.size);
195
+ auto deserializer = BufferedContextDeserializer(context, data.data.get(), data.size);
195
196
 
196
197
  PlanDeserializationState state(context);
197
198
  auto new_plan = LogicalOperator::Deserialize(deserializer, state);