mirror of
https://github.com/pgvector/pgvector.git
synced 2026-12-06 17:28:40 +00:00
Added ivfflat.scan_mem_multiplier [skip ci]
This commit is contained in:
1 parent
088c4f6236
commit
a69ec8bc9b
5 files changed
+39
-1
No files matched your search
@@ -33,6 +33,7 @@
|
||||
int ivfflat_probes;
|
||||
int ivfflat_iterative_scan;
|
||||
int ivfflat_max_probes;
|
||||
double ivfflat_scan_mem_multiplier;
|
||||
static relopt_kind ivfflat_relopt_kind;
|
||||
|
||||
static const struct config_enum_entry ivfflat_iterative_scan_options[] = {
|
||||
@@ -64,6 +65,11 @@ IvfflatInit(void)
|
||||
NULL, &ivfflat_max_probes,
|
||||
IVFFLAT_MAX_LISTS, IVFFLAT_MIN_LISTS, IVFFLAT_MAX_LISTS, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
/* Same range as hash_mem_multiplier */
|
||||
DefineCustomRealVariable("ivfflat.scan_mem_multiplier", "Sets the multiple of work_mem to use for scans",
|
||||
NULL, &ivfflat_scan_mem_multiplier,
|
||||
1, 1, 1000, PGC_USERSET, 0, NULL, NULL, NULL);
|
||||
|
||||
MarkGUCPrefixReserved("ivfflat");
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ typedef Pointer Item;
|
||||
extern int ivfflat_probes;
|
||||
extern int ivfflat_iterative_scan;
|
||||
extern int ivfflat_max_probes;
|
||||
extern double ivfflat_scan_mem_multiplier;
|
||||
|
||||
typedef enum IvfflatIterativeScanMode
|
||||
{
|
||||
|
||||
+2
-1
@@ -621,7 +621,8 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
|
||||
so->listsHeap = pairingheap_allocate(CompareListsMaxHeap, NULL);
|
||||
|
||||
so->useHeap = true;
|
||||
so->maxHeapItems = ComputeMaxHeapItems(mul_size(work_mem, 1024));
|
||||
/* TODO Improve multiplier pattern */
|
||||
so->maxHeapItems = ComputeMaxHeapItems(mul_size(work_mem, 1024 * ivfflat_scan_mem_multiplier));
|
||||
BinaryHeapInit(&so->itemsHeap, Min(32 * 1024, so->maxHeapItems));
|
||||
so->sortstate = NULL;
|
||||
|
||||
|
||||
@@ -181,6 +181,16 @@ SET ivfflat.max_probes = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
SET ivfflat.max_probes = 32769;
|
||||
ERROR: 32769 is outside the valid range for parameter "ivfflat.max_probes" (1 .. 32768)
|
||||
SHOW ivfflat.scan_mem_multiplier;
|
||||
ivfflat.scan_mem_multiplier
|
||||
-----------------------------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
SET ivfflat.scan_mem_multiplier = 0;
|
||||
ERROR: 0 is outside the valid range for parameter "ivfflat.scan_mem_multiplier" (1 .. 1000)
|
||||
SET ivfflat.scan_mem_multiplier = 1001;
|
||||
ERROR: 1001 is outside the valid range for parameter "ivfflat.scan_mem_multiplier" (1 .. 1000)
|
||||
-- dimensions
|
||||
CREATE TABLE t (val vector(2000));
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops);
|
||||
@@ -273,6 +283,16 @@ DEBUG: ivfflat scan no longer fits into work_mem after 1 tuples
|
||||
[1,2,3] | [1,2,3]
|
||||
(3 rows)
|
||||
|
||||
SET ivfflat.scan_mem_multiplier = 2;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
val
|
||||
---------
|
||||
[1,2,3]
|
||||
[1,1,1]
|
||||
[0,0,0]
|
||||
(3 rows)
|
||||
|
||||
RESET ivfflat.scan_mem_multiplier;
|
||||
RESET client_min_messages;
|
||||
DROP TABLE t;
|
||||
RESET work_mem;
|
||||
@@ -95,6 +95,10 @@ SHOW ivfflat.max_probes;
|
||||
SET ivfflat.max_probes = 0;
|
||||
SET ivfflat.max_probes = 32769;
|
||||
|
||||
SHOW ivfflat.scan_mem_multiplier;
|
||||
SET ivfflat.scan_mem_multiplier = 0;
|
||||
SET ivfflat.scan_mem_multiplier = 1001;
|
||||
|
||||
-- dimensions
|
||||
|
||||
CREATE TABLE t (val vector(2000));
|
||||
@@ -142,8 +146,14 @@ INSERT INTO t (val) VALUES ('[0,0,0]'), ('[1,2,3]'), ('[1,1,1]');
|
||||
CREATE INDEX ON t USING ivfflat (val vector_l2_ops) WITH (lists = 1);
|
||||
|
||||
SET client_min_messages = DEBUG;
|
||||
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
SELECT * FROM t CROSS JOIN LATERAL (SELECT * FROM t t2 ORDER BY val <-> t.val LIMIT 1) t2 ORDER BY t.val;
|
||||
|
||||
SET ivfflat.scan_mem_multiplier = 2;
|
||||
SELECT * FROM t ORDER BY val <-> '[3,3,3]';
|
||||
RESET ivfflat.scan_mem_multiplier;
|
||||
|
||||
RESET client_min_messages;
|
||||
|
||||
DROP TABLE t;
|
||||
|
||||
Reference in new issue
Block a user