为了加快update statistics命令,通常需要通过并行执行提升执行效率。下面是一个 ksh/awk 脚本完成此功能。
| #! /usr/bin/ksh
if [[ $# -lt 2 ]]; then echo Usage: $0 database #copies exit 1 fi
dbase=$1 ncopies=$2 if [[ $# -eq 3 ]]; then templ=$3 else templ='*' fi dbaccess $dbase - output to temp$$ without headings select tabname from systables where tabid > 99 and tabname matches "$templ"; EOF
awk -v ncopies=$ncopies -v dbase=$dbase ' BEGIN { cnt=0; pdq=100/ncopies; printf "PDQPRIORITY=%d; export PDQPRIORITY \n", pdq; } { if (length( $1 ) == 0){ next; } } { # Every N copies of dostats insert a wait if ((cnt % ncopies) == 0 && cnt > 0) { print "wait"; }
# output a dostats command for each table in the background printf "dostats -d %s -t %s & \n", dbase, $1, pdq; cnt++; } END { # Now update stats on all stored procedures. print "dostats -d %s -p \n", dbase; } ' temp$$
##### End script #####
|