-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98d6e5e
commit d6c7da7
Showing
12 changed files
with
137 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
\ir utils/random_array.sql | ||
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | ||
begin | ||
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$ | ||
begin | ||
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
\ir utils/random_array.sql | ||
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | ||
begin | ||
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$ | ||
begin | ||
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
\ir utils/random_array.sql | ||
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$ | ||
begin | ||
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
CREATE OR REPLACE FUNCTION random_array(dim integer, min real, max real) RETURNS REAL[] AS $BODY$ | ||
begin | ||
return (select array_agg(random() * (max - min) + min) from generate_series (0, dim - 1)); | ||
end | ||
$BODY$ LANGUAGE plpgsql; | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset | ||
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset | ||
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset | ||
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
id | ||
------ | ||
1111 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1; | ||
id | ||
------ | ||
2222 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1; | ||
id | ||
------ | ||
3333 | ||
(1 row) | ||
|
||
SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1; | ||
id | ||
------ | ||
4444 | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
\ir utils/sift10k_array.sql | ||
\ir utils/random_array.sql | ||
|
||
CREATE SEQUENCE serial START 10001; | ||
CREATE INDEX ON sift_base10k USING HNSW (v) WITH (M=5, ef=20, ef_construction=20); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
\ir utils/random_array.sql | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
\ir utils/random_array.sql | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
\ir utils/random_array.sql | ||
DO $$ | ||
BEGIN | ||
FOR i IN 1..10 LOOP | ||
INSERT INTO sift_base10k (v) VALUES (random_array(128, 0, 128)); | ||
END LOOP; | ||
END; $$ | ||
BEGIN; | ||
INSERT INTO sift_base10k (id, v) VALUES | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)), | ||
(nextval('serial'), random_array(128, 0, 128)); | ||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SELECT v AS v1111 FROM sift_base10k WHERE id = 1111 \gset | ||
SELECT v AS v2222 FROM sift_base10k WHERE id = 2222 \gset | ||
SELECT v AS v3333 FROM sift_base10k WHERE id = 3333 \gset | ||
SELECT v AS v4444 FROM sift_base10k WHERE id = 4444 \gset | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v1111' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v2222' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v3333' ASC LIMIT 1; | ||
SELECT id FROM sift_base10k ORDER BY v <-> :'v4444' ASC LIMIT 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters