duckdb 0.7.2-dev586.0 → 0.7.2-dev654.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 (70) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/icu/icu-table-range.cpp +7 -7
  3. package/src/duckdb/extension/parquet/parquet_reader.cpp +1 -1
  4. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +3 -3
  5. package/src/duckdb/src/catalog/dependency_list.cpp +12 -0
  6. package/src/duckdb/src/common/string_util.cpp +4 -1
  7. package/src/duckdb/src/common/types/blob.cpp +1 -1
  8. package/src/duckdb/src/common/types/chunk_collection.cpp +2 -2
  9. package/src/duckdb/src/common/types/data_chunk.cpp +1 -1
  10. package/src/duckdb/src/common/types/value.cpp +8 -8
  11. package/src/duckdb/src/common/types.cpp +11 -11
  12. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +15 -3
  13. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +3 -0
  14. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +2 -2
  15. package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +6 -11
  16. package/src/duckdb/src/execution/operator/join/physical_range_join.cpp +1 -1
  17. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +2 -2
  18. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +3 -0
  19. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +22 -7
  20. package/src/duckdb/src/function/aggregate/distributive/first.cpp +1 -0
  21. package/src/duckdb/src/function/aggregate/holistic/approximate_quantile.cpp +5 -2
  22. package/src/duckdb/src/function/aggregate/holistic/quantile.cpp +1 -1
  23. package/src/duckdb/src/function/aggregate/nested/list.cpp +8 -8
  24. package/src/duckdb/src/function/cast/struct_cast.cpp +1 -1
  25. package/src/duckdb/src/function/scalar/date/date_part.cpp +1 -1
  26. package/src/duckdb/src/function/scalar/list/list_concat.cpp +5 -4
  27. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +3 -3
  28. package/src/duckdb/src/function/scalar/list/list_value.cpp +1 -1
  29. package/src/duckdb/src/function/scalar/map/map_entries.cpp +1 -1
  30. package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +1 -1
  31. package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +1 -1
  32. package/src/duckdb/src/function/table/arrow.cpp +2 -2
  33. package/src/duckdb/src/function/table/checkpoint.cpp +5 -1
  34. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +2 -2
  35. package/src/duckdb/src/function/table/system/test_all_types.cpp +2 -2
  36. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  37. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +3 -0
  38. package/src/duckdb/src/include/duckdb/common/types/value.hpp +3 -3
  39. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -3
  40. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +3 -0
  41. package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +2 -0
  42. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +0 -1
  43. package/src/duckdb/src/main/config.cpp +4 -0
  44. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +3 -4
  45. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +5 -3
  46. package/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp +33 -5
  47. package/src/duckdb/src/optimizer/rule/move_constants.cpp +8 -2
  48. package/src/duckdb/src/optimizer/unnest_rewriter.cpp +2 -2
  49. package/src/duckdb/src/parser/expression/conjunction_expression.cpp +2 -0
  50. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +17 -1
  51. package/src/duckdb/src/parser/transform/helpers/transform_typename.cpp +3 -2
  52. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -2
  53. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +1 -1
  54. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +4 -3
  55. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +25 -13
  56. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +2 -2
  57. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +2 -1
  58. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +9 -1
  59. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +10 -6
  60. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +3 -1
  61. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +1 -0
  62. package/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +1 -0
  63. package/src/duckdb/src/planner/expression_binder/having_binder.cpp +3 -0
  64. package/src/duckdb/src/planner/expression_binder.cpp +1 -1
  65. package/src/duckdb/src/storage/statistics/column_statistics.cpp +1 -2
  66. package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -0
  67. package/src/duckdb/src/storage/statistics/list_stats.cpp +6 -2
  68. package/src/duckdb/src/storage/statistics/struct_stats.cpp +3 -1
  69. package/src/duckdb/src/storage/table/row_group.cpp +6 -1
  70. package/src/duckdb/src/storage/table/update_segment.cpp +11 -7
@@ -335,6 +335,16 @@ void Binder::BindOnConflictClause(LogicalInsert &insert, TableCatalogEntry &tabl
335
335
  ReplaceColumnBindings(*insert.on_conflict_condition, table_index, projection_index);
336
336
  }
337
337
 
338
+ if (insert.action_type == OnConflictAction::REPLACE) {
339
+ D_ASSERT(on_conflict.set_info == nullptr);
340
+ on_conflict.set_info = CreateSetInfoForReplace(table, stmt);
341
+ insert.action_type = OnConflictAction::UPDATE;
342
+ }
343
+ if (on_conflict.set_info && on_conflict.set_info->columns.empty()) {
344
+ // if we are doing INSERT OR REPLACE on a table with no columns outside of the primary key column
345
+ // convert to INSERT OR IGNORE
346
+ insert.action_type = OnConflictAction::NOTHING;
347
+ }
338
348
  if (insert.action_type == OnConflictAction::NOTHING) {
339
349
  if (!insert.on_conflict_condition) {
340
350
  return;
@@ -346,15 +356,9 @@ void Binder::BindOnConflictClause(LogicalInsert &insert, TableCatalogEntry &tabl
346
356
  insert.columns_to_fetch = table_binding->GetBoundColumnIds();
347
357
  return;
348
358
  }
349
- if (insert.action_type == OnConflictAction::REPLACE) {
350
- D_ASSERT(on_conflict.set_info == nullptr);
351
- on_conflict.set_info = CreateSetInfoForReplace(table, stmt);
352
- insert.action_type = OnConflictAction::UPDATE;
353
- }
354
359
 
355
360
  D_ASSERT(on_conflict.set_info);
356
361
  auto &set_info = *on_conflict.set_info;
357
- D_ASSERT(!set_info.columns.empty());
358
362
  D_ASSERT(set_info.columns.size() == set_info.expressions.size());
359
363
 
360
364
  if (set_info.condition) {
@@ -195,11 +195,13 @@ BoundStatement Binder::Bind(UpdateStatement &stmt) {
195
195
  AddCTEMap(stmt.cte_map);
196
196
 
197
197
  if (stmt.from_table) {
198
+ auto from_binder = Binder::CreateBinder(context, this);
198
199
  BoundJoinRef bound_crossproduct(JoinRefType::CROSS);
199
200
  bound_crossproduct.left = std::move(bound_table);
200
- bound_crossproduct.right = Bind(*stmt.from_table);
201
+ bound_crossproduct.right = from_binder->Bind(*stmt.from_table);
201
202
  root = CreatePlan(bound_crossproduct);
202
203
  get = (LogicalGet *)root->children[0].get();
204
+ bind_context.AddContext(std::move(from_binder->bind_context));
203
205
  } else {
204
206
  root = CreatePlan(*bound_table);
205
207
  get = (LogicalGet *)root.get();
@@ -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
  }
@@ -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
  }
@@ -19,6 +19,9 @@ BindResult HavingBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, i
19
19
  auto &expr = (ColumnRefExpression &)**expr_ptr;
20
20
  auto alias_result = column_alias_binder.BindAlias(*this, expr, depth, root_expression);
21
21
  if (!alias_result.HasError()) {
22
+ if (depth > 0) {
23
+ throw BinderException("Having clause cannot reference alias in correlated subquery");
24
+ }
22
25
  return alias_result;
23
26
  }
24
27
  if (aggregate_handling == AggregateHandling::FORCE_AGGREGATES) {
@@ -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);
@@ -4,8 +4,7 @@
4
4
  namespace duckdb {
5
5
 
6
6
  ColumnStatistics::ColumnStatistics(BaseStatistics stats_p) : stats(std::move(stats_p)) {
7
- auto type = stats.GetType().InternalType();
8
- if (type != PhysicalType::LIST && type != PhysicalType::STRUCT) {
7
+ if (DistinctStatistics::TypeIsSupported(stats.GetType())) {
9
8
  distinct_stats = make_unique<DistinctStatistics>();
10
9
  }
11
10
  }
@@ -94,4 +94,8 @@ idx_t DistinctStatistics::GetCount() const {
94
94
  return MinValue<idx_t>(estimate, total_count);
95
95
  }
96
96
 
97
+ bool DistinctStatistics::TypeIsSupported(const LogicalType &type) {
98
+ return type.InternalType() != PhysicalType::LIST && type.InternalType() != PhysicalType::STRUCT;
99
+ }
100
+
97
101
  } // namespace duckdb
@@ -34,12 +34,16 @@ void ListStats::Copy(BaseStatistics &stats, const BaseStatistics &other) {
34
34
  }
35
35
 
36
36
  const BaseStatistics &ListStats::GetChildStats(const BaseStatistics &stats) {
37
- D_ASSERT(stats.GetStatsType() == StatisticsType::LIST_STATS);
37
+ if (stats.GetStatsType() != StatisticsType::LIST_STATS) {
38
+ throw InternalException("ListStats::GetChildStats called on stats that is not a list");
39
+ }
38
40
  D_ASSERT(stats.child_stats);
39
41
  return stats.child_stats[0];
40
42
  }
41
43
  BaseStatistics &ListStats::GetChildStats(BaseStatistics &stats) {
42
- D_ASSERT(stats.GetStatsType() == StatisticsType::LIST_STATS);
44
+ if (stats.GetStatsType() != StatisticsType::LIST_STATS) {
45
+ throw InternalException("ListStats::GetChildStats called on stats that is not a list");
46
+ }
43
47
  D_ASSERT(stats.child_stats);
44
48
  return stats.child_stats[0];
45
49
  }
@@ -34,7 +34,9 @@ BaseStatistics StructStats::CreateEmpty(LogicalType type) {
34
34
  }
35
35
 
36
36
  const BaseStatistics *StructStats::GetChildStats(const BaseStatistics &stats) {
37
- D_ASSERT(stats.GetStatsType() == StatisticsType::STRUCT_STATS);
37
+ if (stats.GetStatsType() != StatisticsType::STRUCT_STATS) {
38
+ throw InternalException("Calling StructStats::GetChildStats on stats that is not a struct");
39
+ }
38
40
  return stats.child_stats.get();
39
41
  }
40
42
 
@@ -156,7 +156,11 @@ unique_ptr<RowGroup> RowGroup::AlterType(const LogicalType &target_type, idx_t c
156
156
  // scan the original table, and fill the new column with the transformed value
157
157
  InitializeScan(scan_state);
158
158
 
159
- Vector append_vector(target_type);
159
+ DataChunk append_chunk;
160
+ vector<LogicalType> append_types;
161
+ append_types.push_back(target_type);
162
+ append_chunk.Initialize(Allocator::DefaultAllocator(), append_types);
163
+ auto &append_vector = append_chunk.data[0];
160
164
  SegmentStatistics altered_col_stats(target_type);
161
165
  while (true) {
162
166
  // scan the table
@@ -166,6 +170,7 @@ unique_ptr<RowGroup> RowGroup::AlterType(const LogicalType &target_type, idx_t c
166
170
  break;
167
171
  }
168
172
  // execute the expression
173
+ append_chunk.Reset();
169
174
  executor.ExecuteExpression(scan_chunk, append_vector);
170
175
  column_data->Append(altered_col_stats.statistics, append_state, append_vector, scan_chunk.size());
171
176
  }
@@ -38,7 +38,17 @@ UpdateSegment::UpdateSegment(UpdateSegment &other, ColumnData &owner)
38
38
  : column_data(owner), root(std::move(other.root)), stats(std::move(other.stats)), type_size(other.type_size) {
39
39
 
40
40
  this->heap.Move(other.heap);
41
-
41
+ // update the segment links
42
+ if (root) {
43
+ for (idx_t i = 0; i < RowGroup::ROW_GROUP_VECTOR_COUNT; i++) {
44
+ if (!root->info[i]) {
45
+ continue;
46
+ }
47
+ for (auto info = root->info[i]->info.get(); info; info = info->next) {
48
+ info->segment = this;
49
+ }
50
+ }
51
+ }
42
52
  initialize_update_function = other.initialize_update_function;
43
53
  merge_update_function = other.merge_update_function;
44
54
  fetch_update_function = other.fetch_update_function;
@@ -52,12 +62,6 @@ UpdateSegment::UpdateSegment(UpdateSegment &other, ColumnData &owner)
52
62
  UpdateSegment::~UpdateSegment() {
53
63
  }
54
64
 
55
- void UpdateSegment::ClearUpdates() {
56
- stats.statistics.Copy(BaseStatistics::CreateEmpty(stats.statistics.GetType()));
57
- root.reset();
58
- heap.Destroy();
59
- }
60
-
61
65
  //===--------------------------------------------------------------------===//
62
66
  // Update Info Helpers
63
67
  //===--------------------------------------------------------------------===//