Skip to content

Commit d1ebb8d

Browse files
committed
Use -1 for no limit for ivfflat.max_probes [skip ci]
1 parent 42af8aa commit d1ebb8d

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

src/hnsw.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ HnswInit(void)
8282
NULL, &hnsw_iterative_search,
8383
HNSW_ITERATIVE_SEARCH_OFF, hnsw_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
8484

85-
/* TODO Ensure ivfflat.max_probes uses same value for no limit */
8685
DefineCustomIntVariable("hnsw.max_search_tuples", "Sets the max number of candidates to visit for iterative search",
8786
"-1 means no limit", &hnsw_max_search_tuples,
8887
-1, -1, INT_MAX, PGC_USERSET, 0, NULL, NULL, NULL);

src/ivfflat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ IvfflatInit(void)
4646
IVFFLAT_ITERATIVE_SEARCH_OFF, ivfflat_iterative_search_options, PGC_USERSET, 0, NULL, NULL, NULL);
4747

4848
DefineCustomIntVariable("ivfflat.max_probes", "Sets the max number of probes for iterative search",
49-
"Zero sets to the number of lists", &ivfflat_max_probes,
50-
0, 0, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
49+
"-1 means no limit", &ivfflat_max_probes,
50+
-1, -1, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
5151

5252
MarkGUCPrefixReserved("ivfflat");
5353
}

src/ivfscan.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,27 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
259259
/* Get lists and dimensions from metapage */
260260
IvfflatGetMetaPageInfo(index, &lists, &dimensions);
261261

262-
if (probes > lists)
263-
probes = lists;
264-
265262
if (ivfflat_iterative_search != IVFFLAT_ITERATIVE_SEARCH_OFF)
266263
{
267-
if (ivfflat_max_probes == 0)
264+
maxProbes = ivfflat_max_probes;
265+
266+
if (maxProbes < 0)
268267
maxProbes = lists;
269-
else
270-
maxProbes = Min(ivfflat_max_probes, lists);
268+
else if (maxProbes < probes)
269+
{
270+
/* TODO Show notice */
271+
maxProbes = probes;
272+
}
271273
}
272274
else
273275
maxProbes = probes;
274276

277+
if (probes > lists)
278+
probes = lists;
279+
280+
if (maxProbes > lists)
281+
maxProbes = lists;
282+
275283
so = (IvfflatScanOpaque) palloc(offsetof(IvfflatScanOpaqueData, lists) + maxProbes * sizeof(IvfflatScanList));
276284
so->typeInfo = IvfflatGetTypeInfo(index);
277285
so->first = true;

test/expected/ivfflat_vector.out

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,30 @@ SELECT * FROM t ORDER BY val <-> '[3,3,3]';
9595
[0,0,0]
9696
(3 rows)
9797

98+
SET ivfflat.max_probes = 0;
99+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
100+
val
101+
---------
102+
[1,2,3]
103+
(1 row)
104+
105+
SET ivfflat.max_probes = 1;
106+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
107+
val
108+
---------
109+
[1,2,3]
110+
(1 row)
111+
112+
SET ivfflat.max_probes = 2;
113+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
114+
val
115+
---------
116+
[1,2,3]
117+
[1,1,1]
118+
(2 rows)
119+
98120
RESET ivfflat.iterative_search;
121+
RESET ivfflat.max_probes;
99122
DROP TABLE t;
100123
-- unlogged
101124
CREATE UNLOGGED TABLE t (val vector(3));
@@ -140,11 +163,11 @@ HINT: Available values: off, relaxed_order.
140163
SHOW ivfflat.max_probes;
141164
ivfflat.max_probes
142165
--------------------
143-
0
166+
-1
144167
(1 row)
145168

146-
SET ivfflat.max_probes = -1;
147-
ERROR: -1 is outside the valid range for parameter "ivfflat.max_probes" (0 .. 32768)
169+
SET ivfflat.max_probes = -2;
170+
ERROR: -2 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
148171
SET ivfflat.max_probes = 32769;
149-
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (0 .. 32768)
172+
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (-1 .. 32768)
150173
DROP TABLE t;

test/sql/ivfflat_vector.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,17 @@ CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 3);
5353
SET ivfflat.iterative_search = relaxed_order;
5454
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
5555

56+
SET ivfflat.max_probes = 0;
57+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
58+
59+
SET ivfflat.max_probes = 1;
60+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
61+
62+
SET ivfflat.max_probes = 2;
63+
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
64+
5665
RESET ivfflat.iterative_search;
66+
RESET ivfflat.max_probes;
5767
DROP TABLE t;
5868

5969
-- unlogged
@@ -83,7 +93,7 @@ SET ivfflat.iterative_search = on;
8393

8494
SHOW ivfflat.max_probes;
8595

86-
SET ivfflat.max_probes = -1;
96+
SET ivfflat.max_probes = -2;
8797
SET ivfflat.max_probes = 32769;
8898

8999
DROP TABLE t;

0 commit comments

Comments
 (0)