Skip to content

Commit b269a74

Browse files
committed
sql/vecindex: make hnsw alias for cspann for index creation
This commit adds `hnsw` to the accepted list of index types when a vector index is defined using the `USING` syntax. However, we will silently provide a `cspann` index instead. This change is made in anticipation of third-party tools that want to use `cspann`. Fixes #143109 Release note (sql change): When creating a vector index via the `USING` syntax, is is now possible to specify `hnsw` as the index type, although a `cspann` vector index will still be provided. The goal of this change is to increase compatibility with third-party tools.
1 parent 10a44fe commit b269a74

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

pkg/sql/logictest/testdata/logic_test/vector_index

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ ALTER TABLE simple ALTER PRIMARY KEY USING COLUMNS (b)
3838
statement notice CREATE VECTOR INDEX will disable writes to the table while the index is being built
3939
CREATE INDEX ON simple USING cspann (vec1 ASC);
4040

41+
# We allow hnsw as an alias for cspann.
42+
statement ok
43+
CREATE INDEX ON simple USING hnsw (vec1);
44+
4145
query TT
4246
SHOW CREATE TABLE simple
4347
----
@@ -50,6 +54,7 @@ simple CREATE TABLE public.simple (
5054
VECTOR INDEX simple_vec1_idx1 (vec1 vector_l2_ops),
5155
UNIQUE INDEX simple_a_key (a ASC),
5256
VECTOR INDEX simple_vec1_idx2 (vec1 vector_l2_ops),
57+
VECTOR INDEX simple_vec1_idx3 (vec1 vector_l2_ops),
5358
FAMILY fam_0_a_vec1_b (a, vec1, b)
5459
)
5560

@@ -312,8 +317,8 @@ statement error vector indexes don.t support stored columns
312317
CREATE VECTOR INDEX on vec_errors (vec1) STORING (b);
313318

314319
# Try to use unsupported vector index type.
315-
statement error at or near "hnsw": syntax error: unrecognized access method: hnsw
316-
CREATE INDEX ON vec_errors USING hnsw (vec1)
320+
statement error at or near "ivfflat": syntax error: unrecognized access method: ivfflat
321+
CREATE INDEX ON vec_errors USING ivfflat (vec1)
317322

318323
# Operator classes other than vector_l2_ops are not (yet) supported.
319324
statement error pgcode 0A000 pq: unimplemented: operator class vector_l1_ops is not supported

pkg/sql/parser/sql.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12394,7 +12394,7 @@ opt_index_access_method:
1239412394
val = idxtype.INVERTED
1239512395
case "btree":
1239612396
val = idxtype.FORWARD
12397-
case "cspann":
12397+
case "cspann", "hnsw":
1239812398
val = idxtype.VECTOR
1239912399
case "hash", "spgist", "brin":
1240012400
return unimplemented(sqllex, "index using " + $2)

pkg/sql/parser/testdata/create_index

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,3 +532,11 @@ CREATE VECTOR INDEX a ON b (c) WITH ('build_beam_size' = 16, 'min_partition_size
532532
CREATE VECTOR INDEX a ON b (c) WITH ('build_beam_size' = (16), 'min_partition_size' = (8), 'max_partition_size' = (32)) -- fully parenthesized
533533
CREATE VECTOR INDEX a ON b (c) WITH ('build_beam_size' = _, 'min_partition_size' = _, 'max_partition_size' = _) -- literals removed
534534
CREATE VECTOR INDEX _ ON _ (_) WITH ('build_beam_size' = 16, 'min_partition_size' = 8, 'max_partition_size' = 32) -- identifiers removed
535+
536+
parse
537+
CREATE INDEX a ON b USING HNSW (c)
538+
----
539+
CREATE VECTOR INDEX a ON b (c) -- normalized!
540+
CREATE VECTOR INDEX a ON b (c) -- fully parenthesized
541+
CREATE VECTOR INDEX a ON b (c) -- literals removed
542+
CREATE VECTOR INDEX _ ON _ (_) -- identifiers removed

0 commit comments

Comments
 (0)