Kùzu C++ API
Loading...
Searching...
No Matches
version_info.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4
5#include "constants.h"
6#include "copy_constructors.h"
7#include "sel_vector.h"
8#include "types.h"
9
10namespace kuzu {
11namespace transaction {
12class Transaction;
13} // namespace transaction
14
15namespace storage {
16
19 // TODO(Guodong): ALWAYS_INSERTED is not added for now, but it may be useful as an optimization
20 // to mark the vector data after checkpoint is all deleted.
21 enum class DeletionStatus : uint8_t { NO_DELETED, CHECK_VERSION };
22
23 // TODO: Keep an additional same insertion/deletion field as an optimization to avoid the need
24 // of `array` if all are inserted/deleted in the same transaction.
25 // Also, avoid allocate `array` when status are NO_INSERTED and NO_DELETED.
26 // We can even consider separating the insertion and deletion into two separate Vectors.
27 std::array<common::transaction_t, common::DEFAULT_VECTOR_CAPACITY> insertedVersions;
28 std::array<common::transaction_t, common::DEFAULT_VECTOR_CAPACITY> deletedVersions;
31
39
45 common::row_idx_t numRows);
46 bool delete_(common::transaction_t transactionID, common::row_idx_t rowIdx);
47
50 common::sel_t startOutputPos) const;
51
53 void rollbackDeletions(common::row_idx_t startRowInVector, common::row_idx_t numRows);
54
55 void serialize(common::Serializer& serializer) const;
56 static std::unique_ptr<VectorVersionInfo> deSerialize(common::Deserializer& deSer);
57
59
60 // Given startTS and transactionID, if the row is deleted to the transaction, return true.
62 common::row_idx_t rowIdx) const;
63 // Given startTS and transactionID, if the row is readable to the transaction, return true.
65 common::row_idx_t rowIdx) const;
66
68 common::transaction_t transactionID, common::row_idx_t startRow,
69 common::length_t numRows) const;
70
71 // Return true if this vectorInfo needs to be kept after finalize.
73};
74
76public:
78
80 common::row_idx_t startRow, common::row_idx_t numRows);
81 bool delete_(const transaction::Transaction* transaction, common::row_idx_t rowIdx);
82
84 common::SelectionVector& selVector, common::row_idx_t startRow,
85 common::row_idx_t numRows) const;
86
88
89 bool hasDeletions() const;
91 common::row_idx_t startRow, common::length_t numRows) const;
92 bool hasInsertions() const;
93 bool isDeleted(const transaction::Transaction* transaction, common::row_idx_t rowInChunk) const;
94 bool isInserted(const transaction::Transaction* transaction,
95 common::row_idx_t rowInChunk) const;
96
98
99 // Return nullptr when vectorIdx is out of range or when the vector is not created.
101 common::idx_t getNumVectors() const { return vectorsInfo.size(); }
103
105
106 void serialize(common::Serializer& serializer) const;
107 static std::unique_ptr<VersionInfo> deserialize(common::Deserializer& deSer);
108
109private:
110 std::vector<std::unique_ptr<VectorVersionInfo>> vectorsInfo;
111};
112
113} // namespace storage
114} // namespace kuzu
Definition deserializer.h:15
Definition sel_vector.h:12
Definition serializer.h:15
Definition version_info.h:75
bool isDeleted(const transaction::Transaction *transaction, common::row_idx_t rowInChunk) const
common::row_idx_t append(const transaction::Transaction *transaction, common::row_idx_t startRow, common::row_idx_t numRows)
void clearVectorInfo(common::idx_t vectorIdx)
bool delete_(const transaction::Transaction *transaction, common::row_idx_t rowIdx)
VectorVersionInfo & getOrCreateVersionInfo(common::idx_t vectorIdx)
common::row_idx_t getNumDeletions(const transaction::Transaction *transaction) const
common::row_idx_t getNumDeletions(const transaction::Transaction *transaction, common::row_idx_t startRow, common::length_t numRows) const
bool isInserted(const transaction::Transaction *transaction, common::row_idx_t rowInChunk) const
VectorVersionInfo * getVectorVersionInfo(common::idx_t vectorIdx) const
common::idx_t getNumVectors() const
Definition version_info.h:101
void getSelVectorToScan(common::transaction_t startTS, common::transaction_t transactionID, common::SelectionVector &selVector, common::row_idx_t startRow, common::row_idx_t numRows) const
void serialize(common::Serializer &serializer) const
static std::unique_ptr< VersionInfo > deserialize(common::Deserializer &deSer)
VersionInfo()
Definition version_info.h:77
Definition transaction.h:28
uint64_t length_t
Definition types.h:53
uint32_t idx_t
Definition types.h:39
constexpr transaction_t INVALID_TRANSACTION
Definition types.h:58
uint64_t transaction_t
Definition types.h:57
uint64_t sel_t
Definition types.h:24
uint64_t row_idx_t
Definition types.h:46
Definition alter_type.h:5
Definition version_info.h:17
VectorVersionInfo()
Definition version_info.h:32
void getSelVectorForScan(common::transaction_t startTS, common::transaction_t transactionID, common::SelectionVector &selVector, common::row_idx_t startRow, common::row_idx_t numRows, common::sel_t startOutputPos) const
std::array< common::transaction_t, common::DEFAULT_VECTOR_CAPACITY > deletedVersions
Definition version_info.h:28
static std::unique_ptr< VectorVersionInfo > deSerialize(common::Deserializer &deSer)
DELETE_COPY_DEFAULT_MOVE(VectorVersionInfo)
DeletionStatus
Definition version_info.h:21
InsertionStatus
Definition version_info.h:18
bool anyVersions() const
Definition version_info.h:40
std::array< common::transaction_t, common::DEFAULT_VECTOR_CAPACITY > insertedVersions
Definition version_info.h:27
common::row_idx_t append(common::transaction_t transactionID, common::row_idx_t startRow, common::row_idx_t numRows)
bool isDeleted(common::transaction_t startTS, common::transaction_t transactionID, common::row_idx_t rowIdx) const
common::row_idx_t getNumDeletions(common::transaction_t startTS, common::transaction_t transactionID, common::row_idx_t startRow, common::length_t numRows) const
void serialize(common::Serializer &serializer) const
bool delete_(common::transaction_t transactionID, common::row_idx_t rowIdx)
void rollbackInsertions(common::row_idx_t startRowInVector, common::row_idx_t numRows)
InsertionStatus insertionStatus
Definition version_info.h:29
DeletionStatus deletionStatus
Definition version_info.h:30
void rollbackDeletions(common::row_idx_t startRowInVector, common::row_idx_t numRows)
common::row_idx_t numCommittedDeletions(const transaction::Transaction *transaction) const
bool isInserted(common::transaction_t startTS, common::transaction_t transactionID, common::row_idx_t rowIdx) const