duckdb 0.3.5-dev1274.0 → 0.3.5-dev1297.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.
package/src/duckdb.cpp CHANGED
@@ -23775,7 +23775,7 @@ template <typename T>
23775
23775
  struct IntegerCastData {
23776
23776
  using Result = T;
23777
23777
  Result result;
23778
- uint8_t decimal_count;
23778
+ bool seen_decimal;
23779
23779
  };
23780
23780
 
23781
23781
  struct IntegerCastOperation {
@@ -23809,14 +23809,27 @@ struct IntegerCastOperation {
23809
23809
 
23810
23810
  template <class T, bool NEGATIVE>
23811
23811
  static bool HandleDecimal(T &state, uint8_t digit) {
23812
- if (!state.decimal_count) {
23813
- if (NEGATIVE) {
23814
- state.result -= (digit >= 5);
23815
- } else {
23816
- state.result += (digit >= 5);
23812
+ if (state.seen_decimal) {
23813
+ return true;
23814
+ }
23815
+ state.seen_decimal = true;
23816
+ // round the integer based on what is after the decimal point
23817
+ // if digit >= 5, then we round up (or down in case of negative numbers)
23818
+ auto increment = digit >= 5;
23819
+ if (!increment) {
23820
+ return true;
23821
+ }
23822
+ if (NEGATIVE) {
23823
+ if (state.result == NumericLimits<typename T::Result>::Minimum()) {
23824
+ return false;
23825
+ }
23826
+ state.result--;
23827
+ } else {
23828
+ if (state.result == NumericLimits<typename T::Result>::Maximum()) {
23829
+ return false;
23817
23830
  }
23831
+ state.result++;
23818
23832
  }
23819
- ++state.decimal_count;
23820
23833
  return true;
23821
23834
  }
23822
23835
 
@@ -24514,7 +24527,7 @@ struct DecimalCastOperation {
24514
24527
  static bool HandleExponent(T &state, int32_t exponent) {
24515
24528
  Finalize<T>(state);
24516
24529
  if (exponent < 0) {
24517
- for (idx_t i = 0; i < idx_t(-exponent); i++) {
24530
+ for (idx_t i = 0; i < idx_t(-int64_t(exponent)); i++) {
24518
24531
  state.result /= 10;
24519
24532
  if (state.result == 0) {
24520
24533
  break;
@@ -31708,32 +31721,16 @@ static void ComputeStructEntrySizes(Vector &v, idx_t entry_sizes[], idx_t vcount
31708
31721
  const SelectionVector &sel, idx_t offset) {
31709
31722
  // obtain child vectors
31710
31723
  idx_t num_children;
31711
- vector<Vector> struct_vectors;
31712
- if (v.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
31713
- auto &child = DictionaryVector::Child(v);
31714
- auto &dict_sel = DictionaryVector::SelVector(v);
31715
- auto &children = StructVector::GetEntries(child);
31716
- num_children = children.size();
31717
- for (auto &struct_child : children) {
31718
- Vector struct_vector(*struct_child, dict_sel, vcount);
31719
- struct_vectors.push_back(move(struct_vector));
31720
- }
31721
- } else {
31722
- auto &children = StructVector::GetEntries(v);
31723
- num_children = children.size();
31724
- for (auto &struct_child : children) {
31725
- Vector struct_vector(*struct_child);
31726
- struct_vectors.push_back(move(struct_vector));
31727
- }
31728
- }
31724
+ auto &children = StructVector::GetEntries(v);
31725
+ num_children = children.size();
31729
31726
  // add struct validitymask size
31730
31727
  const idx_t struct_validitymask_size = (num_children + 7) / 8;
31731
31728
  for (idx_t i = 0; i < ser_count; i++) {
31732
31729
  entry_sizes[i] += struct_validitymask_size;
31733
31730
  }
31734
31731
  // compute size of child vectors
31735
- for (auto &struct_vector : struct_vectors) {
31736
- RowOperations::ComputeEntrySizes(struct_vector, entry_sizes, vcount, ser_count, sel, offset);
31732
+ for (auto &struct_vector : children) {
31733
+ RowOperations::ComputeEntrySizes(*struct_vector, entry_sizes, vcount, ser_count, sel, offset);
31737
31734
  }
31738
31735
  }
31739
31736
 
@@ -31898,25 +31895,8 @@ static void HeapScatterStructVector(Vector &v, idx_t vcount, const SelectionVect
31898
31895
  VectorData vdata;
31899
31896
  v.Orrify(vcount, vdata);
31900
31897
 
31901
- idx_t num_children;
31902
- vector<Vector> struct_vectors;
31903
- if (v.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
31904
- auto &child = DictionaryVector::Child(v);
31905
- auto &dict_sel = DictionaryVector::SelVector(v);
31906
- auto &children = StructVector::GetEntries(child);
31907
- num_children = children.size();
31908
- for (auto &struct_child : children) {
31909
- Vector struct_vector(*struct_child, dict_sel, vcount);
31910
- struct_vectors.push_back(move(struct_vector));
31911
- }
31912
- } else {
31913
- auto &children = StructVector::GetEntries(v);
31914
- num_children = children.size();
31915
- for (auto &struct_child : children) {
31916
- Vector struct_vector(*struct_child);
31917
- struct_vectors.push_back(move(struct_vector));
31918
- }
31919
- }
31898
+ auto &children = StructVector::GetEntries(v);
31899
+ idx_t num_children = children.size();
31920
31900
 
31921
31901
  // the whole struct itself can be NULL
31922
31902
  idx_t entry_idx;
@@ -31942,8 +31922,8 @@ static void HeapScatterStructVector(Vector &v, idx_t vcount, const SelectionVect
31942
31922
  }
31943
31923
 
31944
31924
  // now serialize the struct vectors
31945
- for (idx_t i = 0; i < struct_vectors.size(); i++) {
31946
- auto &struct_vector = struct_vectors[i];
31925
+ for (idx_t i = 0; i < children.size(); i++) {
31926
+ auto &struct_vector = *children[i];
31947
31927
  RowOperations::HeapScatter(struct_vector, vcount, sel, ser_count, i, key_locations,
31948
31928
  struct_validitymask_locations, offset);
31949
31929
  }
@@ -42815,6 +42795,15 @@ void RowLayout::Initialize(Aggregates aggregates_p, bool align) {
42815
42795
 
42816
42796
  namespace duckdb {
42817
42797
 
42798
+ SelectionData::SelectionData(idx_t count) {
42799
+ owned_data = unique_ptr<sel_t[]>(new sel_t[count]);
42800
+ #ifdef DEBUG
42801
+ for (idx_t i = 0; i < count; i++) {
42802
+ owned_data[i] = std::numeric_limits<sel_t>::max();
42803
+ }
42804
+ #endif
42805
+ }
42806
+
42818
42807
  // LCOV_EXCL_START
42819
42808
  string SelectionVector::ToString(idx_t count) const {
42820
42809
  string result = "Selection Vector (" + to_string(count) + ") [";
@@ -45704,9 +45693,20 @@ void Vector::Slice(const SelectionVector &sel, idx_t count) {
45704
45693
  auto &current_sel = DictionaryVector::SelVector(*this);
45705
45694
  auto sliced_dictionary = current_sel.Slice(sel, count);
45706
45695
  buffer = make_buffer<DictionaryBuffer>(move(sliced_dictionary));
45696
+ if (GetType().InternalType() == PhysicalType::STRUCT) {
45697
+ auto &child_vector = DictionaryVector::Child(*this);
45698
+
45699
+ Vector new_child(child_vector);
45700
+ new_child.auxiliary = make_buffer<VectorStructBuffer>(new_child, sel, count);
45701
+ auxiliary = make_buffer<VectorChildBuffer>(move(new_child));
45702
+ }
45707
45703
  return;
45708
45704
  }
45709
45705
  Vector child_vector(*this);
45706
+ auto internal_type = GetType().InternalType();
45707
+ if (internal_type == PhysicalType::STRUCT) {
45708
+ child_vector.auxiliary = make_buffer<VectorStructBuffer>(*this, sel, count);
45709
+ }
45710
45710
  auto child_ref = make_buffer<VectorChildBuffer>(move(child_vector));
45711
45711
  auto dict_buffer = make_buffer<DictionaryBuffer>(sel);
45712
45712
  vector_type = VectorType::DICTIONARY_VECTOR;
@@ -45715,7 +45715,7 @@ void Vector::Slice(const SelectionVector &sel, idx_t count) {
45715
45715
  }
45716
45716
 
45717
45717
  void Vector::Slice(const SelectionVector &sel, idx_t count, SelCache &cache) {
45718
- if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
45718
+ if (GetVectorType() == VectorType::DICTIONARY_VECTOR && GetType().InternalType() != PhysicalType::STRUCT) {
45719
45719
  // dictionary vector: need to merge dictionaries
45720
45720
  // check if we have a cached entry
45721
45721
  auto &current_sel = DictionaryVector::SelVector(*this);
@@ -45925,32 +45925,44 @@ void Vector::SetValue(idx_t index, const Value &val) {
45925
45925
  }
45926
45926
  }
45927
45927
 
45928
- Value Vector::GetValue(idx_t index) const {
45929
- switch (GetVectorType()) {
45930
- case VectorType::CONSTANT_VECTOR:
45931
- index = 0;
45932
- break;
45933
- case VectorType::FLAT_VECTOR:
45934
- break;
45935
- // dictionary: apply dictionary and forward to child
45936
- case VectorType::DICTIONARY_VECTOR: {
45937
- auto &sel_vector = DictionaryVector::SelVector(*this);
45938
- auto &child = DictionaryVector::Child(*this);
45939
- return child.GetValue(sel_vector.get_index(index));
45940
- }
45941
- case VectorType::SEQUENCE_VECTOR: {
45942
- int64_t start, increment;
45943
- SequenceVector::GetSequence(*this, start, increment);
45944
- return Value::Numeric(GetType(), start + increment * index);
45945
- }
45946
- default:
45947
- throw InternalException("Unimplemented vector type for Vector::GetValue");
45928
+ Value Vector::GetValue(const Vector &v_p, idx_t index_p) {
45929
+ const Vector *vector = &v_p;
45930
+ idx_t index = index_p;
45931
+ bool finished = false;
45932
+ while (!finished) {
45933
+ switch (vector->GetVectorType()) {
45934
+ case VectorType::CONSTANT_VECTOR:
45935
+ index = 0;
45936
+ finished = true;
45937
+ break;
45938
+ case VectorType::FLAT_VECTOR:
45939
+ finished = true;
45940
+ break;
45941
+ // dictionary: apply dictionary and forward to child
45942
+ case VectorType::DICTIONARY_VECTOR: {
45943
+ auto &sel_vector = DictionaryVector::SelVector(*vector);
45944
+ auto &child = DictionaryVector::Child(*vector);
45945
+ vector = &child;
45946
+ index = sel_vector.get_index(index);
45947
+ break;
45948
+ }
45949
+ case VectorType::SEQUENCE_VECTOR: {
45950
+ int64_t start, increment;
45951
+ SequenceVector::GetSequence(*vector, start, increment);
45952
+ return Value::Numeric(vector->GetType(), start + increment * index);
45953
+ }
45954
+ default:
45955
+ throw InternalException("Unimplemented vector type for Vector::GetValue");
45956
+ }
45948
45957
  }
45958
+ auto data = vector->data;
45959
+ auto &validity = vector->validity;
45960
+ auto &type = vector->GetType();
45949
45961
 
45950
45962
  if (!validity.RowIsValid(index)) {
45951
- return Value(GetType());
45963
+ return Value(vector->GetType());
45952
45964
  }
45953
- switch (GetType().id()) {
45965
+ switch (vector->GetType().id()) {
45954
45966
  case LogicalTypeId::BOOLEAN:
45955
45967
  return Value::BOOLEAN(((bool *)data)[index]);
45956
45968
  case LogicalTypeId::TINYINT:
@@ -45990,9 +46002,9 @@ Value Vector::GetValue(idx_t index) const {
45990
46002
  case LogicalTypeId::UUID:
45991
46003
  return Value::UUID(((hugeint_t *)data)[index]);
45992
46004
  case LogicalTypeId::DECIMAL: {
45993
- auto width = DecimalType::GetWidth(GetType());
45994
- auto scale = DecimalType::GetScale(GetType());
45995
- switch (GetType().InternalType()) {
46005
+ auto width = DecimalType::GetWidth(type);
46006
+ auto scale = DecimalType::GetScale(type);
46007
+ switch (type.InternalType()) {
45996
46008
  case PhysicalType::INT16:
45997
46009
  return Value::DECIMAL(((int16_t *)data)[index], width, scale);
45998
46010
  case PhysicalType::INT32:
@@ -46008,13 +46020,13 @@ Value Vector::GetValue(idx_t index) const {
46008
46020
  case LogicalTypeId::ENUM: {
46009
46021
  switch (type.InternalType()) {
46010
46022
  case PhysicalType::UINT8:
46011
- return Value::ENUM(((uint8_t *)data)[index], GetType());
46023
+ return Value::ENUM(((uint8_t *)data)[index], type);
46012
46024
  case PhysicalType::UINT16:
46013
- return Value::ENUM(((uint16_t *)data)[index], GetType());
46025
+ return Value::ENUM(((uint16_t *)data)[index], type);
46014
46026
  case PhysicalType::UINT32:
46015
- return Value::ENUM(((uint32_t *)data)[index], GetType());
46027
+ return Value::ENUM(((uint32_t *)data)[index], type);
46016
46028
  case PhysicalType::UINT64: // DEDUP_POINTER_ENUM
46017
- return Value::ENUM(((uint64_t *)data)[index], GetType());
46029
+ return Value::ENUM(((uint64_t *)data)[index], type);
46018
46030
  default:
46019
46031
  throw InternalException("ENUM can only have unsigned integers as physical types");
46020
46032
  }
@@ -46043,36 +46055,39 @@ Value Vector::GetValue(idx_t index) const {
46043
46055
  return Value::BLOB((const_data_ptr_t)str.GetDataUnsafe(), str.GetSize());
46044
46056
  }
46045
46057
  case LogicalTypeId::MAP: {
46046
- auto &child_entries = StructVector::GetEntries(*this);
46058
+ auto &child_entries = StructVector::GetEntries(*vector);
46047
46059
  Value key = child_entries[0]->GetValue(index);
46048
46060
  Value value = child_entries[1]->GetValue(index);
46049
46061
  return Value::MAP(move(key), move(value));
46050
46062
  }
46051
46063
  case LogicalTypeId::STRUCT: {
46052
46064
  // we can derive the value schema from the vector schema
46053
- auto &child_entries = StructVector::GetEntries(*this);
46065
+ auto &child_entries = StructVector::GetEntries(*vector);
46054
46066
  child_list_t<Value> children;
46055
46067
  for (idx_t child_idx = 0; child_idx < child_entries.size(); child_idx++) {
46056
46068
  auto &struct_child = child_entries[child_idx];
46057
- children.push_back(
46058
- make_pair(StructType::GetChildName(GetType(), child_idx), struct_child->GetValue(index)));
46069
+ children.push_back(make_pair(StructType::GetChildName(type, child_idx), struct_child->GetValue(index_p)));
46059
46070
  }
46060
46071
  return Value::STRUCT(move(children));
46061
46072
  }
46062
46073
  case LogicalTypeId::LIST: {
46063
46074
  auto offlen = ((list_entry_t *)data)[index];
46064
- auto &child_vec = ListVector::GetEntry(*this);
46065
- vector<Value> children;
46075
+ auto &child_vec = ListVector::GetEntry(*vector);
46076
+ std::vector<Value> children;
46066
46077
  for (idx_t i = offlen.offset; i < offlen.offset + offlen.length; i++) {
46067
46078
  children.push_back(child_vec.GetValue(i));
46068
46079
  }
46069
- return Value::LIST(ListType::GetChildType(GetType()), move(children));
46080
+ return Value::LIST(ListType::GetChildType(type), move(children));
46070
46081
  }
46071
46082
  default:
46072
46083
  throw InternalException("Unimplemented type for value access");
46073
46084
  }
46074
46085
  }
46075
46086
 
46087
+ Value Vector::GetValue(idx_t index) const {
46088
+ return GetValue(*this, index);
46089
+ }
46090
+
46076
46091
  // LCOV_EXCL_START
46077
46092
  string VectorTypeToString(VectorType type) {
46078
46093
  switch (type) {
@@ -46513,32 +46528,39 @@ void Vector::UTFVerify(idx_t count) {
46513
46528
  UTFVerify(*flat_sel, count);
46514
46529
  }
46515
46530
 
46516
- void Vector::Verify(const SelectionVector &sel, idx_t count) {
46531
+ void Vector::Verify(Vector &vector_p, const SelectionVector &sel_p, idx_t count) {
46517
46532
  #ifdef DEBUG
46518
46533
  if (count == 0) {
46519
46534
  return;
46520
46535
  }
46521
- if (GetVectorType() == VectorType::DICTIONARY_VECTOR) {
46522
- auto &child = DictionaryVector::Child(*this);
46536
+ Vector *vector = &vector_p;
46537
+ const SelectionVector *sel = &sel_p;
46538
+ SelectionVector owned_sel;
46539
+ auto &type = vector->GetType();
46540
+ auto vtype = vector->GetVectorType();
46541
+ if (vector->GetVectorType() == VectorType::DICTIONARY_VECTOR) {
46542
+ auto &child = DictionaryVector::Child(*vector);
46523
46543
  D_ASSERT(child.GetVectorType() != VectorType::DICTIONARY_VECTOR);
46524
- auto &dict_sel = DictionaryVector::SelVector(*this);
46544
+ auto &dict_sel = DictionaryVector::SelVector(*vector);
46525
46545
  // merge the selection vectors and verify the child
46526
- auto new_buffer = dict_sel.Slice(sel, count);
46527
- SelectionVector new_sel(new_buffer);
46528
- child.Verify(new_sel, count);
46529
- return;
46546
+ auto new_buffer = dict_sel.Slice(*sel, count);
46547
+ owned_sel.Initialize(new_buffer);
46548
+ sel = &owned_sel;
46549
+ vector = &child;
46550
+ vtype = vector->GetVectorType();
46530
46551
  }
46531
- if (TypeIsConstantSize(GetType().InternalType()) &&
46532
- (GetVectorType() == VectorType::CONSTANT_VECTOR || GetVectorType() == VectorType::FLAT_VECTOR)) {
46533
- D_ASSERT(!auxiliary);
46552
+ if (TypeIsConstantSize(type.InternalType()) &&
46553
+ (vtype == VectorType::CONSTANT_VECTOR || vtype == VectorType::FLAT_VECTOR)) {
46554
+ D_ASSERT(!vector->auxiliary);
46534
46555
  }
46535
- if (GetType().id() == LogicalTypeId::VARCHAR || GetType().id() == LogicalTypeId::JSON) {
46556
+ if (type.id() == LogicalTypeId::VARCHAR || type.id() == LogicalTypeId::JSON) {
46536
46557
  // verify that there are no '\0' bytes in string values
46537
- switch (GetVectorType()) {
46558
+ switch (vtype) {
46538
46559
  case VectorType::FLAT_VECTOR: {
46539
- auto strings = FlatVector::GetData<string_t>(*this);
46560
+ auto &validity = FlatVector::Validity(*vector);
46561
+ auto strings = FlatVector::GetData<string_t>(*vector);
46540
46562
  for (idx_t i = 0; i < count; i++) {
46541
- auto oidx = sel.get_index(i);
46563
+ auto oidx = sel->get_index(i);
46542
46564
  if (validity.RowIsValid(oidx)) {
46543
46565
  strings[oidx].VerifyNull();
46544
46566
  }
@@ -46550,57 +46572,76 @@ void Vector::Verify(const SelectionVector &sel, idx_t count) {
46550
46572
  }
46551
46573
  }
46552
46574
 
46553
- if (GetType().InternalType() == PhysicalType::STRUCT) {
46554
- auto &child_types = StructType::GetChildTypes(GetType());
46575
+ if (type.InternalType() == PhysicalType::STRUCT) {
46576
+ auto &child_types = StructType::GetChildTypes(type);
46555
46577
  D_ASSERT(!child_types.empty());
46556
- if (GetVectorType() == VectorType::FLAT_VECTOR || GetVectorType() == VectorType::CONSTANT_VECTOR) {
46557
- // create a selection vector of the non-null entries of the struct vector
46558
- auto &children = StructVector::GetEntries(*this);
46559
- D_ASSERT(child_types.size() == children.size());
46560
- for (idx_t child_idx = 0; child_idx < children.size(); child_idx++) {
46561
- if (GetVectorType() == VectorType::CONSTANT_VECTOR) {
46562
- D_ASSERT(children[child_idx]->GetVectorType() == VectorType::CONSTANT_VECTOR);
46563
- if (ConstantVector::IsNull(*this)) {
46564
- D_ASSERT(ConstantVector::IsNull(*children[child_idx]));
46565
- }
46566
- } else if (GetVectorType() == VectorType::FLAT_VECTOR &&
46567
- children[child_idx]->GetVectorType() == VectorType::FLAT_VECTOR) {
46568
- // for any NULL entry in the struct, the child should be NULL as well
46569
- auto &validity = FlatVector::Validity(*this);
46570
- auto &child_validity = FlatVector::Validity(*children[child_idx]);
46571
- for (idx_t i = 0; i < count; i++) {
46572
- auto index = sel.get_index(i);
46573
- if (!validity.RowIsValid(index)) {
46574
- D_ASSERT(!child_validity.RowIsValid(index));
46575
- }
46576
- }
46578
+ // create a selection vector of the non-null entries of the struct vector
46579
+ auto &children = StructVector::GetEntries(*vector);
46580
+ D_ASSERT(child_types.size() == children.size());
46581
+ for (idx_t child_idx = 0; child_idx < children.size(); child_idx++) {
46582
+ D_ASSERT(children[child_idx]->GetType() == child_types[child_idx].second);
46583
+ children[child_idx]->Verify(count);
46584
+ if (vtype == VectorType::CONSTANT_VECTOR) {
46585
+ D_ASSERT(children[child_idx]->GetVectorType() == VectorType::CONSTANT_VECTOR);
46586
+ if (ConstantVector::IsNull(*vector)) {
46587
+ D_ASSERT(ConstantVector::IsNull(*children[child_idx]));
46588
+ }
46589
+ }
46590
+ if (vtype != VectorType::FLAT_VECTOR) {
46591
+ continue;
46592
+ }
46593
+ ValidityMask *child_validity;
46594
+ SelectionVector owned_child_sel;
46595
+ const SelectionVector *child_sel = &owned_child_sel;
46596
+ if (children[child_idx]->GetVectorType() == VectorType::FLAT_VECTOR) {
46597
+ child_sel = FlatVector::IncrementalSelectionVector();
46598
+ child_validity = &FlatVector::Validity(*children[child_idx]);
46599
+ } else if (children[child_idx]->GetVectorType() == VectorType::DICTIONARY_VECTOR) {
46600
+ auto &child = DictionaryVector::Child(*children[child_idx]);
46601
+ if (child.GetVectorType() != VectorType::FLAT_VECTOR) {
46602
+ continue;
46603
+ }
46604
+ child_validity = &FlatVector::Validity(child);
46605
+ child_sel = &DictionaryVector::SelVector(*children[child_idx]);
46606
+ } else if (children[child_idx]->GetVectorType() == VectorType::CONSTANT_VECTOR) {
46607
+ child_sel = ConstantVector::ZeroSelectionVector(count, owned_child_sel);
46608
+ child_validity = &ConstantVector::Validity(*children[child_idx]);
46609
+ } else {
46610
+ continue;
46611
+ }
46612
+ // for any NULL entry in the struct, the child should be NULL as well
46613
+ auto &validity = FlatVector::Validity(*vector);
46614
+ for (idx_t i = 0; i < count; i++) {
46615
+ auto index = sel->get_index(i);
46616
+ if (!validity.RowIsValid(index)) {
46617
+ auto child_index = child_sel->get_index(sel_p.get_index(i));
46618
+ D_ASSERT(!child_validity->RowIsValid(child_index));
46577
46619
  }
46578
- D_ASSERT(children[child_idx]->GetType() == child_types[child_idx].second);
46579
- children[child_idx]->Verify(sel, count);
46580
46620
  }
46581
46621
  }
46582
46622
  }
46583
46623
 
46584
- if (GetType().InternalType() == PhysicalType::LIST) {
46585
- if (GetVectorType() == VectorType::CONSTANT_VECTOR) {
46586
- if (!ConstantVector::IsNull(*this)) {
46587
- auto &child = ListVector::GetEntry(*this);
46588
- SelectionVector child_sel(ListVector::GetListSize(*this));
46624
+ if (type.InternalType() == PhysicalType::LIST) {
46625
+ if (vtype == VectorType::CONSTANT_VECTOR) {
46626
+ if (!ConstantVector::IsNull(*vector)) {
46627
+ auto &child = ListVector::GetEntry(*vector);
46628
+ SelectionVector child_sel(ListVector::GetListSize(*vector));
46589
46629
  idx_t child_count = 0;
46590
- auto le = ConstantVector::GetData<list_entry_t>(*this);
46591
- D_ASSERT(le->offset + le->length <= ListVector::GetListSize(*this));
46630
+ auto le = ConstantVector::GetData<list_entry_t>(*vector);
46631
+ D_ASSERT(le->offset + le->length <= ListVector::GetListSize(*vector));
46592
46632
  for (idx_t k = 0; k < le->length; k++) {
46593
46633
  child_sel.set_index(child_count++, le->offset + k);
46594
46634
  }
46595
- child.Verify(child_sel, child_count);
46635
+ Vector::Verify(child, child_sel, child_count);
46596
46636
  }
46597
- } else if (GetVectorType() == VectorType::FLAT_VECTOR) {
46598
- auto &child = ListVector::GetEntry(*this);
46599
- auto child_size = ListVector::GetListSize(*this);
46600
- auto list_data = FlatVector::GetData<list_entry_t>(*this);
46637
+ } else if (vtype == VectorType::FLAT_VECTOR) {
46638
+ auto &validity = FlatVector::Validity(*vector);
46639
+ auto &child = ListVector::GetEntry(*vector);
46640
+ auto child_size = ListVector::GetListSize(*vector);
46641
+ auto list_data = FlatVector::GetData<list_entry_t>(*vector);
46601
46642
  idx_t total_size = 0;
46602
46643
  for (idx_t i = 0; i < count; i++) {
46603
- auto idx = sel.get_index(i);
46644
+ auto idx = sel->get_index(i);
46604
46645
  auto &le = list_data[idx];
46605
46646
  if (validity.RowIsValid(idx)) {
46606
46647
  D_ASSERT(le.offset + le.length <= child_size);
@@ -46610,7 +46651,7 @@ void Vector::Verify(const SelectionVector &sel, idx_t count) {
46610
46651
  SelectionVector child_sel(total_size);
46611
46652
  idx_t child_count = 0;
46612
46653
  for (idx_t i = 0; i < count; i++) {
46613
- auto idx = sel.get_index(i);
46654
+ auto idx = sel->get_index(i);
46614
46655
  auto &le = list_data[idx];
46615
46656
  if (validity.RowIsValid(idx)) {
46616
46657
  D_ASSERT(le.offset + le.length <= child_size);
@@ -46619,7 +46660,7 @@ void Vector::Verify(const SelectionVector &sel, idx_t count) {
46619
46660
  }
46620
46661
  }
46621
46662
  }
46622
- child.Verify(child_sel, child_count);
46663
+ Vector::Verify(child, child_sel, child_count);
46623
46664
  }
46624
46665
  }
46625
46666
  #endif
@@ -46627,7 +46668,7 @@ void Vector::Verify(const SelectionVector &sel, idx_t count) {
46627
46668
 
46628
46669
  void Vector::Verify(idx_t count) {
46629
46670
  auto flat_sel = FlatVector::IncrementalSelectionVector();
46630
- Verify(*flat_sel, count);
46671
+ Verify(*this, *flat_sel, count);
46631
46672
  }
46632
46673
 
46633
46674
  void FlatVector::SetNull(Vector &vector, idx_t idx, bool is_null) {
@@ -46714,7 +46755,7 @@ void ConstantVector::Reference(Vector &vector, Vector &source, idx_t position, i
46714
46755
  auto &source_entries = StructVector::GetEntries(source);
46715
46756
  auto &target_entries = StructVector::GetEntries(vector);
46716
46757
  for (idx_t i = 0; i < source_entries.size(); i++) {
46717
- ConstantVector::Reference(*target_entries[i], *source_entries[i], struct_index, count);
46758
+ ConstantVector::Reference(*target_entries[i], *source_entries[i], position, count);
46718
46759
  }
46719
46760
  vector.SetVectorType(VectorType::CONSTANT_VECTOR);
46720
46761
  break;
@@ -47074,6 +47115,15 @@ VectorStructBuffer::VectorStructBuffer(const LogicalType &type, idx_t capacity)
47074
47115
  }
47075
47116
  }
47076
47117
 
47118
+ VectorStructBuffer::VectorStructBuffer(Vector &other, const SelectionVector &sel, idx_t count)
47119
+ : VectorBuffer(VectorBufferType::STRUCT_BUFFER) {
47120
+ auto &other_vector = StructVector::GetEntries(other);
47121
+ for (auto &child_vector : other_vector) {
47122
+ auto vector = make_unique<Vector>(*child_vector, sel, count);
47123
+ children.push_back(move(vector));
47124
+ }
47125
+ }
47126
+
47077
47127
  VectorStructBuffer::~VectorStructBuffer() {
47078
47128
  }
47079
47129
 
@@ -49977,22 +50027,6 @@ idx_t PositionComparator::Final<duckdb::DistinctGreaterThan>(Vector &left, Vecto
49977
50027
 
49978
50028
  using StructEntries = vector<unique_ptr<Vector>>;
49979
50029
 
49980
- static StructEntries &StructVectorGetSlicedEntries(Vector &parent, StructEntries &sliced, const idx_t count) {
49981
- // We have to manually slice STRUCT dictionaries.
49982
- auto &children = StructVector::GetEntries(parent);
49983
- if (parent.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
49984
- auto &dict_sel = DictionaryVector::SelVector(parent);
49985
- for (auto &child : children) {
49986
- auto v = make_unique<Vector>(*child, dict_sel, count);
49987
- sliced.push_back(move(v));
49988
- }
49989
-
49990
- return sliced;
49991
- }
49992
-
49993
- return children;
49994
- }
49995
-
49996
50030
  static void ExtractNestedSelection(const SelectionVector &slice_sel, const idx_t count, const SelectionVector &sel,
49997
50031
  OptionalSelection &opt) {
49998
50032
 
@@ -50019,8 +50053,8 @@ static idx_t DistinctSelectStruct(Vector &left, Vector &right, idx_t count, cons
50019
50053
 
50020
50054
  // Avoid allocating in the 99% of the cases where we don't need to.
50021
50055
  StructEntries lsliced, rsliced;
50022
- auto &lchildren = StructVectorGetSlicedEntries(left, lsliced, count);
50023
- auto &rchildren = StructVectorGetSlicedEntries(right, rsliced, count);
50056
+ auto &lchildren = StructVector::GetEntries(left);
50057
+ auto &rchildren = StructVector::GetEntries(right);
50024
50058
  D_ASSERT(lchildren.size() == rchildren.size());
50025
50059
 
50026
50060
  // In order to reuse the comparators, we have to track what passed and failed internally.
@@ -50087,7 +50121,6 @@ static idx_t DistinctSelectStruct(Vector &left, Vector &right, idx_t count, cons
50087
50121
  match_count += true_count;
50088
50122
  }
50089
50123
  }
50090
-
50091
50124
  return match_count;
50092
50125
  }
50093
50126
 
@@ -50114,6 +50147,8 @@ static idx_t DistinctSelectList(Vector &left, Vector &right, idx_t count, const
50114
50147
  SelectionVector lcursor(count);
50115
50148
  SelectionVector rcursor(count);
50116
50149
 
50150
+ ListVector::GetEntry(left).Normalify(count);
50151
+ ListVector::GetEntry(right).Normalify(count);
50117
50152
  Vector lchild(ListVector::GetEntry(left), lcursor, count);
50118
50153
  Vector rchild(ListVector::GetEntry(right), rcursor, count);
50119
50154
 
@@ -51926,40 +51961,48 @@ static void TemplatedCopy(const Vector &source, const SelectionVector &sel, Vect
51926
51961
  }
51927
51962
  }
51928
51963
 
51929
- void VectorOperations::Copy(const Vector &source, Vector &target, const SelectionVector &sel_p, idx_t source_count,
51964
+ void VectorOperations::Copy(const Vector &source_p, Vector &target, const SelectionVector &sel_p, idx_t source_count,
51930
51965
  idx_t source_offset, idx_t target_offset) {
51931
51966
  D_ASSERT(source_offset <= source_count);
51932
- D_ASSERT(source.GetType() == target.GetType());
51967
+ D_ASSERT(source_p.GetType() == target.GetType());
51933
51968
  idx_t copy_count = source_count - source_offset;
51934
51969
 
51935
51970
  SelectionVector owned_sel;
51936
51971
  const SelectionVector *sel = &sel_p;
51937
- switch (source.GetVectorType()) {
51938
- case VectorType::DICTIONARY_VECTOR: {
51939
- // dictionary vector: merge selection vectors
51940
- auto &child = DictionaryVector::Child(source);
51941
- auto &dict_sel = DictionaryVector::SelVector(source);
51942
- // merge the selection vectors and verify the child
51943
- auto new_buffer = dict_sel.Slice(*sel, source_count);
51944
- SelectionVector merged_sel(new_buffer);
51945
- VectorOperations::Copy(child, target, merged_sel, source_count, source_offset, target_offset);
51946
- return;
51947
- }
51948
- case VectorType::SEQUENCE_VECTOR: {
51949
- int64_t start, increment;
51950
- Vector seq(source.GetType());
51951
- SequenceVector::GetSequence(source, start, increment);
51952
- VectorOperations::GenerateSequence(seq, source_count, *sel, start, increment);
51953
- VectorOperations::Copy(seq, target, *sel, source_count, source_offset, target_offset);
51954
- return;
51955
- }
51956
- case VectorType::CONSTANT_VECTOR:
51957
- sel = ConstantVector::ZeroSelectionVector(copy_count, owned_sel);
51958
- break; // carry on with below code
51959
- case VectorType::FLAT_VECTOR:
51960
- break;
51961
- default:
51962
- throw NotImplementedException("FIXME unimplemented vector type for VectorOperations::Copy");
51972
+
51973
+ const Vector *source = &source_p;
51974
+ bool finished = false;
51975
+ while (!finished) {
51976
+ switch (source->GetVectorType()) {
51977
+ case VectorType::DICTIONARY_VECTOR: {
51978
+ // dictionary vector: merge selection vectors
51979
+ auto &child = DictionaryVector::Child(*source);
51980
+ auto &dict_sel = DictionaryVector::SelVector(*source);
51981
+ // merge the selection vectors and verify the child
51982
+ auto new_buffer = dict_sel.Slice(*sel, source_count);
51983
+ owned_sel.Initialize(new_buffer);
51984
+ sel = &owned_sel;
51985
+ source = &child;
51986
+ break;
51987
+ }
51988
+ case VectorType::SEQUENCE_VECTOR: {
51989
+ int64_t start, increment;
51990
+ Vector seq(source->GetType());
51991
+ SequenceVector::GetSequence(*source, start, increment);
51992
+ VectorOperations::GenerateSequence(seq, source_count, *sel, start, increment);
51993
+ VectorOperations::Copy(seq, target, *sel, source_count, source_offset, target_offset);
51994
+ return;
51995
+ }
51996
+ case VectorType::CONSTANT_VECTOR:
51997
+ sel = ConstantVector::ZeroSelectionVector(copy_count, owned_sel);
51998
+ finished = true;
51999
+ break;
52000
+ case VectorType::FLAT_VECTOR:
52001
+ finished = true;
52002
+ break;
52003
+ default:
52004
+ throw NotImplementedException("FIXME unimplemented vector type for VectorOperations::Copy");
52005
+ }
51963
52006
  }
51964
52007
 
51965
52008
  if (copy_count == 0) {
@@ -51976,13 +52019,13 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
51976
52019
 
51977
52020
  // first copy the nullmask
51978
52021
  auto &tmask = FlatVector::Validity(target);
51979
- if (source.GetVectorType() == VectorType::CONSTANT_VECTOR) {
51980
- const bool valid = !ConstantVector::IsNull(source);
52022
+ if (source->GetVectorType() == VectorType::CONSTANT_VECTOR) {
52023
+ const bool valid = !ConstantVector::IsNull(*source);
51981
52024
  for (idx_t i = 0; i < copy_count; i++) {
51982
52025
  tmask.Set(target_offset + i, valid);
51983
52026
  }
51984
52027
  } else {
51985
- auto &smask = FlatVector::Validity(source);
52028
+ auto &smask = FlatVector::Validity(*source);
51986
52029
  if (smask.IsMaskSet()) {
51987
52030
  for (idx_t i = 0; i < copy_count; i++) {
51988
52031
  auto idx = sel->get_index(source_offset + i);
@@ -52007,46 +52050,46 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
52007
52050
  D_ASSERT(sel);
52008
52051
 
52009
52052
  // now copy over the data
52010
- switch (source.GetType().InternalType()) {
52053
+ switch (source->GetType().InternalType()) {
52011
52054
  case PhysicalType::BOOL:
52012
52055
  case PhysicalType::INT8:
52013
- TemplatedCopy<int8_t>(source, *sel, target, source_offset, target_offset, copy_count);
52056
+ TemplatedCopy<int8_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52014
52057
  break;
52015
52058
  case PhysicalType::INT16:
52016
- TemplatedCopy<int16_t>(source, *sel, target, source_offset, target_offset, copy_count);
52059
+ TemplatedCopy<int16_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52017
52060
  break;
52018
52061
  case PhysicalType::INT32:
52019
- TemplatedCopy<int32_t>(source, *sel, target, source_offset, target_offset, copy_count);
52062
+ TemplatedCopy<int32_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52020
52063
  break;
52021
52064
  case PhysicalType::INT64:
52022
- TemplatedCopy<int64_t>(source, *sel, target, source_offset, target_offset, copy_count);
52065
+ TemplatedCopy<int64_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52023
52066
  break;
52024
52067
  case PhysicalType::UINT8:
52025
- TemplatedCopy<uint8_t>(source, *sel, target, source_offset, target_offset, copy_count);
52068
+ TemplatedCopy<uint8_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52026
52069
  break;
52027
52070
  case PhysicalType::UINT16:
52028
- TemplatedCopy<uint16_t>(source, *sel, target, source_offset, target_offset, copy_count);
52071
+ TemplatedCopy<uint16_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52029
52072
  break;
52030
52073
  case PhysicalType::UINT32:
52031
- TemplatedCopy<uint32_t>(source, *sel, target, source_offset, target_offset, copy_count);
52074
+ TemplatedCopy<uint32_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52032
52075
  break;
52033
52076
  case PhysicalType::UINT64:
52034
- TemplatedCopy<uint64_t>(source, *sel, target, source_offset, target_offset, copy_count);
52077
+ TemplatedCopy<uint64_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52035
52078
  break;
52036
52079
  case PhysicalType::INT128:
52037
- TemplatedCopy<hugeint_t>(source, *sel, target, source_offset, target_offset, copy_count);
52080
+ TemplatedCopy<hugeint_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52038
52081
  break;
52039
52082
  case PhysicalType::FLOAT:
52040
- TemplatedCopy<float>(source, *sel, target, source_offset, target_offset, copy_count);
52083
+ TemplatedCopy<float>(*source, *sel, target, source_offset, target_offset, copy_count);
52041
52084
  break;
52042
52085
  case PhysicalType::DOUBLE:
52043
- TemplatedCopy<double>(source, *sel, target, source_offset, target_offset, copy_count);
52086
+ TemplatedCopy<double>(*source, *sel, target, source_offset, target_offset, copy_count);
52044
52087
  break;
52045
52088
  case PhysicalType::INTERVAL:
52046
- TemplatedCopy<interval_t>(source, *sel, target, source_offset, target_offset, copy_count);
52089
+ TemplatedCopy<interval_t>(*source, *sel, target, source_offset, target_offset, copy_count);
52047
52090
  break;
52048
52091
  case PhysicalType::VARCHAR: {
52049
- auto ldata = FlatVector::GetData<string_t>(source);
52092
+ auto ldata = FlatVector::GetData<string_t>(*source);
52050
52093
  auto tdata = FlatVector::GetData<string_t>(target);
52051
52094
  for (idx_t i = 0; i < copy_count; i++) {
52052
52095
  auto source_idx = sel->get_index(source_offset + i);
@@ -52058,11 +52101,11 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
52058
52101
  break;
52059
52102
  }
52060
52103
  case PhysicalType::STRUCT: {
52061
- auto &source_children = StructVector::GetEntries(source);
52104
+ auto &source_children = StructVector::GetEntries(*source);
52062
52105
  auto &target_children = StructVector::GetEntries(target);
52063
52106
  D_ASSERT(source_children.size() == target_children.size());
52064
52107
  for (idx_t i = 0; i < source_children.size(); i++) {
52065
- VectorOperations::Copy(*source_children[i], *target_children[i], *sel, source_count, source_offset,
52108
+ VectorOperations::Copy(*source_children[i], *target_children[i], sel_p, source_count, source_offset,
52066
52109
  target_offset);
52067
52110
  }
52068
52111
  break;
@@ -52070,8 +52113,8 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
52070
52113
  case PhysicalType::LIST: {
52071
52114
  D_ASSERT(target.GetType().InternalType() == PhysicalType::LIST);
52072
52115
 
52073
- auto &source_child = ListVector::GetEntry(source);
52074
- auto sdata = FlatVector::GetData<list_entry_t>(source);
52116
+ auto &source_child = ListVector::GetEntry(*source);
52117
+ auto sdata = FlatVector::GetData<list_entry_t>(*source);
52075
52118
  auto tdata = FlatVector::GetData<list_entry_t>(target);
52076
52119
 
52077
52120
  if (target_vector_type == VectorType::CONSTANT_VECTOR) {
@@ -52129,7 +52172,7 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
52129
52172
  }
52130
52173
  default:
52131
52174
  throw NotImplementedException("Unimplemented type '%s' for copy!",
52132
- TypeIdToString(source.GetType().InternalType()));
52175
+ TypeIdToString(source->GetType().InternalType()));
52133
52176
  }
52134
52177
 
52135
52178
  if (target_vector_type != VectorType::FLAT_VECTOR) {
@@ -52139,38 +52182,8 @@ void VectorOperations::Copy(const Vector &source, Vector &target, const Selectio
52139
52182
 
52140
52183
  void VectorOperations::Copy(const Vector &source, Vector &target, idx_t source_count, idx_t source_offset,
52141
52184
  idx_t target_offset) {
52142
- switch (source.GetVectorType()) {
52143
- case VectorType::DICTIONARY_VECTOR: {
52144
- // dictionary: continue into child with selection vector
52145
- auto &child = DictionaryVector::Child(source);
52146
- auto &dict_sel = DictionaryVector::SelVector(source);
52147
- VectorOperations::Copy(child, target, dict_sel, source_count, source_offset, target_offset);
52148
- break;
52149
- }
52150
- case VectorType::CONSTANT_VECTOR: {
52151
- SelectionVector owned_sel;
52152
- auto sel = ConstantVector::ZeroSelectionVector(source_count, owned_sel);
52153
- VectorOperations::Copy(source, target, *sel, source_count, source_offset, target_offset);
52154
- break;
52155
- }
52156
- case VectorType::FLAT_VECTOR: {
52157
- auto sel = FlatVector::IncrementalSelectionVector();
52158
- VectorOperations::Copy(source, target, *sel, source_count, source_offset, target_offset);
52159
- break;
52160
- }
52161
- case VectorType::SEQUENCE_VECTOR: {
52162
- int64_t start, increment;
52163
- SequenceVector::GetSequence(source, start, increment);
52164
- Vector flattened(source.GetType());
52165
- VectorOperations::GenerateSequence(flattened, source_count, start, increment);
52166
-
52167
- auto sel = FlatVector::IncrementalSelectionVector();
52168
- VectorOperations::Copy(flattened, target, *sel, source_count, source_offset, target_offset);
52169
- break;
52170
- }
52171
- default:
52172
- throw NotImplementedException("FIXME: unimplemented vector type for VectorOperations::Copy");
52173
- }
52185
+ VectorOperations::Copy(source, target, *FlatVector::IncrementalSelectionVector(), source_count, source_offset,
52186
+ target_offset);
52174
52187
  }
52175
52188
 
52176
52189
  } // namespace duckdb
@@ -54326,11 +54339,14 @@ void ValidityFillLoop(Vector &vector, Vector &result, const SelectionVector &sel
54326
54339
  } else {
54327
54340
  VectorData vdata;
54328
54341
  vector.Orrify(count, vdata);
54342
+ if (vdata.validity.AllValid()) {
54343
+ return;
54344
+ }
54329
54345
  for (idx_t i = 0; i < count; i++) {
54330
54346
  auto source_idx = vdata.sel->get_index(i);
54331
- auto res_idx = sel.get_index(i);
54332
-
54333
- result_mask.Set(res_idx, vdata.validity.RowIsValid(source_idx));
54347
+ if (!vdata.validity.RowIsValid(source_idx)) {
54348
+ result_mask.SetInvalid(sel.get_index(i));
54349
+ }
54334
54350
  }
54335
54351
  }
54336
54352
  }
@@ -54405,7 +54421,7 @@ void ExpressionExecutor::FillSwitch(Vector &vector, Vector &result, const Select
54405
54421
  result_data[result_idx].offset += offset;
54406
54422
  }
54407
54423
 
54408
- result.Verify(sel, count);
54424
+ Vector::Verify(result, sel, count);
54409
54425
  break;
54410
54426
  }
54411
54427
  default:
@@ -67721,6 +67737,7 @@ OperatorResultType PhysicalPiecewiseMergeJoin::Execute(ExecutionContext &context
67721
67737
  }
67722
67738
  }
67723
67739
 
67740
+ input.Verify();
67724
67741
  switch (join_type) {
67725
67742
  case JoinType::SEMI:
67726
67743
  case JoinType::ANTI:
@@ -68319,6 +68336,8 @@ SinkResultType PhysicalOrder::Sink(ExecutionContext &context, GlobalSinkState &g
68319
68336
  lstate.executor.Execute(input, sort);
68320
68337
 
68321
68338
  // Sink the data into the local sort state
68339
+ sort.Verify();
68340
+ input.Verify();
68322
68341
  local_sort_state.SinkChunk(sort, input);
68323
68342
 
68324
68343
  // When sorting data reaches a certain size, we sort it
@@ -82014,15 +82033,16 @@ static bool TemplatedOptimumValue(Vector &left, idx_t lidx, idx_t lcount, Vector
82014
82033
  }
82015
82034
 
82016
82035
  template <class OP>
82017
- static bool TemplatedOptimumStruct(Vector &left, idx_t lidx, idx_t lcount, Vector &right, idx_t ridx, idx_t rcount) {
82036
+ static bool TemplatedOptimumStruct(Vector &left, idx_t lidx_p, idx_t lcount, Vector &right, idx_t ridx_p,
82037
+ idx_t rcount) {
82018
82038
  // STRUCT dictionaries apply to all the children
82019
82039
  // so map the indexes first
82020
82040
  VectorData lvdata, rvdata;
82021
82041
  left.Orrify(lcount, lvdata);
82022
82042
  right.Orrify(rcount, rvdata);
82023
82043
 
82024
- lidx = lvdata.sel->get_index(lidx);
82025
- ridx = rvdata.sel->get_index(ridx);
82044
+ idx_t lidx = lvdata.sel->get_index(lidx_p);
82045
+ idx_t ridx = rvdata.sel->get_index(ridx_p);
82026
82046
 
82027
82047
  // DISTINCT semantics are in effect for nested types
82028
82048
  auto lnull = !lvdata.validity.RowIsValid(lidx);
@@ -82040,7 +82060,7 @@ static bool TemplatedOptimumStruct(Vector &left, idx_t lidx, idx_t lcount, Vecto
82040
82060
  auto &rchild = *rchildren[col_no];
82041
82061
 
82042
82062
  // Strict comparisons use the OP for definite
82043
- if (TemplatedOptimumValue<OP>(lchild, lidx, lcount, rchild, ridx, rcount)) {
82063
+ if (TemplatedOptimumValue<OP>(lchild, lidx_p, lcount, rchild, ridx_p, rcount)) {
82044
82064
  return true;
82045
82065
  }
82046
82066
 
@@ -82049,7 +82069,7 @@ static bool TemplatedOptimumStruct(Vector &left, idx_t lidx, idx_t lcount, Vecto
82049
82069
  }
82050
82070
 
82051
82071
  // Strict comparisons use IS NOT DISTINCT for possible
82052
- if (!TemplatedOptimumValue<NotDistinctFrom>(lchild, lidx, lcount, rchild, ridx, rcount)) {
82072
+ if (!TemplatedOptimumValue<NotDistinctFrom>(lchild, lidx_p, lcount, rchild, ridx_p, rcount)) {
82053
82073
  return false;
82054
82074
  }
82055
82075
  }
@@ -96509,23 +96529,11 @@ static void CardinalityFunction(DataChunk &args, ExpressionState &state, Vector
96509
96529
  result.SetVectorType(VectorType::FLAT_VECTOR);
96510
96530
  auto result_data = FlatVector::GetData<uint64_t>(result);
96511
96531
 
96512
- if (map.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
96513
- auto &child = DictionaryVector::Child(map);
96514
- auto &dict_sel = DictionaryVector::SelVector(map);
96515
-
96516
- auto &children = StructVector::GetEntries(child);
96517
- children[0]->Orrify(args.size(), list_data);
96518
- for (idx_t row = 0; row < args.size(); row++) {
96519
- auto list_entry = ((list_entry_t *)list_data.data)[list_data.sel->get_index(dict_sel.get_index(row))];
96520
- result_data[row] = list_entry.length;
96521
- }
96522
- } else {
96523
- auto &children = StructVector::GetEntries(map);
96524
- children[0]->Orrify(args.size(), list_data);
96525
- for (idx_t row = 0; row < args.size(); row++) {
96526
- auto list_entry = ((list_entry_t *)list_data.data)[list_data.sel->get_index(row)];
96527
- result_data[row] = list_entry.length;
96528
- }
96532
+ auto &children = StructVector::GetEntries(map);
96533
+ children[0]->Orrify(args.size(), list_data);
96534
+ for (idx_t row = 0; row < args.size(); row++) {
96535
+ auto list_entry = ((list_entry_t *)list_data.data)[list_data.sel->get_index(row)];
96536
+ result_data[row] = list_entry.length;
96529
96537
  }
96530
96538
 
96531
96539
  if (args.size() == 1) {
@@ -96673,33 +96681,16 @@ static void MapExtractFunction(DataChunk &args, ExpressionState &state, Vector &
96673
96681
  auto key_value = key.GetValue(0);
96674
96682
  VectorData offset_data;
96675
96683
 
96676
- if (map.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
96677
- auto &child = DictionaryVector::Child(map);
96678
- auto &children = StructVector::GetEntries(child);
96679
- auto &dict_sel = DictionaryVector::SelVector(map);
96680
- children[0]->Orrify(args.size(), offset_data);
96681
- auto &key_type = ListType::GetChildType(children[0]->GetType());
96682
- if (key_type != LogicalTypeId::SQLNULL) {
96683
- key_value = key_value.CastAs(key_type);
96684
- }
96685
- for (idx_t row = 0; row < args.size(); row++) {
96686
- auto offsets =
96687
- ListVector::Search(*children[0], key_value, offset_data.sel->get_index(dict_sel.get_index(row)));
96688
- auto values = ListVector::GetValuesFromOffsets(*children[1], offsets);
96689
- FillResult(values, result, row);
96690
- }
96691
- } else {
96692
- auto &children = StructVector::GetEntries(map);
96693
- children[0]->Orrify(args.size(), offset_data);
96694
- auto &key_type = ListType::GetChildType(children[0]->GetType());
96695
- if (key_type != LogicalTypeId::SQLNULL) {
96696
- key_value = key_value.CastAs(key_type);
96697
- }
96698
- for (idx_t row = 0; row < args.size(); row++) {
96699
- auto offsets = ListVector::Search(*children[0], key_value, offset_data.sel->get_index(row));
96700
- auto values = ListVector::GetValuesFromOffsets(*children[1], offsets);
96701
- FillResult(values, result, row);
96702
- }
96684
+ auto &children = StructVector::GetEntries(map);
96685
+ children[0]->Orrify(args.size(), offset_data);
96686
+ auto &key_type = ListType::GetChildType(children[0]->GetType());
96687
+ if (key_type != LogicalTypeId::SQLNULL) {
96688
+ key_value = key_value.CastAs(key_type);
96689
+ }
96690
+ for (idx_t row = 0; row < args.size(); row++) {
96691
+ auto offsets = ListVector::Search(*children[0], key_value, offset_data.sel->get_index(row));
96692
+ auto values = ListVector::GetValuesFromOffsets(*children[1], offsets);
96693
+ FillResult(values, result, row);
96703
96694
  }
96704
96695
 
96705
96696
  if (args.size() == 1) {
@@ -103954,19 +103945,10 @@ static void StructExtractFunction(DataChunk &args, ExpressionState &state, Vecto
103954
103945
  auto &vec = args.data[0];
103955
103946
 
103956
103947
  vec.Verify(args.size());
103957
- if (vec.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
103958
- auto &child = DictionaryVector::Child(vec);
103959
- auto &dict_sel = DictionaryVector::SelVector(vec);
103960
- auto &children = StructVector::GetEntries(child);
103961
- D_ASSERT(info.index < children.size());
103962
- auto &struct_child = children[info.index];
103963
- result.Slice(*struct_child, dict_sel, args.size());
103964
- } else {
103965
- auto &children = StructVector::GetEntries(vec);
103966
- D_ASSERT(info.index < children.size());
103967
- auto &struct_child = children[info.index];
103968
- result.Reference(*struct_child);
103969
- }
103948
+ auto &children = StructVector::GetEntries(vec);
103949
+ D_ASSERT(info.index < children.size());
103950
+ auto &struct_child = children[info.index];
103951
+ result.Reference(*struct_child);
103970
103952
  result.Verify(args.size());
103971
103953
  }
103972
103954
 
@@ -106635,8 +106617,28 @@ struct DuckDBViewsFun {
106635
106617
  static void RegisterFunction(BuiltinFunctions &set);
106636
106618
  };
106637
106619
 
106620
+ struct TestType {
106621
+ TestType(LogicalType type_p, string name_p)
106622
+ : type(move(type_p)), name(move(name_p)), min_value(Value::MinimumValue(type)),
106623
+ max_value(Value::MaximumValue(type)) {
106624
+ }
106625
+ TestType(LogicalType type_p, string name_p, Value min, Value max)
106626
+ : type(move(type_p)), name(move(name_p)), min_value(move(min)), max_value(move(max)) {
106627
+ }
106628
+
106629
+ LogicalType type;
106630
+ string name;
106631
+ Value min_value;
106632
+ Value max_value;
106633
+ };
106634
+
106638
106635
  struct TestAllTypesFun {
106639
106636
  static void RegisterFunction(BuiltinFunctions &set);
106637
+ static vector<TestType> GetTestTypes();
106638
+ };
106639
+
106640
+ struct TestVectorTypesFun {
106641
+ static void RegisterFunction(BuiltinFunctions &set);
106640
106642
  };
106641
106643
 
106642
106644
  } // namespace duckdb
@@ -110246,22 +110248,7 @@ struct TestAllTypesData : public GlobalTableFunctionState {
110246
110248
  idx_t offset;
110247
110249
  };
110248
110250
 
110249
- struct TestType {
110250
- TestType(LogicalType type_p, string name_p)
110251
- : type(move(type_p)), name(move(name_p)), min_value(Value::MinimumValue(type)),
110252
- max_value(Value::MaximumValue(type)) {
110253
- }
110254
- TestType(LogicalType type_p, string name_p, Value min, Value max)
110255
- : type(move(type_p)), name(move(name_p)), min_value(move(min)), max_value(move(max)) {
110256
- }
110257
-
110258
- LogicalType type;
110259
- string name;
110260
- Value min_value;
110261
- Value max_value;
110262
- };
110263
-
110264
- static vector<TestType> GetTestTypes() {
110251
+ vector<TestType> TestAllTypesFun::GetTestTypes() {
110265
110252
  vector<TestType> result;
110266
110253
  // scalar types/numerics
110267
110254
  result.emplace_back(LogicalType::BOOLEAN, "bool");
@@ -110432,7 +110419,7 @@ static vector<TestType> GetTestTypes() {
110432
110419
 
110433
110420
  static unique_ptr<FunctionData> TestAllTypesBind(ClientContext &context, TableFunctionBindInput &input,
110434
110421
  vector<LogicalType> &return_types, vector<string> &names) {
110435
- auto test_types = GetTestTypes();
110422
+ auto test_types = TestAllTypesFun::GetTestTypes();
110436
110423
  for (auto &test_type : test_types) {
110437
110424
  return_types.push_back(move(test_type.type));
110438
110425
  names.push_back(move(test_type.name));
@@ -110442,7 +110429,7 @@ static unique_ptr<FunctionData> TestAllTypesBind(ClientContext &context, TableFu
110442
110429
 
110443
110430
  unique_ptr<GlobalTableFunctionState> TestAllTypesInit(ClientContext &context, TableFunctionInitInput &input) {
110444
110431
  auto result = make_unique<TestAllTypesData>();
110445
- auto test_types = GetTestTypes();
110432
+ auto test_types = TestAllTypesFun::GetTestTypes();
110446
110433
  // 3 rows: min, max and NULL
110447
110434
  result->entries.resize(3);
110448
110435
  // initialize the values
@@ -110480,6 +110467,256 @@ void TestAllTypesFun::RegisterFunction(BuiltinFunctions &set) {
110480
110467
  } // namespace duckdb
110481
110468
 
110482
110469
 
110470
+
110471
+
110472
+ namespace duckdb {
110473
+
110474
+ // FLAT, CONSTANT, DICTIONARY, SEQUENCE
110475
+ struct TestVectorBindData : public TableFunctionData {
110476
+ LogicalType type;
110477
+ bool all_flat;
110478
+ };
110479
+
110480
+ struct TestVectorTypesData : public GlobalTableFunctionState {
110481
+ TestVectorTypesData() : offset(0) {
110482
+ }
110483
+
110484
+ vector<unique_ptr<DataChunk>> entries;
110485
+ idx_t offset;
110486
+ };
110487
+
110488
+ struct TestVectorInfo {
110489
+ TestVectorInfo(const LogicalType &type, const map<LogicalTypeId, TestType> &test_type_map,
110490
+ vector<unique_ptr<DataChunk>> &entries)
110491
+ : type(type), test_type_map(test_type_map), entries(entries) {
110492
+ }
110493
+
110494
+ const LogicalType &type;
110495
+ const map<LogicalTypeId, TestType> &test_type_map;
110496
+ vector<unique_ptr<DataChunk>> &entries;
110497
+ };
110498
+
110499
+ struct TestVectorFlat {
110500
+ static constexpr const idx_t TEST_VECTOR_CARDINALITY = 3;
110501
+
110502
+ static vector<Value> GenerateValues(TestVectorInfo &info, const LogicalType &type) {
110503
+ vector<Value> result;
110504
+ switch (type.InternalType()) {
110505
+ case PhysicalType::STRUCT: {
110506
+ vector<child_list_t<Value>> struct_children;
110507
+ auto &child_types = StructType::GetChildTypes(type);
110508
+
110509
+ struct_children.resize(TEST_VECTOR_CARDINALITY);
110510
+ for (auto &child_type : child_types) {
110511
+ auto child_values = GenerateValues(info, child_type.second);
110512
+
110513
+ for (idx_t i = 0; i < child_values.size(); i++) {
110514
+ struct_children[i].push_back(make_pair(child_type.first, move(child_values[i])));
110515
+ }
110516
+ }
110517
+ for (auto &struct_child : struct_children) {
110518
+ result.push_back(Value::STRUCT(move(struct_child)));
110519
+ }
110520
+ break;
110521
+ }
110522
+ case PhysicalType::LIST: {
110523
+ auto &child_type = ListType::GetChildType(type);
110524
+ auto child_values = GenerateValues(info, child_type);
110525
+
110526
+ result.push_back(Value::LIST(child_type, {child_values[0], child_values[1]}));
110527
+ result.push_back(Value::LIST(child_type, {}));
110528
+ result.push_back(Value::LIST(child_type, {child_values[2]}));
110529
+ break;
110530
+ }
110531
+ default: {
110532
+ auto entry = info.test_type_map.find(type.id());
110533
+ if (entry == info.test_type_map.end()) {
110534
+ throw NotImplementedException("Unimplemented type for test_vector_types %s", type.ToString());
110535
+ }
110536
+ result.push_back(entry->second.min_value);
110537
+ result.push_back(entry->second.max_value);
110538
+ result.emplace_back(type);
110539
+ break;
110540
+ }
110541
+ }
110542
+ return result;
110543
+ }
110544
+
110545
+ static void Generate(TestVectorInfo &info) {
110546
+ vector<Value> result_values = GenerateValues(info, info.type);
110547
+ for (idx_t cur_row = 0; cur_row < result_values.size(); cur_row += STANDARD_VECTOR_SIZE) {
110548
+ auto result = make_unique<DataChunk>();
110549
+ result->Initialize({info.type});
110550
+ auto cardinality = MinValue<idx_t>(STANDARD_VECTOR_SIZE, result_values.size() - cur_row);
110551
+ for (idx_t i = 0; i < cardinality; i++) {
110552
+ result->data[0].SetValue(i, result_values[cur_row + i]);
110553
+ }
110554
+ result->SetCardinality(cardinality);
110555
+ info.entries.push_back(move(result));
110556
+ }
110557
+ }
110558
+ };
110559
+
110560
+ struct TestVectorConstant {
110561
+ static void Generate(TestVectorInfo &info) {
110562
+ auto values = TestVectorFlat::GenerateValues(info, info.type);
110563
+ for (idx_t cur_row = 0; cur_row < TestVectorFlat::TEST_VECTOR_CARDINALITY; cur_row += STANDARD_VECTOR_SIZE) {
110564
+ auto result = make_unique<DataChunk>();
110565
+ result->Initialize({info.type});
110566
+ auto cardinality = MinValue<idx_t>(STANDARD_VECTOR_SIZE, TestVectorFlat::TEST_VECTOR_CARDINALITY - cur_row);
110567
+ result->data[0].SetValue(0, values[0]);
110568
+ result->data[0].SetVectorType(VectorType::CONSTANT_VECTOR);
110569
+ result->SetCardinality(cardinality);
110570
+
110571
+ info.entries.push_back(move(result));
110572
+ }
110573
+ }
110574
+ };
110575
+
110576
+ struct TestVectorSequence {
110577
+ static void GenerateVector(TestVectorInfo &info, const LogicalType &type, Vector &result) {
110578
+ D_ASSERT(type == result.GetType());
110579
+ switch (type.id()) {
110580
+ case LogicalTypeId::TINYINT:
110581
+ case LogicalTypeId::SMALLINT:
110582
+ case LogicalTypeId::INTEGER:
110583
+ case LogicalTypeId::BIGINT:
110584
+ case LogicalTypeId::UTINYINT:
110585
+ case LogicalTypeId::USMALLINT:
110586
+ case LogicalTypeId::UINTEGER:
110587
+ case LogicalTypeId::UBIGINT:
110588
+ result.Sequence(3, 2);
110589
+ return;
110590
+ default:
110591
+ break;
110592
+ }
110593
+ switch (type.InternalType()) {
110594
+ case PhysicalType::STRUCT: {
110595
+ auto &child_entries = StructVector::GetEntries(result);
110596
+ for (auto &child_entry : child_entries) {
110597
+ GenerateVector(info, child_entry->GetType(), *child_entry);
110598
+ }
110599
+ break;
110600
+ }
110601
+ case PhysicalType::LIST: {
110602
+ auto data = FlatVector::GetData<list_entry_t>(result);
110603
+ data[0].offset = 0;
110604
+ data[0].length = 2;
110605
+ data[1].offset = 2;
110606
+ data[1].length = 0;
110607
+ data[2].offset = 2;
110608
+ data[2].length = 1;
110609
+
110610
+ GenerateVector(info, ListType::GetChildType(type), ListVector::GetEntry(result));
110611
+ ListVector::SetListSize(result, 3);
110612
+ break;
110613
+ }
110614
+ default: {
110615
+ auto entry = info.test_type_map.find(type.id());
110616
+ if (entry == info.test_type_map.end()) {
110617
+ throw NotImplementedException("Unimplemented type for test_vector_types %s", type.ToString());
110618
+ }
110619
+ result.SetValue(0, entry->second.min_value);
110620
+ result.SetValue(1, entry->second.max_value);
110621
+ result.SetValue(2, Value(type));
110622
+ break;
110623
+ }
110624
+ }
110625
+ }
110626
+
110627
+ static void Generate(TestVectorInfo &info) {
110628
+ #if STANDARD_VECTOR_SIZE > 2
110629
+ auto result = make_unique<DataChunk>();
110630
+ result->Initialize({info.type});
110631
+
110632
+ GenerateVector(info, info.type, result->data[0]);
110633
+ result->SetCardinality(3);
110634
+ info.entries.push_back(move(result));
110635
+ #endif
110636
+ }
110637
+ };
110638
+
110639
+ struct TestVectorDictionary {
110640
+ static void Generate(TestVectorInfo &info) {
110641
+ idx_t current_chunk = info.entries.size();
110642
+
110643
+ unordered_set<idx_t> slice_entries {1, 2};
110644
+
110645
+ TestVectorFlat::Generate(info);
110646
+ idx_t current_idx = 0;
110647
+ for (idx_t i = current_chunk; i < info.entries.size(); i++) {
110648
+ auto &chunk = *info.entries[i];
110649
+ SelectionVector sel(STANDARD_VECTOR_SIZE);
110650
+ idx_t sel_idx = 0;
110651
+ for (idx_t k = 0; k < chunk.size(); k++) {
110652
+ if (slice_entries.count(current_idx + k) > 0) {
110653
+ sel.set_index(sel_idx++, k);
110654
+ }
110655
+ }
110656
+ chunk.Slice(sel, sel_idx);
110657
+ current_idx += chunk.size();
110658
+ }
110659
+ }
110660
+ };
110661
+
110662
+ static unique_ptr<FunctionData> TestVectorTypesBind(ClientContext &context, TableFunctionBindInput &input,
110663
+ vector<LogicalType> &return_types, vector<string> &names) {
110664
+ auto result = make_unique<TestVectorBindData>();
110665
+ result->type = input.inputs[0].type();
110666
+ result->all_flat = BooleanValue::Get(input.inputs[1]);
110667
+
110668
+ return_types.push_back(result->type);
110669
+ names.emplace_back("test_vector");
110670
+ return move(result);
110671
+ }
110672
+
110673
+ unique_ptr<GlobalTableFunctionState> TestVectorTypesInit(ClientContext &context, TableFunctionInitInput &input) {
110674
+ auto &bind_data = (TestVectorBindData &)*input.bind_data;
110675
+
110676
+ auto result = make_unique<TestVectorTypesData>();
110677
+
110678
+ auto test_types = TestAllTypesFun::GetTestTypes();
110679
+
110680
+ map<LogicalTypeId, TestType> test_type_map;
110681
+ for (auto &test_type : test_types) {
110682
+ test_type_map.insert(make_pair(test_type.type.id(), move(test_type)));
110683
+ }
110684
+
110685
+ TestVectorInfo info(bind_data.type, test_type_map, result->entries);
110686
+ TestVectorFlat::Generate(info);
110687
+ TestVectorConstant::Generate(info);
110688
+ TestVectorDictionary::Generate(info);
110689
+ TestVectorSequence::Generate(info);
110690
+ for (auto &entry : result->entries) {
110691
+ entry->Verify();
110692
+ }
110693
+ if (bind_data.all_flat) {
110694
+ for (auto &entry : result->entries) {
110695
+ entry->Normalify();
110696
+ entry->Verify();
110697
+ }
110698
+ }
110699
+ return move(result);
110700
+ }
110701
+
110702
+ void TestVectorTypesFunction(ClientContext &context, TableFunctionInput &data_p, DataChunk &output) {
110703
+ auto &data = (TestVectorTypesData &)*data_p.global_state;
110704
+ if (data.offset >= data.entries.size()) {
110705
+ // finished returning values
110706
+ return;
110707
+ }
110708
+ output.Reference(*data.entries[data.offset]);
110709
+ data.offset++;
110710
+ }
110711
+
110712
+ void TestVectorTypesFun::RegisterFunction(BuiltinFunctions &set) {
110713
+ set.AddFunction(TableFunction("test_vector_types", {LogicalType::ANY, LogicalType::BOOLEAN},
110714
+ TestVectorTypesFunction, TestVectorTypesBind, TestVectorTypesInit));
110715
+ }
110716
+
110717
+ } // namespace duckdb
110718
+
110719
+
110483
110720
  //===----------------------------------------------------------------------===//
110484
110721
  // DuckDB
110485
110722
  //
@@ -110595,6 +110832,7 @@ void BuiltinFunctions::RegisterSQLiteFunctions() {
110595
110832
  DuckDBTypesFun::RegisterFunction(*this);
110596
110833
  DuckDBViewsFun::RegisterFunction(*this);
110597
110834
  TestAllTypesFun::RegisterFunction(*this);
110835
+ TestVectorTypesFun::RegisterFunction(*this);
110598
110836
  }
110599
110837
 
110600
110838
  } // namespace duckdb
@@ -126006,7 +126244,8 @@ PreparedStatementData::~PreparedStatementData() {
126006
126244
 
126007
126245
  void PreparedStatementData::Bind(vector<Value> values) {
126008
126246
  // set parameters
126009
- const auto required = unbound_statement ? unbound_statement->n_param : 0;
126247
+ const auto required = properties.parameter_count;
126248
+ D_ASSERT(!unbound_statement || unbound_statement->n_param == properties.parameter_count);
126010
126249
  if (values.size() != required) {
126011
126250
  throw BinderException("Parameter/argument count mismatch for prepared statement. Expected %llu, got %llu",
126012
126251
  required, values.size());
@@ -157861,6 +158100,9 @@ namespace duckdb {
157861
158100
  unique_ptr<ParsedExpression> Transformer::TransformParamRef(duckdb_libpgquery::PGParamRef *node) {
157862
158101
  D_ASSERT(node);
157863
158102
  auto expr = make_unique<ParameterExpression>();
158103
+ if (node->number < 0) {
158104
+ throw ParserException("Parameter numbers cannot be negative");
158105
+ }
157864
158106
  if (node->number == 0) {
157865
158107
  expr->parameter_nr = ParamCount() + 1;
157866
158108
  } else {
@@ -158903,6 +159145,14 @@ static void CheckGroupingSetMax(idx_t count) {
158903
159145
  }
158904
159146
  }
158905
159147
 
159148
+ static void CheckGroupingSetCubes(idx_t current_count, idx_t cube_count) {
159149
+ idx_t combinations = 1;
159150
+ for (idx_t i = 0; i < cube_count; i++) {
159151
+ combinations *= 2;
159152
+ CheckGroupingSetMax(current_count + combinations);
159153
+ }
159154
+ }
159155
+
158906
159156
  struct GroupingExpressionMap {
158907
159157
  expression_map_t<idx_t> map;
158908
159158
  };
@@ -159007,6 +159257,8 @@ void Transformer::TransformGroupByNode(duckdb_libpgquery::PGNode *n, GroupingExp
159007
159257
  cube_sets.push_back(VectorToGroupingSet(cube_set));
159008
159258
  }
159009
159259
  // generate the subsets of the rollup set and add them to the grouping sets
159260
+ CheckGroupingSetCubes(result_sets.size(), cube_sets.size());
159261
+
159010
159262
  GroupingSet current_set;
159011
159263
  AddCubeSets(current_set, cube_sets, result_sets, 0);
159012
159264
  break;
@@ -163258,6 +163510,7 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
163258
163510
  namespace duckdb {
163259
163511
 
163260
163512
  BindResult ExpressionBinder::BindExpression(ParameterExpression &expr, idx_t depth) {
163513
+ D_ASSERT(expr.parameter_nr > 0);
163261
163514
  auto bound_parameter = make_unique<BoundParameterExpression>(expr.parameter_nr);
163262
163515
  if (!binder.parameters) {
163263
163516
  throw std::runtime_error("Unexpected prepared parameter. This type of statement can't be prepared!");
@@ -172832,6 +173085,7 @@ Planner::Planner(ClientContext &context) : binder(Binder::CreateBinder(context))
172832
173085
 
172833
173086
  void Planner::CreatePlan(SQLStatement &statement) {
172834
173087
  auto &profiler = QueryProfiler::Get(context);
173088
+ auto parameter_count = statement.n_param;
172835
173089
 
172836
173090
  vector<BoundParameterExpression *> bound_parameters;
172837
173091
 
@@ -172843,6 +173097,7 @@ void Planner::CreatePlan(SQLStatement &statement) {
172843
173097
  profiler.EndPhase();
172844
173098
 
172845
173099
  this->properties = binder->properties;
173100
+ this->properties.parameter_count = parameter_count;
172846
173101
  this->names = bound_statement.names;
172847
173102
  this->types = bound_statement.types;
172848
173103
  this->plan = move(bound_statement.plan);
@@ -172887,6 +173142,7 @@ shared_ptr<PreparedStatementData> Planner::PrepareSQLStatement(unique_ptr<SQLSta
172887
173142
 
172888
173143
  void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172889
173144
  auto &stmt = (ExecuteStatement &)*statement;
173145
+ auto parameter_count = stmt.n_param;
172890
173146
 
172891
173147
  // bind the prepared statement
172892
173148
  auto &client_data = ClientData::Get(context);
@@ -172925,6 +173181,12 @@ void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172925
173181
  D_ASSERT(prepared->properties.bound_all_parameters);
172926
173182
  rebound = true;
172927
173183
  }
173184
+ // copy the properties of the prepared statement into the planner
173185
+ this->properties = prepared->properties;
173186
+ this->properties.parameter_count = parameter_count;
173187
+ this->names = prepared->names;
173188
+ this->types = prepared->types;
173189
+
172928
173190
  // add casts to the prepared statement parameters as required
172929
173191
  for (idx_t i = 0; i < bind_values.size(); i++) {
172930
173192
  if (prepared->value_map.count(i + 1) == 0) {
@@ -172941,10 +173203,6 @@ void Planner::PlanExecute(unique_ptr<SQLStatement> statement) {
172941
173203
  return;
172942
173204
  }
172943
173205
 
172944
- // copy the properties of the prepared statement into the planner
172945
- this->properties = prepared->properties;
172946
- this->names = prepared->names;
172947
- this->types = prepared->types;
172948
173206
  this->plan = make_unique<LogicalExecute>(move(prepared));
172949
173207
  }
172950
173208
 
@@ -172960,6 +173218,7 @@ void Planner::PlanPrepare(unique_ptr<SQLStatement> statement) {
172960
173218
  properties.requires_valid_transaction = false;
172961
173219
  properties.allow_stream_result = false;
172962
173220
  properties.bound_all_parameters = true;
173221
+ properties.parameter_count = 0;
172963
173222
  properties.return_type = StatementReturnType::NOTHING;
172964
173223
  this->names = {"Success"};
172965
173224
  this->types = {LogicalType::BOOLEAN};