-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
v_check_data_distribution.sql
44 lines (44 loc) · 1.47 KB
/
v_check_data_distribution.sql
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--DROP VIEW admin.v_check_data_distribution;
/**********************************************************************************************
Purpose: View to get data distribution across slices
History:
2014-01-30 jjschmit Created
**********************************************************************************************/
CREATE OR REPLACE VIEW admin.v_check_data_distribution
AS
SELECT
slice
,pgn.oid AS schema_oid
,pgn.nspname AS schemaname
,id AS tbl_oid
,name AS tablename
,stv.diststyle AS diststyle
,stv.sortkey1 AS sortkey
,rows AS rowcount_on_slice
,SUM(rows) OVER (PARTITION BY name, id) AS total_rowcount
,CASE
WHEN rows IS NULL OR rows = 0 THEN 0
ELSE ROUND(CAST(rows AS FLOAT) / CAST((SUM(rows) OVER (PARTITION BY id)) AS FLOAT) * 100, 3)
END AS distrib_pct
,CASE
WHEN rows IS NULL OR rows = 0 THEN 0
ELSE ROUND(CAST((MIN(rows) OVER (PARTITION BY id)) AS FLOAT) / CAST((SUM(rows) OVER (PARTITION BY id)) AS FLOAT) * 100, 3)
END AS min_distrib_pct
,CASE
WHEN rows IS NULL OR rows = 0 THEN 0
ELSE ROUND(CAST((MAX(rows) OVER (PARTITION BY id)) AS FLOAT) / CAST((SUM(rows) OVER (PARTITION BY id)) AS FLOAT) * 100, 3)
END AS max_distrib_pct
FROM
stv_tbl_perm AS perm
INNER JOIN
pg_class AS pgc
ON pgc.oid = perm.id
INNER JOIN
pg_namespace AS pgn
ON pgn.oid = pgc.relnamespace
INNER JOIN
svv_table_info AS stv
ON stv.schema = pgn.nspname AND stv."table" = name
WHERE slice < 3201
AND pgc.relowner > 1
;