Add sanity check for duplicate enum values in GUC definitions

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add sanity check for duplicate enum values in GUC definitions
Date: 2025-12-15 09:16:56
Message-ID: CAEoWx2nAKPx1N1VzKVHjtwqP+s=yMR+Fdmrh44uVNODg--T03w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

The motivation for this patch comes from my own experience. While working
on [1]. I added an enum-typed GUC and made a copy-and-paste mistake,
assigning the same numeric value to two different enum entries. This
resulted in confusing runtime behavior and cost me about an hour to track
down.

I think adding a sanity check for enum-typed GUCs would help catch this
class of mistake early. Ideally, such a check would run at compile time,
but that would require parsing guc_tables.c with Perl. I’m not very
familiar with Perl, so in this patch I instead added the check when
building the GUC hash table.

There are a few existing enum GUCs that intentionally reuse numeric values
(for example, to provide aliases), so I introduced a small whitelist for
those cases. If a new GUC needs duplicate enum values in the future, its
name can simply be added to that list.

This check is intended as a developer-facing sanity guard to catch mistakes
in GUC enum tables. Given that intent, once a duplicate value is detected
the backend aborts early. From that perspective, it might also make sense
to place this check under #ifdef USE_ASSERT_CHECKING. I’m interested in
hearing thoughts on that approach.

[1]
https://postgr.es/m/CAEoWx2mMorbMwjKbT4YCsjDyL3r9Mp+z0bbK57VZ+OkJTgJQVQ@mail.gmail.com

--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v1-0001-Add-sanity-check-for-duplicate-enum-values-in-GUC.patch application/octet-stream 4.7 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-12-15 09:25:18 Re: Proposal: Conflict log history table for Logical Replication
Previous Message shveta malik 2025-12-15 09:10:51 Re: POC: enable logical decoding when wal_level = 'replica' without a server restart