@@ -67,25 +67,32 @@ class ArtPrimaryKeyIndex final : public Index {
6767 const common::ValueVector& nodeIDVector,
6868 const std::vector<common::ValueVector*>& indexVectors,
6969 Index::InsertState& insertState) override ;
70+ std::unique_ptr<UpdateState> initUpdateState (main::ClientContext* context,
71+ common::column_id_t columnID, visible_func isVisible) override ;
72+ void update (transaction::Transaction* transaction, const common::ValueVector& nodeIDVector,
73+ common::ValueVector& propertyVector, UpdateState& updateState) override ;
7074
7175 std::unique_ptr<DeleteState> initDeleteState (const transaction::Transaction*, MemoryManager*,
7276 visible_func) override {
7377 return std::make_unique<DeleteState>();
7478 }
75- void delete_ (transaction::Transaction*, const common::ValueVector&, DeleteState&) override {
76- // Visibility rules filter deleted rows. Physical removal is used only for rollback cleanup.
77- }
79+ void delete_ (transaction::Transaction*, const common::ValueVector& nodeIDVector,
80+ DeleteState&) override ;
7881
7982 bool lookupPrimaryKey (const transaction::Transaction* transaction,
8083 common::ValueVector* keyVector, uint64_t vectorPos, common::offset_t & result,
8184 visible_func isVisible) override ;
85+ bool lookupAll (const transaction::Transaction* transaction, common::ValueVector* keyVector,
86+ uint64_t vectorPos, std::vector<common::offset_t >& results,
87+ visible_func isVisible) override ;
8288 bool scanPrimaryKeyRange (common::ValueVector* lowerBoundVector, uint64_t lowerBoundPos,
8389 bool lowerInclusive, common::ValueVector* upperBoundVector, uint64_t upperBoundPos,
8490 bool upperInclusive, common::idx_t maxResults, std::vector<common::offset_t >& results,
8591 visible_func isVisible) override ;
8692 void discardPrimaryKey (common::ValueVector* keyVector) override ;
8793
8894 void checkpoint (main::ClientContext*, PageAllocator&) override ;
95+ void serialize (common::Serializer& ser) const override ;
8996
9097 static LBUG_API std::unique_ptr<Index> load (main::ClientContext* context,
9198 StorageManager* storageManager, IndexInfo indexInfo, std::span<uint8_t > storageInfoBuffer);
@@ -114,19 +121,26 @@ class ArtPrimaryKeyIndex final : public Index {
114121 };
115122
116123 std::optional<common::offset_t > offset;
124+ std::unique_ptr<std::vector<common::offset_t >> overflowOffsets;
125+ std::vector<uint8_t > prefix;
117126 Kind kind = Kind::NODE4 ;
118127 uint16_t count = 0 ;
119- union {
120- SmallChildren small;
121- Node48Children node48;
122- Node256Children node256;
123- };
128+ SmallChildren small;
129+ std::unique_ptr<Node48Children> node48;
130+ std::unique_ptr<Node256Children> node256;
124131
125132 Node ();
126133 Node* getChild (uint8_t byte) const ;
127134 Node* getOrInsertChild (ArtPrimaryKeyIndex& index, uint8_t byte);
135+ void insertChild (ArtPrimaryKeyIndex& index, uint8_t byte, Node* child);
128136 void removeChild (uint8_t byte);
129- bool empty () const { return !offset.has_value () && count == 0 ; }
137+ bool hasOffsets () const {
138+ return offset.has_value () || (overflowOffsets && !overflowOffsets->empty ());
139+ }
140+ bool empty () const {
141+ return !offset.has_value () && (!overflowOffsets || overflowOffsets->empty ()) &&
142+ count == 0 ;
143+ }
130144 };
131145
132146 static constexpr uint64_t NODE_BLOCK_CAPACITY = 16 * 1024 ;
@@ -144,19 +158,31 @@ class ArtPrimaryKeyIndex final : public Index {
144158 };
145159
146160 bool insertInternal (const ArtKey& key, common::offset_t offset, visible_func isVisible);
161+ void insertSecondaryInternal (const ArtKey& key, common::offset_t offset);
162+ Node* findOrCreateLeaf (const std::vector<uint8_t >& key);
147163 bool lookup (const ArtKey& key, common::offset_t & result, visible_func isVisible) const ;
164+ const Node* findLeaf (const ArtKey& key) const ;
165+ void appendVisibleOffsets (const Node& node, std::vector<common::offset_t >& results,
166+ visible_func isVisible) const ;
148167 bool eraseInternal (Node& node, const std::vector<uint8_t >& key, uint64_t depth);
149168 void erase (const ArtKey& key);
169+ static void eraseOffsetFromLeaf (Node& node, common::offset_t offset);
170+ static void resetNodePayload (Node& node);
171+ bool eraseOffsetInternal (Node& node, common::offset_t offset);
150172 Node* allocateNode ();
151173 void recordKindChange (Node& node, Node::Kind newKind);
152174 void collectRange (const Node& node, std::vector<uint8_t >& key, const ArtKey* lowerBound,
153175 bool lowerInclusive, const ArtKey* upperBound, bool upperInclusive,
154176 common::idx_t maxResults, std::vector<common::offset_t >& results,
155177 visible_func isVisible) const ;
156178 void clear ();
179+ uint64_t calculateSerializedTreeSize (const Node& node) const ;
180+ void serializeTree (const Node& node, common::Serializer& serializer) const ;
181+ void loadTree (common::BufferReader& reader, Node& node);
157182 void collectEntries (const Node& node, std::vector<uint8_t >& key,
158183 std::vector<std::pair<std::vector<uint8_t >, common::offset_t >>& entries) const ;
159184 void loadEntries (const ArtPrimaryKeyIndexStorageInfo& storageInfo);
185+ void loadEntries (common::BufferReader& reader);
160186
161187private:
162188 Node root;
0 commit comments