[18] Fix a few issues with the collation cache

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [18] Fix a few issues with the collation cache
Date: 2024-08-08 19:24:28
Message-ID: 54d20e812bd6c3e44c10eddcd757ec494ebf1803.camel@j-davis.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The collation cache, which maps collation oids to pg_locale_t objects,
has a few longstanding issues:

1. Using TopMemoryContext too much, with potential for leaks on error
paths.

2. Creating collators (UCollator for ICU or locale_t for libc) that can
leak on some error paths. For instance, the following will leak the
result of newlocale():

create collation c2 (provider=libc,
locale='C.utf8', version='bogus');

3. Not invalidating the cache. Collations don't change in a way that
matters during the lifetime of a backend, so the main problem is DROP
COLLATION. That can leave dangling entries in the cache until the
backend exits, and perhaps be a problem if there's OID wraparound.

The patches make use of resource owners for problems #2 and #3. There
aren't a lot of examples where resource owners are used in this way, so
I'd appreciate feedback on whether this is a reasonable thing to do or
not. Does it feel over-engineered? We can solve these problems by
rearranging the code to avoid problem #2 and iterating through the hash
table for problem #3, but using resource owners felt cleaner to me.

These problems exist in all supported branches, but the fixes are
somewhat invasive so I'm not inclined to backport them unless someone
thinks the problems are serious enough.

Regards,
Jeff Davis

Attachment Content-Type Size
v1-0001-Minor-refactor-of-collation-cache.patch text/x-patch 11.7 KB
v1-0002-Tighten-up-make_libc_collator-and-make_icu_collat.patch text/x-patch 6.9 KB
v1-0003-For-collation-cache-use-CollationCacheContext-for.patch text/x-patch 5.7 KB
v1-0004-Use-resource-owners-to-track-locale_t-and-ICU-col.patch text/x-patch 6.0 KB
v1-0005-Invalidate-collation-cache-when-appropriate.patch text/x-patch 3.4 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-08-08 19:28:04 Re: Don't overwrite scan key in systable_beginscan()
Previous Message Robert Haas 2024-08-08 19:24:11 Re: [patch] Imporve pqmq