-
Notifications
You must be signed in to change notification settings - Fork 64
/
cs_all_application_segments.sql
73 lines (73 loc) · 2.61 KB
/
cs_all_application_segments.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
WITH relevant_segments AS (
SELECT /*+ OPT_PARAM('_px_cdb_view_enabled' 'FALSE') */
s.con_id,
s.owner,
s.segment_name,
s.partition_name,
s.segment_type,
s.tablespace_name,
s.bytes,
s.blocks,
CASE
WHEN s.segment_type LIKE 'TABLE%' THEN t.num_rows
END AS num_rows,
CASE
WHEN s.segment_type LIKE 'TABLE%' THEN s.segment_name
WHEN s.segment_type LIKE 'LOB%' AND s.segment_type <> 'LOBINDEX' THEN l.table_name
WHEN s.segment_type LIKE 'INDEX%' OR s.segment_type = 'LOBINDEX' THEN i.table_name
END AS table_name,
CASE
WHEN s.segment_type LIKE 'LOB%' AND s.segment_type <> 'LOBINDEX' THEN l.index_name
WHEN s.segment_type LIKE 'INDEX%' OR s.segment_type = 'LOBINDEX' THEN i.index_name
END AS index_name,
CASE
WHEN s.segment_type LIKE 'LOB%' AND s.segment_type <> 'LOBINDEX' THEN l.column_name
END AS column_name
FROM cdb_users u,
cdb_segments s,
cdb_tables t,
cdb_lobs l,
cdb_indexes i
WHERE u.oracle_maintained = 'N'
AND u.common = 'NO'
AND s.con_id = u.con_id
AND s.owner = u.username
AND s.bytes > 0
AND (s.segment_type LIKE 'TABLE%' OR s.segment_type LIKE 'LOB%' OR s.segment_type LIKE 'INDEX%')
AND t.con_id(+) = s.con_id
AND t.owner(+) = s.owner
AND t.table_name(+) = s.segment_name
AND l.con_id(+) = s.con_id
AND l.owner(+) = s.owner
AND l.segment_name(+) = s.segment_name
AND i.con_id(+) = s.con_id
AND i.owner(+) = s.owner
AND i.index_name(+) = s.segment_name
)
-- SELECT s.con_id,
-- s.owner,
-- s.segment_name,
-- s.partition_name,
-- s.segment_type,
-- s.tablespace_name,
-- s.bytes,
-- s.blocks,
-- s.num_rows,
-- s.table_name,
-- s.index_name,
-- s.column_name
-- FROM relevant_segments s
-- WHERE s.con_id = 3
-- AND s.table_name = 'ROUTE_TABLES_AD'
SELECT COUNT(*) AS cnt, SUM(bytes) AS bytes,
PERCENTILE_DISC(0.50) WITHIN GROUP (ORDER BY bytes) AS pctl_50,
PERCENTILE_DISC(0.70) WITHIN GROUP (ORDER BY bytes) AS pctl_70,
PERCENTILE_DISC(0.75) WITHIN GROUP (ORDER BY bytes) AS pctl_75,
PERCENTILE_DISC(0.80) WITHIN GROUP (ORDER BY bytes) AS pctl_80,
PERCENTILE_DISC(0.85) WITHIN GROUP (ORDER BY bytes) AS pctl_85,
PERCENTILE_DISC(0.90) WITHIN GROUP (ORDER BY bytes) AS pctl_90,
PERCENTILE_DISC(0.95) WITHIN GROUP (ORDER BY bytes) AS pctl_95,
PERCENTILE_DISC(0.99) WITHIN GROUP (ORDER BY bytes) AS pctl_99,
MAX(bytes) AS pctl_100
FROM relevant_segments
/