Skip to content

Commit

Permalink
fix list reader bug
Browse files Browse the repository at this point in the history
  • Loading branch information
acquamarin committed Sep 26, 2023
1 parent 5cbb422 commit e34483c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/include/storage/store/var_list_node_column.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ namespace storage {

struct ListOffsetInfoInStorage {
common::offset_t prevNodeListOffset;
std::unique_ptr<common::ValueVector> offsetVector;
std::vector<std::unique_ptr<common::ValueVector>> offsetVectors;

ListOffsetInfoInStorage(
common::offset_t prevNodeListOffset, std::unique_ptr<common::ValueVector> offsetVector)
: prevNodeListOffset{prevNodeListOffset}, offsetVector{std::move(offsetVector)} {}
ListOffsetInfoInStorage(common::offset_t prevNodeListOffset,
std::vector<std::unique_ptr<common::ValueVector>> offsetVectors)
: prevNodeListOffset{prevNodeListOffset}, offsetVectors{std::move(offsetVectors)} {}

inline common::offset_t getListOffset(uint64_t nodePos) const {
auto offsetVector = offsetVectors[(nodePos - 1) / common::DEFAULT_VECTOR_CAPACITY].get();
return nodePos == 0 ? prevNodeListOffset :
offsetVector->getValue<common::offset_t>(nodePos - 1);
offsetVector->getValue<common::offset_t>(
(nodePos - 1) % common::DEFAULT_VECTOR_CAPACITY);
}

inline uint64_t getListLength(uint64_t nodePos) const {
Expand Down
23 changes: 18 additions & 5 deletions src/storage/store/var_list_node_column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,26 @@ offset_t VarListNodeColumn::readOffset(
ListOffsetInfoInStorage VarListNodeColumn::getListOffsetInfoInStorage(Transaction* transaction,
node_group_idx_t nodeGroupIdx, offset_t startOffsetInNodeGroup, offset_t endOffsetInNodeGroup,
std::shared_ptr<DataChunkState> state) {
auto offsetVector = std::make_unique<ValueVector>(LogicalTypeID::INT64);
offsetVector->setState(std::move(state));
NodeColumn::scan(transaction, nodeGroupIdx, startOffsetInNodeGroup, endOffsetInNodeGroup,
offsetVector.get());
auto numOffsetsToRead = endOffsetInNodeGroup - startOffsetInNodeGroup;
auto numOffsetVectors = numOffsetsToRead / DEFAULT_VECTOR_CAPACITY +
(numOffsetsToRead % DEFAULT_VECTOR_CAPACITY ? 1 : 0);
std::vector<std::unique_ptr<ValueVector>> offsetVectors;
offsetVectors.reserve(numOffsetVectors);
uint64_t numOffsetsRead = 0;
for (auto i = 0u; i < numOffsetVectors; i++) {
auto offsetVector = std::make_unique<ValueVector>(LogicalTypeID::INT64);
auto numOffsetsToReadInCurBatch =
std::min(numOffsetsToRead - numOffsetsRead, DEFAULT_VECTOR_CAPACITY);
offsetVector->setState(state);
NodeColumn::scan(transaction, nodeGroupIdx, startOffsetInNodeGroup + numOffsetsRead,
startOffsetInNodeGroup + numOffsetsRead + numOffsetsToReadInCurBatch,
offsetVector.get());
offsetVectors.push_back(std::move(offsetVector));
numOffsetsRead += numOffsetsToReadInCurBatch;
}
auto prevNodeListOffsetInStorage =
readListOffsetInStorage(transaction, nodeGroupIdx, startOffsetInNodeGroup);
return {prevNodeListOffsetInStorage, std::move(offsetVector)};
return {prevNodeListOffsetInStorage, std::move(offsetVectors)};
}

} // namespace storage
Expand Down

0 comments on commit e34483c

Please sign in to comment.