Skip to content

Commit 2ad9ed6

Browse files
tjgreen42syvb
andauthored
Release 0.7.1 (#226)
Testing: ran upgrade tests manually. --------- Co-authored-by: Smitty <smitty@timescale.com>
1 parent a3aab4f commit 2ad9ed6

12 files changed

+196
-2
lines changed

pgvectorscale/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vectorscale"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
edition = "2021"
55

66
[lib]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vectorscale--0.7.0--0.7.1.sql
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/* <begin connected objects> */
2+
/*
3+
This file is auto generated by pgrx.
4+
5+
The ordering of items is not stable, it is driven by a dependency graph.
6+
*/
7+
/* </end connected objects> */
8+
9+
/* <begin connected objects> */
10+
-- pgvectorscale/src/access_method/mod.rs:38
11+
-- vectorscale::access_method::amhandler
12+
13+
CREATE OR REPLACE FUNCTION diskann_amhandler(internal) RETURNS index_am_handler PARALLEL SAFE IMMUTABLE STRICT COST 0.0001 LANGUAGE c AS '$libdir/vectorscale-0.7.1', 'amhandler_wrapper';
14+
15+
DO $$
16+
DECLARE
17+
c int;
18+
BEGIN
19+
SELECT count(*)
20+
INTO c
21+
FROM pg_catalog.pg_am a
22+
WHERE a.amname = 'diskann';
23+
24+
IF c = 0 THEN
25+
CREATE ACCESS METHOD diskann TYPE INDEX HANDLER diskann_amhandler;
26+
END IF;
27+
END;
28+
$$;
29+
/* </end connected objects> */
30+
31+
/* <begin connected objects> */
32+
-- pgvectorscale/src/access_method/distance.rs:47
33+
-- vectorscale::access_method::distance::distance_type_cosine
34+
CREATE OR REPLACE FUNCTION "distance_type_cosine"() RETURNS smallint /* i16 */
35+
IMMUTABLE STRICT PARALLEL SAFE
36+
LANGUAGE c /* Rust */
37+
AS '$libdir/vectorscale-0.7.1', 'distance_type_cosine_wrapper';
38+
/* </end connected objects> */
39+
40+
/* <begin connected objects> */
41+
-- pgvectorscale/src/access_method/distance.rs:57
42+
-- vectorscale::access_method::distance::distance_type_inner_product
43+
CREATE OR REPLACE FUNCTION "distance_type_inner_product"() RETURNS smallint /* i16 */
44+
IMMUTABLE STRICT PARALLEL SAFE
45+
LANGUAGE c /* Rust */
46+
AS '$libdir/vectorscale-0.7.1', 'distance_type_inner_product_wrapper';
47+
/* </end connected objects> */
48+
49+
/* <begin connected objects> */
50+
-- pgvectorscale/src/access_method/distance.rs:52
51+
-- vectorscale::access_method::distance::distance_type_l2
52+
CREATE OR REPLACE FUNCTION "distance_type_l2"() RETURNS smallint /* i16 */
53+
IMMUTABLE STRICT PARALLEL SAFE
54+
LANGUAGE c /* Rust */
55+
AS '$libdir/vectorscale-0.7.1', 'distance_type_l2_wrapper';
56+
/* </end connected objects> */
57+
58+
/* <begin connected objects> */
59+
-- pgvectorscale/src/access_method/mod.rs:290
60+
-- vectorscale::access_method::smallint_array_overlap
61+
CREATE OR REPLACE FUNCTION "smallint_array_overlap"(
62+
"left" smallint[], /* pgrx::datum::array::Array<i16> */
63+
"right" smallint[] /* pgrx::datum::array::Array<i16> */
64+
) RETURNS bool /* bool */
65+
IMMUTABLE STRICT PARALLEL SAFE
66+
LANGUAGE c /* Rust */
67+
AS '$libdir/vectorscale-0.7.1', 'smallint_array_overlap_wrapper';
68+
/* </end connected objects> */
69+
70+
/* <begin connected objects> */
71+
-- pgvectorscale/src/access_method/mod.rs:172
72+
-- requires:
73+
-- amhandler
74+
-- distance_type_cosine
75+
-- distance_type_l2
76+
-- distance_type_inner_product
77+
-- smallint_array_overlap
78+
79+
80+
DO $$
81+
DECLARE
82+
have_cos_ops int;
83+
have_l2_ops int;
84+
have_ip_ops int;
85+
have_label_ops int;
86+
BEGIN
87+
-- Has cosine operator class been installed previously?
88+
SELECT count(*)
89+
INTO have_cos_ops
90+
FROM pg_catalog.pg_opclass c
91+
WHERE c.opcname = 'vector_cosine_ops'
92+
AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann')
93+
AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@');
94+
95+
-- Has L2 operator class been installed previously?
96+
SELECT count(*)
97+
INTO have_l2_ops
98+
FROM pg_catalog.pg_opclass c
99+
WHERE c.opcname = 'vector_l2_ops'
100+
AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann')
101+
AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@');
102+
103+
-- Has inner product operator class been installed previously?
104+
SELECT count(*)
105+
INTO have_ip_ops
106+
FROM pg_catalog.pg_opclass c
107+
WHERE c.opcname = 'vector_ip_ops'
108+
AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann')
109+
AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@');
110+
111+
-- Has label-filtering support been installed previously?
112+
SELECT count(*)
113+
INTO have_label_ops
114+
FROM pg_catalog.pg_opclass c
115+
WHERE c.opcname = 'vector_smallint_label_ops'
116+
AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann')
117+
AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@');
118+
119+
IF have_cos_ops = 0 THEN
120+
CREATE OPERATOR CLASS vector_cosine_ops DEFAULT
121+
FOR TYPE vector USING diskann AS
122+
OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops,
123+
FUNCTION 1 distance_type_cosine();
124+
ELSIF have_l2_ops = 0 THEN
125+
-- Upgrade from 0.4.0 to 0.5.0. Update cosine opclass to include
126+
-- the distance_type_cosine function.
127+
INSERT INTO pg_amproc (oid, amprocfamily, amproclefttype, amprocrighttype, amprocnum, amproc)
128+
SELECT (select (max(oid)::int + 1)::oid from pg_amproc), c.opcfamily, c.opcintype, c.opcintype, 1, '@extschema@.distance_type_l2'::regproc
129+
FROM pg_opclass c, pg_am a
130+
WHERE a.oid = c.opcmethod AND c.opcname = 'vector_cosine_ops' AND a.amname = 'diskann';
131+
END IF;
132+
133+
IF have_l2_ops = 0 THEN
134+
CREATE OPERATOR CLASS vector_l2_ops
135+
FOR TYPE vector USING diskann AS
136+
OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops,
137+
FUNCTION 1 distance_type_l2();
138+
END IF;
139+
140+
IF have_ip_ops = 0 THEN
141+
CREATE OPERATOR CLASS vector_ip_ops
142+
FOR TYPE vector USING diskann AS
143+
OPERATOR 1 <#> (vector, vector) FOR ORDER BY float_ops,
144+
FUNCTION 1 distance_type_inner_product();
145+
END IF;
146+
147+
-- First, check if the && operator exists for smallint[]
148+
IF NOT EXISTS (
149+
SELECT 1 FROM pg_operator
150+
WHERE oprname = '&&'
151+
AND oprleft = 'smallint[]'::regtype
152+
AND oprright = 'smallint[]'::regtype
153+
) THEN
154+
-- Create the && operator for smallint[]
155+
CREATE OPERATOR && (
156+
LEFTARG = smallint[],
157+
RIGHTARG = smallint[],
158+
PROCEDURE = smallint_array_overlap,
159+
COMMUTATOR = &&,
160+
RESTRICT = contsel,
161+
JOIN = contjoinsel
162+
);
163+
164+
-- Register the operator with the system catalogs for proper selectivity estimation
165+
-- This is done by adding entries to pg_amop for the array_ops operator class
166+
EXECUTE format(
167+
'ALTER OPERATOR FAMILY array_ops USING btree ADD OPERATOR 3 && (smallint[], smallint[]) FOR SEARCH'
168+
);
169+
END IF;
170+
171+
IF have_label_ops = 0 THEN
172+
CREATE OPERATOR CLASS vector_smallint_label_ops
173+
DEFAULT FOR TYPE smallint[] USING diskann AS
174+
OPERATOR 1 &&;
175+
END IF;
176+
END;
177+
$$;
178+
/* </end connected objects> */
179+

pgvectorscale/src/access_method/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub extern "C" fn amvalidate(_opclassoid: pg_sys::Oid) -> bool {
287287

288288
/// Implementation of the array overlap operator (&&) for smallint arrays
289289
/// This function checks if two smallint arrays have at least one element in common
290-
#[pg_extern(immutable, parallel_safe)]
290+
#[pg_extern(immutable, parallel_safe, create_or_replace)]
291291
pub fn smallint_array_overlap(left: Array<i16>, right: Array<i16>) -> bool {
292292
// Early return for empty arrays
293293
if left.is_empty() || right.is_empty() {

pgvectorscale/src/access_method/upgrade_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,11 @@ pub mod tests {
292292
fn test_upgrade_from_0_6_0() {
293293
test_upgrade_base("0.6.0", "0.12.5", "pgvectorscale", "vectorscale", "diskann");
294294
}
295+
296+
#[ignore]
297+
#[serial]
298+
#[test]
299+
fn test_upgrade_from_0_7_0() {
300+
test_upgrade_base("0.7.0", "0.12.9", "pgvectorscale", "vectorscale", "diskann");
301+
}
295302
}

0 commit comments

Comments
 (0)