rm -f params.txt
for series_end in 10000 10000000 1000000 100000; do
	for series_step in 10000 10000000 1000000 100000; do
		for workers in 0 2 4; do
			for work_mem in '4MB' '128MB'; do
				echo $series_end $series_step $workers $work_mem >> params.txt
			done;
		done;
	done;
done;

for r in `seq 1 3`; do

	sort -R params.txt > params.random

	while read line; do

		IFS=" " read -a strarr <<< "$line"

		series_end="${strarr[0]}"
		series_stop="${strarr[1]}"
		workers="${strarr[2]}"
		work_mem="${strarr[3]}"

		echo "set work_mem = '$work_mem';" > script.sql
		echo "set max_parallel_workers_per_gather = '$workers';" >> script.sql

		sed "s/SERIES_END/$series_end/" script.template | sed "s/SERIES_STEP/$series_step/" >> script.sql

		d=`date`
		echo "================================ $d =====================================" >> script.log 2>&1
		cat script.sql >> script.log 2>&1

		dropdb test
		createdb test

		psql test < script.sql >> script.log 2>&1

		sleep 15

	done < params.random

done;
