Обсуждение: What's the prefix?
use these sqls:
create table t(a text);
insert into t values('a');
select lp,lp_len,t_data from heap_page_items(get_raw_page('t',0));
lp | lp_len | t_data
----+--------+--------
1 | 26 | \x0561
as you can see, the 61 is 'a', so what's the 05??? strange.
jacktby@gmail.com
On Sun, Feb 26, 2023 at 9:16 AM jacktby@gmail.com <jacktby@gmail.com> wrote:
use these sqls:create table t(a text);insert into t values('a');select lp,lp_len,t_data from heap_page_items(get_raw_page('t',0));lp | lp_len | t_data----+--------+--------1 | 26 | \x0561as you can see, the 61 is 'a', so what's the 05??? strange.
text is variable length so there is header information built into the datatype representation that indicates how long the content is.
David J.
On Sun, Feb 26, 2023 at 9:16 AM jacktby@gmail.com <jacktby@gmail.com> wrote:use these sqls:create table t(a text);insert into t values('a');select lp,lp_len,t_data from heap_page_items(get_raw_page('t',0));lp | lp_len | t_data----+--------+--------1 | 26 | \x0561as you can see, the 61 is 'a', so what's the 05??? strange.text is variable length so there is header information built into the datatype representation that indicates how long the content is.David J.No, this is the varlena struct:struct varlena{char vl_len_[4]; /* Do not touch this field directly! */char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */};when I insert 'a', this struct will be {vl_len : 00 00 00 05vl_dat: 'a'}the t_data should be \x0000000561, but it's \x0561? strange----------------------------------------------------------------------------------
"jacktby@gmail.com" <jacktby@gmail.com> writes: >> text is variable length so there is header information built into the datatype representation that indicates how longthe content is. David's statement is accurate. > No, this is the varlena struct: > struct varlena > { > char vl_len_[4]; /* Do not touch this field directly! */ > char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */ This struct only accurately describes "untoasted" varlenas. The one you are looking at is a "short header" varlena; see varattrib_1b and nearby comments in src/include/varatt.h, or in postgres.h if you're not looking at current HEAD branch. regards, tom lane