#!/usr/bin/bash

NROWS=$1

dropdb --if-exists test
createdb test

# monotonic, ascending, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select i from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, ascending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select i, md5(i::text) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-asc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, descending, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select i from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, descending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select i, md5(i::text) from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-desc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1

########################################################################

# monotonic, 100 distinct values, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,100) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 100 values, ascending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,100), md5(i::text) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-asc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 100 distinct values, descending, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,100) from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 100 distinct values, descending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select mod(i, 100), md5(i::text) from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-100-desc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1

########################################################################

# monotonic, 10000 distinct values, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,10000) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 10000 values, ascending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,10000), md5(i::text) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-asc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 10000 distinct values, descending, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select mod(i,10000) from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# monotonic, 10000 distinct values, descending, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select mod(i, 10000), md5(i::text) from generate_series($NROWS,1,-1) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo monotonic-10000-desc int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1

########################################################################

# random, 100 distinct values, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select 100 * random() from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# random, 100 values, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select 100 * random(), md5(i::text) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-100 int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1

########################################################################

# random, 10000 distinct values, int4

psql test -c "create unlogged table t (a int)" > /dev/null 2>&1
psql test -c "insert into t select 10000 * random() from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4 btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4 brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4 brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4 brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1


# random, 10000 values, int4, padded

psql test -c "create unlogged table t (a int, b text)" > /dev/null 2>&1
psql test -c "insert into t select 10000 * random(), md5(i::text) from generate_series(1,$NROWS) s(i)" > /dev/null 2>&1
psql test -c "vacuum analyze t" > /dev/null 2>&1
psql test -c "checkpoint" > /dev/null 2>&1

for r in `seq 1 10`; do

	# regular btree index
	psql test > brin.tmp <<EOF
\timing
create index idx on t (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4-padded btree $r $t

	# brin minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4-padded brin-minmax $r $t

	# brin multi minmax index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_minmax_multi_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4-padded brin-multi-minmax $r $t

	# brin bloom index
	psql test > brin.tmp <<EOF
\timing
create index idx on t using brin (a int4_bloom_ops);
drop index idx;
EOF

	t=`grep Time brin.tmp | head -n 1 | awk '{print $2}'`

	echo random-10000 int4-padded brin-bloom $r $t

done

psql test -c "drop table t" > /dev/null 2>&1

