1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

feat(TNS): distribute SortingPQ that supports CountingAllocator

This commit is contained in:
drrtuy
2025-03-10 19:10:45 +00:00
parent be5711cf0d
commit c6dabe7eb5
7 changed files with 93 additions and 73 deletions

View File

@ -772,6 +772,12 @@ void IdbOrderBy::initialize(const RowGroup& rg)
fRowGroup.initRow(&row1);
fRowGroup.initRow(&row2);
// These two blocks contain structs with memory accounting.
{
auto alloc = fRm->getAllocator<OrderByRow>();
fOrderByQueue.reset(new SortingPQ(rowgroup::rgCommonSize, alloc));
}
if (fDistinct)
{
auto alloc = fRm->getAllocator<rowgroup::Row::Pointer>();

View File

@ -22,6 +22,7 @@
#pragma once
#include <memory>
#include <queue>
#include <utility>
#include <vector>
@ -34,7 +35,7 @@
#include "countingallocator.h"
#include "rowgroup.h"
#include "hasher.h"
#include "stlpoolallocator.h"
// #include "stlpoolallocator.h"
// forward reference
namespace joblist
@ -44,16 +45,26 @@ class ResourceManager;
namespace ordering
{
template <typename _Tp, typename _Sequence = std::vector<_Tp>,
template <typename _Tp, typename _Sequence = std::vector<_Tp, allocators::CountingAllocator<_Tp>>,
typename _Compare = std::less<typename _Sequence::value_type> >
class reservablePQ : private std::priority_queue<_Tp, _Sequence, _Compare>
class ReservablePQ : private std::priority_queue<_Tp, _Sequence, _Compare>
{
public:
typedef typename std::priority_queue<_Tp, _Sequence, _Compare>::size_type size_type;
explicit reservablePQ(size_type capacity = 0)
explicit explicit ReservablePQ(size_type capacity, std::atomic<int64_t>* memoryLimit,
const int64_t checkPointStepSize = allocators::CheckPointStepSize,
const int64_t lowerBound = allocators::MemoryLimitLowerBound)
: std::priority_queue<_Tp, _Sequence, _Compare>(_Compare(),
_Sequence(allocators::CountingAllocator<_Tp>(memoryLimit, checkPointStepSize, lowerBound)))
{
reserve(capacity);
};
}
explicit ReservablePQ(size_type capacity, allocators::CountingAllocator<_Tp> alloc)
: std::priority_queue<_Tp, _Sequence, _Compare>(_Compare(),
_Sequence(alloc))
{
reserve(capacity);
}
void reserve(size_type capacity)
{
this->c.reserve(capacity);
@ -73,7 +84,7 @@ class reservablePQ : private std::priority_queue<_Tp, _Sequence, _Compare>
class IdbCompare;
class OrderByRow;
typedef reservablePQ<OrderByRow> SortingPQ;
using SortingPQ = ReservablePQ<OrderByRow>;
// order by specification
struct IdbSortSpec
@ -417,16 +428,17 @@ class IdbOrderBy : public IdbCompare
{
return fDistinct;
}
// INV fOrderByQueue is always a valid pointer that is instantiated in constructor
SortingPQ& getQueue()
{
return fOrderByQueue;
return *fOrderByQueue;
}
CompareRule& getRule()
{
return fRule;
}
SortingPQ fOrderByQueue;
std::unique_ptr<SortingPQ> fOrderByQueue = nullptr;
protected:
std::vector<IdbSortSpec> fOrderByCond;