You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, the vector store would blindly use primary key column bytes
encoded in a vector index key to rebuild the primary key when retrieving
full vector values. SpanBuilder will attempt to reused already encoded
datums when building a span, but it can't do so if the encoded datum was
encoded in a different direction than required for the span being built.
For non-composite columns this was not an issue because they have all
the data needed to re-encode in the key value itself. For composite
column, the data encoded in the key is a key analogue and can't be used
to reconstruct the original column value, which is stored as a suffix
column.
For vector search, the search processor has access to the ValueBytes
array as well as the key, so it's able to rebuild column values as
needed. However, the fixup processor only has access to the key bytes,
which requires a bit of trickery.
In this patch, we disallow assigning directionality to vector index key
columns. The mechanics of similarity search preclude scannign prefixes,
so this was always a nonsensical thing to do. We now disallow it
entirely and take the further step to mechanically switch the
directionality of vector index prefix columns to match the primary key,
ensuring that the encoded value of these shared columns is always
directly usable.
We also move the logic for decoding and rebuilding the primary key into
the vector store so that it can be shared between fixups and the vector
search processor. Note that there is an additional composite key decoder
available for the vector search processor because it does indeed need to
decode the primary key bytes back to column values.
Along the way, we:
* Remove ASC/DESC from vector index columns.
* Introduce a new index type method to describe indexes with
non-directional prefixes.
* Alter SHOW commands to no longer show vector index column
directionality.
* Introduce a bunch of test-gated code to ensure everything I said
above is in fact true and remains so in the future.
Informs: #146046
Release note (sql change): It is no longer permitted to assign
directionality to any vector index column. Prefix columns (those columns
before the vector column in a compound vector index key) are not
scannable in a vector index, so directionality isn't relevant to them.
Copy file name to clipboardExpand all lines: pkg/sql/logictest/testdata/logic_test/expression_index
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ CREATE TABLE t (
10
10
INDEX t_a_plus_b_idx ((a + b)),
11
11
INDEX t_lower_c_a_plus_b_idx (lower(c), (a + b)),
12
12
INVERTED INDEX t_b_j_a_asc (b DESC, (j->'a') ASC),
13
-
VECTOR INDEX t_vec (a DESC, (v::VECTOR(3))),
13
+
VECTOR INDEX t_vec (a, (v::VECTOR(3))),
14
14
FAMILY (k, a, b, c, j, v)
15
15
)
16
16
@@ -30,7 +30,7 @@ CREATE TABLE public.t (
30
30
INDEX t_a_plus_b_idx ((a + b) ASC),
31
31
INDEX t_lower_c_a_plus_b_idx (lower(c) ASC, (a + b) ASC),
32
32
INVERTED INDEX t_b_j_a_asc (b DESC, (j->'a':::STRING)),
33
-
VECTOR INDEX t_vec (a DESC, (v::VECTOR(3)) vector_l2_ops),
33
+
VECTOR INDEX t_vec (a, (v::VECTOR(3)) vector_l2_ops),
34
34
FAMILY fam_0_k_a_b_c_j_v (k, a, b, c, j, v)
35
35
);
36
36
@@ -50,7 +50,7 @@ CREATE TABLE public.t (
50
50
INDEX t_a_plus_b_idx ((a + b) ASC),
51
51
INDEX t_lower_c_a_plus_b_idx (lower(c) ASC, (a + b) ASC),
52
52
INVERTED INDEX t_b_j_a_asc (b DESC, (j->'a':::STRING)),
53
-
VECTOR INDEX t_vec (a DESC, (v::VECTOR(3)) vector_l2_ops),
53
+
VECTOR INDEX t_vec (a, (v::VECTOR(3)) vector_l2_ops),
54
54
FAMILY fam_0_k_a_b_c_j_v (k, a, b, c, j, v)
55
55
) WITH (schema_locked = true);
56
56
@@ -70,7 +70,7 @@ CREATE TABLE public.t (
70
70
INDEX t_a_plus_b_idx ((a + b) ASC),
71
71
INDEX t_lower_c_a_plus_b_idx (lower(c) ASC, (a + b) ASC),
72
72
INVERTED INDEX t_b_j_a_asc (b DESC, (j->‹×›:::STRING)),
73
-
VECTOR INDEX t_vec (a DESC, (v::VECTOR(3)) vector_l2_ops),
73
+
VECTOR INDEX t_vec (a, (v::VECTOR(3)) vector_l2_ops),
74
74
FAMILY fam_0_k_a_b_c_j_v (k, a, b, c, j, v)
75
75
);
76
76
@@ -90,7 +90,7 @@ CREATE TABLE public.t (
90
90
INDEX t_a_plus_b_idx ((a + b) ASC),
91
91
INDEX t_lower_c_a_plus_b_idx (lower(c) ASC, (a + b) ASC),
92
92
INVERTED INDEX t_b_j_a_asc (b DESC, (j->‹×›:::STRING)),
93
-
VECTOR INDEX t_vec (a DESC, (v::VECTOR(3)) vector_l2_ops),
93
+
VECTOR INDEX t_vec (a, (v::VECTOR(3)) vector_l2_ops),
94
94
FAMILY fam_0_k_a_b_c_j_v (k, a, b, c, j, v)
95
95
) WITH (schema_locked = true);
96
96
@@ -178,7 +178,7 @@ CREATE TABLE err (a INT, b INT, VECTOR INDEX (a, (a + b)))
178
178
statement error column \(vec1::VECTOR\(3\)\) has type vector, which is only allowed as the last column in a vector index
179
179
CREATE TABLE err (a INT, vec1 VECTOR, VECTOR INDEX ((vec1::VECTOR(3)), a))
180
180
181
-
statement error the last column in a vector index cannot have the DESC option
181
+
statement error pq: a vector index does not support the DESC option
182
182
CREATE TABLE err (a INT, vec1 VECTOR, VECTOR INDEX (a, (vec1::VECTOR(3)) DESC))
183
183
184
184
statement error vector column \(vec1::VECTOR\) does not have a fixed number of dimensions, so it cannot be indexed\nDETAIL: specify the number of dimensions in the type, like VECTOR\(128\) for 128 dimensions
@@ -476,7 +476,7 @@ CREATE VECTOR INDEX err ON t (a, (a + b))
476
476
statement error column \(v::VECTOR\(3\)\) has type vector, which is only allowed as the last column in a vector index
477
477
CREATE VECTOR INDEX err ON t ((v::VECTOR(3)), a)
478
478
479
-
statement error the last column in a vector index cannot have the DESC option
479
+
statement error pq: a vector index does not support the DESC option
480
480
CREATE VECTOR INDEX err ON t (a, (v::VECTOR(3)) DESC)
481
481
482
482
statement error vector column \(v::VECTOR\) does not have a fixed number of dimensions, so it cannot be indexed\nDETAIL: specify the number of dimensions in the type, like VECTOR\(128\) for 128 dimensions
0 commit comments