Skip to content

Commit 9fd3626

Browse files
craig[bot]jordanlewis
andcommitted
Merge #124292
124292: sql: implement pgvector datatype and evaluation r=jordanlewis a=jordanlewis This commit adds the pgvector datatype and associated evaluation operators and functions. It doesn't include index acceleration. Functionality included: - `CREATE EXTENSION vector` - `vector` datatype with optional length, storage and retrieval in non-indexed table columns - Equality and inequality operators - `<->` operator - L2 distance - `<#>` operator - (negative) inner product - `<=>` operator - cosine distance - `l1_distance` builtin - `l2_distance` builtin - `cosine_distance` builtin - `inner_product` builtin - `vector_dims` builtin - `vector_norm` builtin Updates #121432 Epic: None Release note (sql change): implement pgvector encoding, decoding, and operators, without index acceleration. Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
2 parents c557fb5 + 3e5a520 commit 9fd3626

File tree

102 files changed

+2100
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2100
-86
lines changed

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ col_name_keyword ::=
15681568
| 'VALUES'
15691569
| 'VARBIT'
15701570
| 'VARCHAR'
1571+
| 'VECTOR'
15711572
| 'VIRTUAL'
15721573
| 'WORK'
15731574

@@ -1755,7 +1756,7 @@ backup_options_list ::=
17551756
( backup_options ) ( ( ',' backup_options ) )*
17561757

17571758
a_expr ::=
1758-
( c_expr | '+' a_expr | '-' a_expr | '~' a_expr | 'SQRT' a_expr | 'CBRT' a_expr | qual_op a_expr | 'NOT' a_expr | 'NOT' a_expr | row 'OVERLAPS' row | 'DEFAULT' ) ( ( 'TYPECAST' cast_target | 'TYPEANNOTATE' typename | 'COLLATE' collation_name | 'AT' 'TIME' 'ZONE' a_expr | '+' a_expr | '-' a_expr | '*' a_expr | '/' a_expr | 'FLOORDIV' a_expr | '%' a_expr | '^' a_expr | '#' a_expr | '&' a_expr | '|' a_expr | '<' a_expr | '>' a_expr | '?' a_expr | 'JSON_SOME_EXISTS' a_expr | 'JSON_ALL_EXISTS' a_expr | 'CONTAINS' a_expr | 'CONTAINED_BY' a_expr | '=' a_expr | 'CONCAT' a_expr | 'LSHIFT' a_expr | 'RSHIFT' a_expr | 'FETCHVAL' a_expr | 'FETCHTEXT' a_expr | 'FETCHVAL_PATH' a_expr | 'FETCHTEXT_PATH' a_expr | 'REMOVE_PATH' a_expr | 'INET_CONTAINED_BY_OR_EQUALS' a_expr | 'AND_AND' a_expr | 'AT_AT' a_expr | 'INET_CONTAINS_OR_EQUALS' a_expr | 'LESS_EQUALS' a_expr | 'GREATER_EQUALS' a_expr | 'NOT_EQUALS' a_expr | qual_op a_expr | 'AND' a_expr | 'OR' a_expr | 'LIKE' a_expr | 'LIKE' a_expr 'ESCAPE' a_expr | 'NOT' 'LIKE' a_expr | 'NOT' 'LIKE' a_expr 'ESCAPE' a_expr | 'ILIKE' a_expr | 'ILIKE' a_expr 'ESCAPE' a_expr | 'NOT' 'ILIKE' a_expr | 'NOT' 'ILIKE' a_expr 'ESCAPE' a_expr | 'SIMILAR' 'TO' a_expr | 'SIMILAR' 'TO' a_expr 'ESCAPE' a_expr | 'NOT' 'SIMILAR' 'TO' a_expr | 'NOT' 'SIMILAR' 'TO' a_expr 'ESCAPE' a_expr | '~' a_expr | 'NOT_REGMATCH' a_expr | 'REGIMATCH' a_expr | 'NOT_REGIMATCH' a_expr | 'IS' 'NAN' | 'IS' 'NOT' 'NAN' | 'IS' 'NULL' | 'ISNULL' | 'IS' 'NOT' 'NULL' | 'NOTNULL' | 'IS' 'TRUE' | 'IS' 'NOT' 'TRUE' | 'IS' 'FALSE' | 'IS' 'NOT' 'FALSE' | 'IS' 'UNKNOWN' | 'IS' 'NOT' 'UNKNOWN' | 'IS' 'DISTINCT' 'FROM' a_expr | 'IS' 'NOT' 'DISTINCT' 'FROM' a_expr | 'IS' 'OF' '(' type_list ')' | 'IS' 'NOT' 'OF' '(' type_list ')' | 'BETWEEN' opt_asymmetric b_expr 'AND' a_expr | 'NOT' 'BETWEEN' opt_asymmetric b_expr 'AND' a_expr | 'BETWEEN' 'SYMMETRIC' b_expr 'AND' a_expr | 'NOT' 'BETWEEN' 'SYMMETRIC' b_expr 'AND' a_expr | 'IN' in_expr | 'NOT' 'IN' in_expr | subquery_op sub_type a_expr ) )*
1759+
( c_expr | '+' a_expr | '-' a_expr | '~' a_expr | 'SQRT' a_expr | 'CBRT' a_expr | qual_op a_expr | 'NOT' a_expr | 'NOT' a_expr | row 'OVERLAPS' row | 'DEFAULT' ) ( ( 'TYPECAST' cast_target | 'TYPEANNOTATE' typename | 'COLLATE' collation_name | 'AT' 'TIME' 'ZONE' a_expr | '+' a_expr | '-' a_expr | '*' a_expr | '/' a_expr | 'FLOORDIV' a_expr | '%' a_expr | '^' a_expr | '#' a_expr | '&' a_expr | '|' a_expr | '<' a_expr | '>' a_expr | '?' a_expr | 'JSON_SOME_EXISTS' a_expr | 'JSON_ALL_EXISTS' a_expr | 'CONTAINS' a_expr | 'CONTAINED_BY' a_expr | '=' a_expr | 'CONCAT' a_expr | 'LSHIFT' a_expr | 'RSHIFT' a_expr | 'FETCHVAL' a_expr | 'FETCHTEXT' a_expr | 'FETCHVAL_PATH' a_expr | 'FETCHTEXT_PATH' a_expr | 'REMOVE_PATH' a_expr | 'INET_CONTAINED_BY_OR_EQUALS' a_expr | 'AND_AND' a_expr | 'AT_AT' a_expr | 'DISTANCE' a_expr | 'COS_DISTANCE' a_expr | 'NEG_INNER_PRODUCT' a_expr | 'INET_CONTAINS_OR_EQUALS' a_expr | 'LESS_EQUALS' a_expr | 'GREATER_EQUALS' a_expr | 'NOT_EQUALS' a_expr | qual_op a_expr | 'AND' a_expr | 'OR' a_expr | 'LIKE' a_expr | 'LIKE' a_expr 'ESCAPE' a_expr | 'NOT' 'LIKE' a_expr | 'NOT' 'LIKE' a_expr 'ESCAPE' a_expr | 'ILIKE' a_expr | 'ILIKE' a_expr 'ESCAPE' a_expr | 'NOT' 'ILIKE' a_expr | 'NOT' 'ILIKE' a_expr 'ESCAPE' a_expr | 'SIMILAR' 'TO' a_expr | 'SIMILAR' 'TO' a_expr 'ESCAPE' a_expr | 'NOT' 'SIMILAR' 'TO' a_expr | 'NOT' 'SIMILAR' 'TO' a_expr 'ESCAPE' a_expr | '~' a_expr | 'NOT_REGMATCH' a_expr | 'REGIMATCH' a_expr | 'NOT_REGIMATCH' a_expr | 'IS' 'NAN' | 'IS' 'NOT' 'NAN' | 'IS' 'NULL' | 'ISNULL' | 'IS' 'NOT' 'NULL' | 'NOTNULL' | 'IS' 'TRUE' | 'IS' 'NOT' 'TRUE' | 'IS' 'FALSE' | 'IS' 'NOT' 'FALSE' | 'IS' 'UNKNOWN' | 'IS' 'NOT' 'UNKNOWN' | 'IS' 'DISTINCT' 'FROM' a_expr | 'IS' 'NOT' 'DISTINCT' 'FROM' a_expr | 'IS' 'OF' '(' type_list ')' | 'IS' 'NOT' 'OF' '(' type_list ')' | 'BETWEEN' opt_asymmetric b_expr 'AND' a_expr | 'NOT' 'BETWEEN' opt_asymmetric b_expr 'AND' a_expr | 'BETWEEN' 'SYMMETRIC' b_expr 'AND' a_expr | 'NOT' 'BETWEEN' 'SYMMETRIC' b_expr 'AND' a_expr | 'IN' in_expr | 'NOT' 'IN' in_expr | subquery_op sub_type a_expr ) )*
17591760

17601761
for_schedules_clause ::=
17611762
'FOR' 'SCHEDULES' select_stmt
@@ -3139,6 +3140,9 @@ all_op ::=
31393140
| 'NOT_REGIMATCH'
31403141
| 'AND_AND'
31413142
| 'AT_AT'
3143+
| 'DISTANCE'
3144+
| 'COS_DISTANCE'
3145+
| 'NEG_INNER_PRODUCT'
31423146
| '~'
31433147
| 'SQRT'
31443148
| 'CBRT'
@@ -3397,6 +3401,7 @@ const_typename ::=
33973401
| character_with_length
33983402
| const_datetime
33993403
| const_geo
3404+
| const_vector
34003405

34013406
interval_type ::=
34023407
'INTERVAL'
@@ -4160,6 +4165,7 @@ bare_label_keywords ::=
41604165
| 'VARCHAR'
41614166
| 'VARIABLES'
41624167
| 'VARIADIC'
4168+
| 'VECTOR'
41634169
| 'VERIFY_BACKUP_TABLE_DATA'
41644170
| 'VIEW'
41654171
| 'VIEWACTIVITY'
@@ -4313,6 +4319,10 @@ const_geo ::=
43134319
| 'GEOMETRY' '(' geo_shape_type ',' signed_iconst ')'
43144320
| 'GEOGRAPHY' '(' geo_shape_type ',' signed_iconst ')'
43154321

4322+
const_vector ::=
4323+
'VECTOR'
4324+
| 'VECTOR' '(' iconst32 ')'
4325+
43164326
interval_qualifier ::=
43174327
'YEAR'
43184328
| 'MONTH'

docs/generated/sql/functions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,25 @@ the locality flag on node startup. Returns an error if no region is set.</p>
12791279
</span></td><td>Stable</td></tr></tbody>
12801280
</table>
12811281

1282+
### PGVector functions
1283+
1284+
<table>
1285+
<thead><tr><th>Function &rarr; Returns</th><th>Description</th><th>Volatility</th></tr></thead>
1286+
<tbody>
1287+
<tr><td><a name="cosine_distance"></a><code>cosine_distance(v1: vector, v2: vector) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Returns the cosine distance between the two vectors.</p>
1288+
</span></td><td>Immutable</td></tr>
1289+
<tr><td><a name="inner_product"></a><code>inner_product(v1: vector, v2: vector) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Returns the inner product between the two vectors.</p>
1290+
</span></td><td>Immutable</td></tr>
1291+
<tr><td><a name="l1_distance"></a><code>l1_distance(v1: vector, v2: vector) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Returns the Manhattan distance between the two vectors.</p>
1292+
</span></td><td>Immutable</td></tr>
1293+
<tr><td><a name="l2_distance"></a><code>l2_distance(v1: vector, v2: vector) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Returns the Euclidean distance between the two vectors.</p>
1294+
</span></td><td>Immutable</td></tr>
1295+
<tr><td><a name="vector_dims"></a><code>vector_dims(vector: vector) &rarr; <a href="int.html">int</a></code></td><td><span class="funcdesc"><p>Returns the number of the dimensions in the vector.</p>
1296+
</span></td><td>Immutable</td></tr>
1297+
<tr><td><a name="vector_norm"></a><code>vector_norm(vector: vector) &rarr; <a href="float.html">float</a></code></td><td><span class="funcdesc"><p>Returns the Euclidean norm of the vector.</p>
1298+
</span></td><td>Immutable</td></tr></tbody>
1299+
</table>
1300+
12821301
### STRING[] functions
12831302

12841303
<table>

docs/generated/sql/operators.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<tr><td><a href="interval.html">interval</a> <code>*</code> <a href="decimal.html">decimal</a></td><td><a href="interval.html">interval</a></td></tr>
5656
<tr><td><a href="interval.html">interval</a> <code>*</code> <a href="float.html">float</a></td><td><a href="interval.html">interval</a></td></tr>
5757
<tr><td><a href="interval.html">interval</a> <code>*</code> <a href="int.html">int</a></td><td><a href="interval.html">interval</a></td></tr>
58+
<tr><td>vector <code>*</code> vector</td><td>vector</td></tr>
5859
</tbody></table>
5960
<table><thead>
6061
<tr><td><code>+</code></td><td>Return</td></tr>
@@ -89,6 +90,7 @@
8990
<tr><td><a href="timestamp.html">timestamptz</a> <code>+</code> <a href="interval.html">interval</a></td><td><a href="timestamp.html">timestamptz</a></td></tr>
9091
<tr><td>timetz <code>+</code> <a href="date.html">date</a></td><td><a href="timestamp.html">timestamptz</a></td></tr>
9192
<tr><td>timetz <code>+</code> <a href="interval.html">interval</a></td><td>timetz</td></tr>
93+
<tr><td>vector <code>+</code> vector</td><td>vector</td></tr>
9294
</tbody></table>
9395
<table><thead>
9496
<tr><td><code>-</code></td><td>Return</td></tr>
@@ -123,6 +125,7 @@
123125
<tr><td><a href="timestamp.html">timestamptz</a> <code>-</code> <a href="timestamp.html">timestamp</a></td><td><a href="interval.html">interval</a></td></tr>
124126
<tr><td><a href="timestamp.html">timestamptz</a> <code>-</code> <a href="timestamp.html">timestamptz</a></td><td><a href="interval.html">interval</a></td></tr>
125127
<tr><td>timetz <code>-</code> <a href="interval.html">interval</a></td><td>timetz</td></tr>
128+
<tr><td>vector <code>-</code> vector</td><td>vector</td></tr>
126129
</tbody></table>
127130
<table><thead>
128131
<tr><td><code>-></code></td><td>Return</td></tr>
@@ -213,6 +216,17 @@
213216
<tr><td><a href="uuid.html">uuid</a> <code><</code> <a href="uuid.html">uuid</a></td><td><a href="bool.html">bool</a></td></tr>
214217
<tr><td><a href="uuid.html">uuid[]</a> <code><</code> <a href="uuid.html">uuid[]</a></td><td><a href="bool.html">bool</a></td></tr>
215218
<tr><td>varbit <code><</code> varbit</td><td><a href="bool.html">bool</a></td></tr>
219+
<tr><td>vector <code><</code> vector</td><td><a href="bool.html">bool</a></td></tr>
220+
</tbody></table>
221+
<table><thead>
222+
<tr><td><code><#></code></td><td>Return</td></tr>
223+
</thead><tbody>
224+
<tr><td>vector <code><#></code> vector</td><td><a href="float.html">float</a></td></tr>
225+
</tbody></table>
226+
<table><thead>
227+
<tr><td><code><-></code></td><td>Return</td></tr>
228+
</thead><tbody>
229+
<tr><td>vector <code><-></code> vector</td><td><a href="float.html">float</a></td></tr>
216230
</tbody></table>
217231
<table><thead>
218232
<tr><td><code><<</code></td><td>Return</td></tr>
@@ -278,6 +292,12 @@
278292
<tr><td><a href="uuid.html">uuid</a> <code><=</code> <a href="uuid.html">uuid</a></td><td><a href="bool.html">bool</a></td></tr>
279293
<tr><td><a href="uuid.html">uuid[]</a> <code><=</code> <a href="uuid.html">uuid[]</a></td><td><a href="bool.html">bool</a></td></tr>
280294
<tr><td>varbit <code><=</code> varbit</td><td><a href="bool.html">bool</a></td></tr>
295+
<tr><td>vector <code><=</code> vector</td><td><a href="bool.html">bool</a></td></tr>
296+
</tbody></table>
297+
<table><thead>
298+
<tr><td><code><=></code></td><td>Return</td></tr>
299+
</thead><tbody>
300+
<tr><td>vector <code><=></code> vector</td><td><a href="float.html">float</a></td></tr>
281301
</tbody></table>
282302
<table><thead>
283303
<tr><td><code><@</code></td><td>Return</td></tr>
@@ -344,6 +364,7 @@
344364
<tr><td><a href="uuid.html">uuid</a> <code>=</code> <a href="uuid.html">uuid</a></td><td><a href="bool.html">bool</a></td></tr>
345365
<tr><td><a href="uuid.html">uuid[]</a> <code>=</code> <a href="uuid.html">uuid[]</a></td><td><a href="bool.html">bool</a></td></tr>
346366
<tr><td>varbit <code>=</code> varbit</td><td><a href="bool.html">bool</a></td></tr>
367+
<tr><td>vector <code>=</code> vector</td><td><a href="bool.html">bool</a></td></tr>
347368
</tbody></table>
348369
<table><thead>
349370
<tr><td><code>>></code></td><td>Return</td></tr>
@@ -412,6 +433,7 @@
412433
<tr><td>tuple <code>IN</code> tuple</td><td><a href="bool.html">bool</a></td></tr>
413434
<tr><td><a href="uuid.html">uuid</a> <code>IN</code> tuple</td><td><a href="bool.html">bool</a></td></tr>
414435
<tr><td>varbit <code>IN</code> tuple</td><td><a href="bool.html">bool</a></td></tr>
436+
<tr><td>vector <code>IN</code> tuple</td><td><a href="bool.html">bool</a></td></tr>
415437
</tbody></table>
416438
<table><thead>
417439
<tr><td><code>IS NOT DISTINCT FROM</code></td><td>Return</td></tr>
@@ -475,6 +497,7 @@
475497
<tr><td><a href="uuid.html">uuid</a> <code>IS NOT DISTINCT FROM</code> <a href="uuid.html">uuid</a></td><td><a href="bool.html">bool</a></td></tr>
476498
<tr><td><a href="uuid.html">uuid[]</a> <code>IS NOT DISTINCT FROM</code> <a href="uuid.html">uuid[]</a></td><td><a href="bool.html">bool</a></td></tr>
477499
<tr><td>varbit <code>IS NOT DISTINCT FROM</code> varbit</td><td><a href="bool.html">bool</a></td></tr>
500+
<tr><td>vector <code>IS NOT DISTINCT FROM</code> vector</td><td><a href="bool.html">bool</a></td></tr>
478501
<tr><td>void <code>IS NOT DISTINCT FROM</code> unknown</td><td><a href="bool.html">bool</a></td></tr>
479502
</tbody></table>
480503
<table><thead>

pkg/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ALL_TESTS = [
5454
"//pkg/ccl/logictestccl/tests/3node-tenant-multiregion:3node-tenant-multiregion_test",
5555
"//pkg/ccl/logictestccl/tests/3node-tenant:3node-tenant_test",
5656
"//pkg/ccl/logictestccl/tests/5node:5node_test",
57+
"//pkg/ccl/logictestccl/tests/cockroach-go-testserver-23.2:cockroach-go-testserver-23_2_test",
5758
"//pkg/ccl/logictestccl/tests/fakedist-disk:fakedist-disk_test",
5859
"//pkg/ccl/logictestccl/tests/fakedist-vec-off:fakedist-vec-off_test",
5960
"//pkg/ccl/logictestccl/tests/fakedist:fakedist_test",
@@ -754,6 +755,7 @@ ALL_TESTS = [
754755
"//pkg/util/ulid:ulid_test",
755756
"//pkg/util/unique:unique_test",
756757
"//pkg/util/uuid:uuid_test",
758+
"//pkg/util/vector:vector_test",
757759
"//pkg/util/version:version_test",
758760
"//pkg/util:util_test",
759761
"//pkg/workload/bank:bank_test",
@@ -899,6 +901,7 @@ GO_TARGETS = [
899901
"//pkg/ccl/logictestccl/tests/3node-tenant-multiregion:3node-tenant-multiregion_test",
900902
"//pkg/ccl/logictestccl/tests/3node-tenant:3node-tenant_test",
901903
"//pkg/ccl/logictestccl/tests/5node:5node_test",
904+
"//pkg/ccl/logictestccl/tests/cockroach-go-testserver-23.2:cockroach-go-testserver-23_2_test",
902905
"//pkg/ccl/logictestccl/tests/fakedist-disk:fakedist-disk_test",
903906
"//pkg/ccl/logictestccl/tests/fakedist-vec-off:fakedist-vec-off_test",
904907
"//pkg/ccl/logictestccl/tests/fakedist:fakedist_test",
@@ -2604,6 +2607,8 @@ GO_TARGETS = [
26042607
"//pkg/util/unique:unique_test",
26052608
"//pkg/util/uuid:uuid",
26062609
"//pkg/util/uuid:uuid_test",
2610+
"//pkg/util/vector:vector",
2611+
"//pkg/util/vector:vector_test",
26072612
"//pkg/util/version:version",
26082613
"//pkg/util/version:version_test",
26092614
"//pkg/util:util",

pkg/ccl/changefeedccl/avro_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ func TestAvroSchema(t *testing.T) {
320320
case types.AnyFamily, types.OidFamily, types.TupleFamily:
321321
// These aren't expected to be needed for changefeeds.
322322
return true
323+
case types.PGVectorFamily:
324+
// We don't support PGVector in Avro yet.
325+
return true
323326
case types.ArrayFamily:
324327
if !randgen.IsAllowedForArray(typ.ArrayContents()) {
325328
return true

pkg/ccl/changefeedccl/encoder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ func TestJsonRountrip(t *testing.T) {
11671167
switch typ {
11681168
case types.Jsonb:
11691169
// Unsupported by sql/catalog/colinfo
1170-
case types.TSQuery, types.TSVector:
1170+
case types.TSQuery, types.TSVector, types.PGVector:
11711171
// Unsupported by pkg/sql/parser
11721172
default:
11731173
if arrayTyp.InternalType.ArrayContents == typ {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# LogicTest: cockroach-go-testserver-23.2
2+
3+
# Verify that all nodes are running the previous version.
4+
5+
query T nodeidx=0
6+
SELECT crdb_internal.node_executable_version()
7+
----
8+
23.2
9+
10+
query T nodeidx=1
11+
SELECT crdb_internal.node_executable_version()
12+
----
13+
23.2
14+
15+
query T nodeidx=2
16+
SELECT crdb_internal.node_executable_version()
17+
----
18+
23.2
19+
20+
statement error syntax error
21+
CREATE TABLE t (v VECTOR(1))
22+
23+
# Upgrade one node to 24.2
24+
25+
upgrade 0
26+
27+
# Verify that node index 0 is now running 24.2 binary.
28+
29+
query T nodeidx=0
30+
SELECT crdb_internal.release_series(crdb_internal.node_executable_version())
31+
----
32+
24.2
33+
34+
statement error pg_vector not supported until version 24.2
35+
CREATE TABLE t (v VECTOR(1))
36+
37+
upgrade 1
38+
39+
upgrade 2
40+
41+
statement ok
42+
SET CLUSTER SETTING version = crdb_internal.node_executable_version();
43+
44+
query T nodeidx=1
45+
SELECT crdb_internal.release_series(crdb_internal.node_executable_version())
46+
----
47+
24.2
48+
49+
query T nodeidx=2
50+
SELECT crdb_internal.release_series(crdb_internal.node_executable_version())
51+
----
52+
24.2
53+
54+
query B retry
55+
SELECT crdb_internal.is_at_least_version('24.1-02')
56+
----
57+
true
58+
59+
# Note: the following statement would succeed if there cluster had an enterprise
60+
# license, but the mixed version logic framework doesn't support adding one.
61+
# This is tested normally in the vector ccl logic test.
62+
statement error pgcode XXC02 use of vector datatype requires an enterprise license
63+
CREATE TABLE t (v VECTOR(1))
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# LogicTest: !local-mixed-23.2
2+
3+
query F
4+
SELECT '[1,2,3]'::vector <-> '[4,5,6]'::vector
5+
----
6+
5.196152422706632
7+
8+
statement error pgcode 42601 dimensions for type vector must be at least 1
9+
CREATE TABLE v (v vector(0))
10+
11+
statement error pgcode 42601 dimensions for type vector cannot exceed 16000
12+
CREATE TABLE v (v vector(16001))
13+
14+
statement error column v is of type vector and thus is not indexable
15+
CREATE TABLE v (v vector(2) PRIMARY KEY)
16+
17+
statement ok
18+
CREATE TABLE v (v vector);
19+
CREATE TABLE v2 (v vector(2))
20+
21+
statement ok
22+
INSERT INTO v VALUES('[1]'), ('[2,3]')
23+
24+
query T rowsort
25+
SELECT * FROM v
26+
----
27+
[1]
28+
[2,3]
29+
30+
query T
31+
SELECT * FROM v WHERE v = '[1,2]'
32+
----
33+
34+
query error pgcode 22000 different vector dimensions 2 and 1
35+
SELECT l2_distance('[1,2]', '[1]')
36+
37+
statement error pgcode 22000 expected 2 dimensions, not 1
38+
INSERT INTO v2 VALUES('[1]'), ('[2,3]')
39+
40+
statement ok
41+
INSERT INTO v2 VALUES('[1,2]'), ('[3,4]')
42+
43+
query T rowsort
44+
SELECT * FROM v2
45+
----
46+
[1,2]
47+
[3,4]
48+
49+
query T
50+
SELECT * FROM v2 WHERE v = '[1,2]'
51+
----
52+
[1,2]
53+
54+
query TT
55+
SELECT '[1,2]'::text::vector, ARRAY[1,2]::vector
56+
----
57+
[1,2] [1,2]
58+
59+
query error pgcode 22004 array must not contain nulls
60+
SELECT ARRAY[1,2,null]::vector
61+
62+
query error pgcode 22000 expected 1 dimensions, not 2
63+
select '[3,1]'::vector(1)
64+
65+
query error pgcode 22000 NaN not allowed in vector
66+
select '[3,NaN]'::vector
67+
68+
query error pgcode 22000 infinite value not allowed in vector
69+
select '[3,Inf]'::vector
70+
71+
query error pgcode 22000 infinite value not allowed in vector
72+
select '[3,-Inf]'::vector
73+
74+
statement ok
75+
CREATE TABLE x (a float[], b real[])
76+
77+
# Test implicit cast from vector to array.
78+
statement ok
79+
INSERT INTO x VALUES('[1,2]'::vector, '[3,4]'::vector)
80+
81+
statement ok
82+
CREATE TABLE v3 (v1 vector(1), v2 vector(1));
83+
INSERT INTO v3 VALUES
84+
('[1]', '[2]'),
85+
('[1]', '[-2]'),
86+
(NULL, '[1]'),
87+
('[1]', NULL)
88+
89+
query FFFTTT rowsort
90+
SELECT v1<->v2, v1<#>v2, v1<=>v2, v1+v2, v1-v2, v1*v2 FROM v3
91+
----
92+
1 -2 0 [3] [-1] [2]
93+
3 2 2 [-1] [3] [-2]
94+
NULL NULL NULL NULL NULL NULL
95+
NULL NULL NULL NULL NULL NULL
96+
97+
query FFFFFI rowsort
98+
SELECT l1_distance(v1,v2), l2_distance(v1,v2), cosine_distance(v1,v2), inner_product(v1,v2), vector_norm(v1), vector_dims(v1) FROM v3
99+
----
100+
1 1 0 2 1 1
101+
3 3 2 -2 1 1
102+
NULL NULL NULL NULL NULL NULL
103+
NULL NULL NULL NULL 1 1

pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)