Skip to content

Commit

Permalink
prefetch threshold(2MB); mini batch; prefetch exists key; prefetch in…
Browse files Browse the repository at this point in the history
…sertResultInto

Signed-off-by: guo-shaoge <[email protected]>
  • Loading branch information
guo-shaoge committed Dec 24, 2024
1 parent dc0973a commit 9623368
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 70 deletions.
15 changes: 0 additions & 15 deletions dbms/src/AggregateFunctions/IAggregateFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,40 +236,25 @@ class IAggregateFunctionHelper : public IAggregateFunction
ssize_t if_argument_pos = -1) const override
{
const auto end = start_offset + batch_size;
static constexpr size_t prefetch_step = 16;
if (if_argument_pos >= 0)
{
const auto & flags = assert_cast<const ColumnUInt8 &>(*columns[if_argument_pos]).getData();
for (size_t i = start_offset; i < end; ++i)
{
const auto place_idx = i - start_offset;
const auto prefetch_idx = place_idx + prefetch_step;

if (flags[i] && places[place_idx])
{
// Only prefetch first agg function data for simplicity.
// This may not work when there are too many agg functions.
if likely (prefetch_idx < end)
__builtin_prefetch(places[prefetch_idx]);

static_cast<const Derived *>(this)->add(places[place_idx] + place_offset, columns, i, arena);
}
}
}
else
{
for (size_t i = start_offset; i < end; ++i)
{
const auto place_idx = i - start_offset;
const auto prefetch_idx = place_idx + prefetch_step;

if (places[place_idx])
{
if likely (prefetch_idx < end)
__builtin_prefetch(places[prefetch_idx]);

static_cast<const Derived *>(this)->add(places[place_idx] + place_offset, columns, i, arena);
}
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions dbms/src/Common/ColumnsHashingImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ class HashMethodBase
return emplaceImpl(key_holder, data);
}

template <typename Data>
ALWAYS_INLINE inline EmplaceResult emplaceKey(
Data & data,
size_t row,
Arena & pool,
std::vector<String> & sort_key_containers,
size_t hashval)
{
auto key_holder = static_cast<Derived &>(*this).getKeyHolder(row, &pool, sort_key_containers);
return emplaceImpl(key_holder, data, hashval);
}

template <typename Data>
ALWAYS_INLINE inline FindResult findKey(
Data & data,
Expand All @@ -161,6 +173,18 @@ class HashMethodBase
return findKeyImpl(keyHolderGetKey(key_holder), data);
}

template <typename Data>
ALWAYS_INLINE inline FindResult findKey(
Data & data,
size_t row,
Arena & pool,
std::vector<String> & sort_key_containers,
size_t hashval)
{
auto key_holder = static_cast<Derived &>(*this).getKeyHolder(row, &pool, sort_key_containers);
return findKeyImpl(keyHolderGetKey(key_holder), data, hashval);
}

// Emplace key using hashval, you can enable prefetch or not.
template <bool enable_prefetch = false, typename Data>
ALWAYS_INLINE inline EmplaceResult emplaceKey(
Expand Down
Loading

0 comments on commit 9623368

Please sign in to comment.