Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadfb81d

Browse files
committed
pageinspect: Add tests
1 parent3a47c70 commitadfb81d

File tree

10 files changed

+284
-0
lines changed

10 files changed

+284
-0
lines changed

‎contrib/pageinspect/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Generated subdirectories
2+
/log/
3+
/results/
4+
/tmp_check/

‎contrib/pageinspect/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ DATA = pageinspect--1.5.sql pageinspect--1.4--1.5.sql \
1111
pageinspect--unpackaged--1.0.sql
1212
PGFILEDESC = "pageinspect - functions to inspect contents of database pages"
1313

14+
REGRESS = page btree brin gin
15+
1416
ifdefUSE_PGXS
1517
PG_CONFIG = pg_config
1618
PGXS :=$(shell$(PG_CONFIG) --pgxs)

‎contrib/pageinspect/expected/brin.out

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CREATE TABLE test1 (a int, b text);
2+
INSERT INTO test1 VALUES (1, 'one');
3+
CREATE INDEX test1_a_idx ON test1 USING brin (a);
4+
SELECT brin_page_type(get_raw_page('test1_a_idx', 0));
5+
brin_page_type
6+
----------------
7+
meta
8+
(1 row)
9+
10+
SELECT brin_page_type(get_raw_page('test1_a_idx', 1));
11+
brin_page_type
12+
----------------
13+
revmap
14+
(1 row)
15+
16+
SELECT brin_page_type(get_raw_page('test1_a_idx', 2));
17+
brin_page_type
18+
----------------
19+
regular
20+
(1 row)
21+
22+
SELECT * FROM brin_metapage_info(get_raw_page('test1_a_idx', 0));
23+
magic | version | pagesperrange | lastrevmappage
24+
------------+---------+---------------+----------------
25+
0xA8109CFA | 1 | 128 | 1
26+
(1 row)
27+
28+
SELECT * FROM brin_metapage_info(get_raw_page('test1_a_idx', 1));
29+
ERROR: page is not a BRIN page of type "metapage"
30+
DETAIL: Expected special type 0000f091, got 0000f092.
31+
SELECT * FROM brin_revmap_data(get_raw_page('test1_a_idx', 0)) LIMIT 5;
32+
ERROR: page is not a BRIN page of type "revmap"
33+
DETAIL: Expected special type 0000f092, got 0000f091.
34+
SELECT * FROM brin_revmap_data(get_raw_page('test1_a_idx', 1)) LIMIT 5;
35+
pages
36+
-------
37+
(2,1)
38+
(0,0)
39+
(0,0)
40+
(0,0)
41+
(0,0)
42+
(5 rows)
43+
44+
SELECT * FROM brin_page_items(get_raw_page('test1_a_idx', 2), 'test1_a_idx')
45+
ORDER BY blknum, attnum LIMIT 5;
46+
itemoffset | blknum | attnum | allnulls | hasnulls | placeholder | value
47+
------------+--------+--------+----------+----------+-------------+----------
48+
1 | 0 | 1 | f | f | f | {1 .. 1}
49+
(1 row)
50+
51+
DROP TABLE test1;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
CREATE TABLE test1 (a int, b text);
2+
INSERT INTO test1 VALUES (1, 'one');
3+
CREATE INDEX test1_a_idx ON test1 USING btree (a);
4+
\x
5+
SELECT * FROM bt_metap('test1_a_idx');
6+
-[ RECORD 1 ]-----
7+
magic | 340322
8+
version | 2
9+
root | 1
10+
level | 0
11+
fastroot | 1
12+
fastlevel | 0
13+
14+
SELECT * FROM bt_page_stats('test1_a_idx', 0);
15+
ERROR: block 0 is a meta page
16+
SELECT * FROM bt_page_stats('test1_a_idx', 1);
17+
-[ RECORD 1 ]-+-----
18+
blkno | 1
19+
type | l
20+
live_items | 1
21+
dead_items | 0
22+
avg_item_size | 16
23+
page_size | 8192
24+
free_size | 8128
25+
btpo_prev | 0
26+
btpo_next | 0
27+
btpo | 0
28+
btpo_flags | 3
29+
30+
SELECT * FROM bt_page_stats('test1_a_idx', 2);
31+
ERROR: block number out of range
32+
SELECT * FROM bt_page_items('test1_a_idx', 0);
33+
ERROR: block 0 is a meta page
34+
SELECT * FROM bt_page_items('test1_a_idx', 1);
35+
-[ RECORD 1 ]-----------------------
36+
itemoffset | 1
37+
ctid | (0,1)
38+
itemlen | 16
39+
nulls | f
40+
vars | f
41+
data | 01 00 00 00 00 00 00 00
42+
43+
SELECT * FROM bt_page_items('test1_a_idx', 2);
44+
ERROR: block number out of range
45+
DROP TABLE test1;

‎contrib/pageinspect/expected/gin.out

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TABLE test1 (x int, y int[]);
2+
INSERT INTO test1 VALUES (1, ARRAY[11, 111]);
3+
CREATE INDEX test1_y_idx ON test1 USING gin (y);
4+
\x
5+
SELECT * FROM gin_metapage_info(get_raw_page('test1_y_idx', 0));
6+
-[ RECORD 1 ]----+-----------
7+
pending_head | 4294967295
8+
pending_tail | 4294967295
9+
tail_free_size | 0
10+
n_pending_pages | 0
11+
n_pending_tuples | 0
12+
n_total_pages | 2
13+
n_entry_pages | 1
14+
n_data_pages | 0
15+
n_entries | 2
16+
version | 2
17+
18+
SELECT * FROM gin_metapage_info(get_raw_page('test1_y_idx', 1));
19+
ERROR: input page is not a GIN metapage
20+
DETAIL: Flags 0002, expected 0008
21+
SELECT * FROM gin_page_opaque_info(get_raw_page('test1_y_idx', 1));
22+
-[ RECORD 1 ]---------
23+
rightlink | 4294967295
24+
maxoff | 0
25+
flags | {leaf}
26+
27+
SELECT * FROM gin_leafpage_items(get_raw_page('test1_y_idx', 1));
28+
ERROR: input page is not a compressed GIN data leaf page
29+
DETAIL: Flags 0002, expected 0083
30+
DROP TABLE test1;

‎contrib/pageinspect/expected/page.out

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
CREATE EXTENSION pageinspect;
2+
CREATE TABLE test1 (a int, b text);
3+
INSERT INTO test1 VALUES (1, 'one');
4+
VACUUM test1; -- set up FSM
5+
-- The page contents can vary, so just test that it can be read
6+
-- successfully, but don't keep the output.
7+
SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
8+
main_0
9+
--------
10+
8192
11+
(1 row)
12+
13+
SELECT octet_length(get_raw_page('test1', 'main', 1)) AS main_1;
14+
ERROR: block number 1 is out of range for relation "test1"
15+
SELECT octet_length(get_raw_page('test1', 'fsm', 0)) AS fsm_0;
16+
fsm_0
17+
-------
18+
8192
19+
(1 row)
20+
21+
SELECT octet_length(get_raw_page('test1', 'fsm', 1)) AS fsm_1;
22+
fsm_1
23+
-------
24+
8192
25+
(1 row)
26+
27+
SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
28+
vm_0
29+
------
30+
8192
31+
(1 row)
32+
33+
SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
34+
ERROR: block number 1 is out of range for relation "test1"
35+
SELECT octet_length(get_raw_page('xxx', 'main', 0));
36+
ERROR: relation "xxx" does not exist
37+
SELECT octet_length(get_raw_page('test1', 'xxx', 0));
38+
ERROR: invalid fork name
39+
HINT: Valid fork names are "main", "fsm", "vm", and "init".
40+
SELECT get_raw_page('test1', 0) = get_raw_page('test1', 'main', 0);
41+
?column?
42+
----------
43+
t
44+
(1 row)
45+
46+
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
47+
FROM heap_page_items(get_raw_page('test1', 0));
48+
tuple_data_split
49+
-------------------------------
50+
{"\\x01000000","\\x096f6e65"}
51+
(1 row)
52+
53+
SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
54+
fsm_page_contents
55+
-------------------
56+
0: 254 +
57+
1: 254 +
58+
3: 254 +
59+
7: 254 +
60+
15: 254 +
61+
31: 254 +
62+
63: 254 +
63+
127: 254 +
64+
255: 254 +
65+
511: 254 +
66+
1023: 254 +
67+
2047: 254 +
68+
4095: 254 +
69+
fp_next_slot: 0 +
70+
71+
(1 row)
72+
73+
DROP TABLE test1;

‎contrib/pageinspect/sql/brin.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATETABLEtest1 (aint, btext);
2+
INSERT INTO test1VALUES (1,'one');
3+
CREATEINDEXtest1_a_idxON test1 USING brin (a);
4+
5+
SELECT brin_page_type(get_raw_page('test1_a_idx',0));
6+
SELECT brin_page_type(get_raw_page('test1_a_idx',1));
7+
SELECT brin_page_type(get_raw_page('test1_a_idx',2));
8+
9+
SELECT*FROM brin_metapage_info(get_raw_page('test1_a_idx',0));
10+
SELECT*FROM brin_metapage_info(get_raw_page('test1_a_idx',1));
11+
12+
SELECT*FROM brin_revmap_data(get_raw_page('test1_a_idx',0))LIMIT5;
13+
SELECT*FROM brin_revmap_data(get_raw_page('test1_a_idx',1))LIMIT5;
14+
15+
SELECT*FROM brin_page_items(get_raw_page('test1_a_idx',2),'test1_a_idx')
16+
ORDER BY blknum, attnumLIMIT5;
17+
18+
DROPTABLE test1;

‎contrib/pageinspect/sql/btree.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CREATETABLEtest1 (aint, btext);
2+
INSERT INTO test1VALUES (1,'one');
3+
CREATEINDEXtest1_a_idxON test1 USING btree (a);
4+
5+
\x
6+
7+
SELECT*FROM bt_metap('test1_a_idx');
8+
9+
SELECT*FROM bt_page_stats('test1_a_idx',0);
10+
SELECT*FROM bt_page_stats('test1_a_idx',1);
11+
SELECT*FROM bt_page_stats('test1_a_idx',2);
12+
13+
SELECT*FROM bt_page_items('test1_a_idx',0);
14+
SELECT*FROM bt_page_items('test1_a_idx',1);
15+
SELECT*FROM bt_page_items('test1_a_idx',2);
16+
17+
DROPTABLE test1;

‎contrib/pageinspect/sql/gin.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATETABLEtest1 (xint, yint[]);
2+
INSERT INTO test1VALUES (1, ARRAY[11,111]);
3+
CREATEINDEXtest1_y_idxON test1 USING gin (y);
4+
5+
\x
6+
7+
SELECT*FROM gin_metapage_info(get_raw_page('test1_y_idx',0));
8+
SELECT*FROM gin_metapage_info(get_raw_page('test1_y_idx',1));
9+
10+
SELECT*FROM gin_page_opaque_info(get_raw_page('test1_y_idx',1));
11+
12+
SELECT*FROM gin_leafpage_items(get_raw_page('test1_y_idx',1));
13+
14+
DROPTABLE test1;

‎contrib/pageinspect/sql/page.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE EXTENSION pageinspect;
2+
3+
CREATETABLEtest1 (aint, btext);
4+
INSERT INTO test1VALUES (1,'one');
5+
6+
VACUUM test1;-- set up FSM
7+
8+
-- The page contents can vary, so just test that it can be read
9+
-- successfully, but don't keep the output.
10+
11+
SELECT octet_length(get_raw_page('test1','main',0))AS main_0;
12+
SELECT octet_length(get_raw_page('test1','main',1))AS main_1;
13+
14+
SELECT octet_length(get_raw_page('test1','fsm',0))AS fsm_0;
15+
SELECT octet_length(get_raw_page('test1','fsm',1))AS fsm_1;
16+
17+
SELECT octet_length(get_raw_page('test1','vm',0))AS vm_0;
18+
SELECT octet_length(get_raw_page('test1','vm',1))AS vm_1;
19+
20+
SELECT octet_length(get_raw_page('xxx','main',0));
21+
SELECT octet_length(get_raw_page('test1','xxx',0));
22+
23+
SELECT get_raw_page('test1',0)= get_raw_page('test1','main',0);
24+
25+
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
26+
FROM heap_page_items(get_raw_page('test1',0));
27+
28+
SELECT*FROM fsm_page_contents(get_raw_page('test1','fsm',0));
29+
30+
DROPTABLE test1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp