|
| 1 | +\ir utils/small_world_array.sql |
| 2 | +CREATE TABLE small_world ( |
| 3 | + id VARCHAR(3), |
| 4 | + b BOOLEAN, |
| 5 | + v REAL[3] |
| 6 | +); |
| 7 | +INSERT INTO small_world (id, b, v) VALUES |
| 8 | + ('000', TRUE, '{0,0,0}'), |
| 9 | + ('001', TRUE, '{0,0,1}'), |
| 10 | + ('010', FALSE, '{0,1,0}'), |
| 11 | + ('011', TRUE, '{0,1,1}'), |
| 12 | + ('100', FALSE, '{1,0,0}'), |
| 13 | + ('101', FALSE, '{1,0,1}'), |
| 14 | + ('110', FALSE, '{1,1,0}'), |
| 15 | + ('111', TRUE, '{1,1,1}'); |
| 16 | +DROP EXTENSION lantern; |
| 17 | +\set ON_ERROR_STOP off |
| 18 | +-- make sure the extension was dropped. |
| 19 | +CREATE INDEX ON small_world USING hnsw (v) WITH (dim=3); |
| 20 | +ERROR: access method "hnsw" does not exist |
| 21 | +\set ON_ERROR_STOP on |
| 22 | +-- test creating lantern on different schemas |
| 23 | +CREATE SCHEMA schema1; |
| 24 | +CREATE SCHEMA schema2; |
| 25 | +CREATE EXTENSION lantern WITH SCHEMA schema1; |
| 26 | +-- show all the extension functions and operators |
| 27 | +SELECT ne.nspname AS extschema, p.proname, np.nspname AS proschema |
| 28 | +FROM pg_catalog.pg_extension AS e |
| 29 | + INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) |
| 30 | + INNER JOIN pg_catalog.pg_proc AS p ON (p.oid = d.objid) |
| 31 | + INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace) |
| 32 | + INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = p.pronamespace) |
| 33 | +WHERE d.deptype = 'e' AND e.extname = 'lantern' |
| 34 | +ORDER BY 1, 3; |
| 35 | + extschema | proname | proschema |
| 36 | +-----------+------------------------------+------------------- |
| 37 | + schema1 | _create_ldb_operator_classes | _lantern_internal |
| 38 | + schema1 | ldb_generic_dist | schema1 |
| 39 | + schema1 | ldb_generic_dist | schema1 |
| 40 | + schema1 | hnsw_handler | schema1 |
| 41 | + schema1 | cos_dist | schema1 |
| 42 | + schema1 | hamming_dist | schema1 |
| 43 | + schema1 | l2sq_dist | schema1 |
| 44 | +(7 rows) |
| 45 | + |
| 46 | +-- show all the extension operators |
| 47 | +SELECT ne.nspname AS extschema, op.oprname, np.nspname AS proschema |
| 48 | +FROM pg_catalog.pg_extension AS e |
| 49 | + INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) |
| 50 | + INNER JOIN pg_catalog.pg_operator AS op ON (op.oid = d.objid) |
| 51 | + INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace) |
| 52 | + INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = op.oprnamespace) |
| 53 | +WHERE d.deptype = 'e' AND e.extname = 'lantern' |
| 54 | +ORDER BY 1, 3; |
| 55 | + extschema | oprname | proschema |
| 56 | +-----------+---------+----------- |
| 57 | + schema1 | <-> | schema1 |
| 58 | + schema1 | <-> | schema1 |
| 59 | +(2 rows) |
| 60 | + |
| 61 | +SET search_path TO public, schema1; |
| 62 | +-- extension function is accessible |
| 63 | +SELECT l2sq_dist(ARRAY[1.0, 2.0, 3.0], ARRAY[4.0, 5.0, 6.0]); |
| 64 | + l2sq_dist |
| 65 | +----------- |
| 66 | + 27 |
| 67 | +(1 row) |
| 68 | + |
| 69 | +CREATE INDEX hnsw_index ON small_world USING hnsw(v) WITH (dim=3); |
| 70 | +INFO: done init usearch index |
| 71 | +INFO: inserted 8 elements |
| 72 | +INFO: done saving 8 vectors |
| 73 | +\set ON_ERROR_STOP off |
| 74 | +-- lantern does not support relocation. |
| 75 | +-- Postgres will not allow it to support this since its objects span over more than one schema |
| 76 | +ALTER EXTENSION lantern SET SCHEMA schema2; |
| 77 | +ERROR: extension "lantern" does not support SET SCHEMA |
| 78 | +\set ON_ERROR_STOP on |
| 79 | +SELECT ne.nspname AS extschema, op.oprname, np.nspname AS proschema |
| 80 | +FROM pg_catalog.pg_extension AS e |
| 81 | + INNER JOIN pg_catalog.pg_depend AS d ON (d.refobjid = e.oid) |
| 82 | + INNER JOIN pg_catalog.pg_operator AS op ON (op.oid = d.objid) |
| 83 | + INNER JOIN pg_catalog.pg_namespace AS ne ON (ne.oid = e.extnamespace) |
| 84 | + INNER JOIN pg_catalog.pg_namespace AS np ON (np.oid = op.oprnamespace) |
| 85 | +WHERE d.deptype = 'e' AND e.extname = 'lantern' |
| 86 | +ORDER BY 1, 3; |
| 87 | + extschema | oprname | proschema |
| 88 | +-----------+---------+----------- |
| 89 | + schema1 | <-> | schema1 |
| 90 | + schema1 | <-> | schema1 |
| 91 | +(2 rows) |
| 92 | + |
| 93 | +SET search_path TO public, schema2; |
| 94 | +--extension access method is still accessible since access methods are not schema-qualified |
| 95 | +CREATE INDEX hnsw_index2 ON small_world USING hnsw(v) WITH (dim=3); |
| 96 | +INFO: done init usearch index |
| 97 | +INFO: inserted 8 elements |
| 98 | +INFO: done saving 8 vectors |
| 99 | +\set ON_ERROR_STOP on |
| 100 | +-- extension function cannot be found without schema-qualification |
| 101 | +SELECT l2sq_dist(ARRAY[1.0, 2.0, 3.0], ARRAY[4.0, 5.0, 6.0]); |
| 102 | +ERROR: function l2sq_dist(numeric[], numeric[]) does not exist at character 8 |
0 commit comments