-
Notifications
You must be signed in to change notification settings - Fork 0
/
pg_decode_infomask--0.1.sql
78 lines (72 loc) · 2.38 KB
/
pg_decode_infomask--0.1.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
74
75
76
77
/*
* infomask/infomask2 decoding functions
* for PostgreSQL 9.6
*
* author: Thomas Reiss
*
* all defined hintbits are given in form of a boolean columns, to permit the use
* of a WHERE clause, for example to detect inconsistencies.
*
*/
CREATE OR REPLACE FUNCTION pg_get_xact_infomask_bits(infomask int,
OUT xmin_committed boolean,
OUT xmin_invalid boolean,
OUT xmin_frozen boolean,
OUT xmax_committed boolean,
OUT xmax_invalid boolean
)
RETURNS record
LANGUAGE c COST 10
AS '$libdir/pg_decode_infomask', 'pg_get_xact_infomask_details';
CREATE OR REPLACE FUNCTION pg_get_lock_infomask_bits(infomask int,
OUT is_locked_only boolean,
OUT is_locked_upgraded boolean,
OUT is_shr_locked boolean,
OUT is_excl_locked boolean,
OUT is_keyshr_locked boolean,
OUT xmax_keyshr_lock boolean,
OUT xmax_excl_lock boolean,
OUT xmax_lock_only boolean,
OUT xmax_is_multi boolean
)
RETURNS record
LANGUAGE c COST 10
AS '$libdir/pg_decode_infomask', 'pg_get_lock_infomask_details';
CREATE OR REPLACE FUNCTION pg_get_infomask2_bits(infomask2 int,
OUT natts integer,
OUT keys_updated boolean,
OUT hot_updated boolean,
OUT heap_only_tuple boolean
)
RETURNS record
LANGUAGE c COST 10
AS '$libdir/pg_decode_infomask', 'pg_get_infomask2_details';
CREATE OR REPLACE FUNCTION pg_get_xact_infomask(infomask int,
OUT xmin_committed boolean,
OUT xmin_invalid boolean,
OUT xmin_frozen boolean,
OUT xmax_committed boolean,
OUT xmax_invalid boolean,
OUT xmin_status text[],
OUT xmax_status text[]
)
AS $$
SELECT xmin_committed, xmin_invalid, xmin_frozen,
xmax_committed, xmax_invalid,
xmin_status.xmin_status, xmax_status.xmax_status
FROM pg_get_xact_infomask_bits($1) xact,
LATERAL ( SELECT array_agg(xminstatus) AS xmin_status FROM (
SELECT 'COMMITTED' AS xminstatus WHERE xmin_committed
UNION ALL
SELECT 'INVALID' WHERE xmin_invalid
UNION ALL
SELECT 'FROZEN' WHERE xmin_frozen
) s
) xmin_status,
LATERAL ( SELECT array_agg(xmaxstatus) AS xmax_status FROM (
SELECT 'COMMITTED' AS xmaxstatus WHERE xmax_committed
UNION ALL
SELECT 'INVALID' WHERE xmax_invalid
) s
) xmax_status
$$ LANGUAGE sql;