select_deform_bench.sh.txt

text/plain

Filename: select_deform_bench.sh.txt
Type: text/plain
Part: 0
Message: Selective tuple deformation
#!/bin/bash

seconds=5
maxcols=40
database=postgres
rows=1000000
varlena_first=0

unameOut="$(uname -s)"
case "${unameOut}" in
    Linux*)     machine=Linux;;
    Darwin*)    machine=Mac;;
    CYGWIN*)    machine=Cygwin;;
    MINGW*)     machine=MinGw;;
    MSYS_NT*)   machine=MSys;;
    *)          machine="UNKNOWN:${unameOut}"
esac

if [[ "$1" == "setup" ]]
then
	echo "Running Setup..."
	tablename="t_${maxcols}_cols"
	psql -c "drop table if exists $tablename;" $database

	sql="create table $tablename ("

	# Add a varlena as the first column when enabled
	if [ $varlena_first -ne 0 ]
	then
		sql="${sql}t text not null default '',"
	fi

	for i in $(seq 1 $maxcols)
	do
		sql="${sql}c${i} int not null default 1,"
	done
	sql="${sql}col int not null);"
	psql -c "$sql" $database
	psql -c "insert into $tablename (col) select a from generate_Series(1,$rows) a;" $database
	psql -c "vacuum freeze analyze $tablename;" $database
	psql -c "create extension if not exists pg_prewarm;" $database
elif [[ "$1" == "run" ]]
then
	echo "Running benchmark..."
	psql -c "select pg_prewarm('"t_${maxcols}_cols"'::regclass);" $database
	for setting in "incremental" "selective" "auto"
	do
		psql -c "alter system set debug_tuple_deform = '$setting';" $database > /dev/null
		psql -c "select pg_reload_conf();" $database > /dev/null
		echo "Testing debug_tuple_deform = $setting"

		echo "ncols,$setting (ms)"	
		for c in $(seq 0 $maxcols)
		do
			sql="select "
			startcol=$((maxcols - c + 1))
			for i in $(seq $startcol $maxcols)
			do
				sql="${sql}c${i},"
			done
			sql="${sql}col FROM t_40_cols WHERE col = 0"
			echo $sql > bench.sql
			ncols=$((c + 1))
#			echo $sql
			echo -n "$ncols,"
			if [ $machine = "Mac" ]
			then
				pgbench -n -f bench.sql -M prepared -T $secsonds $database | grep latency | ggrep -Po "\d+\.\d+"
			else
				pgbench -n -f bench.sql -M prepared -T $seconds $database | grep latency | grep -Po "\d+\.\d+"
			fi
		done
	done
else
	echo "Please use the 'run' or 'setup' option in command line"
fi