Skip to content

Commit 1095d6c

Browse files
committed
cspann: pass tree key to delete vector fixup
Previously, the delete vector fixup did not take a tree key parameter, which meant it always searched the default tree for the vector to delete. This commit fixes that by passing the tree key to the fixup. Epic: CRDB-42943 Release note: None
1 parent 7552695 commit 1095d6c

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

pkg/sql/vecindex/cspann/fixup_processor.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,10 @@ func (fp *FixupProcessor) DelayInsertOrDelete(ctx context.Context) error {
287287

288288
// AddDeleteVector enqueues a vector deletion fixup for later processing.
289289
func (fp *FixupProcessor) AddDeleteVector(
290-
ctx context.Context, partitionKey PartitionKey, vectorKey KeyBytes,
290+
ctx context.Context, treeKey TreeKey, partitionKey PartitionKey, vectorKey KeyBytes,
291291
) {
292292
fp.addFixup(ctx, fixup{
293+
TreeKey: treeKey,
293294
Type: vectorDeleteFixup,
294295
PartitionKey: partitionKey,
295296
VectorKey: vectorKey,

pkg/sql/vecindex/cspann/index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ func (vi *Index) getFullVectors(
921921
// the case of a dangling partition key.
922922
if candidates[i].ChildKey.KeyBytes != nil {
923923
// Vector was deleted, so add fixup to delete it.
924-
vi.fixups.AddDeleteVector(
925-
ctx, candidates[i].ParentPartitionKey, candidates[i].ChildKey.KeyBytes)
924+
vi.fixups.AddDeleteVector(ctx, idxCtx.treeKey,
925+
candidates[i].ParentPartitionKey, candidates[i].ChildKey.KeyBytes)
926926
}
927927

928928
// Move the last candidate to the current position and reduce size

pkg/sql/vecindex/cspann/testdata/tree-key.ddt

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,70 @@ format-tree
106106
├───• vec1 (1, 2)
107107
├───• vec2 (7, 4)
108108
└───• vec3 (4, 3)
109+
110+
# ----------------------------------------------------------------------
111+
# Test delete vector fixup in non-default tree.
112+
# ----------------------------------------------------------------------
113+
new-index min-partition-size=2 max-partition-size=4 beam-size=2 tree=1
114+
vec1: (1, 2)
115+
vec2: (7, 4)
116+
vec3: (4, 3)
117+
vec4: (8, 11)
118+
vec5: (14, 1)
119+
vec6: (0, 0)
120+
----
121+
• 1 (0, 0)
122+
123+
├───• 2 (1.6667, 1.6667)
124+
│ │
125+
│ ├───• vec1 (1, 2)
126+
│ ├───• vec6 (0, 0)
127+
│ └───• vec3 (4, 3)
128+
129+
└───• 3 (9.6667, 5.3333)
130+
131+
├───• vec4 (8, 11)
132+
├───• vec5 (14, 1)
133+
└───• vec2 (7, 4)
134+
135+
# Delete vector from primary index, but not from secondary index.
136+
delete not-found tree=1
137+
vec1
138+
----
139+
• 1 (0, 0)
140+
141+
├───• 2 (1.6667, 1.6667)
142+
│ │
143+
│ ├───• vec1 (MISSING)
144+
│ ├───• vec6 (0, 0)
145+
│ └───• vec3 (4, 3)
146+
147+
└───• 3 (9.6667, 5.3333)
148+
149+
├───• vec4 (8, 11)
150+
├───• vec5 (14, 1)
151+
└───• vec2 (7, 4)
152+
153+
# Ensure deleted vector is not returned by search. This should enqueue a fixup
154+
# that removes the vector from the index.
155+
search max-results=1 tree=1
156+
(1, 2)
157+
----
158+
vec6: 5 (centroid=2.36)
159+
6 leaf vectors, 8 vectors, 2 full vectors, 3 partitions
160+
161+
# Vector should now be gone from the index.
162+
format-tree tree=1
163+
----
164+
• 1 (0, 0)
165+
166+
├───• 2 (1.6667, 1.6667)
167+
│ │
168+
│ ├───• vec3 (4, 3)
169+
│ └───• vec6 (0, 0)
170+
171+
└───• 3 (9.6667, 5.3333)
172+
173+
├───• vec4 (8, 11)
174+
├───• vec5 (14, 1)
175+
└───• vec2 (7, 4)

0 commit comments

Comments
 (0)