I am trying to run a stress test on a vector data type table. But not able to run pgbench with custom functions: random_between and random_array. Kindly suggest how to perform the stress test with custom functions.
random_between:
CREATE OR REPLACE FUNCTION random_between(low INT ,high INT)
RETURNS INT AS
$$
BEGIN
RETURN floor(random()* (high-low + 1) + low);
END;
$$ language 'plpgsql' STRICT;
random_array:
CREATE OR REPLACE FUNCTION random_array(dim integer)
RETURNS DOUBLE PRECISION[]
AS $$
SELECT array_agg(random())
FROM generate_series(1, dim);
$$
LANGUAGE SQL
VOLATILE
COST 1;
Table “public.vtest”
+------------+-----------------------------+-----------+----------+---------+
| Column | Type | Collation | Nullable | Default |
+------------+-----------------------------+-----------+----------+---------+
| id | bigint | | | |
| v | vector(1536) | | | |
| created_at | timestamp without time zone | | | now() |
+------------+-----------------------------+-----------+----------+---------+
cat simple-read-write.sql
set id random_between(1, 100000)
set v random_array(1536)::VECTOR(1536)
BEGIN;
--UPDATE
UPDATE vtest SET v = :v WHERE id = :id;
--SELECT
SELECT v FROM vtet WHERE id = :id;
--INSERT
INSERT INTO vtest (id,v,created_at) VALUES (:id, :v, CURRENT_TIMESTAMP);
END;
Pgbench command:
/usr/pgsql-14/bin/pgbench -f ./simple-read-write.sql -c2 -T10 -P1 -U postgres -p 5432 -d pgvector
Error:
set id random_between(1, 100000)
^ error found here
set v random_array(1536)::VECTOR(1536)
^ error found here
Expecting to run pgbench with custom functions and custom sql script.