#!/bin/bash

export PATH=$PATH:$PWD/bin
dbname=postgres
secs=30
psql -c "alter system set max_parallel_workers_per_gather = 0;" $dbname > /dev/null
psql -c "select pg_reload_conf();" $dbname > /dev/null
psql -c "create extension if not exists url;" $dbname > /dev/null


cat << EOSQL > bench.sql
WITH u(url) AS MATERIALIZED (
  SELECT 'https://example.com#comments'::url
)
SELECT url_fragment_set(
           url_path_set(
             url_port_set(
               url_host_set(
                 url_password_set(
                   url_username_set(
                     url_scheme_set( url, 'wss' )
                   , 'guest' )
                 , '12345' )
               , '事例.com' )
             , '8080' )
           , '/а/б/в' )
       , 'comment' )
  FROM u;
EOSQL

for i in {1..5}
do
	pgbench -n -f bench.sql -M prepared -T $secs $dbname | grep tps
done