Skip to content

Commit

Permalink
improve fixed_size_map performance and more sane templating
Browse files Browse the repository at this point in the history
  • Loading branch information
lnkuiper committed Jul 14, 2024
1 parent e656d73 commit fd7be24
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 172 deletions.
21 changes: 5 additions & 16 deletions src/common/types/column/partitioned_column_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ void PartitionedColumnData::Append(PartitionedColumnDataAppendState &state, Data
BuildPartitionSel(state, input.size());

// Early out: check if everything belongs to a single partition
optional_idx partition_index;
if (UseFixedSizeMap()) {
if (state.fixed_partition_entries.size() == 1) {
partition_index = state.fixed_partition_entries.begin().GetKey();
}
} else {
if (state.partition_entries.size() == 1) {
partition_index = state.partition_entries.begin()->first;
}
}

// Early out: check if everything belongs to a single partition
const auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap());
if (partition_index.IsValid()) {
auto &partition = *partitions[partition_index.GetIndex()];
auto &partition_append_state = *state.partition_append_states[partition_index.GetIndex()];
Expand Down Expand Up @@ -103,8 +92,8 @@ perfect_map_t<list_entry_t> &PartitionedColumnDataGetMap(PartitionedColumnDataAp

template <bool fixed>
void PartitionedColumnData::BuildPartitionSel(PartitionedColumnDataAppendState &state, const idx_t append_count) {
using GETTER = TemplatedMapGetter<list_entry_t>::Functor<fixed>;
auto &partition_entries = GETTER::GetMap(state.fixed_partition_entries, state.partition_entries);
using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
auto &partition_entries = state.GetMap<fixed>();
partition_entries.clear();
const auto partition_indices = FlatVector::GetData<idx_t>(state.partition_indices);
switch (state.partition_indices.GetVectorType()) {
Expand Down Expand Up @@ -150,8 +139,8 @@ void PartitionedColumnData::BuildPartitionSel(PartitionedColumnDataAppendState &

template <bool fixed>
void PartitionedColumnData::AppendInternal(PartitionedColumnDataAppendState &state, DataChunk &input) {
using GETTER = TemplatedMapGetter<list_entry_t>::Functor<fixed>;
auto &partition_entries = GETTER::GetMap(state.fixed_partition_entries, state.partition_entries);
using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
const auto &partition_entries = state.GetMap<fixed>();

// Loop through the partitions to append the new data to the partition buffers, and flush the buffers if necessary
SelectionVector partition_sel;
Expand Down
31 changes: 6 additions & 25 deletions src/common/types/row/partitioned_tuple_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ void PartitionedTupleData::AppendUnified(PartitionedTupleDataAppendState &state,
BuildPartitionSel(state, append_sel, actual_append_count);

// Early out: check if everything belongs to a single partition
optional_idx partition_index;
if (UseFixedSizeMap()) {
if (state.fixed_partition_entries.size() == 1) {
partition_index = state.fixed_partition_entries.begin().GetKey();
}
} else {
if (state.partition_entries.size() == 1) {
partition_index = state.partition_entries.begin()->first;
}
}
const auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap());
if (partition_index.IsValid()) {
auto &partition = *partitions[partition_index.GetIndex()];
auto &partition_pin_state = *state.partition_pin_states[partition_index.GetIndex()];
Expand Down Expand Up @@ -99,17 +90,7 @@ void PartitionedTupleData::Append(PartitionedTupleDataAppendState &state, TupleD
BuildPartitionSel(state, *FlatVector::IncrementalSelectionVector(), append_count);

// Early out: check if everything belongs to a single partition
optional_idx partition_index;
if (UseFixedSizeMap()) {
if (state.fixed_partition_entries.size() == 1) {
partition_index = state.fixed_partition_entries.begin().GetKey();
}
} else {
if (state.partition_entries.size() == 1) {
partition_index = state.partition_entries.begin()->first;
}
}

auto partition_index = state.GetPartitionIndexIfSinglePartition(UseFixedSizeMap());
if (partition_index.IsValid()) {
auto &partition = *partitions[partition_index.GetIndex()];
auto &partition_pin_state = *state.partition_pin_states[partition_index.GetIndex()];
Expand Down Expand Up @@ -147,8 +128,8 @@ void PartitionedTupleData::BuildPartitionSel(PartitionedTupleDataAppendState &st
template <bool fixed>
void PartitionedTupleData::BuildPartitionSel(PartitionedTupleDataAppendState &state, const SelectionVector &append_sel,
const idx_t append_count) {
using GETTER = TemplatedMapGetter<list_entry_t>::Functor<fixed>;
auto &partition_entries = GETTER::GetMap(state.fixed_partition_entries, state.partition_entries);
using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
auto &partition_entries = state.GetMap<fixed>();
const auto partition_indices = FlatVector::GetData<idx_t>(state.partition_indices);
partition_entries.clear();
switch (state.partition_indices.GetVectorType()) {
Expand Down Expand Up @@ -210,8 +191,8 @@ void PartitionedTupleData::BuildBufferSpace(PartitionedTupleDataAppendState &sta

template <bool fixed>
void PartitionedTupleData::BuildBufferSpace(PartitionedTupleDataAppendState &state) {
using GETTER = TemplatedMapGetter<list_entry_t>::Functor<fixed>;
const auto &partition_entries = GETTER::GetMap(state.fixed_partition_entries, state.partition_entries);
using GETTER = TemplatedMapGetter<list_entry_t, fixed>;
const auto &partition_entries = state.GetMap<fixed>();
for (auto it = partition_entries.begin(); it != partition_entries.end(); ++it) {
const auto &partition_index = GETTER::GetKey(it);

Expand Down
Loading

0 comments on commit fd7be24

Please sign in to comment.