Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::ColumnSegment Class Reference

TableFilter represents a filter pushed down into the table scan. More...

#include <duckdb.hpp>

Inheritance diagram for duckdb::ColumnSegment:
Collaboration diagram for duckdb::ColumnSegment:

Public Member Functions

 ColumnSegment (DatabaseInstance &db, shared_ptr< BlockHandle > block, const LogicalType &type, const ColumnSegmentType segment_type, const idx_t count, const CompressionFunction &function_p, BaseStatistics statistics, const block_id_t block_id_p, const idx_t offset, const idx_t segment_size_p, unique_ptr< ColumnSegmentState > segment_state_p=nullptr)
 Construct a column segment.
 ColumnSegment (ColumnSegment &other)
 Construct a column segment from another column segment. The other column segment becomes invalid (std::move).
void InitializePrefetch (PrefetchState &prefetch_state, ColumnScanState &scan_state)
void InitializeScan (ColumnScanState &state)
void Scan (ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset, ScanVectorType scan_type)
 Scan one vector from this segment.
void Select (ColumnScanState &state, idx_t scan_count, Vector &result, const SelectionVector &sel, idx_t sel_count)
 Scan a subset of a vector (defined by the selection vector).
void Filter (ColumnScanState &state, idx_t scan_count, Vector &result, SelectionVector &sel, idx_t &sel_count, const TableFilter &filter, TableFilterState &filter_state)
 Scan one vector while applying a filter to the vector, returning only the matching elements.
void FetchRow (ColumnFetchState &state, row_t row_id, Vector &result, idx_t result_idx)
 Fetch a value of the specific row id and append it to the result.
void Skip (ColumnScanState &state)
 Skip a scan forward to the row_index specified in the scan state.
idx_t SegmentSize () const
void Resize (idx_t segment_size)
 Resize the block.
const CompressionFunction & GetCompressionFunction ()
void InitializeAppend (ColumnAppendState &state)
 Initialize an append of this segment. Appends are only supported on transient segments.
idx_t Append (ColumnAppendState &state, UnifiedVectorFormat &data, idx_t offset, idx_t count)
 Appends a (part of) vector to the segment, returns the amount of entries successfully appended.
idx_t FinalizeAppend (ColumnAppendState &state)
 Finalize the segment for appending - no more appends can follow on this segment The segment should be compacted as much as possible Returns the number of bytes occupied within the segment.
void RevertAppend (idx_t new_count)
 Revert an append made to this segment.
void ConvertToPersistent (QueryContext context, optional_ptr< BlockManager > block_manager, const block_id_t block_id)
 Convert a transient in-memory segment to a persistent segment backed by an on-disk block. Only used during checkpointing.
void MarkAsPersistent (shared_ptr< BlockHandle > block, uint32_t offset_in_block)
 Updates pointers to refer to the given block and offset. This is only used when sharing a block among segments. This is invoked only AFTER the block is written.
void SetBlock (shared_ptr< BlockHandle > block, uint32_t offset)
DataPointer GetDataPointer (idx_t row_start)
 Gets a data pointer from a persistent column segment.
block_id_t GetBlockId ()
idx_t GetBlockSize () const
 Returns the size of the underlying block of the segment. It is size is the size available for usage on a block.
idx_t GetBlockOffset ()
optional_ptr< CompressedSegmentState > GetSegmentState () const
void VisitBlockIds (BlockIdVisitor &visitor) const
Public Member Functions inherited from duckdb::SegmentBase< ColumnSegment >
 SegmentBase (idx_t count)

Static Public Member Functions

static unique_ptr< ColumnSegment > CreatePersistentSegment (DatabaseInstance &db, BlockManager &block_manager, block_id_t id, idx_t offset, const LogicalType &type_p, idx_t count, CompressionType compression_type, BaseStatistics statistics, unique_ptr< ColumnSegmentState > segment_state)
static unique_ptr< ColumnSegment > CreateTransientSegment (DatabaseInstance &db, const CompressionFunction &function, const LogicalType &type, const idx_t segment_size, BlockManager &block_manager)
static idx_t FilterSelection (SelectionVector &sel, Vector &vector, UnifiedVectorFormat &vdata, const TableFilter &filter, TableFilterState &filter_state, idx_t scan_count, idx_t &approved_tuple_count)

Public Attributes

DatabaseInstance & db
 The database instance.
LogicalType type
 The type stored in the column.
idx_t type_size
 The size of the type.
ColumnSegmentType segment_type
 The column segment type (transient or persistent).
SegmentStatistics stats
 The statistics for the segment.
shared_ptr< BlockHandle > block
 The block that this segment relates to.
Public Attributes inherited from duckdb::SegmentBase< ColumnSegment >
atomic< idx_t > count
 The amount of entries in this storage chunk.

Private Member Functions

void Scan (ColumnScanState &state, idx_t scan_count, Vector &result)
void ScanPartial (ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset)

Private Attributes

reference< const CompressionFunction > function
 The compression function.
block_id_t block_id
 The block id that this segment relates to (persistent segment only).
idx_t offset
 The offset into the block (persistent segment only).
idx_t segment_size
 The allocated segment size, which is bounded by Storage::BLOCK_SIZE.
unique_ptr< CompressedSegmentState > segment_state
 Storage associated with the compressed segment.

Detailed Description

TableFilter represents a filter pushed down into the table scan.

Constructor & Destructor Documentation

◆ ColumnSegment() [1/2]

duckdb::ColumnSegment::ColumnSegment ( DatabaseInstance & db,
shared_ptr< BlockHandle > block,
const LogicalType & type,
const ColumnSegmentType segment_type,
const idx_t count,
const CompressionFunction & function_p,
BaseStatistics statistics,
const block_id_t block_id_p,
const idx_t offset,
const idx_t segment_size_p,
unique_ptr< ColumnSegmentState > segment_state_p = nullptr )

Construct a column segment.

430591 : SegmentBase<ColumnSegment>(count), db(db), type(type), type_size(GetTypeIdSize(type.InternalType())),
430592 segment_type(segment_type), stats(std::move(statistics)), block(std::move(block_p)), function(function_p),
430593 block_id(block_id_p), offset(offset), segment_size(segment_size_p) {
430594 if (function.get().init_segment) {
430595 segment_state = function.get().init_segment(*this, block_id, segment_state_p.get());
430596 }
430597
430598 // For constant segments (CompressionType::COMPRESSION_CONSTANT) the block is a nullptr.
430599 D_ASSERT(!block || segment_size <= GetBlockSize());
430600}
block_id_t block_id
The block id that this segment relates to (persistent segment only).
Definition duckdb.hpp:49105
SegmentStatistics stats
The statistics for the segment.
Definition duckdb.hpp:49097
LogicalType type
The type stored in the column.
Definition duckdb.hpp:49091
shared_ptr< BlockHandle > block
The block that this segment relates to.
Definition duckdb.hpp:49099
unique_ptr< CompressedSegmentState > segment_state
Storage associated with the compressed segment.
Definition duckdb.hpp:49111
reference< const CompressionFunction > function
The compression function.
Definition duckdb.hpp:49103
idx_t segment_size
The allocated segment size, which is bounded by Storage::BLOCK_SIZE.
Definition duckdb.hpp:49109
idx_t GetBlockSize() const
Returns the size of the underlying block of the segment. It is size is the size available for usage o...
Definition duckdb.hpp:49068
idx_t offset
The offset into the block (persistent segment only).
Definition duckdb.hpp:49107
DatabaseInstance & db
The database instance.
Definition duckdb.hpp:49089
ColumnSegmentType segment_type
The column segment type (transient or persistent).
Definition duckdb.hpp:49095
idx_t type_size
The size of the type.
Definition duckdb.hpp:49093
atomic< idx_t > count
Definition duckdb.hpp:23007
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ColumnSegment() [2/2]

duckdb::ColumnSegment::ColumnSegment ( ColumnSegment & other)

Construct a column segment from another column segment. The other column segment becomes invalid (std::move).

430603 : SegmentBase<ColumnSegment>(other.count.load()), db(other.db), type(std::move(other.type)),
430604 type_size(other.type_size), segment_type(other.segment_type), stats(std::move(other.stats)),
430605 block(std::move(other.block)), function(other.function), block_id(other.block_id), offset(other.offset),
430606 segment_size(other.segment_size), segment_state(std::move(other.segment_state)) {
430607 // For constant segments (CompressionType::COMPRESSION_CONSTANT) the block is a nullptr.
430608 D_ASSERT(!block || segment_size <= GetBlockSize());
430609}
Here is the call graph for this function:

◆ ~ColumnSegment()

duckdb::ColumnSegment::~ColumnSegment ( )
430611 {
430612}

Member Function Documentation

◆ CreatePersistentSegment()

unique_ptr< ColumnSegment > duckdb::ColumnSegment::CreatePersistentSegment ( DatabaseInstance & db,
BlockManager & block_manager,
block_id_t id,
idx_t offset,
const LogicalType & type_p,
idx_t count,
CompressionType compression_type,
BaseStatistics statistics,
unique_ptr< ColumnSegmentState > segment_state )
static
430555 {
430556 auto &config = DBConfig::GetConfig(db);
430557 shared_ptr<BlockHandle> block;
430558
430559 auto function = config.GetCompressionFunction(compression_type, type.InternalType());
430560 if (block_id != INVALID_BLOCK) {
430561 block = block_manager.RegisterBlock(block_id);
430562 }
430563
430564 auto segment_size = block_manager.GetBlockSize();
430565 return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::PERSISTENT, count, function,
430566 std::move(statistics), block_id, offset, segment_size, std::move(segment_state));
430567}

◆ CreateTransientSegment()

unique_ptr< ColumnSegment > duckdb::ColumnSegment::CreateTransientSegment ( DatabaseInstance & db,
const CompressionFunction & function,
const LogicalType & type,
const idx_t segment_size,
BlockManager & block_manager )
static
430572 {
430573 // Allocate a buffer for the uncompressed segment.
430574 auto &buffer_manager = BufferManager::GetBufferManager(db);
430575 D_ASSERT(&buffer_manager == &block_manager.buffer_manager);
430576 auto block = buffer_manager.RegisterTransientMemory(segment_size, block_manager);
430577
430578 return make_uniq<ColumnSegment>(db, std::move(block), type, ColumnSegmentType::TRANSIENT, 0U, function,
430579 BaseStatistics::CreateEmpty(type), INVALID_BLOCK, 0U, segment_size);
430580}
static BaseStatistics CreateEmpty(LogicalType type)
Definition duckdb.cpp:422871

◆ InitializePrefetch()

void duckdb::ColumnSegment::InitializePrefetch ( PrefetchState & prefetch_state,
ColumnScanState & scan_state )
430617 {
430618 if (!block || block->BlockId() >= MAXIMUM_BLOCK) {
430619 // not an on-disk block
430620 return;
430621 }
430622 if (function.get().init_prefetch) {
430623 function.get().init_prefetch(*this, prefetch_state);
430624 } else {
430625 prefetch_state.AddBlock(block);
430626 }
430627}

◆ InitializeScan()

void duckdb::ColumnSegment::InitializeScan ( ColumnScanState & state)
430629 {
430630 state.scan_state = function.get().init_scan(state.context, *this);
430631}

◆ Scan() [1/2]

void duckdb::ColumnSegment::Scan ( ColumnScanState & state,
idx_t scan_count,
Vector & result,
idx_t result_offset,
ScanVectorType scan_type )

Scan one vector from this segment.

430634 {
430635 if (scan_type == ScanVectorType::SCAN_ENTIRE_VECTOR) {
430636 D_ASSERT(result_offset == 0);
430637 Scan(state, scan_count, result);
430638 } else {
430639 D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR);
430640 ScanPartial(state, scan_count, result, result_offset);
430641 D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR);
430642 }
430643}
void Scan(ColumnScanState &state, idx_t scan_count, Vector &result, idx_t result_offset, ScanVectorType scan_type)
Scan one vector from this segment.
Definition duckdb.cpp:430633
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Select()

void duckdb::ColumnSegment::Select ( ColumnScanState & state,
idx_t scan_count,
Vector & result,
const SelectionVector & sel,
idx_t sel_count )

Scan a subset of a vector (defined by the selection vector).

430646 {
430647 if (!function.get().select) {
430648 throw InternalException("ColumnSegment::Select not implemented for this compression method");
430649 }
430650 function.get().select(*this, state, scan_count, result, sel, sel_count);
430651}

◆ Filter()

void duckdb::ColumnSegment::Filter ( ColumnScanState & state,
idx_t scan_count,
Vector & result,
SelectionVector & sel,
idx_t & sel_count,
const TableFilter & filter,
TableFilterState & filter_state )

Scan one vector while applying a filter to the vector, returning only the matching elements.

430654 {
430655 if (!function.get().filter) {
430656 throw InternalException("ColumnSegment::Filter not implemented for this compression method");
430657 }
430658 function.get().filter(*this, state, scan_count, result, sel, sel_count, filter, filter_state);
430659}

◆ FetchRow()

void duckdb::ColumnSegment::FetchRow ( ColumnFetchState & state,
row_t row_id,
Vector & result,
idx_t result_idx )

Fetch a value of the specific row id and append it to the result.

430677 {
430678 if (UnsafeNumericCast<idx_t>(row_id) > count) {
430679 throw InternalException("ColumnSegment::FetchRow - row_id out of range for segment");
430680 }
430681 function.get().fetch_row(*this, state, row_id, result, result_idx);
430682}

◆ FilterSelection()

idx_t duckdb::ColumnSegment::FilterSelection ( SelectionVector & sel,
Vector & vector,
UnifiedVectorFormat & vdata,
const TableFilter & filter,
TableFilterState & filter_state,
idx_t scan_count,
idx_t & approved_tuple_count )
static
430932 {
430933 switch (filter.filter_type) {
430934 case TableFilterType::OPTIONAL_FILTER: {
430935 auto &opt_filter = filter.Cast<OptionalFilter>();
430936 return opt_filter.FilterSelection(sel, vector, vdata, filter_state, scan_count, approved_tuple_count);
430937 }
430938 case TableFilterType::CONJUNCTION_OR: {
430939 // similar to the CONJUNCTION_AND, but we need to take care of the SelectionVectors (OR all of them)
430940 auto &state = filter_state.Cast<ConjunctionOrFilterState>();
430941 idx_t count_total = 0;
430942 SelectionVector result_sel(approved_tuple_count);
430943 auto &conjunction_or = filter.Cast<ConjunctionOrFilter>();
430944 for (idx_t child_idx = 0; child_idx < conjunction_or.child_filters.size(); child_idx++) {
430945 auto &child_filter = *conjunction_or.child_filters[child_idx];
430946 SelectionVector temp_sel;
430947 temp_sel.Initialize(sel);
430948 idx_t temp_tuple_count = approved_tuple_count;
430949 idx_t temp_count = FilterSelection(temp_sel, vector, vdata, child_filter, *state.child_states[child_idx],
430950 scan_count, temp_tuple_count);
430951 // tuples passed, move them into the actual result vector
430952 for (idx_t i = 0; i < temp_count; i++) {
430953 auto new_idx = temp_sel.get_index(i);
430954 bool is_new_idx = true;
430955 for (idx_t res_idx = 0; res_idx < count_total; res_idx++) {
430956 if (result_sel.get_index(res_idx) == new_idx) {
430957 is_new_idx = false;
430958 break;
430959 }
430960 }
430961 if (is_new_idx) {
430962 result_sel.set_index(count_total++, new_idx);
430963 }
430964 }
430965 }
430966 sel.Initialize(result_sel);
430967 approved_tuple_count = count_total;
430968 return approved_tuple_count;
430969 }
430970 case TableFilterType::CONJUNCTION_AND: {
430971 auto &conjunction_and = filter.Cast<ConjunctionAndFilter>();
430972 auto &state = filter_state.Cast<ConjunctionAndFilterState>();
430973 for (idx_t child_idx = 0; child_idx < conjunction_and.child_filters.size(); child_idx++) {
430974 auto &child_filter = *conjunction_and.child_filters[child_idx];
430975 FilterSelection(sel, vector, vdata, child_filter, *state.child_states[child_idx], scan_count,
430976 approved_tuple_count);
430977 }
430978 return approved_tuple_count;
430979 }
430980 case TableFilterType::CONSTANT_COMPARISON: {
430981 auto &constant_filter = filter.Cast<ConstantFilter>();
430982 switch (vector.GetType().InternalType()) {
430983 case PhysicalType::UINT8: {
430984 auto predicate = UTinyIntValue::Get(constant_filter.constant);
430985 FilterSelectionSwitch<uint8_t>(vdata, predicate, sel, approved_tuple_count,
430986 constant_filter.comparison_type);
430987 break;
430988 }
430989 case PhysicalType::UINT16: {
430990 auto predicate = USmallIntValue::Get(constant_filter.constant);
430991 FilterSelectionSwitch<uint16_t>(vdata, predicate, sel, approved_tuple_count,
430992 constant_filter.comparison_type);
430993 break;
430994 }
430995 case PhysicalType::UINT32: {
430996 auto predicate = UIntegerValue::Get(constant_filter.constant);
430997 FilterSelectionSwitch<uint32_t>(vdata, predicate, sel, approved_tuple_count,
430998 constant_filter.comparison_type);
430999 break;
431000 }
431001 case PhysicalType::UINT64: {
431002 auto predicate = UBigIntValue::Get(constant_filter.constant);
431003 FilterSelectionSwitch<uint64_t>(vdata, predicate, sel, approved_tuple_count,
431004 constant_filter.comparison_type);
431005 break;
431006 }
431007 case PhysicalType::INT8: {
431008 auto predicate = TinyIntValue::Get(constant_filter.constant);
431009 FilterSelectionSwitch<int8_t>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431010 break;
431011 }
431012 case PhysicalType::INT16: {
431013 auto predicate = SmallIntValue::Get(constant_filter.constant);
431014 FilterSelectionSwitch<int16_t>(vdata, predicate, sel, approved_tuple_count,
431015 constant_filter.comparison_type);
431016 break;
431017 }
431018 case PhysicalType::INT32: {
431019 auto predicate = IntegerValue::Get(constant_filter.constant);
431020 FilterSelectionSwitch<int32_t>(vdata, predicate, sel, approved_tuple_count,
431021 constant_filter.comparison_type);
431022 break;
431023 }
431024 case PhysicalType::INT64: {
431025 auto predicate = BigIntValue::Get(constant_filter.constant);
431026 FilterSelectionSwitch<int64_t>(vdata, predicate, sel, approved_tuple_count,
431027 constant_filter.comparison_type);
431028 break;
431029 }
431030 case PhysicalType::INT128: {
431031 auto predicate = HugeIntValue::Get(constant_filter.constant);
431032 FilterSelectionSwitch<hugeint_t>(vdata, predicate, sel, approved_tuple_count,
431033 constant_filter.comparison_type);
431034 break;
431035 }
431036 case PhysicalType::UINT128: {
431037 auto predicate = UhugeIntValue::Get(constant_filter.constant);
431038 FilterSelectionSwitch<uhugeint_t>(vdata, predicate, sel, approved_tuple_count,
431039 constant_filter.comparison_type);
431040 break;
431041 }
431042 case PhysicalType::FLOAT: {
431043 auto predicate = FloatValue::Get(constant_filter.constant);
431044 FilterSelectionSwitch<float>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431045 break;
431046 }
431047 case PhysicalType::DOUBLE: {
431048 auto predicate = DoubleValue::Get(constant_filter.constant);
431049 FilterSelectionSwitch<double>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431050 break;
431051 }
431052 case PhysicalType::VARCHAR: {
431053 auto predicate = string_t(StringValue::Get(constant_filter.constant));
431054 FilterSelectionSwitch<string_t>(vdata, predicate, sel, approved_tuple_count,
431055 constant_filter.comparison_type);
431056 break;
431057 }
431058 case PhysicalType::BOOL: {
431059 auto predicate = BooleanValue::Get(constant_filter.constant);
431060 FilterSelectionSwitch<bool>(vdata, predicate, sel, approved_tuple_count, constant_filter.comparison_type);
431061 break;
431062 }
431063 default:
431064 throw InvalidTypeException(vector.GetType(), "Invalid type for filter pushed down to table comparison");
431065 }
431066 return approved_tuple_count;
431067 }
431068 case TableFilterType::IS_NULL: {
431069 return TemplatedNullSelection<true>(vdata, sel, approved_tuple_count);
431070 }
431071 case TableFilterType::IS_NOT_NULL: {
431072 return TemplatedNullSelection<false>(vdata, sel, approved_tuple_count);
431073 }
431074 case TableFilterType::STRUCT_EXTRACT: {
431075 auto &struct_filter = filter.Cast<StructFilter>();
431076 // Apply the filter on the child vector
431077 auto &child_vec = StructVector::GetEntries(vector)[struct_filter.child_idx];
431078 UnifiedVectorFormat child_data;
431079 child_vec->ToUnifiedFormat(scan_count, child_data);
431080 return FilterSelection(sel, *child_vec, child_data, *struct_filter.child_filter, filter_state, scan_count,
431081 approved_tuple_count);
431082 }
431083 case TableFilterType::BLOOM_FILTER: {
431084 auto &bloom_filter = filter.Cast<BFTableFilter>();
431085 auto &state = filter_state.Cast<BFTableFilterState>();
431086 return bloom_filter.Filter(vector, sel, approved_tuple_count, state);
431087 }
431088 case TableFilterType::EXPRESSION_FILTER: {
431089 auto &state = filter_state.Cast<ExpressionFilterState>();
431090 SelectionVector result_sel(approved_tuple_count);
431091 if (scan_count > STANDARD_VECTOR_SIZE) {
431092 // scan count is > vector size - split up the vector into multiple chunks
431093 idx_t offset = 0;
431094 idx_t result_offset = 0;
431095 idx_t current_sel_offset = 0;
431096 SelectionVector current_sel(approved_tuple_count);
431097 while (offset < scan_count) {
431098 idx_t chunk_count = MinValue<idx_t>(STANDARD_VECTOR_SIZE, scan_count - offset);
431099 idx_t chunk_end = offset + chunk_count;
431100 DataChunk chunk;
431101 chunk.data.emplace_back(vector, offset, chunk_end);
431102 chunk.SetCardinality(chunk_count);
431103
431104 // construct the relevant selection vector for the current chunk (offset ... offset + chunk_count)
431105 idx_t current_count = 0;
431106 for (; current_sel_offset < approved_tuple_count; current_sel_offset++) {
431107 auto sel_index = sel.get_index(current_sel_offset);
431108 if (sel_index >= chunk_end) {
431109 // exhausted the chunk
431110 break;
431111 }
431112 if (sel_index < offset) {
431113 throw InternalException("sel_index < offset in expression filter");
431114 }
431115 current_sel.set_index(current_count++, sel_index - offset);
431116 }
431117 if (current_count == 0) {
431118 // no matching tuples in this chunk
431119 offset += chunk_count;
431120 continue;
431121 }
431122 auto current_result_data = result_sel.data() + result_offset;
431123 SelectionVector current_result_sel(current_result_data);
431124 idx_t new_matches =
431125 state.executor.SelectExpression(chunk, current_result_sel, current_sel, current_count);
431126 // increment all matches by the offset
431127 for (idx_t i = 0; i < new_matches; i++) {
431128 current_result_data[i] += offset;
431129 }
431130 result_offset += new_matches;
431131 offset += chunk_count;
431132 }
431133 approved_tuple_count = result_offset;
431134 } else {
431135 // standard case: we can handle everything at once - run the expression once
431136 DataChunk chunk;
431137 chunk.data.emplace_back(vector);
431138 chunk.SetCardinality(scan_count);
431139 approved_tuple_count = state.executor.SelectExpression(chunk, result_sel, sel, approved_tuple_count);
431140 }
431141 sel.Initialize(result_sel);
431142 return approved_tuple_count;
431143 }
431144 default:
431145 throw InternalException("FIXME: unsupported type for filter selection");
431146 }
431147}
vector< Vector > data
The vectors owned by the DataChunk.
Definition duckdb.hpp:11445
void filter(InputArray image, InputArray kernel, OutputArray output)
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ INT64
Signed 64-bit little-endian integer.
Definition duckdb.hpp:2767
@ INT16
Signed 16-bit little-endian integer.
Definition duckdb.hpp:2755
@ INT32
Signed 32-bit little-endian integer.
Definition duckdb.hpp:2761
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ INT8
Signed 8-bit little-endian integer.
Definition duckdb.hpp:2749
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Skip()

void duckdb::ColumnSegment::Skip ( ColumnScanState & state)

Skip a scan forward to the row_index specified in the scan state.

430661 {
430662 function.get().skip(*this, state, state.offset_in_column - state.internal_index);
430663 state.internal_index = state.offset_in_column;
430664}

◆ SegmentSize()

idx_t duckdb::ColumnSegment::SegmentSize ( ) const
430687 {
430688 return segment_size;
430689}

◆ Resize()

void duckdb::ColumnSegment::Resize ( idx_t segment_size)

Resize the block.

430691 {
430692 D_ASSERT(new_size > segment_size);
430693 D_ASSERT(offset == 0);
430694 D_ASSERT(block && new_size <= GetBlockSize());
430695
430696 auto &buffer_manager = BufferManager::GetBufferManager(db);
430697 auto old_handle = buffer_manager.Pin(block);
430698 auto new_handle = buffer_manager.Allocate(MemoryTag::IN_MEMORY_TABLE, new_size);
430699 auto new_block = new_handle.GetBlockHandle();
430700 memcpy(new_handle.Ptr(), old_handle.Ptr(), segment_size);
430701
430702 this->block_id = new_block->BlockId();
430703 this->block = std::move(new_block);
430704 this->segment_size = new_size;
430705}
Here is the call graph for this function:

◆ GetCompressionFunction()

const CompressionFunction & duckdb::ColumnSegment::GetCompressionFunction ( )
431149 {
431150 return function.get();
431151}

◆ InitializeAppend()

void duckdb::ColumnSegment::InitializeAppend ( ColumnAppendState & state)

Initialize an append of this segment. Appends are only supported on transient segments.

430707 {
430708 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430709 if (!function.get().init_append) {
430710 throw InternalException("Attempting to init append to a segment without init_append method");
430711 }
430712 state.append_state = function.get().init_append(*this);
430713}

◆ Append()

idx_t duckdb::ColumnSegment::Append ( ColumnAppendState & state,
UnifiedVectorFormat & data,
idx_t offset,
idx_t count )

Appends a (part of) vector to the segment, returns the amount of entries successfully appended.

430715 {
430716 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430717 if (!function.get().append) {
430718 throw InternalException("Attempting to append to a segment without append method");
430719 }
430720 return function.get().append(*state.append_state, *this, stats, append_data, offset, count);
430721}

◆ FinalizeAppend()

idx_t duckdb::ColumnSegment::FinalizeAppend ( ColumnAppendState & state)

Finalize the segment for appending - no more appends can follow on this segment The segment should be compacted as much as possible Returns the number of bytes occupied within the segment.

430723 {
430724 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430725 if (!function.get().finalize_append) {
430726 throw InternalException("Attempting to call FinalizeAppend on a segment without a finalize_append method");
430727 }
430728 auto result_count = function.get().finalize_append(*this, stats);
430729 state.append_state.reset();
430730 return result_count;
430731}

◆ RevertAppend()

void duckdb::ColumnSegment::RevertAppend ( idx_t new_count)

Revert an append made to this segment.

430733 {
430734 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430735 if (function.get().revert_append) {
430736 function.get().revert_append(*this, new_count);
430737 }
430738 this->count = new_count;
430739}

◆ ConvertToPersistent()

void duckdb::ColumnSegment::ConvertToPersistent ( QueryContext context,
optional_ptr< BlockManager > block_manager,
const block_id_t block_id )

Convert a transient in-memory segment to a persistent segment backed by an on-disk block. Only used during checkpointing.

430745 {
430746 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430747 segment_type = ColumnSegmentType::PERSISTENT;
430748 block_id = block_id_p;
430749 offset = 0;
430750
430751 if (block_id != INVALID_BLOCK) {
430752 D_ASSERT(!stats.statistics.IsConstant());
430753 // Non-constant block: write the block to disk.
430754 // The block data already exists in memory, so we alter the metadata,
430755 // which ensures that the buffer points to an on-disk block.
430756 block = block_manager->ConvertToPersistent(context, block_id, std::move(block));
430757 return;
430758 }
430759
430760 // Constant block: no need to write anything to disk besides the stats (metadata).
430761 // I.e., we do not need to write an actual block.
430762 // Thus, we set the compression function to constant and reset the block buffer.
430763 D_ASSERT(stats.statistics.IsConstant());
430764 auto &config = DBConfig::GetConfig(db);
430765 function = config.GetCompressionFunction(CompressionType::COMPRESSION_CONSTANT, type.InternalType());
430766 block.reset();
430767}
Here is the call graph for this function:

◆ MarkAsPersistent()

void duckdb::ColumnSegment::MarkAsPersistent ( shared_ptr< BlockHandle > block,
uint32_t offset_in_block )

Updates pointers to refer to the given block and offset. This is only used when sharing a block among segments. This is invoked only AFTER the block is written.

430769 {
430770 D_ASSERT(segment_type == ColumnSegmentType::TRANSIENT);
430771 block_id = block_p->BlockId();
430772 SetBlock(std::move(block_p), offset_p);
430773}

◆ SetBlock()

void duckdb::ColumnSegment::SetBlock ( shared_ptr< BlockHandle > block,
uint32_t offset )
430775 {
430776 segment_type = ColumnSegmentType::PERSISTENT;
430777 offset = offset_p;
430778 block = std::move(block_p);
430779}

◆ GetDataPointer()

DataPointer duckdb::ColumnSegment::GetDataPointer ( idx_t row_start)

Gets a data pointer from a persistent column segment.

430781 {
430782 if (segment_type != ColumnSegmentType::PERSISTENT) {
430783 throw InternalException("Attempting to call ColumnSegment::GetDataPointer on a transient segment");
430784 }
430785 // set up the data pointer directly using the data from the persistent segment
430786 DataPointer pointer(stats.statistics.Copy());
430787 pointer.block_pointer.block_id = GetBlockId();
430788 pointer.block_pointer.offset = NumericCast<uint32_t>(GetBlockOffset());
430789 pointer.row_start = row_start;
430790 pointer.tuple_count = count;
430791 pointer.compression_type = function.get().type;
430792 if (function.get().serialize_state) {
430793 pointer.segment_state = function.get().serialize_state(*this);
430794 }
430795 return pointer;
430796}

◆ GetBlockId()

block_id_t duckdb::ColumnSegment::GetBlockId ( )
inline
49062 {
49063 D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT);
49064 return block_id;
49065 }

◆ GetBlockSize()

idx_t duckdb::ColumnSegment::GetBlockSize ( ) const
inline

Returns the size of the underlying block of the segment. It is size is the size available for usage on a block.

49068 {
49069 return block->GetBlockSize();
49070 }
Here is the caller graph for this function:

◆ GetBlockOffset()

idx_t duckdb::ColumnSegment::GetBlockOffset ( )
inline
49072 {
49073 D_ASSERT(segment_type == ColumnSegmentType::PERSISTENT || offset == 0);
49074 return offset;
49075 }

◆ GetSegmentState()

optional_ptr< CompressedSegmentState > duckdb::ColumnSegment::GetSegmentState ( ) const
inline
49077 {
49078 return segment_state.get();
49079 }

◆ VisitBlockIds()

void duckdb::ColumnSegment::VisitBlockIds ( BlockIdVisitor & visitor) const
430801 {
430802 if (block_id != INVALID_BLOCK) {
430803 visitor.Visit(block_id);
430804 }
430805 if (function.get().visit_block_ids) {
430806 function.get().visit_block_ids(*this, visitor);
430807 }
430808}

◆ Scan() [2/2]

void duckdb::ColumnSegment::Scan ( ColumnScanState & state,
idx_t scan_count,
Vector & result )
private
430666 {
430667 function.get().scan_vector(*this, state, scan_count, result);
430668}

◆ ScanPartial()

void duckdb::ColumnSegment::ScanPartial ( ColumnScanState & state,
idx_t scan_count,
Vector & result,
idx_t result_offset )
private
430670 {
430671 function.get().scan_partial(*this, state, scan_count, result, result_offset);
430672}

The documentation for this class was generated from the following files: