Skip to content

Commit 51bb1de

Browse files
committed
cspann: do not retry search when deleting vector
Previously, if the search for a vector to delete fails, the index would fetch a second batch of partitions to search. However, if a vector cannot be found in the first batch, it's very unlikely to be found at all, so better to abort at that point. This is important for the case when a split or merge is in progress and the vector is found in a draining partition and skipped. It's a waste to keep searching in that case. Epic: CRDB-42943 Release note: None
1 parent dfd37a7 commit 51bb1de

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

pkg/sql/vecindex/cspann/index.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ func NewIndex(
270270
vi.options.MaxInsertAttempts = 32
271271
}
272272
if vi.options.MaxDeleteAttempts == 0 {
273-
vi.options.MaxDeleteAttempts = 3
273+
// Note that fetching the batch and getting the first result from the
274+
// batch are both counted as "attempts", so this needs to be at least 2.
275+
vi.options.MaxDeleteAttempts = 2
274276
}
275277

276278
if vi.options.MaxPartitionSize < 2 {

pkg/sql/vecindex/cspann/testdata/delete.ddt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ vec7: (2, 8)
9494
9595
└───• vec4 (-4, 5)
9696

97-
# Test case where initial search fails to find vector to delete and it must be
98-
# retried.
97+
# Test case where search fails to find vector to delete.
9998
delete
10099
vec1: (2, 4)
101100
----
@@ -116,6 +115,7 @@ vec1: (2, 4)
116115
117116
├───• 4 (1, -2)
118117
│ │
118+
│ ├───• vec1 (MISSING)
119119
│ └───• vec6 (1, -6)
120120
121121
└───• 2 (5.5, 3.5)
@@ -141,6 +141,9 @@ vec6
141141
└───• 9 (3.25, 0.75)
142142
143143
├───• 4 (1, -2)
144+
│ │
145+
│ └───• vec1 (MISSING)
146+
144147
└───• 2 (5.5, 3.5)
145148
146149
├───• vec3 (4, 3)

pkg/sql/vecindex/cspann/testdata/search-for-delete.ddt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ----------------------------------------------------------------------
22
# Search tree with multiple partitions and duplicate data.
33
# ----------------------------------------------------------------------
4-
new-index dims=2 min-partition-size=1 max-partition-size=4 beam-size=1
4+
new-index dims=2 min-partition-size=1 max-partition-size=4 beam-size=2
55
vec1: (1, 2)
66
vec2: (7, 4)
77
vec3: (4, 3)
@@ -68,9 +68,9 @@ vec100: (1, 2)
6868
----
6969
vec100: vector not found
7070

71-
# Search for vector with wrong value, which forces internal retry.
71+
# Search for vector with wrong value that cannot be found with beam_size=2.
7272
search-for-delete
73-
vec1:(0, 9)
73+
vec1:(6, 2)
7474
----
7575
vec1: partition 7
7676

0 commit comments

Comments
 (0)