create or replace function heap_page(relname text, pageno integer)
returns
table ( ctid tid,state text,xmin text,xmax text,hhu text,hot text,t_ctid tid)
as $$
select
(pageno,lp)::text::tid as ctid,
case lp_flags
when 0 then 'unused'
when 1 then 'normal'
when 2 then 'redirect to '|| lp_off
when 3 then 'dead'
end as state,
t_xmin || case
when (t_infomask & 256) > 0 then 'c'
when (t_infomask & 512) > 0 then 'a'
else ''
end as xmin,
t_xmax || case
when (t_infomask & 1024) >0 then 'c'
when (t_infomask & 2048) >0 then 'a'
else ''
end as xmax,
case when (t_infomask2 & 16384) >0 then 't' end as hhu,
case when (t_infomask2 & 32768) >0 then 't' end as hot,
t_ctid
from heap_page_items
(get_raw_page(relname, pageno))
order by lp
$$ language sql;
https://www.postgresql.org/docs/current/pageinspect.html
https://www.postgresql.org/docs/current/functions-math.html
https://doxygen.postgresql.org/htup__details_8h_source.html
我可以理解手动按位运算符&
示例。
但在这里我不明白所有的比较t_infomask
和t_infomask2
变体整数。
您可以在 中找到该信息
src/include/access/htup_details.h
。关于
t_infomask
:关于
t_infomask2
:所以
t_infomask & 256
意味着存储的事务xmin
被标记为已提交,并且t_infomask & 512
意味着存储的事务xmin
被回滚或无效。t_infomask & 1024
并且t_infomask & 2048
对于 是相同的xmax
。这些所谓的“提示位”提供了提交有关元组可见性的日志信息的快捷方式。
t_infomask2 & 16384
表示该元组已使用HOT update进行了更新,并且t_infomask2 & 32768
表示该元组是仅堆元组。