From: Michael Paquier <michael@paquier.xyz>
To: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table
Date: Tue, 19 Dec 2023 18:20:44 +0900
Message-ID: <ZYFgbOGYpsaen5LF@paquier.xyz> (raw)
In-Reply-To: <11c0916f-82de-decf-c27a-c01a4f8dfcef@gmail.com>
References: <18246-f4d9ff7cb3af77e6@postgresql.org>
<ZXm9Js8D_W_cFWzW@paquier.xyz>
<876b6e52-f068-648a-3f0e-7eaabd57cf77@gmail.com>
<11c0916f-82de-decf-c27a-c01a4f8dfcef@gmail.com>
On Fri, Dec 15, 2023 at 04:00:01PM +0300, Alexander Lakhin wrote:
> 13.12.2023 21:00, Alexander Lakhin wrote:
>> 13.12.2023 17:18, Michael Paquier wrote:
>> > On Wed, Dec 13, 2023 at 09:00:01AM +0000, PG Bug reporting form wrote:
>> > > This anomaly can be observed since 8b08f7d48 from 2018-01-19, but IMO the
>> > > culprit is e759854a0 from 2017-02-03, which introduced the following
>> > > asymmetry in pgstatindex.c:
>> > > if (!IS_INDEX(rel) || !IS_BTREE(rel))
>> > > if (!IS_INDEX(rel) || !IS_GIN(rel))
>> > > But:
>> > > if (!IS_HASH(rel))
>> > Fun, let's fix that. Would you like to write a patch?
>>
>> Yes, please look at the attached,
Thanks. The one for pgstattuple has been applied down to 12 as of
a8dd62ef4959.
> Looking around, I found the similar index_open() usage within pageinspect,
> function hash_bitmap_info():
> CREATE EXTENSION pageinspect;
> CREATE TABLE t (a int, b int[], c int) PARTITION BY RANGE (a);
> CREATE INDEX c_idx ON t USING hash(c);
> SELECT hash_bitmap_info('c_idx'::regclass, 1);
>
> Leads to:
> TRAP: failed Assert("false"), File: "bufmgr.c", Line: 3606, PID: 3984550
Right.
> I'm inclined to leave index_open() there for the internal consistency
> inside pageinspect, and to use the same condition as in
> bt_index_block_validate(), which called by functions bt_page_stats(...),
> bt_multi_page_stats(...), bt_page_items(relname text, blkno bigint).
>
> Functions for other index types, brin/gin/gist, don't read the index,
> instead they receive a page as input.
Not sure to agree on that. It seems a bit strange to bump on a
different error when using a partitioned index or a relkind not
allowed by index_open(). And this is after looking at the pgstattuple
code.
At the end, I've switched to relation_open() for this one, added a
test and applied the second patch as of 208470136421. I've checked
the rest and yes, it looks like there are no other holes like the
ones you have reported for the contrib modules when it comes to index
manipulations.
--
Michael
Attachments:
[application/pgp-signature] signature.asc (832B, ../ZYFgbOGYpsaen5LF@paquier.xyz/2-signature.asc)
download
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-bugs@postgresql.org
Cc: michael@paquier.xyz, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table
In-Reply-To: <ZYFgbOGYpsaen5LF@paquier.xyz>
* 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