@@ -3484,6 +3484,9 @@ string IndexCatalogEntry::ToSQL() {
34843484 if (sql.empty()) {
34853485 throw InternalException("Cannot convert INDEX to SQL because it was not created with a SQL statement");
34863486 }
3487+ if (sql[sql.size() - 1] != ';') {
3488+ sql += ";";
3489+ }
34873490 return sql;
34883491}
34893492
@@ -63943,6 +63946,7 @@ void PhysicalIEJoin::GetData(ExecutionContext &context, DataChunk &result, Globa
6394363946 const idx_t count = ie_lstate.SelectOuterRows(ie_lstate.right_matches);
6394463947 if (!count) {
6394563948 ie_gstate.GetNextPair(context.client, ie_sink, ie_lstate);
63949+ continue;
6394663950 }
6394763951
6394863952 SliceSortedPayload(result, ie_sink.tables[1]->global_sort_state, ie_lstate.right_base, ie_lstate.true_sel,
@@ -72020,12 +72024,12 @@ void PartitionableHashTable::Partition() {
7202072024 D_ASSERT(radix_partitioned_hts.size() == 0);
7202172025 D_ASSERT(partition_info.n_partitions > 1);
7202272026
72023- vector<GroupedAggregateHashTable *> partition_hts;
72027+ vector<GroupedAggregateHashTable *> partition_hts(partition_info.n_partitions) ;
7202472028 for (auto &unpartitioned_ht : unpartitioned_hts) {
7202572029 for (idx_t r = 0; r < partition_info.n_partitions; r++) {
7202672030 radix_partitioned_hts[r].push_back(make_unique<GroupedAggregateHashTable>(
7202772031 buffer_manager, group_types, payload_types, bindings, HtEntryType::HT_WIDTH_32));
72028- partition_hts.push_back( radix_partitioned_hts[r].back().get() );
72032+ partition_hts[r] = radix_partitioned_hts[r].back().get();
7202972033 }
7203072034 unpartitioned_ht->Partition(partition_hts, partition_info.radix_mask, partition_info.RADIX_SHIFT);
7203172035 unpartitioned_ht.reset();
@@ -72504,6 +72508,8 @@ template <>
7250472508bool TrySubtractOperator::Operation(int32_t left, int32_t right, int32_t &result);
7250572509template <>
7250672510bool TrySubtractOperator::Operation(int64_t left, int64_t right, int64_t &result);
72511+ template <>
72512+ bool TrySubtractOperator::Operation(hugeint_t left, hugeint_t right, hugeint_t &result);
7250772513
7250872514struct SubtractOperatorOverflowCheck {
7250972515 template <class TA, class TB, class TR>
@@ -83750,6 +83756,9 @@ void HistogramFun::RegisterFunction(BuiltinFunctions &set) {
8375083756 fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_S));
8375183757 fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_MS));
8375283758 fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIMESTAMP_NS));
83759+ fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIME));
83760+ fun.AddFunction(GetHistogramFunction<int64_t>(LogicalType::TIME_TZ));
83761+ fun.AddFunction(GetHistogramFunction<int32_t>(LogicalType::DATE));
8375383762 set.AddFunction(fun);
8375483763}
8375583764
@@ -91556,6 +91565,10 @@ static void TemplatedContainsOrPosition(DataChunk &args, ExpressionState &state,
9155691565 VectorData value_data;
9155791566 value_vector.Orrify(count, value_data);
9155891567
91568+ // not required for a comparison of nested types
91569+ auto child_value = FlatVector::GetData<CHILD_TYPE>(child_vector);
91570+ auto values = FlatVector::GetData<CHILD_TYPE>(value_vector);
91571+
9155991572 for (idx_t i = 0; i < count; i++) {
9156091573 auto list_index = list_data.sel->get_index(i);
9156191574 auto value_index = value_data.sel->get_index(i);
@@ -91566,31 +91579,26 @@ static void TemplatedContainsOrPosition(DataChunk &args, ExpressionState &state,
9156691579 }
9156791580
9156891581 const auto &list_entry = list_entries[list_index];
91569- auto source_idx = child_data.sel->get_index(list_entry.offset);
9157091582
91571- // not required for a comparison of nested types
91572- auto child_value = FlatVector::GetData<CHILD_TYPE>(child_vector);
91573- auto values = FlatVector::GetData<CHILD_TYPE>(value_vector);
91574-
91575- result_entries[list_index] = OP::Initialize();
91583+ result_entries[i] = OP::Initialize();
9157691584 for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
91577- auto child_value_idx = source_idx + child_idx;
9157891585
91586+ auto child_value_idx = child_data.sel->get_index(list_entry.offset + child_idx);
9157991587 if (!child_data.validity.RowIsValid(child_value_idx)) {
9158091588 continue;
9158191589 }
9158291590
9158391591 if (!is_nested) {
9158491592 if (ValueEqualsOrNot<CHILD_TYPE>(child_value[child_value_idx], values[value_index])) {
91585- result_entries[list_index ] = OP::UpdateResultEntries(child_idx);
91593+ result_entries[i ] = OP::UpdateResultEntries(child_idx);
9158691594 break; // Found value in list, no need to look further
9158791595 }
9158891596 } else {
9158991597 // FIXME: using Value is less efficient than modifying the vector comparison code
9159091598 // to more efficiently compare nested types
9159191599 if (ValueEqualsOrNot<Value>(child_vector.GetValue(child_value_idx),
9159291600 value_vector.GetValue(value_index))) {
91593- result_entries[list_index ] = OP::UpdateResultEntries(child_idx);
91601+ result_entries[i ] = OP::UpdateResultEntries(child_idx);
9159491602 break; // Found value in list, no need to look further
9159591603 }
9159691604 }
@@ -92009,10 +92017,7 @@ static void ListAggregateFunction(DataChunk &args, ExpressionState &state, Vecto
9200992017 continue;
9201092018 }
9201192019
92012- auto source_idx = child_data.sel->get_index(list_entry.offset);
92013- idx_t child_idx = 0;
92014-
92015- while (child_idx < list_entry.length) {
92020+ for (idx_t child_idx = 0; child_idx < list_entry.length; child_idx++) {
9201692021
9201792022 // states vector is full, update
9201892023 if (states_idx == STANDARD_VECTOR_SIZE) {
@@ -92025,10 +92030,10 @@ static void ListAggregateFunction(DataChunk &args, ExpressionState &state, Vecto
9202592030 states_idx = 0;
9202692031 }
9202792032
92028- sel_vector.set_index(states_idx, source_idx + child_idx);
92033+ auto source_idx = child_data.sel->get_index(list_entry.offset + child_idx);
92034+ sel_vector.set_index(states_idx, source_idx);
9202992035 states_update[states_idx] = state_ptr;
9203092036 states_idx++;
92031- child_idx++;
9203292037 }
9203392038 }
9203492039
@@ -92065,7 +92070,7 @@ static unique_ptr<FunctionData> ListAggregateBind(ClientContext &context, Scalar
9206592070
9206692071 // get the function name
9206792072 Value function_value = ExpressionExecutor::EvaluateScalar(*arguments[1]);
92068- auto function_name = StringValue::Get( function_value);
92073+ auto function_name = function_value.ToString( );
9206992074
9207092075 vector<LogicalType> types;
9207192076 types.push_back(list_child_type);
@@ -96177,6 +96182,12 @@ bool TrySubtractOperator::Operation(int64_t left, int64_t right, int64_t &result
9617796182 return true;
9617896183}
9617996184
96185+ template <>
96186+ bool TrySubtractOperator::Operation(hugeint_t left, hugeint_t right, hugeint_t &result) {
96187+ result = left;
96188+ return Hugeint::SubtractInPlace(result, right);
96189+ }
96190+
9618096191//===--------------------------------------------------------------------===//
9618196192// subtract decimal with overflow check
9618296193//===--------------------------------------------------------------------===//
@@ -133896,51 +133907,37 @@ unique_ptr<BaseStatistics> StatisticsPropagator::PropagateExpression(BoundAggreg
133896133907
133897133908namespace duckdb {
133898133909
133899- unique_ptr<Expression> CastHugeintToSmallestType(unique_ptr<Expression> expr, NumericStatistics &num_stats) {
133900- // Compute range
133901- if (num_stats.min.IsNull() || num_stats.max.IsNull()) {
133902- return expr;
133903- }
133904-
133905- auto min_val = num_stats.min.GetValue<hugeint_t>();
133906- auto max_val = num_stats.max.GetValue<hugeint_t>();
133907- if (max_val < min_val) {
133908- return expr;
133909- }
133910+ template <class T>
133911+ bool GetCastType(T signed_range, LogicalType &cast_type) {
133912+ auto range = static_cast<typename std::make_unsigned<decltype(signed_range)>::type>(signed_range);
133910133913
133911- // Prevent overflow
133912- if (min_val < NumericLimits<int64_t>().Minimum() && max_val > NumericLimits<int64_t>().Maximum()) {
133913- return expr;
133914+ // Check if this range fits in a smaller type
133915+ if (range < NumericLimits<uint8_t>::Maximum()) {
133916+ cast_type = LogicalType::UTINYINT;
133917+ } else if (sizeof(T) > sizeof(uint16_t) && range < NumericLimits<uint16_t>::Maximum()) {
133918+ cast_type = LogicalType::USMALLINT;
133919+ } else if (sizeof(T) > sizeof(uint32_t) && range < NumericLimits<uint32_t>::Maximum()) {
133920+ cast_type = LogicalType::UINTEGER;
133921+ } else {
133922+ return false;
133914133923 }
133924+ return true;
133925+ }
133915133926
133916- // Compute range
133917- auto range = max_val - min_val;
133918-
133919- // Check if this range fits in a smaller type
133920- LogicalType cast_type;
133927+ template <>
133928+ bool GetCastType(hugeint_t range, LogicalType &cast_type) {
133921133929 if (range < NumericLimits<uint8_t>().Maximum()) {
133922133930 cast_type = LogicalType::UTINYINT;
133923133931 } else if (range < NumericLimits<uint16_t>().Maximum()) {
133924133932 cast_type = LogicalType::USMALLINT;
133925133933 } else if (range < NumericLimits<uint32_t>().Maximum()) {
133926133934 cast_type = LogicalType::UINTEGER;
133927133935 } else if (range < NumericLimits<uint64_t>().Maximum()) {
133928- cast_type = LogicalTypeId ::UBIGINT;
133936+ cast_type = LogicalType ::UBIGINT;
133929133937 } else {
133930- return expr ;
133938+ return false ;
133931133939 }
133932-
133933- // Create expression to map to a smaller range
133934- auto input_type = expr->return_type;
133935- auto minimum_expr = make_unique<BoundConstantExpression>(Value::CreateValue(min_val));
133936- vector<unique_ptr<Expression>> arguments;
133937- arguments.push_back(move(expr));
133938- arguments.push_back(move(minimum_expr));
133939- auto minus_expr = make_unique<BoundFunctionExpression>(input_type, SubtractFun::GetFunction(input_type, input_type),
133940- move(arguments), nullptr, true);
133941-
133942- // Cast to smaller type
133943- return make_unique<BoundCastExpression>(move(minus_expr), cast_type);
133940+ return true;
133944133941}
133945133942
133946133943template <class T>
@@ -133958,21 +133955,14 @@ unique_ptr<Expression> TemplatedCastToSmallestType(unique_ptr<Expression> expr,
133958133955
133959133956 // Compute range, cast to unsigned to prevent comparing signed with unsigned
133960133957 T signed_range;
133961- if (!TrySubtractOperator::Operation(signed_min_val, signed_max_val , signed_range)) {
133958+ if (!TrySubtractOperator::Operation(signed_max_val, signed_min_val , signed_range)) {
133962133959 // overflow in subtraction: cannot do any simplification
133963133960 return expr;
133964133961 }
133965- auto range = static_cast<typename std::make_unsigned<decltype(signed_range)>::type>(signed_range);
133966133962
133967133963 // Check if this range fits in a smaller type
133968133964 LogicalType cast_type;
133969- if (range < NumericLimits<uint8_t>::Maximum()) {
133970- cast_type = LogicalType::UTINYINT;
133971- } else if (sizeof(T) > sizeof(uint16_t) && range < NumericLimits<uint16_t>::Maximum()) {
133972- cast_type = LogicalType::USMALLINT;
133973- } else if (sizeof(T) > sizeof(uint32_t) && range < NumericLimits<uint32_t>::Maximum()) {
133974- cast_type = LogicalType::UINTEGER;
133975- } else {
133965+ if (!GetCastType(signed_range, cast_type)) {
133976133966 return expr;
133977133967 }
133978133968
@@ -134008,7 +133998,7 @@ unique_ptr<Expression> CastToSmallestType(unique_ptr<Expression> expr, NumericSt
134008133998 case PhysicalType::INT64:
134009133999 return TemplatedCastToSmallestType<int64_t>(move(expr), num_stats);
134010134000 case PhysicalType::INT128:
134011- return CastHugeintToSmallestType (move(expr), num_stats);
134001+ return TemplatedCastToSmallestType<hugeint_t> (move(expr), num_stats);
134012134002 default:
134013134003 throw NotImplementedException("Unknown integer type!");
134014134004 }
@@ -134976,6 +134966,8 @@ void StatisticsPropagator::PropagateStatistics(LogicalComparisonJoin &join, uniq
134976134966 if (join.conditions.size() > 1) {
134977134967 // there are multiple conditions: erase this condition
134978134968 join.conditions.erase(join.conditions.begin() + i);
134969+ // remove the corresponding statistics
134970+ join.join_stats.clear();
134979134971 i--;
134980134972 continue;
134981134973 } else {
@@ -160505,8 +160497,7 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
160505160497 auto copy = make_unique<LogicalCopyToFile>(copy_function->function, move(function_data));
160506160498 copy->file_path = stmt.info->file_path;
160507160499 copy->use_tmp_file = use_tmp_file;
160508- LocalFileSystem fs;
160509- copy->is_file_and_exists = fs.FileExists(copy->file_path);
160500+ copy->is_file_and_exists = config.file_system->FileExists(copy->file_path);
160510160501
160511160502 copy->AddChild(move(select_node.plan));
160512160503
@@ -175021,6 +175012,10 @@ DataTable::DataTable(ClientContext &context, DataTable &parent, idx_t removed_co
175021175012 D_ASSERT(removed_column < column_definitions.size());
175022175013 column_definitions.erase(column_definitions.begin() + removed_column);
175023175014
175015+ for (idx_t i = 0; i < column_definitions.size(); i++) {
175016+ column_definitions[i].oid = i;
175017+ }
175018+
175024175019 // alter the row_groups and remove the column from each of them
175025175020 this->row_groups = make_shared<SegmentTree>();
175026175021 auto current_row_group = (RowGroup *)parent.row_groups->GetRootSegment();
0 commit comments