#!/bin/bash

scale=100     # pgbench scale
fraction=0.8  # fraction of tuples to delete

pgbench -i -s "${scale}" postgres

psql postgres -c "create index seq_1 on pgbench_accounts(aid)"
psql postgres -c "create index seq_2 on pgbench_accounts(aid)"
psql postgres -c "create index seq_3 on pgbench_accounts(aid)"
psql postgres -c "create index seq_4 on pgbench_accounts(aid)"
psql postgres -c "create index seq_5 on pgbench_accounts(aid)"
psql postgres -c "create index seq_6 on pgbench_accounts(aid)"
psql postgres -c "create index seq_7 on pgbench_accounts(aid)"
psql postgres -c "create index seq_8 on pgbench_accounts(aid)"
psql postgres -c "create index seq_9 on pgbench_accounts(aid)"
psql postgres -c "create index seq_10 on pgbench_accounts(aid)"

psql postgres -c "create index random_1 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_2 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_3 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_4 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_5 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_6 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_7 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_8 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_9 on pgbench_accounts((hashint4(aid)))"
psql postgres -c "create index random_10 on pgbench_accounts((hashint4(aid)))"

psql postgres -c 'delete from pgbench_accounts where random() < '${fraction};
psql postgres -c "checkpoint"
sync
time psql postgres -c "vacuum verbose pgbench_accounts"
