pgvector.git / summary / log / commit / refs
commit 2d85af51a80734c8d9baa3500db2b2bde2780540
Author: Andrew Kane <andrew@ankane.org>
Date: Wed Sep 25 22:53:34 2024 +0000
Added test for IVFFlat costs [skip ci]
test/t/040_ivfflat_cost.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/test/t/040_ivfflat_cost.pl b/test/t/040_ivfflat_cost.pl
new file mode 100644
index 00000000..8042e4db
--- /dev/null
+++ b/test/t/040_ivfflat_cost.pl
@@ -0,0 +1,45 @@
+use strict;
+use warnings FATAL => 'all';
+use PostgreSQL::Test::Cluster;
+use PostgreSQL::Test::Utils;
+use Test::More;
+
+my @dims = (384, 1536);
+my $limit = 10;
+
+# Initialize node
+my $node = PostgreSQL::Test::Cluster->new('node');
+$node->init;
+$node->start;
+
+$node->safe_psql("postgres", "CREATE EXTENSION vector;");
+
+for my $dim (@dims)
+{
+ my $array_sql = join(",", ('random()') x $dim);
+
+ # Create table and index
+ $node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim));");
+ $node->safe_psql("postgres",
+ "INSERT INTO tst SELECT i, ARRAY[$array_sql] FROM generate_series(1, 10000) i;"
+ );
+ $node->safe_psql("postgres", "CREATE INDEX idx ON tst USING ivfflat (v vector_l2_ops) WITH (lists = 10);");
+ $node->safe_psql("postgres", "ANALYZE tst;");
+
+ # Generate query
+ my @r = ();
+ for (1 .. $dim)
+ {
+ push(@r, rand());
+ }
+ my $query = "[" . join(",", @r) . "]";
+
+ my $explain = $node->safe_psql("postgres", qq(
+ EXPLAIN ANALYZE SELECT i FROM tst ORDER BY v <-> '$query' LIMIT $limit;
+ ));
+ like($explain, qr/Index Scan using idx/);
+
+ $node->safe_psql("postgres", "DROP TABLE tst;");
+}
+
+done_testing();
[parent: e0ad441306fa]