Commit Graph
1522 Commits
Author SHA1 Message Date
Andrew Kane a6b7acf3e7 Removed unneeded floor and fixed comment formatting [skip ci] 2024-09-25 14:13:02 -07:00
Andrew Kane 15f312fed1 Ran pgindent [skip ci] 2024-09-25 14:03:51 -07:00
9371ba7f43 Update HNSW cost estimatation to utilize search and index info (#682)
Previously, the cost estimation formula for a HNSW index scan utilized
a methodology that only factored in the entry level for an HNSW scan
and the "m" index parameter, which reflects the number of tuples (or
vectors) to scan at each step of a HNSW graph traversal. While this
would bias the PostgreSQL query planner to choose an HNSW index scan
over other available paths, this could lead to potential suboptimal
index selection, for example, choosing to use a HNSW index instead of
an available B-tree index that has better selectivity.

The number of tuples scanned during HNSW graph traversal is principally
influenced by these factors:

 * The number of tuples stored in the index
 * `m` - the number of tuples that are scanned in each step of the graph
   traversal
 * `hnsw.ef_search` - which influences the total number of steps it
   takes for the scan to converge on the approximated nearest neighbors

Through testing different source models for vectors, we also observed
that the correlation of vectors in mdoels would impact this convergence.
For this first iteration, we've opted to hardcode a constant scaling
factor and set it to `0.55`, though a future commit may turn this into
a configurable parameter.

The high-level formula for estimating the cost of a HNSW index scan is
as such:

```
(entryLevel * m) + (layer0TuplesMax * layer0Selectivity)
```

where

- `(entryLevel * m)` is the lower bound of tuples to scan, as it
accounts for the graph traversal to layer 0 (L0). (L1 and above has an ef=1)
- `layer0TuplesMax` is an estimate of the maximum number of tuples to
scan at L0. This accounts for tuples that may end up being discarded due
to them already being visited. Testing shows that the number of steps
until converge is similar to the value of `hnsw.ef_search`, thus we can
estimate tuples max at `hnsw.ef_search * m * 2`
- `layer0Selectivity` - estimates the percentage of tuples that will
actually be scanned during the index traversal, multipled by the scaling
factor

In addition to the `m` build parameter and `hsnw.ef_search`, costs
estimates can be influenced by standard PostgreSQL costing parameters,
though adjusting those (e.g. `random_page_cost`) should be done with
care.

Co-authored-by: @ankane
2024-09-25 14:01:33 -07:00
Andrew Kane fb7c86e572 Do not adjust index selectivity based on probes [skip ci] 2024-09-25 13:48:24 -07:00
Andrew Kane 81a7ac3f56 Added test for join with attribute filtering [skip ci] 2024-09-24 23:21:34 -07:00
Andrew Kane 079133f821 Improved test [skip ci] 2024-09-24 23:13:30 -07:00
Andrew Kane 5ef14ea3aa Added test for join [skip ci] 2024-09-24 23:12:27 -07:00
Andrew Kane 11c72a711d Removed code for Postgres 12 [skip ci] 2024-09-23 15:26:31 -07:00
Andrew Kane db196c0dd5 Free TupleDesc [skip ci] 2024-09-21 19:15:34 -07:00
Andrew Kane 204dd71b81 Moved allocations out of GetScanItems [skip ci] 2024-09-21 19:10:25 -07:00
Andrew Kane 10712d2f37 Added macros for IvfflatScanList [skip ci] 2024-09-21 18:10:37 -07:00
Andrew Kane c0e2c23acc Changed HnswPairingHeapNode to HnswSearchCandidate to reduce allocations and improve code 2024-09-21 12:07:44 -07:00
Andrew Kane f6b040eea9 Improved code [skip ci] 2024-09-20 15:21:57 -07:00
Andrew Kane b7343d7863 Fixed CI 2024-09-19 20:50:51 -07:00
Andrew Kane bae726a4c6 Improved code [skip ci] 2024-09-19 19:57:16 -07:00
Andrew Kane 5cf1e7b99e Fixed array_to_sparsevec on Windows [skip ci] 2024-09-19 19:52:16 -07:00
f37b369f00 Added casts for arrays to sparsevec - #604
Co-authored-by: Narek Galstyan <[email protected]>
Co-authored-by: Di Qi <[email protected]>
2024-09-19 19:17:05 -07:00
Andrew Kane ca2ebbc623 Dropped support for Postgres 12 2024-09-19 18:13:54 -07:00
Heikki LinnakangasandGitHub 6c3178bb87 Add error codes to a few errors (#657)
With elog(), you get XX000 "internal_error", which sounds scary.

It's not self-evident what the right error codes for some of these
errors are, but I tried to use my best judgment.
2024-09-19 18:04:23 -07:00
Andrew Kane 4a8a81a036 Updated changelog [skip ci] 2024-09-19 18:03:20 -07:00
Jonathan S. KatzandGitHub 091a854aee Swap max costing values to align with upstream guidance (#658)
A feature targeted for PostgreSQL 18 (postgres/postgres@e2225346)
that makes optimizations around disabled path nodes impacted pgvector
such that PostgreSQL would choose to perform an index scan when it
should have used a different scan (e.g. `SELECT count(*) FROM table`).
Per upstream guidance[1], the recommendation is to switch to using
`get_float8_infinity()`, which achieves the same behavior in backbranches,
and can be adapated to work with the new behavior introduced in PostgreSQL 18.

[1] https://www.postgresql.org/message-id/2281822.1724441531%40sss.pgh.pa.us
2024-09-19 18:01:59 -07:00
Andrew Kane 435358dc80 Improved variable name [skip ci] 2024-09-19 15:09:40 -07:00
Andrew Kane 45c4769e62 Simplified HnswLoadUnvisitedFromMemory [skip ci] 2024-09-19 04:39:46 -07:00
Andrew Kane a45322d8f7 Simplified CountElement [skip ci] 2024-09-19 04:32:38 -07:00
Andrew Kane 9836ae640b Keep scan-build happy 2024-09-19 04:02:09 -07:00
Andrew Kane c924803bc5 Reduced memory usage for HNSW index scans 2024-09-19 03:27:35 -07:00
Andrew Kane fff3c1224f Updated changelog [skip ci] 2024-09-19 02:42:33 -07:00
Andrew Kane 0f29d49ade Updated AddToVisited to use HnswElementPtr 2024-09-19 02:41:20 -07:00
Andrew KaneandHeikki Linnakangas c5f71a0a8c Reduced memory usage for HNSW index scans
Co-authored-by: Heikki Linnakangas <[email protected]>
2024-09-19 02:17:51 -07:00
Andrew Kane f0c5ebfdb2 Reduced allocations for pairing heap 2024-09-19 01:59:46 -07:00
Andrew Kane 397edbc32b Updated readme 2024-09-05 23:13:12 -07:00
Andrew Kane 3e4bed63b0 Revert "Improved cleanup for IVFFlat index scans [skip ci]"
This reverts commit 8b1cf46ddc.
2024-09-02 01:52:28 -07:00
Andrew Kane 3ee2d46973 Fixed CI 2024-09-02 01:44:03 -07:00
Andrew Kane 2d57e15aa9 Updated links [skip ci] 2024-08-28 13:39:03 -07:00
Andrew Kane 95b1a65827 Reset tuple sort for Postgres 12 [skip ci] 2024-08-24 22:10:26 -07:00
Andrew Kane 8b1cf46ddc Improved cleanup for IVFFlat index scans [skip ci] 2024-08-24 21:59:44 -07:00
Andrew Kane af1088c43f Renamed InitSortState to InitScanSortState [skip ci] 2024-08-24 21:53:15 -07:00
Andrew Kane 3ac7572e54 Added InitBuildSortState function [skip ci] 2024-08-24 21:50:31 -07:00
Andrew Kane 8e1e57c24b Added InitSortState function [skip ci] 2024-08-24 21:42:18 -07:00
Andrew Kane a5884e8ce0 Added memory usage for IVFFlat index scans [skip ci] 2024-08-24 21:30:40 -07:00
Andrew Kane 226fa316e8 Fixed -DIVFFLAT_MEMORY [skip ci] 2024-08-24 20:56:33 -07:00
Andrew Kane 5ada54af47 Added fields to IndexAmRoutine 2024-08-22 20:39:16 -07:00
Samuel MarksandGitHub c141a5c164 [src/hnswutils.c] Resolve 1 -Wmaybe-uninitialized (#654) 2024-08-22 19:51:16 -07:00
Andrew Kane 3c230fec75 Added Postgres 18 to CI [skip ci] 2024-08-13 02:24:42 -07:00
Andrew Kane e499e61fda Updated comment [skip ci] 2024-08-06 10:35:26 -07:00
Andrew Kane 409e3372a5 Version bump to 0.7.4 [skip ci] v0.7.4 2024-08-05 10:44:01 -07:00
Andrew Kane 5303418fa7 Fixed locking for parallel HNSW index builds - fixes #635 2024-08-04 11:27:51 -07:00
Andrew Kane 80b91a1bbc Changed warnings to errors for TAP tests [skip ci] 2024-07-27 12:28:03 -07:00
Andrew Kane b95ce7b660 Updated TAP tests to use PostgreSQL::Test packages [skip ci] 2024-07-27 12:24:15 -07:00
Andrew Kane c841afc6f6 Updated comment [skip ci] 2024-07-27 11:36:48 -07:00