Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/duckdb/src/common/enum_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "duckdb/common/enums/subquery_type.hpp"
#include "duckdb/common/enums/tableref_type.hpp"
#include "duckdb/common/enums/thread_pin_mode.hpp"
#include "duckdb/common/enums/tuple_data_layout_enums.hpp"
#include "duckdb/common/enums/undo_flags.hpp"
#include "duckdb/common/enums/vector_type.hpp"
#include "duckdb/common/enums/wal_type.hpp"
Expand Down Expand Up @@ -4500,6 +4501,24 @@ TransactionType EnumUtil::FromString<TransactionType>(const char *value) {
return static_cast<TransactionType>(StringUtil::StringToEnum(GetTransactionTypeValues(), 4, "TransactionType", value));
}

const StringUtil::EnumStringLiteral *GetTupleDataNestednessTypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(TupleDataNestednessType::TOP_LEVEL_LAYOUT), "TOP_LEVEL_LAYOUT" },
{ static_cast<uint32_t>(TupleDataNestednessType::NESTED_STRUCT_LAYOUT), "NESTED_STRUCT_LAYOUT" }
};
return values;
}

template<>
const char* EnumUtil::ToChars<TupleDataNestednessType>(TupleDataNestednessType value) {
return StringUtil::EnumToString(GetTupleDataNestednessTypeValues(), 2, "TupleDataNestednessType", static_cast<uint32_t>(value));
}

template<>
TupleDataNestednessType EnumUtil::FromString<TupleDataNestednessType>(const char *value) {
return static_cast<TupleDataNestednessType>(StringUtil::StringToEnum(GetTupleDataNestednessTypeValues(), 2, "TupleDataNestednessType", value));
}

const StringUtil::EnumStringLiteral *GetTupleDataPinPropertiesValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(TupleDataPinProperties::INVALID), "INVALID" },
Expand All @@ -4521,6 +4540,24 @@ TupleDataPinProperties EnumUtil::FromString<TupleDataPinProperties>(const char *
return static_cast<TupleDataPinProperties>(StringUtil::StringToEnum(GetTupleDataPinPropertiesValues(), 5, "TupleDataPinProperties", value));
}

const StringUtil::EnumStringLiteral *GetTupleDataValidityTypeValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(TupleDataValidityType::CAN_HAVE_NULL_VALUES), "CAN_HAVE_NULL_VALUES" },
{ static_cast<uint32_t>(TupleDataValidityType::CANNOT_HAVE_NULL_VALUES), "CANNOT_HAVE_NULL_VALUES" }
};
return values;
}

template<>
const char* EnumUtil::ToChars<TupleDataValidityType>(TupleDataValidityType value) {
return StringUtil::EnumToString(GetTupleDataValidityTypeValues(), 2, "TupleDataValidityType", static_cast<uint32_t>(value));
}

template<>
TupleDataValidityType EnumUtil::FromString<TupleDataValidityType>(const char *value) {
return static_cast<TupleDataValidityType>(StringUtil::StringToEnum(GetTupleDataValidityTypeValues(), 2, "TupleDataValidityType", value));
}

const StringUtil::EnumStringLiteral *GetUndoFlagsValues() {
static constexpr StringUtil::EnumStringLiteral values[] {
{ static_cast<uint32_t>(UndoFlags::EMPTY_ENTRY), "EMPTY_ENTRY" },
Expand Down
24 changes: 24 additions & 0 deletions src/duckdb/src/common/extra_type_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ shared_ptr<ExtraTypeInfo> ExtraTypeInfo::Copy() const {
return shared_ptr<ExtraTypeInfo>(new ExtraTypeInfo(*this));
}

shared_ptr<ExtraTypeInfo> ExtraTypeInfo::DeepCopy() const {
return Copy();
}

bool ExtraTypeInfo::Equals(ExtraTypeInfo *other_p) const {
if (type == ExtraTypeInfoType::INVALID_TYPE_INFO || type == ExtraTypeInfoType::STRING_TYPE_INFO ||
type == ExtraTypeInfoType::GENERIC_TYPE_INFO) {
Expand Down Expand Up @@ -202,6 +206,10 @@ shared_ptr<ExtraTypeInfo> ListTypeInfo::Copy() const {
return make_shared_ptr<ListTypeInfo>(*this);
}

shared_ptr<ExtraTypeInfo> ListTypeInfo::DeepCopy() const {
return make_shared_ptr<ListTypeInfo>(child_type.DeepCopy());
}

//===--------------------------------------------------------------------===//
// Struct Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -221,6 +229,14 @@ shared_ptr<ExtraTypeInfo> StructTypeInfo::Copy() const {
return make_shared_ptr<StructTypeInfo>(*this);
}

shared_ptr<ExtraTypeInfo> StructTypeInfo::DeepCopy() const {
child_list_t<LogicalType> copied_child_types;
for (const auto &child_type : child_types) {
copied_child_types.emplace_back(child_type.first, child_type.second.DeepCopy());
}
return make_shared_ptr<StructTypeInfo>(std::move(copied_child_types));
}

//===--------------------------------------------------------------------===//
// Aggregate State Type Info
//===--------------------------------------------------------------------===//
Expand Down Expand Up @@ -423,6 +439,10 @@ shared_ptr<ExtraTypeInfo> ArrayTypeInfo::Copy() const {
return make_shared_ptr<ArrayTypeInfo>(*this);
}

shared_ptr<ExtraTypeInfo> ArrayTypeInfo::DeepCopy() const {
return make_shared_ptr<ArrayTypeInfo>(child_type.DeepCopy(), size);
}

//===--------------------------------------------------------------------===//
// Any Type Info
//===--------------------------------------------------------------------===//
Expand All @@ -442,6 +462,10 @@ shared_ptr<ExtraTypeInfo> AnyTypeInfo::Copy() const {
return make_shared_ptr<AnyTypeInfo>(*this);
}

shared_ptr<ExtraTypeInfo> AnyTypeInfo::DeepCopy() const {
return make_shared_ptr<AnyTypeInfo>(target_type.DeepCopy(), cast_score);
}

//===--------------------------------------------------------------------===//
// Integer Literal Type Info
//===--------------------------------------------------------------------===//
Expand Down
19 changes: 8 additions & 11 deletions src/duckdb/src/common/row_operations/row_aggregate.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/common/types/row_operations/row_aggregate.cpp
//
//
//===----------------------------------------------------------------------===//
#include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp"
#include "duckdb/common/row_operations/row_operations.hpp"
#include "duckdb/common/types/row/tuple_data_layout.hpp"
Expand All @@ -22,10 +15,14 @@ void RowOperations::InitializeStates(TupleDataLayout &layout, Vector &addresses,
auto aggr_idx = layout.ColumnCount();

for (const auto &aggr : layout.GetAggregates()) {
for (idx_t i = 0; i < count; ++i) {
auto row_idx = sel.get_index(i);
auto row = pointers[row_idx];
aggr.function.initialize(aggr.function, row + offsets[aggr_idx]);
if (sel.IsSet()) {
for (idx_t i = 0; i < count; ++i) {
aggr.function.initialize(aggr.function, pointers[sel.get_index_unsafe(i)] + offsets[aggr_idx]);
}
} else {
for (idx_t i = 0; i < count; ++i) {
aggr.function.initialize(aggr.function, pointers[i] + offsets[aggr_idx]);
}
}
++aggr_idx;
}
Expand Down
7 changes: 0 additions & 7 deletions src/duckdb/src/common/row_operations/row_external.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//===----------------------------------------------------------------------===//
// DuckDB
//
// duckdb/common/types/row_operations/row_external.cpp
//
//
//===----------------------------------------------------------------------===//
#include "duckdb/common/row_operations/row_operations.hpp"
#include "duckdb/common/types/row/row_layout.hpp"

Expand Down
5 changes: 0 additions & 5 deletions src/duckdb/src/common/row_operations/row_gather.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//===--------------------------------------------------------------------===//
// row_gather.cpp
// Description: This file contains the implementation of the gather operators
//===--------------------------------------------------------------------===//

#include "duckdb/common/exception.hpp"
#include "duckdb/common/operator/constant_operators.hpp"
#include "duckdb/common/row_operations/row_operations.hpp"
Expand Down
92 changes: 55 additions & 37 deletions src/duckdb/src/common/row_operations/row_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace duckdb {

using ValidityBytes = TupleDataLayout::ValidityBytes;

template <bool NO_MATCH_SEL, class T, class OP, bool LHS_ALL_VALID>
#ifdef DUCKDB_SMALLER_BINARY
template <bool NO_MATCH_SEL, class T, class OP>
#else
template <bool NO_MATCH_SEL, class T, class OP, bool LHS_ALL_VALID, bool RHS_ALL_VALID>
#endif
static idx_t TemplatedMatchLoop(const TupleDataVectorFormat &lhs_format, SelectionVector &sel, const idx_t count,
const TupleDataLayout &rhs_layout, Vector &rhs_row_locations, const idx_t col_idx,
SelectionVector *no_match_sel, idx_t &no_match_count) {
Expand All @@ -19,26 +23,33 @@ static idx_t TemplatedMatchLoop(const TupleDataVectorFormat &lhs_format, Selecti
const auto lhs_data = UnifiedVectorFormat::GetData<T>(lhs_format.unified);
const auto &lhs_validity = lhs_format.unified.validity;

#ifdef DUCKDB_SMALLER_BINARY
const auto LHS_ALL_VALID = lhs_validity.AllValid();
const auto RHS_ALL_VALID = rhs_layout.AllValid();
#endif

// RHS
const auto rhs_locations = FlatVector::GetData<data_ptr_t>(rhs_row_locations);
const auto rhs_offset_in_row = rhs_layout.GetOffsets()[col_idx];
idx_t entry_idx;
idx_t idx_in_entry;
ValidityBytes::GetEntryIndex(col_idx, entry_idx, idx_in_entry);
const auto rhs_column_count = rhs_layout.ColumnCount();

idx_t match_count = 0;
for (idx_t i = 0; i < count; i++) {
const auto idx = sel.get_index(i);

const auto lhs_idx = lhs_sel.get_index(idx);
const auto lhs_null = LHS_ALL_VALID ? false : !lhs_validity.RowIsValid(lhs_idx);

const auto &rhs_location = rhs_locations[idx];
const ValidityBytes rhs_mask(rhs_location, rhs_layout.ColumnCount());
const auto rhs_null = !rhs_mask.RowIsValid(rhs_mask.GetValidityEntryUnsafe(entry_idx), idx_in_entry);

if (COMPARISON_OP::template Operation<T>(lhs_data[lhs_idx], Load<T>(rhs_location + rhs_offset_in_row), lhs_null,
rhs_null)) {
if (COMPARISON_OP::template Operation<T>(
lhs_data[lhs_idx], Load<T>(rhs_location + rhs_offset_in_row),
LHS_ALL_VALID ? false : !lhs_validity.RowIsValidUnsafe(lhs_idx),
RHS_ALL_VALID ? false
: !ValidityBytes::RowIsValid(
ValidityBytes(rhs_location, rhs_column_count).GetValidityEntryUnsafe(entry_idx),
idx_in_entry))) {
sel.set_index(match_count++, idx);
} else if (NO_MATCH_SEL) {
no_match_sel->set_index(no_match_count++, idx);
Expand All @@ -51,13 +62,28 @@ template <bool NO_MATCH_SEL, class T, class OP>
static idx_t TemplatedMatch(Vector &, const TupleDataVectorFormat &lhs_format, SelectionVector &sel, const idx_t count,
const TupleDataLayout &rhs_layout, Vector &rhs_row_locations, const idx_t col_idx,
const vector<MatchFunction> &, SelectionVector *no_match_sel, idx_t &no_match_count) {
#ifdef DUCKDB_SMALLER_BINARY
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP>(lhs_format, sel, count, rhs_layout, rhs_row_locations, col_idx,
no_match_sel, no_match_count);
#else
if (lhs_format.unified.validity.AllValid()) {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, true>(lhs_format, sel, count, rhs_layout, rhs_row_locations,
col_idx, no_match_sel, no_match_count);
if (rhs_layout.AllValid()) {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, true, true>(
lhs_format, sel, count, rhs_layout, rhs_row_locations, col_idx, no_match_sel, no_match_count);
} else {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, true, false>(
lhs_format, sel, count, rhs_layout, rhs_row_locations, col_idx, no_match_sel, no_match_count);
}
} else {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, false>(lhs_format, sel, count, rhs_layout, rhs_row_locations,
col_idx, no_match_sel, no_match_count);
if (rhs_layout.AllValid()) {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, false, true>(
lhs_format, sel, count, rhs_layout, rhs_row_locations, col_idx, no_match_sel, no_match_count);
} else {
return TemplatedMatchLoop<NO_MATCH_SEL, T, OP, false, false>(
lhs_format, sel, count, rhs_layout, rhs_row_locations, col_idx, no_match_sel, no_match_count);
}
}
#endif
}

template <bool NO_MATCH_SEL, class OP>
Expand Down Expand Up @@ -85,8 +111,10 @@ static idx_t StructMatchEquality(Vector &lhs_vector, const TupleDataVectorFormat
const auto lhs_null = lhs_validity.AllValid() ? false : !lhs_validity.RowIsValid(lhs_idx);

const auto &rhs_location = rhs_locations[idx];
const ValidityBytes rhs_mask(rhs_location, rhs_layout.ColumnCount());
const auto rhs_null = !rhs_mask.RowIsValid(rhs_mask.GetValidityEntryUnsafe(entry_idx), idx_in_entry);
const auto rhs_null =
!rhs_layout.AllValid() &&
!ValidityBytes::RowIsValid(
ValidityBytes(rhs_location, rhs_layout.ColumnCount()).GetValidityEntryUnsafe(entry_idx), idx_in_entry);

// For structs there is no value to compare, here we match NULLs and let recursion do the rest
// So we use the comparison only if rhs or LHS is NULL and COMPARE_NULL is true
Expand Down Expand Up @@ -204,15 +232,18 @@ static idx_t GenericNestedMatch(Vector &lhs_vector, const TupleDataVectorFormat
return SelectComparison<OP>(sliced, key, sel, count, &sel, nullptr);
}

void RowMatcher::Initialize(const bool no_match_sel, const TupleDataLayout &layout, const Predicates &predicates) {
match_functions.reserve(predicates.size());
for (idx_t col_idx = 0; col_idx < predicates.size(); col_idx++) {
match_functions.push_back(GetMatchFunction(no_match_sel, layout.GetTypes()[col_idx], predicates[col_idx]));
void RowMatcher::Initialize(const bool no_match_sel, const TupleDataLayout &layout, const Predicates &predicates,
vector<column_t> columns_p) {
if (columns_p.empty()) {
// Assume all columns
columns_p.reserve(predicates.size());
for (column_t col_idx = 0; col_idx < predicates.size(); col_idx++) {
columns_p.emplace_back(col_idx);
}
}
}

void RowMatcher::Initialize(const bool no_match_sel, const TupleDataLayout &layout, const Predicates &predicates,
vector<column_t> &columns) {
rhs_layout = &layout;
columns = columns_p;

// The columns must have the same size as the predicates vector
D_ASSERT(columns.size() == predicates.size());
Expand All @@ -222,27 +253,14 @@ void RowMatcher::Initialize(const bool no_match_sel, const TupleDataLayout &layo

match_functions.reserve(predicates.size());
for (idx_t idx = 0; idx < predicates.size(); idx++) {
column_t col_idx = columns[idx];
const column_t col_idx = columns[idx];
match_functions.push_back(GetMatchFunction(no_match_sel, layout.GetTypes()[col_idx], predicates[idx]));
rhs_types.push_back(layout.GetTypes()[col_idx]);
}
}

idx_t RowMatcher::Match(DataChunk &lhs, const vector<TupleDataVectorFormat> &lhs_formats, SelectionVector &sel,
idx_t count, const TupleDataLayout &rhs_layout, Vector &rhs_row_locations,
SelectionVector *no_match_sel, idx_t &no_match_count) {
D_ASSERT(!match_functions.empty());
for (idx_t col_idx = 0; col_idx < match_functions.size(); col_idx++) {
const auto &match_function = match_functions[col_idx];
count =
match_function.function(lhs.data[col_idx], lhs_formats[col_idx], sel, count, rhs_layout, rhs_row_locations,
col_idx, match_function.child_functions, no_match_sel, no_match_count);
}
return count;
}

idx_t RowMatcher::Match(DataChunk &lhs, const vector<TupleDataVectorFormat> &lhs_formats, SelectionVector &sel,
idx_t count, const TupleDataLayout &rhs_layout, Vector &rhs_row_locations,
SelectionVector *no_match_sel, idx_t &no_match_count, const vector<column_t> &columns) {
idx_t count, Vector &rhs_row_locations, SelectionVector *no_match_sel, idx_t &no_match_count) {
D_ASSERT(!match_functions.empty());

// The column_ids must have the same size as the match_functions vector
Expand All @@ -258,7 +276,7 @@ idx_t RowMatcher::Match(DataChunk &lhs, const vector<TupleDataVectorFormat> &lhs

const auto &match_function = match_functions[fun_idx];
count =
match_function.function(lhs.data[col_idx], lhs_formats[col_idx], sel, count, rhs_layout, rhs_row_locations,
match_function.function(lhs.data[col_idx], lhs_formats[col_idx], sel, count, *rhs_layout, rhs_row_locations,
col_idx, match_function.child_functions, no_match_sel, no_match_count);
}
return count;
Expand Down
6 changes: 0 additions & 6 deletions src/duckdb/src/common/row_operations/row_scatter.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//===--------------------------------------------------------------------===//
// row_scatter.cpp
// Description: This file contains the implementation of the row scattering
// operators
//===--------------------------------------------------------------------===//

#include "duckdb/common/exception.hpp"
#include "duckdb/common/helper.hpp"
#include "duckdb/common/row_operations/row_operations.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/duckdb/src/common/sort/partition_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ PartitionGlobalSinkState::PartitionGlobalSinkState(ClientContext &context,
if (!orders.empty()) {
if (partitions.empty()) {
// Sort early into a dedicated hash group if we only sort.
grouping_types_ptr->Initialize(payload_types);
grouping_types_ptr->Initialize(payload_types, TupleDataValidityType::CAN_HAVE_NULL_VALUES);
auto new_group = make_uniq<PartitionGlobalHashGroup>(context, partitions, orders, payload_types, external);
hash_groups.emplace_back(std::move(new_group));
} else {
auto types = payload_types;
types.push_back(LogicalType::HASH);
grouping_types_ptr->Initialize(types);
grouping_types_ptr->Initialize(types, TupleDataValidityType::CAN_HAVE_NULL_VALUES);
ResizeGroupingData(estimated_cardinality);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/duckdb/src/common/sorting/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Sort::Sort(ClientContext &context, const vector<BoundOrderByNode> &orders, const
input_projection_map.push_back(input_col_idx);
}
}
payload_layout->Initialize(payload_types, false);
payload_layout->Initialize(payload_types, TupleDataValidityType::CAN_HAVE_NULL_VALUES);

// Sort the output projection columns so we're gathering the columns in order
std::sort(output_projection_columns.begin(), output_projection_columns.end(),
Expand Down
13 changes: 11 additions & 2 deletions src/duckdb/src/common/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,11 +1414,20 @@ bool ApproxEqual(double ldecimal, double rdecimal) {
//===--------------------------------------------------------------------===//
// Extra Type Info
//===--------------------------------------------------------------------===//
LogicalType LogicalType::Copy() const {
LogicalType copy = *this;
if (type_info_ && type_info_->type != ExtraTypeInfoType::ENUM_TYPE_INFO) {
// We copy (i.e., create new) type info, unless the type is an ENUM, otherwise we have to copy the whole dict
copy.type_info_ = type_info_->Copy();
}
return copy;
}

LogicalType LogicalType::DeepCopy() const {
LogicalType copy = *this;
if (type_info_) {
copy.type_info_ = type_info_->Copy();
if (type_info_ && type_info_->type != ExtraTypeInfoType::ENUM_TYPE_INFO) {
// We copy (i.e., create new) type info, unless the type is an ENUM, otherwise we have to copy the whole dict
copy.type_info_ = type_info_->DeepCopy();
}
return copy;
}
Expand Down
Loading