pg_walfile_name_offset can return inconsistent values

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: pg_walfile_name_offset can return inconsistent values
Date: 2019-07-26 08:21:20
Message-ID: 20190726.172120.101752680.horikyota.ntt@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello.

While looking [1], I noticed that pg_walfile_name_offset behaves
somewhat oddly at segment boundary.

select * from (values ('0/16ffffff'), ('0/17000000'), ('0/17000001')) as t(lsn), lateral pg_walfile_name_offset(lsn::pg_lsn);
lsn | file_name | file_offset
------------+--------------------------+-------------
0/16ffffff | 000000020000000000000016 | 16777215
0/17000000 | 000000020000000000000016 | 0
0/17000001 | 000000020000000000000017 | 1

The file names are right as defined, but the return value of the
second line wrong, or at least misleading. It should be (16,
1000000) or (16, FFFFFF). The former is out-of-domain so we would
have no way than choosing the latter. I'm not sure the purpose of
the second output parameter, thus the former might be right
decision.

The function returns the following result after this patch is
applied.

select * from (values ('0/16ffffff'), ('0/17000000'), ('0/17000001')) as t(lsn), lateral pg_walfile_name_offset(lsn::pg_lsn);
lsn | file_name | file_offset
------------+--------------------------+-------------
0/16ffffff | 000000020000000000000016 | 16777214
0/17000000 | 000000020000000000000016 | 16777215
0/17000001 | 000000020000000000000017 | 0

regards.

[1]: https://www.postgresql.org/message-id/20190725193808.1648ddc8@firost

--
Kyotaro Horiguchi
NTT Open Source Software Center

Attachment Content-Type Size
0001-Fix-offset-of-pg_walfile_name_offset.patch text/x-patch 1.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jehan-Guillaume de Rorthais 2019-07-26 09:30:19 Re: pg_walfile_name_offset can return inconsistent values
Previous Message Fabien COELHO 2019-07-26 08:19:47 Re: psql - add SHOW_ALL_RESULTS option