-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdbsee_tableskew.sql
More file actions
29 lines (28 loc) · 1.29 KB
/
dbsee_tableskew.sql
File metadata and controls
29 lines (28 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*********************************************************************/
/* Author : VLDB */
/* Date : 07/02/2017 */
/* Version : 1 */
/* Description : Generate report on skewed tables */
/*********************************************************************/
select t1.databasename as database_name
,t1.tablename as table_name
,t1.currentperm as current_perm
,t2.total_perm as total_perm
,cast(t2.total_perm/(select max(vproc) +1
from dbc.tablesizev) as bigint) as avg_size_by_amp
,t1.vproc as vproc
,cast((currentperm - avg_size_by_amp) as bigint) as deviation
,cast(case when deviation = 0 then 0
else (cast(deviation as decimal(25,4))/cast(avg_size_by_amp as decimal(25,4)))*100
end as decimal(23,2)) as deviation_perc
from dbc.tablesizev t1
inner join
(select databasename
,tablename
,sum(currentperm) as total_perm
from dbc.tablesizev
group by 1,2) t2
on t1.tablename = t2.tablename
and t1.databasename = t2.databasename
group by 1,2,3,4,6
;