1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Redesign pageinspect function printing infomask bits

After more discussion, the new function added by ddbd5d8 could have been
designed in a better way.  Based on an idea from Álvaro, instead of
returning one column which includes both the raw and combined flags, use
two columns, with one for the raw flags and one for the combined flags.

This also takes care of some issues with HEAP_LOCKED_UPGRADED and
HEAP_XMAX_IS_LOCKED_ONLY which are not really combined flags as they
depend on conditions defined by other raw bits, as mentioned by Amit.

While on it, fix an extra issue with combined flags.  A combined flag
was returned if at least one of its bits was set, but all its bits need
to be set to include it in the result.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Amit Kapila
Discussion: https://postgr.es/m/20190913114950.GA3824@alvherre.pgsql
This commit is contained in:
Michael Paquier
2019-09-19 11:01:52 +09:00
parent 59354ccef5
commit 58b4cb30a5
5 changed files with 153 additions and 224 deletions

View File

@ -36,42 +36,34 @@ SELECT * FROM fsm_page_contents(get_raw_page('test1', 'fsm', 0));
-- default: HEAP_XMIN_COMMITTED and HEAP_XMIN_INVALID.
VACUUM FREEZE test1;
SELECT t_infomask, t_infomask2, flags
SELECT t_infomask, t_infomask2, raw_flags, combined_flags
FROM heap_page_items(get_raw_page('test1', 0)),
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2) m(flags);
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
-- output the decoded flag HEAP_XMIN_FROZEN instead
SELECT t_infomask, t_infomask2, flags
SELECT t_infomask, t_infomask2, raw_flags, combined_flags
FROM heap_page_items(get_raw_page('test1', 0)),
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2, true) m(flags);
LATERAL heap_tuple_infomask_flags(t_infomask, t_infomask2);
-- tests for decoding of combined flags
-- HEAP_XMAX_SHR_LOCK = (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK)
SELECT heap_tuple_infomask_flags(x'0050'::int, 0, true);
SELECT heap_tuple_infomask_flags(x'0050'::int, 0, false);
SELECT * FROM heap_tuple_infomask_flags(x'0050'::int, 0);
-- HEAP_XMIN_FROZEN = (HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID)
SELECT heap_tuple_infomask_flags(x'0300'::int, 0, true);
SELECT heap_tuple_infomask_flags(x'0300'::int, 0, false);
SELECT * FROM heap_tuple_infomask_flags(x'0300'::int, 0);
-- HEAP_MOVED = (HEAP_MOVED_IN | HEAP_MOVED_OFF)
SELECT heap_tuple_infomask_flags(x'C000'::int, 0, true);
SELECT heap_tuple_infomask_flags(x'C000'::int, 0, false);
-- HEAP_LOCKED_UPGRADED = (HEAP_XMAX_IS_MULTI | HEAP_XMAX_LOCK_ONLY)
SELECT heap_tuple_infomask_flags(x'1080'::int, 0, true);
SELECT heap_tuple_infomask_flags(x'1080'::int, 0, false);
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
SELECT * FROM heap_tuple_infomask_flags(x'C000'::int, 0);
-- test all flags of t_infomask and t_infomask2
SELECT unnest(heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int, false))
AS flags ORDER BY 1;
SELECT unnest(heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int, true))
AS flags ORDER BY 1;
SELECT unnest(heap_tuple_infomask_flags(-1, -1, false))
AS flags ORDER BY 1;
SELECT unnest(heap_tuple_infomask_flags(-1, -1, true))
AS flags ORDER BY 1;
SELECT unnest(raw_flags)
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
SELECT unnest(combined_flags)
FROM heap_tuple_infomask_flags(x'FFFF'::int, x'FFFF'::int) ORDER BY 1;
-- no flags
SELECT unnest(heap_tuple_infomask_flags(0, 0, false));
SELECT unnest(heap_tuple_infomask_flags(0, 0, true));
-- no flags at all
SELECT * FROM heap_tuple_infomask_flags(0, 0);
-- no combined flags
SELECT * FROM heap_tuple_infomask_flags(x'0010'::int, 0);
DROP TABLE test1;