HASH_FIXED_SIZE flag gets lost when attaching to existing hash table

From: Aidar Imamov <a(dot)imamov(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: HASH_FIXED_SIZE flag gets lost when attaching to existing hash table
Date: 2025-07-24 15:41:36
Message-ID: 4d0cb35ff01c5c74d2b9a582ecb73823@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Recently, while working with hash tables in dynahash.c, I noticed
something weird.
When a hash table is already created in shared memory, and the another
process
calls hash_create attempting to attach to it, it seems like the
HASH_FIXED_SIZE
flag gets lost.

For example, if you start the server compiled with the EXEC_BACKEND
option, and a
hash table with a fixed size is created at the beginning in shared
memory, any
other process started by the postmaster then tries to initialize its
hash table
pointer by calling hash_create with HASH_ATTACH flag. But the table
structure it
points to has 'isfixed' flag set to false, even though the original
table was
created with a HASH_FIXED_SIZE provided.

This could lead to the situation where, when the table's capacity limit
is reached
(which was specified when the table was created), the process will
silently occupy
more of the shared memory (up to a certain point?). Then, another insert
could
trigger an out of shared memory error.

Any thoughts?

Regards,
Aidar Imamov

Attachment Content-Type Size
isfixed_check.patch text/x-diff 456 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2025-07-24 16:47:58 Re: PoC: adding CustomJoin, separate from CustomScan
Previous Message vignesh C 2025-07-24 15:31:50 Re: Logical Replication of sequences