|
| 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 | +-- src/access_method/mod.rs:29 |
| 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.5.0', '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 | +-- src/access_method/distance.rs:42 |
| 33 | +-- vectorscale::access_method::distance::distance_type_cosine |
| 34 | +CREATE FUNCTION "distance_type_cosine"() RETURNS smallint /* i16 */ |
| 35 | +IMMUTABLE STRICT PARALLEL SAFE |
| 36 | +LANGUAGE c /* Rust */ |
| 37 | +AS '$libdir/vectorscale-0.5.0', 'distance_type_cosine_wrapper'; |
| 38 | +/* </end connected objects> */ |
| 39 | + |
| 40 | +/* <begin connected objects> */ |
| 41 | +-- src/access_method/distance.rs:47 |
| 42 | +-- vectorscale::access_method::distance::distance_type_l2 |
| 43 | +CREATE FUNCTION "distance_type_l2"() RETURNS smallint /* i16 */ |
| 44 | +IMMUTABLE STRICT PARALLEL SAFE |
| 45 | +LANGUAGE c /* Rust */ |
| 46 | +AS '$libdir/vectorscale-0.5.0', 'distance_type_l2_wrapper'; |
| 47 | +/* </end connected objects> */ |
| 48 | + |
| 49 | +/* <begin connected objects> */ |
| 50 | +-- src/access_method/mod.rs:163 |
| 51 | +-- requires: |
| 52 | +-- amhandler |
| 53 | +-- distance_type_cosine |
| 54 | +-- distance_type_l2 |
| 55 | + |
| 56 | + |
| 57 | +DO $$ |
| 58 | +DECLARE |
| 59 | + have_cos_ops int; |
| 60 | + have_l2_ops int; |
| 61 | +BEGIN |
| 62 | + -- Has cosine operator class been installed previously? |
| 63 | + SELECT count(*) |
| 64 | + INTO have_cos_ops |
| 65 | + FROM pg_catalog.pg_opclass c |
| 66 | + WHERE c.opcname = 'vector_cosine_ops' |
| 67 | + AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann') |
| 68 | + AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@'); |
| 69 | + |
| 70 | + -- Has L2 operator class been installed previously? |
| 71 | + SELECT count(*) |
| 72 | + INTO have_l2_ops |
| 73 | + FROM pg_catalog.pg_opclass c |
| 74 | + WHERE c.opcname = 'vector_l2_ops' |
| 75 | + AND c.opcmethod = (SELECT oid FROM pg_catalog.pg_am am WHERE am.amname = 'diskann') |
| 76 | + AND c.opcnamespace = (SELECT oid FROM pg_catalog.pg_namespace where nspname='@extschema@'); |
| 77 | + |
| 78 | + IF have_cos_ops = 0 THEN |
| 79 | + -- Fresh install from scratch |
| 80 | + CREATE OPERATOR CLASS vector_cosine_ops DEFAULT |
| 81 | + FOR TYPE vector USING diskann AS |
| 82 | + OPERATOR 1 <=> (vector, vector) FOR ORDER BY float_ops, |
| 83 | + FUNCTION 1 distance_type_cosine(); |
| 84 | + |
| 85 | + CREATE OPERATOR CLASS vector_l2_ops |
| 86 | + FOR TYPE vector USING diskann AS |
| 87 | + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops, |
| 88 | + FUNCTION 1 distance_type_l2(); |
| 89 | + ELSIF have_l2_ops = 0 THEN |
| 90 | + -- Upgrade to add L2 distance support and update cosine opclass to |
| 91 | + -- include the distance_type_cosine function |
| 92 | + INSERT INTO pg_amproc (oid, amprocfamily, amproclefttype, amprocrighttype, amprocnum, amproc) |
| 93 | + SELECT (select (max(oid)::int + 1)::oid from pg_amproc), c.opcfamily, c.opcintype, c.opcintype, 1, '@extschema@.distance_type_l2'::regproc |
| 94 | + FROM pg_opclass c, pg_am a |
| 95 | + WHERE a.oid = c.opcmethod AND c.opcname = 'vector_cosine_ops' AND a.amname = 'diskann'; |
| 96 | + |
| 97 | + CREATE OPERATOR CLASS vector_l2_ops |
| 98 | + FOR TYPE vector USING diskann AS |
| 99 | + OPERATOR 1 <-> (vector, vector) FOR ORDER BY float_ops, |
| 100 | + FUNCTION 1 distance_type_l2(); |
| 101 | + END IF; |
| 102 | +END; |
| 103 | +$$; |
| 104 | +/* </end connected objects> */ |
| 105 | + |
0 commit comments