Skip to content

Commit

Permalink
enhancing RowContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPresent-Han committed Nov 7, 2024
1 parent 44ca1cf commit 17d0f6f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
7 changes: 7 additions & 0 deletions internal/core/src/common/BitUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

namespace milvus {
namespace bits {

template <typename T>
inline bool isBitSet(const T* bits, uint32_t idx){
return bits[idx/(sizeof(bits[0])*8)] &
(static_cast<T>(1) << (idx & ((sizeof(bits[0]) * 8) - 1)));
}

template <typename T, typename U>
constexpr T roundUp(T value, U factor) {
return (value + (factor - 1)) / factor * factor;
Expand Down
2 changes: 0 additions & 2 deletions internal/core/src/exec/VectorHasher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ void VectorHasher::hashValues(const ColumnVectorPtr& column_data, bool mix, uint
}
}



void
VectorHasher::hash(bool mix, std::vector<uint64_t>& result) {

Expand Down
14 changes: 8 additions & 6 deletions internal/core/src/exec/operator/query-agg/RowContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ RowContainer::RowContainer(const std::vector<DataType> &keyTypes,
accumulators_(accumulators),
nullableKeys_(nullableKeys),
hasNormalizedKeys_(hasNormalizedKeys){
int32_t offset = 0;
int32_t nullOffset = 0;
uint32_t offset = 0;
uint32_t nullOffset = 0;
bool isVariableWidth = false;
for(auto& type: keyTypes_){
offsets_.push_back(offset);
Expand All @@ -43,8 +43,8 @@ RowContainer::RowContainer(const std::vector<DataType> &keyTypes,
}
// Make offset at least sizeof pointer so that there is space for a
// free list next pointer below the bit at 'freeFlagOffset_'.
offset = std::max<int32_t>(offset, sizeof(void*));
const int32_t firstAggregateOffset = offset;
offset = std::max<uint32_t>(offset, sizeof(void*));
const uint32_t firstAggregateOffset = offset;
if (!accumulators.empty()) {
// This moves nullOffset to the start of the next byte.
// This is to guarantee the null and initialized bits for an aggregate
Expand All @@ -69,7 +69,7 @@ RowContainer::RowContainer(const std::vector<DataType> &keyTypes,
++nullOffset;
// Add 1 to the last null offset to get the number of bits.
flagBytes_ = milvus::bits::nBytes(nullOffsets_.back() + 1);
for (int32_t i = 0; i < nullOffsets_.size(); i++) {
for (auto i = 0; i < nullOffsets_.size(); i++) {
nullOffsets_[i] += firstAggregateOffset * 8;
}
offset += flagBytes_;
Expand Down Expand Up @@ -114,9 +114,11 @@ char* RowContainer::newRow() {
char* row;
if (firstFreeRow_) {
row = firstFreeRow_;
AssertInfo(milvus::bits::isBitSet(row, freeFlagOffset_), "freeRow must be freed before inserted into the linked list");
firstFreeRow_ = nextFree(row);
--numFreeRows_;
} else {
//row = new char*
row = new char[fixedRowSize_ + alignment_];
}
return nullptr;
}
Expand Down
16 changes: 11 additions & 5 deletions internal/core/src/exec/operator/query-agg/RowContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ class RowContainer {
return *reinterpret_cast<const T*>(group + offset);
}

char*& nextFree(char* row) {
return *reinterpret_cast<char**>(row + kNextFreeOffset_);
}

template <DataType Type>
inline bool equalsNoNulls(
Expand Down Expand Up @@ -219,21 +222,24 @@ class RowContainer {
}

private:
// Offset of the pointer to the next free row on a free row.
static constexpr uint32_t kNextFreeOffset_ = 0;

const std::vector<DataType> keyTypes_;
const bool nullableKeys_;
const bool hasNormalizedKeys_;
std::vector<int32_t> offsets_;
std::vector<int32_t> nullOffsets_;
std::vector<uint32_t> offsets_;
std::vector<uint32_t> nullOffsets_;

std::vector<RowColumn> rowColumns_;

// How many bytes do the flags (null, free) occupy.
uint32_t fixedRowSize_;
int32_t flagBytes_;
uint32_t flagBytes_;

// Bit position of free bit.
int32_t freeFlagOffset_ = 0;
int32_t rowSizeOffset_ = 0;
uint32_t freeFlagOffset_ = 0;
uint32_t rowSizeOffset_ = 0;

int alignment_ = 1;

Expand Down

0 comments on commit 17d0f6f

Please sign in to comment.