Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18246: pgstathashindex() attempts to read invalid file for hash index attached to partitioned table
Date: 2023-12-15 13:00:01
Message-ID: 11c0916f-82de-decf-c27a-c01a4f8dfcef@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

13.12.2023 21:00, Alexander Lakhin wrote:
> Hello Michael,
>
> 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,

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

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.

Please look at the additional patch.

Best regards,
Alexander

Attachment Content-Type Size
v1-fix-hash_bitmap_info.patch text/x-patch 792 bytes
v1-fix-pgstathashindex.patch text/x-patch 4.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Laurenz Albe 2023-12-15 13:03:43 Re: BUG #18249: pg_dump/pg_restore single schema with function1 calling function2
Previous Message Richard Guo 2023-12-15 12:01:45 Re: BUG #18247: Integer overflow leads to negative width