Add sanity check for duplicate enum values in GUC definitions

Поиск
Список
Период
Сортировка
От Chao Li
Тема Add sanity check for duplicate enum values in GUC definitions
Дата
Msg-id CAEoWx2nAKPx1N1VzKVHjtwqP+s=yMR+Fdmrh44uVNODg--T03w@mail.gmail.com
обсуждение исходный текст
Список 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.

Вложения

В списке pgsql-hackers по дате отправления: