#include "storage/table/column_chunk_data.h" #include #include #include "common/data_chunk/sel_vector.h" #include "common/exception/copy.h" #include "common/null_mask.h" #include "common/serializer/deserializer.h" #include "common/serializer/serializer.h" #include "common/system_config.h" #include "common/type_utils.h" #include "common/types/types.h" #include "common/vector/value_vector.h" #include "expression_evaluator/expression_evaluator.h" #include "storage/buffer_manager/buffer_manager.h" #include "storage/buffer_manager/memory_manager.h" #include "storage/buffer_manager/spill_result.h" #include "storage/buffer_manager/spiller.h" #include "storage/compression/compression.h" #include "storage/compression/float_compression.h" #include "storage/enums/residency_state.h" #include "storage/stats/column_stats.h" #include "storage/table/column.h" #include "storage/table/column_chunk_metadata.h" #include "storage/table/compression_flush_buffer.h" #include "storage/table/list_chunk_data.h" #include "storage/table/page_reclaim_deferral.h" #include "storage/table/string_chunk_data.h" #include "storage/table/struct_chunk_data.h" #include using namespace lbug::common; using namespace lbug::evaluator; using namespace lbug::transaction; namespace lbug { namespace storage { void SegmentState::reclaimAllocatedPages(PageAllocator& pageAllocator) const { if (auto* deferral = PageReclaimDeferral::current()) { deferral->defer(*this, pageAllocator); return; } const auto& entry = metadata.pageRange; if (entry.startPageIdx != INVALID_PAGE_IDX) { pageAllocator.freePageRange(entry); } if (nullState) { nullState->reclaimAllocatedPages(pageAllocator); } for (const auto& child : childrenStates) { child.reclaimAllocatedPages(pageAllocator); } } std::shared_ptr PageReclaimDeferral::create() { return std::make_shared(); } void PageReclaimDeferral::defer(PageRange range, PageAllocator& pageAllocator) { if (range.startPageIdx == INVALID_PAGE_IDX) { return; } frees.push_back(Free{range, &pageAllocator}); } void PageReclaimDeferral::defer(const SegmentState& state, PageAllocator& pageAllocator) { defer(state.metadata.pageRange, pageAllocator); if (state.nullState) { defer(*state.nullState, pageAllocator); } for (const auto& child : state.childrenStates) { defer(child, pageAllocator); } } void PageReclaimDeferral::discard() { frees.clear(); committed = false; } PageReclaimDeferral::~PageReclaimDeferral() { if (!committed) { return; } for (auto& freePage : frees) { freePage.pageAllocator->freePageRange(freePage.range); } } PageReclaimDeferral*& PageReclaimDeferral::current() { static thread_local PageReclaimDeferral* currentDeferral = nullptr; return currentDeferral; } static std::shared_ptr getCompression(const LogicalType& dataType, bool enableCompression) { if (!enableCompression) { return std::make_shared(dataType); } switch (dataType.getPhysicalType()) { case PhysicalTypeID::INT128: { return std::make_shared>(); } case PhysicalTypeID::INT64: { return std::make_shared>(); } case PhysicalTypeID::INT32: { return std::make_shared>(); } case PhysicalTypeID::INT16: { return std::make_shared>(); } case PhysicalTypeID::INT8: { return std::make_shared>(); } case PhysicalTypeID::INTERNAL_ID: case PhysicalTypeID::UINT64: { return std::make_shared>(); } case PhysicalTypeID::UINT32: { return std::make_shared>(); } case PhysicalTypeID::UINT16: { return std::make_shared>(); } case PhysicalTypeID::UINT8: { return std::make_shared>(); } case PhysicalTypeID::FLOAT: { return std::make_shared>(); } case PhysicalTypeID::DOUBLE: { return std::make_shared>(); } default: { return std::make_shared(dataType); } } } ColumnChunkData::ColumnChunkData(MemoryManager& mm, LogicalType dataType, uint64_t capacity, bool enableCompression, ResidencyState residencyState, bool hasNullData, bool initializeToZero) : residencyState{residencyState}, dataType{std::move(dataType)}, enableCompression{enableCompression}, numBytesPerValue{getDataTypeSizeInChunk(this->dataType)}, capacity{capacity}, numValues{0}, inMemoryStats() { if (hasNullData) { nullData = std::make_unique(mm, capacity, enableCompression, residencyState); } initializeBuffer(this->dataType.getPhysicalType(), mm, initializeToZero); initializeFunction(); } ColumnChunkData::ColumnChunkData(MemoryManager& mm, LogicalType dataType, bool enableCompression, const ColumnChunkMetadata& metadata, bool hasNullData, bool initializeToZero) : residencyState(ResidencyState::ON_DISK), dataType{std::move(dataType)}, enableCompression{enableCompression}, numBytesPerValue{getDataTypeSizeInChunk(this->dataType)}, capacity{0}, numValues{metadata.numValues}, metadata{metadata} { if (hasNullData) { nullData = std::make_unique(mm, enableCompression, metadata); } initializeBuffer(this->dataType.getPhysicalType(), mm, initializeToZero); initializeFunction(); } ColumnChunkData::ColumnChunkData(MemoryManager& mm, PhysicalTypeID dataType, bool enableCompression, const ColumnChunkMetadata& metadata, bool hasNullData, bool initializeToZero) : ColumnChunkData(mm, LogicalType::ANY(dataType), enableCompression, metadata, hasNullData, initializeToZero) {} void ColumnChunkData::initializeBuffer(PhysicalTypeID physicalType, MemoryManager& mm, bool initializeToZero) { numBytesPerValue = getDataTypeSizeInChunk(physicalType); // Some columnChunks are much smaller than the 256KB minimum size used by allocateBuffer // Which would lead to excessive memory use, particularly in the partitioner buffer = mm.allocateBuffer(initializeToZero, getBufferSize(capacity)); } void ColumnChunkData::initializeFunction() { compressionAlg = getCompression(dataType, enableCompression); } ColumnChunkMetadata ColumnChunkData::getMetadataImpl(std::span buffer, uint64_t numValues, StorageValue minValue, StorageValue maxValue) const { return GetCompressionMetadata(compressionAlg, dataType)(buffer, numValues, minValue, maxValue); } ColumnChunkMetadata ColumnChunkData::flushBufferImpl(std::span buffer, FileHandle* dataFH, const PageRange& entry, const ColumnChunkMetadata& otherMetadata) const { switch (dataType.getPhysicalType()) { case PhysicalTypeID::BOOL: { // Since we compress into memory, storage is the same as fixed-sized // values, but we need to mark it as being boolean compressed. return uncompressedFlushBuffer(buffer, dataFH, entry, otherMetadata); } case PhysicalTypeID::STRING: case PhysicalTypeID::JSON: case PhysicalTypeID::INT64: case PhysicalTypeID::INT32: case PhysicalTypeID::INT16: case PhysicalTypeID::INT8: case PhysicalTypeID::INTERNAL_ID: case PhysicalTypeID::ARRAY: case PhysicalTypeID::LIST: case PhysicalTypeID::UINT64: case PhysicalTypeID::UINT32: case PhysicalTypeID::UINT16: case PhysicalTypeID::UINT8: case PhysicalTypeID::INT128: { return CompressedFlushBuffer(compressionAlg, dataType)(buffer, dataFH, entry, otherMetadata); } case PhysicalTypeID::DOUBLE: { return CompressedFloatFlushBuffer(compressionAlg, dataType)(buffer, dataFH, entry, otherMetadata); } case PhysicalTypeID::FLOAT: { return CompressedFloatFlushBuffer(compressionAlg, dataType)(buffer, dataFH, entry, otherMetadata); } default: { return uncompressedFlushBuffer(buffer, dataFH, entry, otherMetadata); } } } void ColumnChunkData::resetToAllNull() { DASSERT(residencyState != ResidencyState::ON_DISK); if (nullData) { nullData->resetToAllNull(); } resetInMemoryStats(); } void ColumnChunkData::resetToEmpty() { DASSERT(residencyState != ResidencyState::ON_DISK); if (nullData) { nullData->resetToEmpty(); } DASSERT(getBufferSize() == getBufferSize(capacity)); memset(getData(), 0x00, getBufferSize()); numValues = 0; resetInMemoryStats(); } static void updateInMemoryStats(ColumnChunkStats& stats, const ValueVector& values, uint64_t offset = 0, uint64_t numValues = std::numeric_limits::max()) { const auto physicalType = values.dataType.getPhysicalType(); const auto numValuesToCheck = std::min(numValues, values.state->getSelSize()); stats.update(values, offset, numValuesToCheck, physicalType); } static void updateInMemoryStats(ColumnChunkStats& stats, const ColumnChunkData* values, uint64_t offset = 0, uint64_t numValues = std::numeric_limits::max()) { const auto physicalType = values->getDataType().getPhysicalType(); const auto numValuesToCheck = std::min(values->getNumValues(), numValues); const auto nullMask = values->getNullMask(); stats.update(*values, offset, numValuesToCheck, physicalType); } MergedColumnChunkStats ColumnChunkData::getMergedColumnChunkStats() const { const CompressionMetadata& onDiskMetadata = metadata.compMeta; ColumnChunkStats stats = inMemoryStats; const auto physicalType = getDataType().getPhysicalType(); const bool isStorageValueType = TypeUtils::visit(physicalType, [](T) { return StorageValueType; }); if (isStorageValueType) { stats.update(onDiskMetadata.min, onDiskMetadata.max, physicalType); } return MergedColumnChunkStats{stats, !nullData || nullData->haveNoNullsGuaranteed(), nullData && nullData->haveAllNullsGuaranteed()}; } void ColumnChunkData::updateStats(const ValueVector* vector, const SelectionView& selView) { if (selView.isUnfiltered()) { updateInMemoryStats(inMemoryStats, *vector); } else { TypeUtils::visit( getDataType().getPhysicalType(), [&](T) { std::optional firstValue; // ValueVector::firstNonNull uses the vector's builtin selection vector, not the one // passed as an argument selView.forEachBreakWhenFalse([&](auto i) { if (vector->isNull(i)) { return true; } else { firstValue = vector->getValue(i); return false; } }); if (!firstValue) { return; } // For floats, seed from the first non-NaN value: NaN is unordered // and would otherwise pin min/max (gh-1043). If every value is // NaN, fall back to the first value. std::optional min, max; if constexpr (std::floating_point) { selView.forEachBreakWhenFalse([&](auto i) { if (vector->isNull(i)) { return true; } const auto val = vector->getValue(i); if (std::isnan(val)) { return true; } min = val; max = val; return false; }); if (!min) { min = *firstValue; max = *firstValue; } } else { min = *firstValue; max = *firstValue; } auto update = [&](sel_t pos) { const auto val = vector->getValue(pos); if constexpr (std::floating_point) { if (std::isnan(val)) { return; } } if (val < *min) { min = val; } else if (val > *max) { max = val; } }; if (vector->hasNoNullsGuarantee()) { selView.forEach(update); } else { selView.forEach([&](auto pos) { if (!vector->isNull(pos)) { update(pos); } }); } inMemoryStats.update(StorageValue(*min), StorageValue(*max), getDataType().getPhysicalType()); }, [](T) { static_assert(!StorageValueType); }); } } void ColumnChunkData::resetInMemoryStats() { inMemoryStats.reset(); } ColumnChunkMetadata ColumnChunkData::getMetadataToFlush() const { DASSERT(numValues <= capacity); StorageValue minValue = {}, maxValue = {}; if (capacity > 0) { std::optional nullMask; if (nullData) { nullMask = nullData->getNullMask(); } auto [min, max] = getMinMaxStorageValue(getData(), 0 /*offset*/, numValues, dataType.getPhysicalType(), nullMask.has_value() ? &*nullMask : nullptr, true /*valueRequiredIfUnsupported*/); minValue = min.value_or(StorageValue()); maxValue = max.value_or(StorageValue()); } DASSERT(getBufferSize() == getBufferSize(capacity)); return getMetadataImpl(buffer->getBuffer(), numValues, minValue, maxValue); } void ColumnChunkData::append(ValueVector* vector, const SelectionView& selView) { DASSERT(vector->dataType.getPhysicalType() == dataType.getPhysicalType()); copyVectorToBuffer(vector, numValues, selView); numValues += selView.getSelSize(); updateStats(vector, selView); } void ColumnChunkData::append(const ColumnChunkData* other, offset_t startPosInOtherChunk, uint32_t numValuesToAppend) { DASSERT(other->dataType.getPhysicalType() == dataType.getPhysicalType()); if (nullData) { DASSERT(nullData->getNumValues() == getNumValues()); nullData->append(other->nullData.get(), startPosInOtherChunk, numValuesToAppend); } DASSERT(numValues + numValuesToAppend <= capacity); memcpy(getData() + numValues * numBytesPerValue, other->getData() + startPosInOtherChunk * numBytesPerValue, numValuesToAppend * numBytesPerValue); numValues += numValuesToAppend; updateInMemoryStats(inMemoryStats, other, startPosInOtherChunk, numValuesToAppend); } void ColumnChunkData::flush(PageAllocator& pageAllocator) { const auto preScanMetadata = getMetadataToFlush(); auto allocatedEntry = pageAllocator.allocatePageRange(preScanMetadata.getNumPages()); const auto flushedMetadata = flushBuffer(pageAllocator, allocatedEntry, preScanMetadata); setToOnDisk(flushedMetadata); if (nullData) { nullData->flush(pageAllocator); } } // Note: This function is not setting child/null chunk data recursively. void ColumnChunkData::setToOnDisk(const ColumnChunkMetadata& otherMetadata) { residencyState = ResidencyState::ON_DISK; capacity = 0; // Note: We don't need to set the buffer to nullptr, as it allows ColumnChunkData to be resized. buffer = buffer->getMemoryManager()->allocateBuffer(true, 0 /*size*/); this->metadata = otherMetadata; this->numValues = otherMetadata.numValues; resetInMemoryStats(); } ColumnChunkMetadata ColumnChunkData::flushBuffer(PageAllocator& pageAllocator, const PageRange& entry, const ColumnChunkMetadata& otherMetadata) const { const auto bufferSizeToFlush = getBufferSize(numValues); if (!otherMetadata.compMeta.isConstant() && bufferSizeToFlush != 0) { DASSERT(bufferSizeToFlush <= buffer->getBuffer().size_bytes()); const auto bufferToFlush = buffer->getBuffer().subspan(0, bufferSizeToFlush); return flushBufferImpl(bufferToFlush, pageAllocator.getDataFH(), entry, otherMetadata); } DASSERT(otherMetadata.getNumPages() == 0); return otherMetadata; } uint64_t ColumnChunkData::getBufferSize(uint64_t capacity_) const { switch (dataType.getLogicalTypeID()) { case LogicalTypeID::BOOL: { // 8 values per byte, and we need a buffer size which is a // multiple of 8 bytes. return ceil(capacity_ / 8.0 / 8.0) * 8; } default: { return numBytesPerValue * capacity_; } } } void ColumnChunkData::initializeScanState(SegmentState& state, const Column* column) const { if (nullData) { DASSERT(state.nullState); nullData->initializeScanState(*state.nullState, column->getNullColumn()); } state.column = column; if (residencyState == ResidencyState::ON_DISK) { state.metadata = metadata; state.numValuesPerPage = state.metadata.compMeta.numValues(LBUG_PAGE_SIZE, dataType); state.column->populateExtraChunkState(state); } } void ColumnChunkData::scan(ValueVector& output, offset_t offset, length_t length, sel_t posInOutputVector) const { // Scanning zero rows must not touch data buffers: empty (e.g. freshly created) // chunks may hold null/zero-size buffers, and memcpy with a null source is UB // even when the byte count is 0 (issue #840: SIGSEGV in memmove under // NodeTableScanState::scanNext on empty tables via a parallel scan morsel). if (length == 0) { return; } DASSERT(offset + length <= numValues); DASSERT(getData() != nullptr); if (nullData) { nullData->scan(output, offset, length, posInOutputVector); } memcpy(output.getData() + posInOutputVector * numBytesPerValue, getData() + offset * numBytesPerValue, numBytesPerValue * length); } void ColumnChunkData::lookup(offset_t offsetInChunk, ValueVector& output, sel_t posInOutputVector) const { DASSERT(offsetInChunk < capacity); output.setNull(posInOutputVector, isNull(offsetInChunk)); if (!output.isNull(posInOutputVector)) { memcpy(output.getData() + posInOutputVector * numBytesPerValue, getData() + offsetInChunk * numBytesPerValue, numBytesPerValue); } } void ColumnChunkData::write(ColumnChunkData* chunk, ColumnChunkData* dstOffsets, RelMultiplicity multiplicity) { DASSERT(chunk->dataType.getPhysicalType() == dataType.getPhysicalType() && dstOffsets->getDataType().getPhysicalType() == PhysicalTypeID::INTERNAL_ID && chunk->getNumValues() == dstOffsets->getNumValues()); for (auto i = 0u; i < dstOffsets->getNumValues(); i++) { const auto dstOffset = dstOffsets->getValue(i); DASSERT(dstOffset < capacity); memcpy(getData() + dstOffset * numBytesPerValue, chunk->getData() + i * numBytesPerValue, numBytesPerValue); numValues = dstOffset >= numValues ? dstOffset + 1 : numValues; } if (nullData || multiplicity == RelMultiplicity::ONE) { for (auto i = 0u; i < dstOffsets->getNumValues(); i++) { const auto dstOffset = dstOffsets->getValue(i); if (multiplicity == RelMultiplicity::ONE && isNull(dstOffset)) { throw CopyException( std::format("Node with offset: {} can only have one neighbour due " "to the MANY-ONE/ONE-ONE relationship constraint.", dstOffset)); } if (nullData) { nullData->setNull(dstOffset, chunk->isNull(i)); } } } updateInMemoryStats(inMemoryStats, chunk); } // NOTE: This function is only called in LocalTable right now when // performing out-of-place committing. LIST has a different logic for // handling out-of-place committing as it has to be slided. However, // this is unsafe, as this function can also be used for other purposes // later. Thus, an assertion is added at the first line. void ColumnChunkData::write(const ValueVector* vector, offset_t offsetInVector, offset_t offsetInChunk) { DASSERT(dataType.getPhysicalType() != PhysicalTypeID::BOOL && dataType.getPhysicalType() != PhysicalTypeID::LIST && dataType.getPhysicalType() != PhysicalTypeID::ARRAY); if (nullData) { nullData->setNull(offsetInChunk, vector->isNull(offsetInVector)); } if (offsetInChunk >= numValues) { numValues = offsetInChunk + 1; } if (!vector->isNull(offsetInVector)) { memcpy(getData() + offsetInChunk * numBytesPerValue, vector->getData() + offsetInVector * numBytesPerValue, numBytesPerValue); } static constexpr uint64_t numValuesToWrite = 1; updateInMemoryStats(inMemoryStats, *vector, offsetInVector, numValuesToWrite); } void ColumnChunkData::write(const ColumnChunkData* srcChunk, offset_t srcOffsetInChunk, offset_t dstOffsetInChunk, offset_t numValuesToCopy) { DASSERT(srcChunk->dataType.getPhysicalType() == dataType.getPhysicalType()); if ((dstOffsetInChunk + numValuesToCopy) >= numValues) { numValues = dstOffsetInChunk + numValuesToCopy; } memcpy(getData() + dstOffsetInChunk * numBytesPerValue, srcChunk->getData() + srcOffsetInChunk * numBytesPerValue, numValuesToCopy * numBytesPerValue); if (nullData) { DASSERT(srcChunk->getNullData()); nullData->write(srcChunk->getNullData(), srcOffsetInChunk, dstOffsetInChunk, numValuesToCopy); } updateInMemoryStats(inMemoryStats, srcChunk, srcOffsetInChunk, numValuesToCopy); } void ColumnChunkData::resetNumValuesFromMetadata() { DASSERT(residencyState == ResidencyState::ON_DISK); numValues = metadata.numValues; if (nullData) { nullData->resetNumValuesFromMetadata(); // FIXME(bmwinger): not always working // DASSERT(numValues == nullData->numValues); } } void ColumnChunkData::setToInMemory() { DASSERT(residencyState == ResidencyState::ON_DISK); DASSERT(capacity == 0 && getBufferSize() == 0); residencyState = ResidencyState::IN_MEMORY; numValues = 0; if (nullData) { nullData->setToInMemory(); } } void ColumnChunkData::resize(uint64_t newCapacity) { const auto numBytesAfterResize = getBufferSize(newCapacity); if (numBytesAfterResize > getBufferSize()) { auto resizedBuffer = buffer->getMemoryManager()->allocateBuffer(false, numBytesAfterResize); auto bufferSize = getBufferSize(); auto resizedBufferData = resizedBuffer->getBuffer().data(); memcpy(resizedBufferData, buffer->getBuffer().data(), bufferSize); memset(resizedBufferData + bufferSize, 0, numBytesAfterResize - bufferSize); buffer = std::move(resizedBuffer); } if (nullData) { nullData->resize(newCapacity); } if (newCapacity > capacity) { capacity = newCapacity; } } void ColumnChunkData::resizeWithoutPreserve(uint64_t newCapacity) { const auto numBytesAfterResize = getBufferSize(newCapacity); if (numBytesAfterResize > getBufferSize()) { auto resizedBuffer = buffer->getMemoryManager()->allocateBuffer(false, numBytesAfterResize); buffer = std::move(resizedBuffer); } if (nullData) { nullData->resize(newCapacity); } if (newCapacity > capacity) { capacity = newCapacity; } } void ColumnChunkData::populateWithDefaultVal(ExpressionEvaluator& defaultEvaluator, uint64_t& numValues_, ColumnStats* newColumnStats) { auto numValuesAppended = 0u; const auto numValuesToPopulate = numValues_; while (numValuesAppended < numValuesToPopulate) { const auto numValuesToAppend = std::min(DEFAULT_VECTOR_CAPACITY, numValuesToPopulate - numValuesAppended); defaultEvaluator.evaluate(numValuesToAppend); auto resultVector = defaultEvaluator.resultVector.get(); DASSERT(resultVector->state->getSelVector().getSelSize() == numValuesToAppend); append(resultVector, resultVector->state->getSelVector()); if (newColumnStats) { newColumnStats->update(resultVector); } numValuesAppended += numValuesToAppend; } } void ColumnChunkData::copyVectorToBuffer(ValueVector* vector, offset_t startPosInChunk, const SelectionView& selView) { auto bufferToWrite = buffer->getBuffer().data() + startPosInChunk * numBytesPerValue; DASSERT(startPosInChunk + selView.getSelSize() <= capacity); const auto vectorDataToWriteFrom = vector->getData(); if (nullData) { nullData->appendNulls(vector, selView, startPosInChunk); } if (selView.isUnfiltered()) { memcpy(bufferToWrite, vectorDataToWriteFrom, selView.getSelSize() * numBytesPerValue); } else { selView.forEach([&](auto pos) { memcpy(bufferToWrite, vectorDataToWriteFrom + pos * numBytesPerValue, numBytesPerValue); bufferToWrite += numBytesPerValue; }); } } void ColumnChunkData::setNumValues(uint64_t numValues_) { DASSERT(numValues_ <= capacity); numValues = numValues_; if (nullData) { nullData->setNumValues(numValues_); } } bool ColumnChunkData::numValuesSanityCheck() const { if (nullData) { return numValues == nullData->getNumValues(); } return numValues <= capacity; } bool ColumnChunkData::sanityCheck() const { if (nullData) { return nullData->sanityCheck() && numValuesSanityCheck(); } return numValues <= capacity; } uint64_t ColumnChunkData::getEstimatedMemoryUsage() const { return buffer->getBuffer().size() + (nullData ? nullData->getEstimatedMemoryUsage() : 0); } void ColumnChunkData::serialize(Serializer& serializer) const { DASSERT(residencyState == ResidencyState::ON_DISK); serializer.writeDebuggingInfo("data_type"); dataType.serialize(serializer); serializer.writeDebuggingInfo("metadata"); metadata.serialize(serializer); serializer.writeDebuggingInfo("enable_compression"); serializer.write(enableCompression); serializer.writeDebuggingInfo("has_null"); serializer.write(nullData != nullptr); if (nullData) { serializer.writeDebuggingInfo("null_data"); nullData->serialize(serializer); } } std::unique_ptr ColumnChunkData::deserialize(MemoryManager& memoryManager, Deserializer& deSer) { std::string key; ColumnChunkMetadata metadata; bool enableCompression = false; bool hasNull = false; bool initializeToZero = true; deSer.validateDebuggingInfo(key, "data_type"); const auto dataType = LogicalType::deserialize(deSer); deSer.validateDebuggingInfo(key, "metadata"); metadata = decltype(metadata)::deserialize(deSer); deSer.validateDebuggingInfo(key, "enable_compression"); deSer.deserializeValue(enableCompression); deSer.validateDebuggingInfo(key, "has_null"); deSer.deserializeValue(hasNull); auto chunkData = ColumnChunkFactory::createColumnChunkData(memoryManager, dataType.copy(), enableCompression, metadata, hasNull, initializeToZero); if (hasNull) { deSer.validateDebuggingInfo(key, "null_data"); chunkData->nullData = NullChunkData::deserialize(memoryManager, deSer); } switch (dataType.getPhysicalType()) { case PhysicalTypeID::STRUCT: { StructChunkData::deserialize(deSer, *chunkData); } break; case PhysicalTypeID::STRING: case PhysicalTypeID::JSON: { StringChunkData::deserialize(deSer, *chunkData); } break; case PhysicalTypeID::ARRAY: case PhysicalTypeID::LIST: { ListChunkData::deserialize(deSer, *chunkData); } break; default: { // DO NOTHING. } } return chunkData; } void BoolChunkData::append(ValueVector* vector, const SelectionView& selView) { DASSERT(vector->dataType.getPhysicalType() == PhysicalTypeID::BOOL); for (auto i = 0u; i < selView.getSelSize(); i++) { const auto pos = selView[i]; NullMask::setNull(getData(), numValues + i, vector->getValue(pos)); } if (nullData) { nullData->appendNulls(vector, selView, numValues); } numValues += selView.getSelSize(); updateStats(vector, selView); } void BoolChunkData::append(const ColumnChunkData* other, offset_t startPosInOtherChunk, uint32_t numValuesToAppend) { NullMask::copyNullMask(other->getData(), startPosInOtherChunk, getData(), numValues, numValuesToAppend); if (nullData) { nullData->append(other->getNullData(), startPosInOtherChunk, numValuesToAppend); } numValues += numValuesToAppend; updateInMemoryStats(inMemoryStats, other, startPosInOtherChunk, numValuesToAppend); } void BoolChunkData::scan(ValueVector& output, offset_t offset, length_t length, sel_t posInOutputVector) const { DASSERT(offset + length <= numValues); if (nullData) { nullData->scan(output, offset, length, posInOutputVector); } for (auto i = 0u; i < length; i++) { output.setValue(posInOutputVector + i, NullMask::isNull(getData(), offset + i)); } } void BoolChunkData::lookup(offset_t offsetInChunk, ValueVector& output, sel_t posInOutputVector) const { DASSERT(offsetInChunk < capacity); output.setNull(posInOutputVector, nullData->isNull(offsetInChunk)); if (!output.isNull(posInOutputVector)) { output.setValue(posInOutputVector, NullMask::isNull(getData(), offsetInChunk)); } } void BoolChunkData::write(ColumnChunkData* chunk, ColumnChunkData* dstOffsets, RelMultiplicity) { DASSERT(chunk->getDataType().getPhysicalType() == PhysicalTypeID::BOOL && dstOffsets->getDataType().getPhysicalType() == PhysicalTypeID::INTERNAL_ID && chunk->getNumValues() == dstOffsets->getNumValues()); for (auto i = 0u; i < dstOffsets->getNumValues(); i++) { const auto dstOffset = dstOffsets->getValue(i); DASSERT(dstOffset < capacity); NullMask::setNull(getData(), dstOffset, chunk->getValue(i)); if (nullData) { nullData->setNull(dstOffset, chunk->getNullData()->isNull(i)); } numValues = dstOffset >= numValues ? dstOffset + 1 : numValues; } updateInMemoryStats(inMemoryStats, chunk); } void BoolChunkData::write(const ValueVector* vector, offset_t offsetInVector, offset_t offsetInChunk) { DASSERT(vector->dataType.getPhysicalType() == PhysicalTypeID::BOOL); DASSERT(offsetInChunk < capacity); const auto valueToSet = vector->getValue(offsetInVector); setValue(valueToSet, offsetInChunk); if (nullData) { nullData->write(vector, offsetInVector, offsetInChunk); } numValues = offsetInChunk >= numValues ? offsetInChunk + 1 : numValues; if (!vector->isNull(offsetInVector)) { inMemoryStats.update(StorageValue{valueToSet}, dataType.getPhysicalType()); } } void BoolChunkData::write(const ColumnChunkData* srcChunk, offset_t srcOffsetInChunk, offset_t dstOffsetInChunk, offset_t numValuesToCopy) { if (nullData) { nullData->write(srcChunk->getNullData(), srcOffsetInChunk, dstOffsetInChunk, numValuesToCopy); } if ((dstOffsetInChunk + numValuesToCopy) >= numValues) { numValues = dstOffsetInChunk + numValuesToCopy; } NullMask::copyNullMask(srcChunk->getData(), srcOffsetInChunk, getData(), dstOffsetInChunk, numValuesToCopy); updateInMemoryStats(inMemoryStats, srcChunk, srcOffsetInChunk, numValuesToCopy); } NullMask NullChunkData::getNullMask() const { return NullMask( std::span(getData(), ceilDiv(capacity, NullMask::NUM_BITS_PER_NULL_ENTRY)), !noNullsGuaranteedInMem()); } void NullChunkData::setNull(offset_t pos, bool isNull) { setValue(isNull, pos); // TODO(Guodong): Better let NullChunkData also support `append` a // vector. } void NullChunkData::write(const ValueVector* vector, offset_t offsetInVector, offset_t offsetInChunk) { const bool isNull = vector->isNull(offsetInVector); setValue(isNull, offsetInChunk); } void NullChunkData::write(const ColumnChunkData* srcChunk, offset_t srcOffsetInChunk, offset_t dstOffsetInChunk, offset_t numValuesToCopy) { if (numValuesToCopy == 0) { return; } DASSERT(srcChunk->getBufferSize() >= sizeof(uint64_t)); copyFromBuffer(srcChunk->getData(), srcOffsetInChunk, dstOffsetInChunk, numValuesToCopy); } void NullChunkData::append(const ColumnChunkData* other, offset_t startOffsetInOtherChunk, uint32_t numValuesToAppend) { write(other, startOffsetInOtherChunk, numValues, numValuesToAppend); } bool NullChunkData::haveNoNullsGuaranteed() const { return noNullsGuaranteedInMem() && !metadata.compMeta.max.get(); } bool NullChunkData::haveAllNullsGuaranteed() const { return allNullsGuaranteedInMem() && metadata.compMeta.min.get(); } void NullChunkData::serialize(Serializer& serializer) const { DASSERT(residencyState == ResidencyState::ON_DISK); serializer.writeDebuggingInfo("null_chunk_metadata"); metadata.serialize(serializer); } std::unique_ptr NullChunkData::deserialize(MemoryManager& memoryManager, Deserializer& deSer) { std::string key; ColumnChunkMetadata metadata; deSer.validateDebuggingInfo(key, "null_chunk_metadata"); metadata = decltype(metadata)::deserialize(deSer); // TODO: FIX-ME. enableCompression. return std::make_unique(memoryManager, true, metadata); } void NullChunkData::scan(ValueVector& output, offset_t offset, length_t length, sel_t posInOutputVector) const { if (length == 0) { return; } output.setNullFromBits(getNullMask().getData(), offset, posInOutputVector, length); } void NullChunkData::appendNulls(const ValueVector* vector, const SelectionView& selView, offset_t startPosInChunk) { if (selView.isUnfiltered()) { copyFromBuffer(vector->getNullMask().getData(), 0, startPosInChunk, selView.getSelSize()); } else { for (auto i = 0u; i < selView.getSelSize(); i++) { const auto pos = selView[i]; setNull(startPosInChunk + i, vector->isNull(pos)); } } } void InternalIDChunkData::append(ValueVector* vector, const SelectionView& selView) { switch (vector->dataType.getPhysicalType()) { case PhysicalTypeID::INTERNAL_ID: { copyVectorToBuffer(vector, numValues, selView); } break; case PhysicalTypeID::INT64: { copyInt64VectorToBuffer(vector, numValues, selView); } break; default: { UNREACHABLE_CODE; } } numValues += selView.getSelSize(); } void InternalIDChunkData::copyVectorToBuffer(ValueVector* vector, offset_t startPosInChunk, const SelectionView& selView) { DASSERT(vector->dataType.getPhysicalType() == PhysicalTypeID::INTERNAL_ID); const auto relIDsInVector = reinterpret_cast(vector->getData()); if (commonTableID == INVALID_TABLE_ID) { commonTableID = relIDsInVector[selView[0]].tableID; } for (auto i = 0u; i < selView.getSelSize(); i++) { const auto pos = selView[i]; if (vector->isNull(pos)) { continue; } DASSERT(relIDsInVector[pos].tableID == commonTableID); memcpy(getData() + (startPosInChunk + i) * numBytesPerValue, &relIDsInVector[pos].offset, numBytesPerValue); } } void InternalIDChunkData::copyInt64VectorToBuffer(ValueVector* vector, offset_t startPosInChunk, const SelectionView& selView) const { DASSERT(vector->dataType.getPhysicalType() == PhysicalTypeID::INT64); for (auto i = 0u; i < selView.getSelSize(); i++) { const auto pos = selView[i]; if (vector->isNull(pos)) { continue; } memcpy(getData() + (startPosInChunk + i) * numBytesPerValue, &vector->getValue(pos), numBytesPerValue); } } void InternalIDChunkData::scan(ValueVector& output, offset_t offset, length_t length, sel_t posInOutputVector) const { DASSERT(offset + length <= numValues); DASSERT(commonTableID != INVALID_TABLE_ID); internalID_t relID; relID.tableID = commonTableID; for (auto i = 0u; i < length; i++) { relID.offset = getValue(offset + i); output.setValue(posInOutputVector + i, relID); } } void InternalIDChunkData::lookup(offset_t offsetInChunk, ValueVector& output, sel_t posInOutputVector) const { DASSERT(offsetInChunk < capacity); internalID_t relID; relID.offset = getValue(offsetInChunk); DASSERT(commonTableID != INVALID_TABLE_ID); relID.tableID = commonTableID; output.setValue(posInOutputVector, relID); } void InternalIDChunkData::write(const ValueVector* vector, offset_t offsetInVector, offset_t offsetInChunk) { DASSERT(vector->dataType.getPhysicalType() == PhysicalTypeID::INTERNAL_ID); const auto relIDsInVector = reinterpret_cast(vector->getData()); if (commonTableID == INVALID_TABLE_ID) { commonTableID = relIDsInVector[offsetInVector].tableID; } DASSERT(commonTableID == relIDsInVector[offsetInVector].tableID); if (!vector->isNull(offsetInVector)) { memcpy(getData() + offsetInChunk * numBytesPerValue, &relIDsInVector[offsetInVector].offset, numBytesPerValue); } if (offsetInChunk >= numValues) { numValues = offsetInChunk + 1; } } void InternalIDChunkData::append(const ColumnChunkData* other, offset_t startPosInOtherChunk, uint32_t numValuesToAppend) { ColumnChunkData::append(other, startPosInOtherChunk, numValuesToAppend); commonTableID = other->cast().commonTableID; } std::optional ColumnChunkData::getNullMask() const { return nullData ? std::optional(nullData->getNullMask()) : std::nullopt; } std::unique_ptr ColumnChunkFactory::createColumnChunkData(MemoryManager& mm, LogicalType dataType, bool enableCompression, uint64_t capacity, ResidencyState residencyState, bool hasNullData, bool initializeToZero) { switch (dataType.getPhysicalType()) { case PhysicalTypeID::BOOL: { return std::make_unique(mm, capacity, enableCompression, residencyState, hasNullData); } case PhysicalTypeID::INT64: case PhysicalTypeID::INT32: case PhysicalTypeID::INT16: case PhysicalTypeID::INT8: case PhysicalTypeID::UINT64: case PhysicalTypeID::UINT32: case PhysicalTypeID::UINT16: case PhysicalTypeID::UINT8: case PhysicalTypeID::INT128: case PhysicalTypeID::UINT128: case PhysicalTypeID::DOUBLE: case PhysicalTypeID::FLOAT: case PhysicalTypeID::INTERVAL: { return std::make_unique(mm, std::move(dataType), capacity, enableCompression, residencyState, hasNullData, initializeToZero); } case PhysicalTypeID::INTERNAL_ID: { return std::make_unique(mm, capacity, enableCompression, residencyState); } case PhysicalTypeID::STRING: case PhysicalTypeID::JSON: { return std::make_unique(mm, std::move(dataType), capacity, enableCompression, residencyState); } case PhysicalTypeID::ARRAY: case PhysicalTypeID::LIST: { return std::make_unique(mm, std::move(dataType), capacity, enableCompression, residencyState); } case PhysicalTypeID::STRUCT: { return std::make_unique(mm, std::move(dataType), capacity, enableCompression, residencyState); } default: UNREACHABLE_CODE; } } std::unique_ptr ColumnChunkFactory::createColumnChunkData(MemoryManager& mm, LogicalType dataType, bool enableCompression, ColumnChunkMetadata& metadata, bool hasNullData, bool initializeToZero) { switch (dataType.getPhysicalType()) { case PhysicalTypeID::BOOL: { return std::make_unique(mm, enableCompression, metadata, hasNullData); } case PhysicalTypeID::INT64: case PhysicalTypeID::INT32: case PhysicalTypeID::INT16: case PhysicalTypeID::INT8: case PhysicalTypeID::UINT64: case PhysicalTypeID::UINT32: case PhysicalTypeID::UINT16: case PhysicalTypeID::UINT8: case PhysicalTypeID::INT128: case PhysicalTypeID::UINT128: case PhysicalTypeID::DOUBLE: case PhysicalTypeID::FLOAT: case PhysicalTypeID::INTERVAL: { return std::make_unique(mm, std::move(dataType), enableCompression, metadata, hasNullData, initializeToZero); } // Physically, we only materialize offset of INTERNAL_ID, which is same as INT64, case PhysicalTypeID::INTERNAL_ID: { // INTERNAL_ID should never have nulls. return std::make_unique(mm, enableCompression, metadata); } case PhysicalTypeID::STRING: case PhysicalTypeID::JSON: { return std::make_unique(mm, std::move(dataType), enableCompression, metadata); } case PhysicalTypeID::ARRAY: case PhysicalTypeID::LIST: { return std::make_unique(mm, std::move(dataType), enableCompression, metadata); } case PhysicalTypeID::STRUCT: { return std::make_unique(mm, std::move(dataType), enableCompression, metadata); } default: UNREACHABLE_CODE; } } bool ColumnChunkData::isNull(offset_t pos) const { return nullData && nullData->isNull(pos); } MemoryManager& ColumnChunkData::getMemoryManager() const { return *buffer->getMemoryManager(); } uint8_t* ColumnChunkData::getData() const { return buffer->getBuffer().data(); } uint64_t ColumnChunkData::getBufferSize() const { return buffer->getBuffer().size_bytes(); } void ColumnChunkData::loadFromDisk() { buffer->getMemoryManager()->getBufferManager()->getSpillerOrSkip( [&](auto& spiller) { spiller.loadFromDisk(*this); }); } SpillResult ColumnChunkData::spillToDisk() { SpillResult spilled{}; buffer->getMemoryManager()->getBufferManager()->getSpillerOrSkip( [&](auto& spiller) { spilled = spiller.spillToDisk(*this); }); return spilled; } void ColumnChunkData::reclaimStorage(PageAllocator& pageAllocator) { if (auto* deferral = PageReclaimDeferral::current()) { if (nullData) { nullData->reclaimStorage(pageAllocator); } if (residencyState == ResidencyState::ON_DISK) { deferral->defer(metadata.pageRange, pageAllocator); } return; } if (nullData) { nullData->reclaimStorage(pageAllocator); } if (residencyState == ResidencyState::ON_DISK) { if (metadata.getStartPageIdx() != INVALID_PAGE_IDX) { pageAllocator.freePageRange(metadata.pageRange); } } } uint64_t ColumnChunkData::getSizeOnDisk() const { // Probably could just return the actual size from the metadata if it's on-disk, but it's not // currently needed for on-disk segments DASSERT(ResidencyState::IN_MEMORY == residencyState); auto metadata = getMetadataToFlush(); uint64_t nullSize = 0; if (nullData) { nullSize = nullData->getSizeOnDisk(); } return metadata.getNumDataPages(dataType.getPhysicalType()) * common::LBUG_PAGE_SIZE + nullSize; } uint64_t ColumnChunkData::getSizeOnDiskInMemoryStats() const { // Probably could just return the actual size from the metadata if it's on-disk, but it's not // currently needed for on-disk segments DASSERT(ResidencyState::IN_MEMORY == residencyState); uint64_t nullSize = 0; if (nullData) { nullSize = nullData->getSizeOnDiskInMemoryStats(); } auto metadata = getMetadataImpl(buffer->getBuffer(), numValues, inMemoryStats.min.value_or(StorageValue{}), inMemoryStats.max.value_or(StorageValue{})); return metadata.getNumDataPages(dataType.getPhysicalType()) * common::LBUG_PAGE_SIZE + nullSize; } std::vector> ColumnChunkData::split(bool targetMaxSize) const { // FIXME(bmwinger): we either need to split recursively, or detect individual values which bring // the size above MAX_SEGMENT_SIZE, since this will still sometimes produce segments larger than // MAX_SEGMENT_SIZE auto maxSegmentSize = std::max(getMinimumSizeOnDisk(), common::StorageConfig::MAX_SEGMENT_SIZE); // Compute compression metadata once. This runs expensive analysis (e.g., ALP's // find_top_k_combinations for float types) exactly once for the whole chunk, instead of O(N) // times in the inner loop below. auto meta = getMetadataToFlush(); auto dataPages = meta.getNumDataPages(dataType.getPhysicalType()); // Use the virtual getSizeOnDisk() instead of recomputing the size from base-class metadata // alone: subclasses can own additional storage that must be counted when sizing segments // (StringChunkData adds its index and dictionary chunks). The previously inlined formula // reported a size of 0 for variable-size types (numBytesPerValue == 0), which collapsed // targetSize below to 0 on the checkpoint compaction path and shattered chunks into // single-batch segments: a 131072-value string chunk became 2048 segments instead of ~3, // bloating files ~2x and slowing down COPY FROM (gh-835). auto totalSize = getSizeOnDisk(); auto targetSize = targetMaxSize ? maxSegmentSize : std::min(totalSize / 2, maxSegmentSize); // Defensive fallback: if the size computation still degenerates to 0 for a non-empty chunk // (which would fragment it into one minimal segment per batch), split by the maximum // segment size instead. if (targetSize == 0 && numValues > 0) { targetSize = maxSegmentSize; } // For fixed-size types, compute a count-based bound directly from the compression metadata. // Using pages * valuesPerPage is accurate because it respects page boundaries and avoids the // integer-division bias of a simple avg-bytes-per-value approach. uint64_t maxValuesPerSegment = UINT64_MAX; if (numBytesPerValue > 0 && numValues > 0 && dataPages > 0) { const auto valuesPerPage = common::ceilDiv(numValues, static_cast(dataPages)); const auto maxPages = targetSize / common::LBUG_PAGE_SIZE; if (maxPages > 0) { maxValuesPerSegment = maxPages * valuesPerPage; } } std::vector> newSegments; uint64_t pos = 0; const uint64_t chunkSize = 64; // Shrinks an oversized segment back under targetSize. Each size evaluation scans the whole // segment (e.g. full ALP analysis for floats), so removing one batch per evaluation is // O(N^2) when the fill bound overshoots by many batches (gh-1071: 581 evaluations over // ~280k values for a single DOUBLE segment whose segment-local ALP encoding was one bit // wider than the whole-chunk encoding the count bound was derived from). Jump to the // estimated fit instead and re-estimate a bounded number of times; size is near-linear in // row count locally so this converges in a couple of evaluations. auto shrinkSegmentToFit = [&](ColumnChunkData& segment, uint64_t& posRef) { for (uint64_t round = 0; round < 4; ++round) { if (posRef >= numValues || segment.getNumValues() <= chunkSize) { break; } auto segSize = segment.getSizeOnDiskInMemoryStats(); if (segSize <= targetSize) { break; } auto segValues = segment.getNumValues(); // Estimate the row count that fits, rounded down to a batch boundary // (at least one batch is always kept). uint64_t fitValues = segSize == 0 ? 0 : (uint64_t)((double)targetSize * (double)segValues / (double)segSize); fitValues = fitValues / chunkSize * chunkSize; if (fitValues < chunkSize) { fitValues = chunkSize; } if (fitValues >= segValues) { // The estimate grants the whole segment but it still measures over target // (nonlinear size function): remove one batch and re-measure. posRef -= chunkSize; segment.truncate(segValues - chunkSize); } else { posRef -= (segValues - fitValues); segment.truncate(fitValues); } } // If the segment still exceeds targetSize after the bounded rounds above, keep it // as-is (it's the minimum viable segment / best effort; see FIXME above). }; // A chunk large enough to require splitting must receive a target size of at least one // page; a smaller (especially zero) target fragments it into single-batch segments. DASSERT(numValues <= chunkSize || getSizeOnDisk() <= common::StorageConfig::MAX_SEGMENT_SIZE || targetSize >= common::LBUG_PAGE_SIZE); uint64_t initialCapacity = std::min(chunkSize, numValues); while (pos < numValues) { std::unique_ptr newSegment = ColumnChunkFactory::createColumnChunkData(getMemoryManager(), getDataType().copy(), isCompressionEnabled(), initialCapacity, ResidencyState::IN_MEMORY, hasNullData()); // Fast inner loop: use the count-based bound for fixed-size types (avoiding O(N) metadata // recomputation). Variable-size types (strings/lists) have no count bound, so fall back // to size evaluations; those still scan the whole segment, so evaluate them periodically // (adapted to the observed density) instead of after every batch: per-batch evaluation // is O(N^2) over the segment fill (gh-1071). uint64_t rowsSinceEval = 0; uint64_t evalInterval = chunkSize * 4; while (pos < numValues) { if (maxValuesPerSegment != UINT64_MAX) { if (newSegment->getNumValues() >= maxValuesPerSegment) { break; } } else if (rowsSinceEval >= evalInterval) { auto curSize = newSegment->getSizeOnDiskInMemoryStats(); if (curSize > targetSize) { break; } rowsSinceEval = 0; // Space out evaluations so each segment needs only a handful of them: aim to // re-evaluate ~16 times over the remaining fill at the current bytes-per-row, // keeping at least one batch between evaluations (to bound overshoot past the // target) and at most 64 batches (so a single segment can't grow without bound // before its first evaluation). auto curValues = newSegment->getNumValues(); if (curValues > 0 && curSize > 0) { uint64_t estTotalRows = (uint64_t)((double)targetSize * (double)curValues / (double)curSize); uint64_t remaining = estTotalRows > curValues ? estTotalRows - curValues : 0; evalInterval = remaining / 16 / chunkSize * chunkSize; if (evalInterval < chunkSize) { evalInterval = chunkSize; } else if (evalInterval > chunkSize * 64) { evalInterval = chunkSize * 64; } } } if (newSegment->getNumValues() == newSegment->getCapacity()) { newSegment->resize(newSegment->getCapacity() * 2); } auto numValuesToAppendInChunk = std::min(numValues - pos, chunkSize); newSegment->append(this, pos, numValuesToAppendInChunk); pos += numValuesToAppendInChunk; rowsSinceEval += numValuesToAppendInChunk; } // Verify the segment fits within targetSize. The count-based bound is an approximation; // segment-specific overhead (e.g., null pages, per-segment bitpacking width) can make // the actual size differ. Shrink until the segment fits (bounded evaluations). if (maxValuesPerSegment != UINT64_MAX && pos < numValues && newSegment->getNumValues() > chunkSize && newSegment->getSizeOnDiskInMemoryStats() > targetSize) { shrinkSegmentToFit(*newSegment, pos); // If the segment still exceeds targetSize after the bounded shrink above, // keep it as-is (it's the minimum viable segment). } else if (maxValuesPerSegment == UINT64_MAX && pos < numValues && newSegment->getNumValues() > chunkSize && newSegment->getSizeOnDiskInMemoryStats() > targetSize) { // The throttled in-loop checks above can overshoot the target by more than one // batch; shrink back under it with a bounded number of size evaluations. shrinkSegmentToFit(*newSegment, pos); } newSegments.push_back(std::move(newSegment)); } // Guard against excessive segmentation: apart from the trailing remainder, a segment must // not stop after a single batch while still fitting comfortably within the target size. // That is the signature of a degenerate targetSize (gh-835). Single-batch segments holding // genuinely large values (e.g., multi-KB strings exceeding the target size) are legitimate // and excluded by the size condition. DASSERT([&]() { if (newSegments.size() <= 1 || numValues <= 2 * chunkSize) { return true; } for (auto iter = newSegments.begin(); iter != newSegments.end() - 1; ++iter) { const auto& segment = **iter; if (segment.getNumValues() <= chunkSize && segment.getSizeOnDiskInMemoryStats() <= targetSize / 2) { return false; } } return true; }()); return newSegments; } void ColumnChunkData::setNullData(std::unique_ptr nullData_) { nullData = std::move(nullData_); } std::unique_ptr ColumnChunkData::moveNullData() { return std::move(nullData); } ColumnChunkData::~ColumnChunkData() = default; uint64_t ColumnChunkData::getMinimumSizeOnDisk() const { if (hasNullData() && nullData->getSizeOnDisk() > 0) { return 2 * LBUG_PAGE_SIZE; } return LBUG_PAGE_SIZE; } } // namespace storage } // namespace lbug