-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgin_hexedit
executable file
·93 lines (85 loc) · 1.93 KB
/
gin_hexedit
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
#
# gin_hexedit: Don't set any offsets in wxHexEditor cache. Instead, output
# a summary of interesting offsets for the GIN index to stdout for user.
#
# Unlike relation_hexedit, this script does not set any offsets in the
# wxHexEditor cache/registry.
usage() {
cat <<EOM
Usage:
$(basename "$0") relname
EOM
exit 0
}
[ -z "$1" ] && { usage; }
source ./hexedit.cfg
relname=$1
# Print useful byte offsets for user to stdout:
if ! psql --no-psqlrc -c "CREATE EXTENSION IF NOT EXISTS pageinspect"
then
echo "creating pageinspect extension failed"
exit 1
fi
echo "Contiguous flags in GIN index summary:"
if ! psql --no-psqlrc -P pager=off -c "WITH recursive index_details AS (
SELECT '$relname'::text AS idx
),
size_in_pages_index AS (
SELECT
(pg_relation_size(idx::regclass) / (2^13))::int4 AS size_pages
FROM
index_details
),
page_stats AS (
SELECT
index_details.*,
stats.*,
i AS series
FROM
index_details,
size_in_pages_index,
LATERAL (SELECT i FROM generate_series(0, size_pages - 1) i) AS series,
LATERAL (SELECT * FROM gin_page_opaque_info(get_raw_page(idx, i))) AS stats
ORDER BY
i
),
recursive_rangewise_blocks(flags, series, first) AS (
SELECT
p.flags,
0,
0
FROM
page_stats p
WHERE
series = 0
UNION
SELECT
i.flags,
i.series,
CASE WHEN i.flags = o.flags THEN o.first ELSE i.series END
FROM
page_stats AS i,
recursive_rangewise_blocks AS o
WHERE
i.series = o.series + 1
)
SELECT
flags,
first AS first_block_in_series,
lead(series, 1, size_pages) OVER() - 1 AS last_block_in_series,
first * (2^13) AS offset_bytes_first
FROM
recursive_rangewise_blocks,
size_in_pages_index
WHERE
series = first
ORDER BY
first;"
then
echo "displaying contiguous range of blocks failed"
exit 1
fi
export OFFSETS=""
echo "Note: no offsets are set in cache when using $(basename "$0") convenience script"
./__open_relation "$relname"