From 08d034065565dee30cb626bf311cb1440bcdfce0 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 10 Oct 2024 14:24:26 -0700 Subject: [PATCH] Improved IVFFlat vacuum test [skip ci] --- test/t/002_ivfflat_vacuum.pl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/t/002_ivfflat_vacuum.pl b/test/t/002_ivfflat_vacuum.pl index d4cfeaf..a7f1d9e 100644 --- a/test/t/002_ivfflat_vacuum.pl +++ b/test/t/002_ivfflat_vacuum.pl @@ -6,13 +6,7 @@ use Test::More; my $dim = 3; -my @r = (); -for (1 .. $dim) -{ - my $v = int(rand(1000)) + 1; - push(@r, "i % $v"); -} -my $array_sql = join(", ", @r); +my $array_sql = join(",", ('random()') x $dim); # Initialize node my $node = PostgreSQL::Test::Cluster->new('node'); @@ -23,19 +17,20 @@ $node->start; $node->safe_psql("postgres", "CREATE EXTENSION vector;"); $node->safe_psql("postgres", "CREATE TABLE tst (i int4, v vector($dim));"); $node->safe_psql("postgres", - "INSERT INTO tst SELECT i % 10, ARRAY[$array_sql] FROM generate_series(1, 100000) i;" + "INSERT INTO tst SELECT i, ARRAY[$array_sql] FROM generate_series(1, 100000) i;" ); $node->safe_psql("postgres", "CREATE INDEX ON tst USING ivfflat (v vector_l2_ops);"); # Get size my $size = $node->safe_psql("postgres", "SELECT pg_total_relation_size('tst_v_idx');"); +# Store values +$node->safe_psql("postgres", "CREATE TABLE tmp AS SELECT * FROM tst;"); + # Delete all, vacuum, and insert same data $node->safe_psql("postgres", "DELETE FROM tst;"); $node->safe_psql("postgres", "VACUUM tst;"); -$node->safe_psql("postgres", - "INSERT INTO tst SELECT i % 10, ARRAY[$array_sql] FROM generate_series(1, 100000) i;" -); +$node->safe_psql("postgres", "INSERT INTO tst SELECT * FROM tmp;"); # Check size my $new_size = $node->safe_psql("postgres", "SELECT pg_total_relation_size('tst_v_idx');");