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::ChunkVectorInfo Class Reference
Inheritance diagram for duckdb::ChunkVectorInfo:
Collaboration diagram for duckdb::ChunkVectorInfo:

Public Member Functions

 ChunkVectorInfo (FixedSizeAllocator &allocator, idx_t start, transaction_t insert_id=0)
idx_t GetSelVector (ScanOptions options, optional_ptr< SelectionVector > sel_vector, idx_t max_count) const override
bool Fetch (TransactionData transaction, row_t row) override
 Returns whether or not a single row in the ChunkInfo should be used or not for the given transaction.
void CommitAppend (transaction_t commit_id, idx_t start, idx_t end) override
bool Cleanup (transaction_t lowest_transaction) const override
string ToString (idx_t max_count) const override
void Append (idx_t start, idx_t end, transaction_t commit_id)
idx_t Delete (transaction_t transaction_id, row_t rows[], idx_t count)
void CommitDelete (transaction_t commit_id, const DeleteInfo &info)
bool HasDeletes (transaction_t transaction_id=MAX_TRANSACTION_ID) const override
bool AnyDeleted () const
bool HasConstantInsertionId () const
transaction_t ConstantInsertId () const
void Write (WriteStream &writer, transaction_t transaction_id) const override
Public Member Functions inherited from duckdb::ChunkInfo
 ChunkInfo (idx_t start, ChunkInfoType type)
idx_t GetCheckpointRowCount (TransactionData transaction, idx_t max_count)
idx_t GetCommittedDeletedCount (idx_t max_count) const
template<class TARGET>
TARGET & Cast ()
template<class TARGET>
const TARGET & Cast () const

Static Public Member Functions

static unique_ptr< ChunkInfo > Read (FixedSizeAllocator &allocator, ReadStream &reader)
Static Public Member Functions inherited from duckdb::ChunkInfo
static unique_ptr< ChunkInfo > Read (FixedSizeAllocator &allocator, ReadStream &reader)

Static Public Attributes

static constexpr const ChunkInfoType TYPE = ChunkInfoType::VECTOR_INFO

Private Member Functions

template<class INSERT_OP, class DELETE_OP>
idx_t TemplatedGetSelVector (transaction_t start_time, transaction_t transaction_id, optional_ptr< SelectionVector > sel_vector, idx_t max_count) const
IndexPointer GetInsertedPointer () const
IndexPointer GetDeletedPointer () const
IndexPointer GetInitializedInsertedPointer ()
IndexPointer GetInitializedDeletedPointer ()

Private Attributes

FixedSizeAllocator & allocator
IndexPointer inserted_data
 The transaction ids of the transactions that inserted the tuples (if any).
transaction_t constant_insert_id
 The constant insert id (if there is only one).
IndexPointer deleted_data
 The transaction ids of the transactions that deleted the tuples (if any).

Additional Inherited Members

Public Attributes inherited from duckdb::ChunkInfo
idx_t start
 The row index of the first row.
ChunkInfoType type
 The ChunkInfo type.

Constructor & Destructor Documentation

◆ ChunkVectorInfo()

duckdb::ChunkVectorInfo::ChunkVectorInfo ( FixedSizeAllocator & allocator,
idx_t start,
transaction_t insert_id = 0 )
explicit
427710 : ChunkInfo(start, ChunkInfoType::VECTOR_INFO), allocator(allocator_p), constant_insert_id(insert_id_p) {
427711}
idx_t start
The row index of the first row.
Definition duckdb.hpp:22704
transaction_t constant_insert_id
The constant insert id (if there is only one).
Definition duckdb.hpp:22819

◆ ~ChunkVectorInfo()

duckdb::ChunkVectorInfo::~ChunkVectorInfo ( )
override
427713 {
427714 if (AnyDeleted()) {
427715 allocator.Free(deleted_data);
427716 }
427717 if (!HasConstantInsertionId()) {
427718 allocator.Free(inserted_data);
427719 }
427720}
IndexPointer inserted_data
The transaction ids of the transactions that inserted the tuples (if any).
Definition duckdb.hpp:22817
IndexPointer deleted_data
The transaction ids of the transactions that deleted the tuples (if any).
Definition duckdb.hpp:22822

Member Function Documentation

◆ GetSelVector()

idx_t duckdb::ChunkVectorInfo::GetSelVector ( ScanOptions options,
optional_ptr< SelectionVector > sel_vector,
idx_t max_count ) const
overridevirtual

Gets up to max_count entries from the chunk info. If the ret is 0>ret>max_count, the selection vector is filled with the tuples

Implements duckdb::ChunkInfo.

427793 {
427794 auto &transaction = options.transaction;
427795 if (options.insert_type == InsertedScanType::STANDARD) {
427796 if (options.delete_type == DeletedScanType::STANDARD) {
427797 return TemplatedGetSelVector<StandardInsertOperator, StandardDeleteOperator>(
427798 transaction.start_time, transaction.transaction_id, sel_vector, max_count);
427799 }
427800 if (options.delete_type == DeletedScanType::INCLUDE_ALL_DELETED) {
427801 return TemplatedGetSelVector<StandardInsertOperator, IncludeAllDeletedOperator>(
427802 transaction.start_time, transaction.transaction_id, sel_vector, max_count);
427803 }
427804 if (options.delete_type == DeletedScanType::OMIT_COMMITTED_DELETES) {
427805 return TemplatedGetSelVector<StandardInsertOperator, CommittedDeleteOperator>(
427806 transaction.start_time, transaction.transaction_id, sel_vector, max_count);
427807 }
427808 }
427809 if (options.insert_type == InsertedScanType::ALL_ROWS) {
427810 if (options.delete_type == DeletedScanType::STANDARD) {
427811 return TemplatedGetSelVector<IncludeAllInsertedOperator, StandardDeleteOperator>(
427812 transaction.start_time, transaction.transaction_id, sel_vector, max_count);
427813 }
427814 if (options.delete_type == DeletedScanType::OMIT_COMMITTED_DELETES) {
427815 return TemplatedGetSelVector<IncludeAllInsertedOperator, CommittedDeleteOperator>(
427816 transaction.start_time, transaction.transaction_id, sel_vector, max_count);
427817 }
427818 }
427819 throw InternalException("Unsupported combination of insert / delete types in ChunkVectorInfo::GetSelVector");
427820}
@ INCLUDE_ALL_DELETED
include all rows, including all deleted rows
Definition duckdb.hpp:22650
@ OMIT_COMMITTED_DELETES
omit only deleted rows that have been committed and have a commit ts lower than the transaction start
Definition duckdb.hpp:22652
@ STANDARD
omit any rows that are deleted
Definition duckdb.hpp:22648

◆ Fetch()

bool duckdb::ChunkVectorInfo::Fetch ( TransactionData transaction,
row_t row )
overridevirtual

Returns whether or not a single row in the ChunkInfo should be used or not for the given transaction.

Implements duckdb::ChunkInfo.

427822 {
427823 transaction_t fetch_insert_id;
427824 transaction_t fetch_deleted_id;
427825 if (HasConstantInsertionId()) {
427826 fetch_insert_id = ConstantInsertId();
427827 } else {
427828 auto insert_segment = allocator.GetHandle(GetInsertedPointer());
427829 auto inserted = insert_segment.GetPtr<transaction_t>();
427830 fetch_insert_id = inserted[row];
427831 }
427832 if (!AnyDeleted()) {
427833 fetch_deleted_id = NOT_DELETED_ID;
427834 } else {
427835 auto delete_segment = allocator.GetHandle(GetDeletedPointer());
427836 auto deleted = delete_segment.GetPtr<transaction_t>();
427837 fetch_deleted_id = deleted[row];
427838 }
427839
427840 return UseVersion(transaction, fetch_insert_id) && !UseVersion(transaction, fetch_deleted_id);
427841}
idx_t transaction_t
Type used for transaction timestamps.
Definition duckdb.hpp:253

◆ CommitAppend()

void duckdb::ChunkVectorInfo::CommitAppend ( transaction_t commit_id,
idx_t start,
idx_t end )
overridevirtual

Implements duckdb::ChunkInfo.

427945 {
427946 if (HasConstantInsertionId()) {
427947 constant_insert_id = commit_id;
427948 return;
427949 }
427950 auto segment = allocator.GetHandle(GetInsertedPointer());
427951 auto inserted = segment.GetPtr<transaction_t>();
427952
427953 for (idx_t i = start; i < end; i++) {
427954 inserted[i] = commit_id;
427955 }
427956}
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237

◆ Cleanup()

bool duckdb::ChunkVectorInfo::Cleanup ( transaction_t lowest_transaction) const
overridevirtual

Reimplemented from duckdb::ChunkInfo.

427958 {
427959 if (AnyDeleted()) {
427960 // if any rows are deleted we can't clean-up
427961 return false;
427962 }
427963 // check if the insertion markers have to be used by all transactions going forward
427964 if (!HasConstantInsertionId()) {
427965 auto segment = allocator.GetHandle(GetInsertedPointer());
427966 auto inserted = segment.GetPtr<transaction_t>();
427967
427968 for (idx_t idx = 1; idx < STANDARD_VECTOR_SIZE; idx++) {
427969 if (inserted[idx] > lowest_transaction) {
427970 // transaction was inserted after the lowest transaction start
427971 // we still need to use an older version - cannot compress
427972 return false;
427973 }
427974 }
427975 } else if (ConstantInsertId() > lowest_transaction) {
427976 // transaction was inserted after the lowest transaction start
427977 // we still need to use an older version - cannot compress
427978 return false;
427979 }
427980 return true;
427981}

◆ ToString()

string duckdb::ChunkVectorInfo::ToString ( idx_t max_count) const
overridevirtual

Implements duckdb::ChunkInfo.

428009 {
428010 string result;
428011 result += "Vector [Count: " + to_string(max_count);
428012 result += ", ";
428013 if (HasConstantInsertionId()) {
428014 result += "Insert Id: " + to_string(constant_insert_id);
428015 } else {
428016 result += "Insert Ids: [";
428017 auto segment = allocator.GetHandle(GetInsertedPointer());
428018 auto inserted = segment.GetPtr<transaction_t>();
428019
428020 for (idx_t idx = 0; idx < max_count; idx++) {
428021 if (idx > 0) {
428022 result += ", ";
428023 }
428024 result += to_string(inserted[idx]);
428025 }
428026 result += "]";
428027 }
428028 result += "]";
428029 return result;
428030}
std::string to_string(const T &value)
Definition duckdb.cpp:19425

◆ Append()

void duckdb::ChunkVectorInfo::Append ( idx_t start,
idx_t end,
transaction_t commit_id )
427927 {
427928 if (start == 0) {
427929 // first insert to this vector - just assign the commit id
427930 constant_insert_id = commit_id;
427931 return;
427932 }
427933 if (HasConstantInsertionId() && ConstantInsertId() == commit_id) {
427934 // we are inserting again, but we have the same id as before - still the same insert id
427935 return;
427936 }
427937
427938 auto segment = allocator.GetHandle(GetInitializedInsertedPointer());
427939 auto inserted = segment.GetPtr<transaction_t>();
427940 for (idx_t i = start; i < end; i++) {
427941 inserted[i] = commit_id;
427942 }
427943}

◆ Delete()

idx_t duckdb::ChunkVectorInfo::Delete ( transaction_t transaction_id,
row_t rows[],
idx_t count )

Performs a delete in the ChunkVectorInfo - returns how many tuples were actually deleted The number of rows that were actually deleted might be lower than the input count In case we delete rows that were already deleted Note that "rows" is written to to reflect the row ids that were actually deleted i.e. after calling this function, rows will hold [0..actual_delete_count] row ids of the actually deleted tuples

427885 {
427886 auto segment = allocator.GetHandle(GetInitializedDeletedPointer());
427887 auto deleted = segment.GetPtr<transaction_t>();
427888
427889 idx_t deleted_tuples = 0;
427890 for (idx_t i = 0; i < count; i++) {
427891 if (deleted[rows[i]] == transaction_id) {
427892 continue;
427893 }
427894 // first check the chunk for conflicts
427895 if (deleted[rows[i]] != NOT_DELETED_ID) {
427896 // tuple was already deleted by another transaction - conflict
427897 // unset any deleted tuples we set in this loop
427898 for (idx_t k = 0; k < i; k++) {
427899 deleted[rows[k]] = NOT_DELETED_ID;
427900 }
427901 throw TransactionException("Conflict on tuple deletion!");
427902 }
427903 // after verifying that there are no conflicts we mark the tuple as deleted
427904 deleted[rows[i]] = transaction_id;
427905 rows[deleted_tuples] = rows[i];
427906 deleted_tuples++;
427907 }
427908 return deleted_tuples;
427909}
int rows

◆ CommitDelete()

void duckdb::ChunkVectorInfo::CommitDelete ( transaction_t commit_id,
const DeleteInfo & info )
427911 {
427912 auto segment = allocator.GetHandle(GetDeletedPointer());
427913 auto deleted = segment.GetPtr<transaction_t>();
427914
427915 if (info.is_consecutive) {
427916 for (idx_t i = 0; i < info.count; i++) {
427917 deleted[i] = commit_id;
427918 }
427919 } else {
427920 auto rows = info.GetRows();
427921 for (idx_t i = 0; i < info.count; i++) {
427922 deleted[rows[i]] = commit_id;
427923 }
427924 }
427925}

◆ HasDeletes()

bool duckdb::ChunkVectorInfo::HasDeletes ( transaction_t transaction_id = MAX_TRANSACTION_ID) const
overridevirtual

Implements duckdb::ChunkInfo.

427983 {
427984 if (!AnyDeleted()) {
427985 return false;
427986 }
427987 if (transaction_id == MAX_TRANSACTION_ID) {
427988 return true;
427989 }
427990 auto segment = allocator.GetHandle(deleted_data);
427991 auto deleted = segment.GetPtr<transaction_t>();
427992
427993 for (idx_t i = 0; i < STANDARD_VECTOR_SIZE; i++) {
427994 if (deleted[i] <= transaction_id) {
427995 return true;
427996 }
427997 }
427998 return false;
427999}

◆ AnyDeleted()

bool duckdb::ChunkVectorInfo::AnyDeleted ( ) const
428001 {
428002 return deleted_data.HasMetadata();
428003}

◆ HasConstantInsertionId()

bool duckdb::ChunkVectorInfo::HasConstantInsertionId ( ) const
428005 {
428006 return !inserted_data.HasMetadata();
428007}

◆ ConstantInsertId()

transaction_t duckdb::ChunkVectorInfo::ConstantInsertId ( ) const
428032 {
428033 if (!HasConstantInsertionId()) {
428034 throw InternalException("ConstantInsertId() called but vector info does not have a constant insertion id");
428035 }
428036 return constant_insert_id;
428037}

◆ Write()

void duckdb::ChunkVectorInfo::Write ( WriteStream & writer,
transaction_t transaction_id ) const
overridevirtual

Reimplemented from duckdb::ChunkInfo.

428039 {
428040 SelectionVector sel(STANDARD_VECTOR_SIZE);
428041 transaction_t start_time = checkpoint_id == MAX_TRANSACTION_ID ? TRANSACTION_ID_START - 1 : checkpoint_id + 1;
428042 transaction_t transaction_id = DConstants::INVALID_INDEX;
428043 idx_t count = GetSelVector(TransactionData(transaction_id, start_time), sel, STANDARD_VECTOR_SIZE);
428044 if (count == STANDARD_VECTOR_SIZE) {
428045 // nothing is deleted: skip writing anything
428046 writer.Write<ChunkInfoType>(ChunkInfoType::EMPTY_INFO);
428047 return;
428048 }
428049 if (count == 0) {
428050 // everything is deleted: write a constant vector
428051 writer.Write<ChunkInfoType>(ChunkInfoType::CONSTANT_INFO);
428052 writer.Write<idx_t>(start);
428053 return;
428054 }
428055 // write a boolean vector
428056 ChunkInfo::Write(writer, checkpoint_id);
428057 writer.Write<idx_t>(start);
428058 ValidityMask mask(STANDARD_VECTOR_SIZE);
428059 mask.Initialize(STANDARD_VECTOR_SIZE);
428060 for (idx_t i = 0; i < count; i++) {
428061 mask.SetInvalid(sel.get_index(i));
428062 }
428063 mask.Write(writer, STANDARD_VECTOR_SIZE);
428064}
idx_t GetSelVector(ScanOptions options, optional_ptr< SelectionVector > sel_vector, idx_t max_count) const override
Definition duckdb.cpp:427792
GMat mask(const GMat &src, const GMat &mask)
static constexpr const idx_t INVALID_INDEX
The value used to signify an invalid index entry.
Definition duckdb.hpp:1117

◆ Read()

unique_ptr< ChunkInfo > duckdb::ChunkVectorInfo::Read ( FixedSizeAllocator & allocator,
ReadStream & reader )
static
428066 {
428067 auto start = reader.Read<idx_t>();
428068 auto result = make_uniq<ChunkVectorInfo>(allocator, start);
428069 ValidityMask mask;
428070 mask.Read(reader, STANDARD_VECTOR_SIZE);
428071
428072 auto segment = allocator.GetHandle(result->GetInitializedDeletedPointer());
428073 auto deleted = segment.GetPtr<transaction_t>();
428074 for (idx_t i = 0; i < STANDARD_VECTOR_SIZE; i++) {
428075 if (mask.RowIsValid(i)) {
428076 deleted[i] = 0;
428077 }
428078 }
428079 return std::move(result);
428080}

◆ TemplatedGetSelVector()

template<class INSERT_OP, class DELETE_OP>
idx_t duckdb::ChunkVectorInfo::TemplatedGetSelVector ( transaction_t start_time,
transaction_t transaction_id,
optional_ptr< SelectionVector > sel_vector,
idx_t max_count ) const
private
427724 {
427725 if (HasConstantInsertionId()) {
427726 if (!AnyDeleted()) {
427727 // all tuples have the same inserted id: and no tuples were deleted
427728 if (INSERT_OP::UseInsertedVersion(start_time, transaction_id, ConstantInsertId())) {
427729 return max_count;
427730 } else {
427731 return 0;
427732 }
427733 }
427734 if (!INSERT_OP::UseInsertedVersion(start_time, transaction_id, ConstantInsertId())) {
427735 return 0;
427736 }
427737 // have to check deleted flag
427738 idx_t count = 0;
427739 auto segment = allocator.GetHandle(GetDeletedPointer());
427740 auto deleted = segment.GetPtr<transaction_t>();
427741 for (idx_t i = 0; i < max_count; i++) {
427742 if (DELETE_OP::IsDeleted(start_time, transaction_id, deleted[i])) {
427743 continue;
427744 }
427745 if (sel_vector) {
427746 sel_vector->set_index(count, i);
427747 }
427748 count++;
427749 }
427750 return count;
427751 }
427752 if (!AnyDeleted()) {
427753 // have to check inserted flag
427754 auto insert_segment = allocator.GetHandle(GetInsertedPointer());
427755 auto inserted = insert_segment.GetPtr<transaction_t>();
427756
427757 idx_t count = 0;
427758 for (idx_t i = 0; i < max_count; i++) {
427759 if (!INSERT_OP::UseInsertedVersion(start_time, transaction_id, inserted[i])) {
427760 continue;
427761 }
427762 if (sel_vector) {
427763 sel_vector->set_index(count, i);
427764 }
427765 count++;
427766 }
427767 return count;
427768 }
427769
427770 idx_t count = 0;
427771 // have to check both flags
427772 auto insert_segment = allocator.GetHandle(GetInsertedPointer());
427773 auto inserted = insert_segment.GetPtr<transaction_t>();
427774
427775 auto delete_segment = allocator.GetHandle(GetDeletedPointer());
427776 auto deleted = delete_segment.GetPtr<transaction_t>();
427777 for (idx_t i = 0; i < max_count; i++) {
427778 if (!INSERT_OP::UseInsertedVersion(start_time, transaction_id, inserted[i])) {
427779 continue;
427780 }
427781 if (DELETE_OP::IsDeleted(start_time, transaction_id, deleted[i])) {
427782 continue;
427783 }
427784 if (sel_vector) {
427785 sel_vector->set_index(count, i);
427786 }
427787 count++;
427788 }
427789 return count;
427790}

◆ GetInsertedPointer()

IndexPointer duckdb::ChunkVectorInfo::GetInsertedPointer ( ) const
private
427843 {
427844 if (HasConstantInsertionId()) {
427845 throw InternalException("ChunkVectorInfo: insert id requested but insertions were not initialized");
427846 }
427847 return inserted_data;
427848}

◆ GetDeletedPointer()

IndexPointer duckdb::ChunkVectorInfo::GetDeletedPointer ( ) const
private
427850 {
427851 if (!AnyDeleted()) {
427852 throw InternalException("ChunkVectorInfo: deleted id requested but deletions were not initialized");
427853 }
427854 return deleted_data;
427855}

◆ GetInitializedInsertedPointer()

IndexPointer duckdb::ChunkVectorInfo::GetInitializedInsertedPointer ( )
private
427857 {
427858 if (HasConstantInsertionId()) {
427859 transaction_t constant_id = ConstantInsertId();
427860
427861 inserted_data = allocator.New();
427862 inserted_data.SetMetadata(1);
427863 auto segment = allocator.GetHandle(inserted_data);
427864 auto inserted = segment.GetPtr<transaction_t>();
427865 for (idx_t i = 0; i < STANDARD_VECTOR_SIZE; i++) {
427866 inserted[i] = constant_id;
427867 }
427868 }
427869 return inserted_data;
427870}

◆ GetInitializedDeletedPointer()

IndexPointer duckdb::ChunkVectorInfo::GetInitializedDeletedPointer ( )
private
427872 {
427873 if (!AnyDeleted()) {
427874 deleted_data = allocator.New();
427875 deleted_data.SetMetadata(1);
427876 auto segment = allocator.GetHandle(deleted_data);
427877 auto deleted = segment.GetPtr<transaction_t>();
427878 for (idx_t i = 0; i < STANDARD_VECTOR_SIZE; i++) {
427879 deleted[i] = NOT_DELETED_ID;
427880 }
427881 }
427882 return deleted_data;
427883}

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