Re: Reducing relcache memory usage 2: shrink sizeof(RelationData)

From: David Geier <geidav(dot)pg(at)gmail(dot)com>
To: Yilin Zhang <jiezhilove(at)126(dot)com>
Cc: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Haibo Yan <tristan(dot)yim(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Reducing relcache memory usage 2: shrink sizeof(RelationData)
Date: 2026-10-20 12:31:56
Message-ID: 83bf34d1-8e57-4d14-b2a1-fbc677a31742@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Yilin,

> There is still a crash in the v5 patch series, similar to the predicate
> crash that Haibo already mentioned.
> Minimal reproduction steps:
>
> CREATE TABLE t(a int primary key, b text);
> CREATE INDEX t_b_idx ON t(b);
>
> SELECT pg_relation_is_updatable('t_b_idx'::regclass, false);
> -- server closed the connection unexpectedly
>
> SELECT pg_column_is_updatable('t_b_idx'::regclass, 1::int2, false);
> -- server closed the connection unexpectedly
>
> Please take this into consideration.
Thanks for testing the patch!

The problem was that relation_is_updatable() accessed rel->rd_rules
without checking that the relcache entry is actually for a relation and
not for an index. Bailing for indexes fixes the crash:

/* Indexes are not updatable */
if (RelationIsIndex(rel))
{
relation_close(rel, AccessShareLock);
return 0;
}

Attached is patch set v6 with the fix.

--
David Geier

Attachment Content-Type Size
v6-0001-Assert-CacheMemoryContext-exists-in-relcache-call.patch text/x-patch 1.7 KB
v6-0002-Allocate-RelationData-structs-in-a-dedicated-slab.patch text/x-patch 4.1 KB
v6-0003-Move-RelationData-to-an-internal-header.patch text/x-patch 22.8 KB
v6-0004-Overlay-relation-kind-specific-relcache-fields.patch text/x-patch 39.7 KB
v6-0005-Allocate-partition-cache-data-lazily.patch text/x-patch 20.5 KB
v6-0006-Pack-RelationData-to-eliminate-padding.patch text/x-patch 5.1 KB
v6-0007-Compute-relation-lock-identifiers-on-demand.patch text/x-patch 20.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2026-10-20 12:36:05 Re: [PATCH] Fix segmentation fault caused by reentrancy in RI_Fkey_cascade_del (ri_triggers.c)
Previous Message kedar anavardekar 2026-10-20 12:22:49 Re: Publication of same parent table with ONLY-ness mismatch should error