
上QQ阅读APP看书,第一时间看更新
How to do it...
- Pick the database on which you need to analyze the skew tables.
- Execute this query to get the list of tables:
/**Skew table in a database query**/
Lock Dbc.TableSize For Access
Lock Dbc.tables For Access
SELECT B.databasename , B.TableName , A.LastAccessTimeStAMP , SUM ( currentperm ) ( NAMED CurrentPerm ) ,
MAXIMUM ( currentperm ) ( NAMED MaxPerm ) , AVG ( currentperm ) ( NAMED AvgPerm ) ,
( ( MAXIMUM ( currentperm ) - AVG ( currentperm ) ) * 100.0 ) / ( MAXIMUM ( currentperm ) ) ( NAMED SkewPercent )
FROM dbc.tablesize B INNER JOIN DBC.TABLES A
ON A.DATABASENAME = B.DATABASENAME
AND A.TABLENAME = B.TABLENAME
WHERE B.DATABASENAME = <my_database>
GROUP BY 1 , 2 , 3
HAVING ( ( MAXIMUM ( currentperm ) - AVG ( currentperm ) ) * 100.0 ) / ( MAXIMUM ( currentperm ) ) > 20
ORDER BY 1 , 2 ;
The following is the list of tables in the database test_db with their space in GB and skew percentage:

- Once you have identified a target table, you can display the detailed distribution with the following query:
/**Table distribution**/
Lock dbc.tablesize for Access
SELECT vproc, CurrentPerm FROM dbc.TableSize
WHERE DatabaseName = <my_database>
AND TableName = <my_table>
ORDER BY 1;
- Once you identify the problematic tables you can check their PI distribution from the query shared.
- Rebuild the tables with new PI columns with better distributions.