From: Maksim Milyutin <milyutinma@gmail.com>
To: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Subject: [HACKERS] wrong t_bits alignment in pageinspect
Date: Fri, 15 Dec 2017 16:53:41 +0300
Message-ID: <ec295792-a69f-350f-6287-25a20e8f31d5@gmail.com> (raw)
Hi!
I found out the problem in exposing values of t_bits field from
heap_page_items function.
When the number of attributes in table is multiple of eight, t_bits
column shows double number of bits in which data fields are included.
For example:
# create table tbl(f1 int, f2 int, f3 int, f4 int, f5 int, f6 int, f7
int, f8 int);
# insert into tbl(f1, f8) values (x'f1'::int, 0);
# select t_bits, t_data from heap_page_items(get_raw_page('tbl', 0));
t_bits | t_data
------------------+--------------------
1000000110001111 | \xf100000000000000
I suppose the prefix 10000001 corresponds to real value of t_bits, the
rest part 10001111 - to the lower byte of f1 field of tbl.
Attached patch fixes this issue.
--
Regards,
Maksim Milyutin
Attachments:pageinspect_tbits_alignment_fix.patch (text/x-patch, 506B) downloaddiff --git a/contrib/pageinspect/heapfuncs.c b/contrib/pageinspect/heapfuncs.cindex ca4d3f5..fe53a1a 100644--- a/contrib/pageinspect/heapfuncs.c+++ b/contrib/pageinspect/heapfuncs.c@@ -234,7 +234,7 @@ heap_page_items(PG_FUNCTION_ARGS)
int bits_len;
bits_len =
- ((tuphdr->t_infomask2 & HEAP_NATTS_MASK) / 8 + 1) * 8;+ TYPEALIGN(8, (tuphdr->t_infomask2 & HEAP_NATTS_MASK));
values[11] = CStringGetTextDatum(
bits_to_text(tuphdr->t_bits, bits_len));
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: milyutinma@gmail.com
Subject: Re: [HACKERS] wrong t_bits alignment in pageinspect
In-Reply-To: <ec295792-a69f-350f-6287-25a20e8f31d5@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox