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+okjtgj...@mail.gmail.com -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
v1-0001-Add-sanity-check-for-duplicate-enum-values-in-GUC.patch
Description: Binary data
