mirror of
https://github.com/postgres/postgres.git
synced 2025-08-08 06:02:22 +03:00
pageinspect: Change block number arguments to bigint
Block numbers are 32-bit unsigned integers. Therefore, the smallest SQL integer type that they can fit in is bigint. However, in the pageinspect module, most input and output parameters dealing with block numbers were declared as int. The behavior with block numbers larger than a signed 32-bit integer was therefore dubious. Change these arguments to type bigint and add some more explicit error checking on the block range. (Other contrib modules appear to do this correctly already.) Since we are changing argument types of existing functions, in order to not misbehave if the binary is updated before the extension is updated, we need to create new C symbols for the entry points, similar to how it's done in other extensions as well. Reported-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/d8f6bdd536df403b9b33816e9f7e0b9d@G08CNEXMBPEKD05.g08.fujitsu.local
This commit is contained in:
@@ -14,6 +14,8 @@ oldest_xact | 0
|
||||
last_cleanup_num_tuples | -1
|
||||
allequalimage | t
|
||||
|
||||
SELECT * FROM bt_page_stats('test1_a_idx', -1);
|
||||
ERROR: invalid block number
|
||||
SELECT * FROM bt_page_stats('test1_a_idx', 0);
|
||||
ERROR: block 0 is a meta page
|
||||
SELECT * FROM bt_page_stats('test1_a_idx', 1);
|
||||
@@ -32,6 +34,8 @@ btpo_flags | 3
|
||||
|
||||
SELECT * FROM bt_page_stats('test1_a_idx', 2);
|
||||
ERROR: block number out of range
|
||||
SELECT * FROM bt_page_items('test1_a_idx', -1);
|
||||
ERROR: invalid block number
|
||||
SELECT * FROM bt_page_items('test1_a_idx', 0);
|
||||
ERROR: block 0 is a meta page
|
||||
SELECT * FROM bt_page_items('test1_a_idx', 1);
|
||||
@@ -48,6 +52,8 @@ tids |
|
||||
|
||||
SELECT * FROM bt_page_items('test1_a_idx', 2);
|
||||
ERROR: block number out of range
|
||||
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', -1));
|
||||
ERROR: invalid block number
|
||||
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 0));
|
||||
ERROR: block is a meta page
|
||||
SELECT * FROM bt_page_items(get_raw_page('test1_a_idx', 1));
|
||||
|
@@ -35,3 +35,4 @@ FROM gin_leafpage_items(get_raw_page('test1_y_idx',
|
||||
-[ RECORD 1 ]
|
||||
?column? | t
|
||||
|
||||
DROP TABLE test1;
|
||||
|
@@ -28,6 +28,8 @@ hash_page_type | bitmap
|
||||
|
||||
SELECT hash_page_type(get_raw_page('test_hash_a_idx', 6));
|
||||
ERROR: block number 6 is out of range for relation "test_hash_a_idx"
|
||||
SELECT * FROM hash_bitmap_info('test_hash_a_idx', -1);
|
||||
ERROR: invalid block number
|
||||
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 0);
|
||||
ERROR: invalid overflow block number 0
|
||||
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 1);
|
||||
@@ -40,6 +42,8 @@ SELECT * FROM hash_bitmap_info('test_hash_a_idx', 4);
|
||||
ERROR: invalid overflow block number 4
|
||||
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 5);
|
||||
ERROR: invalid overflow block number 5
|
||||
SELECT * FROM hash_bitmap_info('test_hash_a_idx', 6);
|
||||
ERROR: block number 6 is out of range for relation "test_hash_a_idx"
|
||||
SELECT magic, version, ntuples, bsize, bmsize, bmshift, maxbucket, highmask,
|
||||
lowmask, ovflpoint, firstfree, nmaps, procid, spares, mapp FROM
|
||||
hash_metapage_info(get_raw_page('test_hash_a_idx', 0));
|
||||
|
40
contrib/pageinspect/expected/oldextversions.out
Normal file
40
contrib/pageinspect/expected/oldextversions.out
Normal file
@@ -0,0 +1,40 @@
|
||||
-- test old extension version entry points
|
||||
DROP EXTENSION pageinspect;
|
||||
CREATE EXTENSION pageinspect VERSION '1.8';
|
||||
CREATE TABLE test1 (a int8, b text);
|
||||
INSERT INTO test1 VALUES (72057594037927937, 'text');
|
||||
CREATE INDEX test1_a_idx ON test1 USING btree (a);
|
||||
-- from page.sql
|
||||
SELECT octet_length(get_raw_page('test1', 0)) AS main_0;
|
||||
main_0
|
||||
--------
|
||||
8192
|
||||
(1 row)
|
||||
|
||||
SELECT octet_length(get_raw_page('test1', 'main', 0)) AS main_0;
|
||||
main_0
|
||||
--------
|
||||
8192
|
||||
(1 row)
|
||||
|
||||
SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_test;
|
||||
silly_checksum_test
|
||||
---------------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
-- from btree.sql
|
||||
SELECT * FROM bt_page_stats('test1_a_idx', 1);
|
||||
blkno | type | live_items | dead_items | avg_item_size | page_size | free_size | btpo_prev | btpo_next | btpo | btpo_flags
|
||||
-------+------+------------+------------+---------------+-----------+-----------+-----------+-----------+------+------------
|
||||
1 | l | 1 | 0 | 16 | 8192 | 8128 | 0 | 0 | 0 | 3
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM bt_page_items('test1_a_idx', 1);
|
||||
itemoffset | ctid | itemlen | nulls | vars | data | dead | htid | tids
|
||||
------------+-------+---------+-------+------+-------------------------+------+-------+------
|
||||
1 | (0,1) | 16 | f | f | 01 00 00 00 00 00 00 01 | f | (0,1) |
|
||||
(1 row)
|
||||
|
||||
DROP TABLE test1;
|
||||
DROP EXTENSION pageinspect;
|
@@ -32,6 +32,8 @@ SELECT octet_length(get_raw_page('test1', 'vm', 0)) AS vm_0;
|
||||
|
||||
SELECT octet_length(get_raw_page('test1', 'vm', 1)) AS vm_1;
|
||||
ERROR: block number 1 is out of range for relation "test1"
|
||||
SELECT octet_length(get_raw_page('test1', 'main', -1));
|
||||
ERROR: invalid block number
|
||||
SELECT octet_length(get_raw_page('xxx', 'main', 0));
|
||||
ERROR: relation "xxx" does not exist
|
||||
SELECT octet_length(get_raw_page('test1', 'xxx', 0));
|
||||
@@ -55,6 +57,8 @@ SELECT page_checksum(get_raw_page('test1', 0), 0) IS NOT NULL AS silly_checksum_
|
||||
t
|
||||
(1 row)
|
||||
|
||||
SELECT page_checksum(get_raw_page('test1', 0), -1);
|
||||
ERROR: invalid block number
|
||||
SELECT tuple_data_split('test1'::regclass, t_data, t_infomask, t_infomask2, t_bits)
|
||||
FROM heap_page_items(get_raw_page('test1', 0));
|
||||
tuple_data_split
|
||||
|
Reference in New Issue
Block a user