Unfortunately version lacks of two facts:
* Biased values are truncated to 26 Characters in the "SHOW STATISTICS VALUES COLUMN
SHOW STATISTICS VALUES COLUMN"
* Script fails when column is part of multi column statistics.
Therefore new awk script
BR
Roland
BEGIN { CUTPERCENTAGE=1;
print ".errorlevel (3582) severity 0";
print ".errorlevel (6956) severity 0";
}
/ COLUMN \(/ { COL=$3; }
/ ON / { DBTAB=$2; }
/^ \/\*\* / { BIASEDON=0; }
/NumOfRows/ { CUTROWS=$4*CUTPERCENTAGE/100;
BIASED=="";
if (0+CUTROWS<0+NULLROWS) BIASED="NULL,";
}
/\/\* NumOfNulls/ { NULLROWS=$4; }
/^ \/\*\* Biased:/ { BIASEDON=1;}
/^ \/\* / { if (BIASEDON==1)
{
if (CUTROWS < 0+gensub(".*,","","",gensub(",? ?$","","g")))
if (length (gensub("^ */[^/]*/","","g",gensub(",[0-9 ]*,? ?$","","g")))<28)
BIASED=BIASED gensub("^ */[^/]*/","","g",gensub(",[0-9 ]*,? ?$","","g")) ",";
}
}
/^COLLECT STATISTICS/ { COLSTATON=1; }
{ if (COLSTATON==1) COLSTAT=COLSTAT "\n" $0; }
/^);/ { BIASEDON=0;
COLSTATON=0;
if (BIASED=="")
{
COLSTAT="";
next;
}
if (DBTAB!=DBTABOLD)
{
if (DBTABOLD!="")
{
print DROPSTATS;
print ALTERTABLE ";";
print COLSTATALL;
COLSTATALL="";
}
ALTERTABLE="ALTER TABLE " DBTAB " ADD " COL " COMPRESS (" gensub(",$","","",BIASED) ")";
DROPSTATS="DROP STATISTICS COLUMN " COL " ON " DBTAB ";";
DBTABOLD=DBTAB;
}
else
{
ALTERTABLE=ALTERTABLE "\n"" ,ADD " COL " COMPRESS (" gensub(",$","","",BIASED) " )";
DROPSTATS=DROPSTATS "\n""DROP STATISTICS COLUMN " COL " ON " DBTAB ";";
}
COLSTATALL=COLSTATALL "\n" COLSTAT;
COLSTAT="";
BIASED="";
}
END {
print ";";
}
Unfortunately version lacks of two facts:
* Biased values are truncated to 26 Characters in the "
SHOW STATISTICS VALUES COLUMN
SHOW STATISTICS VALUES COLUMN"
* Script fails when column is part of multi column statistics.
Therefore new awk script
BR
Roland
BEGIN { CUTPERCENTAGE=1;
print ".errorlevel (3582) severity 0";
print ".errorlevel (6956) severity 0";
}
/ COLUMN \(/ { COL=$3; }
/ ON / { DBTAB=$2; }
/^ \/\*\* / { BIASEDON=0; }
/NumOfRows/ { CUTROWS=$4*CUTPERCENTAGE/100;
BIASED=="";
if (0+CUTROWS<0+NULLROWS) BIASED="NULL,";
}
/\/\* NumOfNulls/ { NULLROWS=$4; }
/^ \/\*\* Biased:/ { BIASEDON=1;}
/^ \/\* / { if (BIASEDON==1)
{
if (CUTROWS < 0+gensub(".*,","","",gensub(",? ?$","","g")))
if (length (gensub("^ */[^/]*/","","g",gensub(",[0-9 ]*,? ?$","","g")))<28)
BIASED=BIASED gensub("^ */[^/]*/","","g",gensub(",[0-9 ]*,? ?$","","g")) ",";
}
}
/^COLLECT STATISTICS/ { COLSTATON=1; }
{ if (COLSTATON==1) COLSTAT=COLSTAT "\n" $0; }
/^);/ { BIASEDON=0;
COLSTATON=0;
if (BIASED=="")
{
COLSTAT="";
next;
}
if (DBTAB!=DBTABOLD)
{
if (DBTABOLD!="")
{
print DROPSTATS;
print ALTERTABLE ";";
print COLSTATALL;
COLSTATALL="";
}
ALTERTABLE="ALTER TABLE " DBTAB " ADD " COL " COMPRESS (" gensub(",$","","",BIASED) ")";
DROPSTATS="DROP STATISTICS COLUMN " COL " ON " DBTAB ";";
DBTABOLD=DBTAB;
}
else
{
ALTERTABLE=ALTERTABLE "\n"" ,ADD " COL " COMPRESS (" gensub(",$","","",BIASED) " )";
DROPSTATS=DROPSTATS "\n""DROP STATISTICS COLUMN " COL " ON " DBTAB ";";
}
COLSTATALL=COLSTATALL "\n" COLSTAT;
COLSTAT="";
BIASED="";
}
END {
print ";";
}