Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bool column chunk buffer size #1953

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/include/storage/copier/column_chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ class BoolColumnChunk : public ColumnChunk {

void append(ColumnChunk* other, common::offset_t startPosInOtherChunk,
common::offset_t startPosInChunk, uint32_t numValuesToAppend) final;

void resize(uint64_t capacity) final;

protected:
inline uint64_t numBytesForValues(common::offset_t numValues) const {
// 8 values per byte, and we need a buffer size which is a multiple of 8 bytes
return ceil(numValues / 8.0 / 8.0) * 8;
}

void initialize(common::offset_t capacity) final;
};

class NullColumnChunk : public BoolColumnChunk {
Expand All @@ -193,21 +203,7 @@ class NullColumnChunk : public BoolColumnChunk {
inline bool isNull(common::offset_t pos) const { return getValue<bool>(pos); }
inline void setNull(common::offset_t pos, bool isNull) { setValue(isNull, pos); }

void resize(uint64_t numValues) final;

inline void resetNullBuffer() { memset(buffer.get(), 0 /* non null */, bufferSize); }

protected:
inline uint64_t numBytesForValues(common::offset_t numValues) const {
// 8 values per byte, and we need a buffer size which is a multiple of 8 bytes
return ceil(numValues / 8.0 / 8.0) * 8;
}
inline void initialize(common::offset_t numValues) final {
numBytesPerValue = 0;
bufferSize = numBytesForValues(numValues);
// Each byte defaults to 0, indicating everything is non-null
buffer = std::make_unique<uint8_t[]>(bufferSize);
}
};

class FixedListColumnChunk : public ColumnChunk {
Expand Down
16 changes: 14 additions & 2 deletions src/storage/copier/column_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,26 @@
}
}

void NullColumnChunk::resize(uint64_t numValues) {
auto numBytesAfterResize = numBytesForValues(numValues);
inline void BoolColumnChunk::initialize(common::offset_t capacity) {
numBytesPerValue = 0;
bufferSize = numBytesForValues(capacity);
buffer = std::make_unique<uint8_t[]>(bufferSize);
if (nullChunk) {
static_cast<BoolColumnChunk*>(nullChunk.get())->initialize(capacity);
}
}

void BoolColumnChunk::resize(uint64_t capacity) {
auto numBytesAfterResize = numBytesForValues(capacity);
assert(numBytesAfterResize > bufferSize);
auto reservedBuffer = std::make_unique<uint8_t[]>(numBytesAfterResize);
memset(reservedBuffer.get(), 0 /* non null */, numBytesAfterResize);
memcpy(reservedBuffer.get(), buffer.get(), bufferSize);
buffer = std::move(reservedBuffer);
bufferSize = numBytesAfterResize;
if (nullChunk) {
nullChunk->resize(capacity);

Check warning on line 563 in src/storage/copier/column_chunk.cpp

View check run for this annotation

Codecov / codecov/patch

src/storage/copier/column_chunk.cpp#L563

Added line #L563 was not covered by tests
}
}

} // namespace storage
Expand Down