#!/bin/sh

for power in 5 6;
do
  table=t${power}
  index=${table}_trgm_re_idx
  echo "-- generating table $table with index $index";
  time perl -E'
  sub ss{ join"",@_[ map{rand @_} 1 .. shift ] };
  say(ss(80,"a".."g"," ","h".."m"," ","n".."s"," ","t".."z"))
     for 1 .. 1e'"${power};" \
  | psql -aqXc "
    drop table if exists $table;
    create table $table(txt text);
    copy $table from stdin;";
  echo "set session maintenance_work_mem='1GB';
    create index $index on $table using gin (txt gin_trgm_ops);
    analyze $table;" | psql -qtAX;
  echo "select current_setting('server_version') as version,'$table' as table
  ,pg_size_pretty(pg_relation_size('public.$table')) as data
  ,pg_size_pretty(pg_relation_size('public.$index')) as idx
  ,(select reltuples+0 from pg_class where relname='$table')as rowcount;"|psql;
done

echo

#if [[ 1 -eq 1 ]];
#then
#	echo "-- pg_dump -F c -f azjunk5.dump testdb"
#	         pg_dump -F c -f azjunk5.dump testdb
#fi


