Invalid result from hash_page_items function

From: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Invalid result from hash_page_items function
Date: 2018-01-25 21:50:59
Message-ID: CAD21AoBc5Asx7pXdUWu6NqU_g=Ysn95EGL9SMeYhLLduYoO_OA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

While researching hash index, I found that hash_page_items could
return an invalid result as follows.

postgres(1:1056)=# create table hash_test (c int);
CREATE TABLE
postgres(1:1056)=# insert into hash_test select generate_series(1,50) % 5;
INSERT 0 50
postgres(1:1056)=# create index hash_idx on hash_test using hash (c);
CREATE INDEX
postgres(1:1056)=# create extension pageinspect ;
CREATE EXTENSION
postgres(1:1056)=# select * from hash_page_items(get_raw_page('hash_idx',
4));
itemoffset | ctid | data
------------+--------------------+------------
1 | (0,49) | 3283889963
2 | (2139062143,32639) | 2139062143
3 | (2139062143,32639) | 2139062143
4 | (2139062143,32639) | 2139062143
5 | (2139062143,32639) | 2139062143
6 | (2139062143,32639) | 2139062143
7 | (2139062143,32639) | 2139062143
8 | (2139062143,32639) | 2139062143
9 | (2139062143,32639) | 2139062143
10 | (2139062143,32639) | 2139062143
(10 rows)

This appears at PostgreSQL 10 and current HEAD. The cause of this
seems that hash_page_items allocates the memory space for the page
before switching memory context. AFAICS there is no similar problem in
pageinspect contrib module. Attached patch fixes it.

Regards,

--
Masahiko Sawada
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachment Content-Type Size
fix_hash_page_items.patch application/octet-stream 561 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2018-01-25 21:52:47 Re: [HACKERS] Patch: Add --no-comments to skip COMMENTs with pg_dump
Previous Message Bruce Momjian 2018-01-25 21:38:07 Re: After dropping the rule - Not able to insert / server crash (one time ONLY)