Обсуждение: remove unnecessary include in src/backend/commands/policy.c

Поиск
Список
Период
Сортировка

remove unnecessary include in src/backend/commands/policy.c

От
jian he
Дата:
hi.

in src/backend/commands/policy.c, i found that
#include "access/htup.h"
#include "access/htup_details.h"
#include "catalog/catalog.h"
#include "nodes/pg_list.h"
#include "parser/parse_node.h"
#include "utils/array.h"

is not necessary "include", so I removed it.

we can also remove
#include "access/relation.h"
replace relation_open to table_open, since we already did relkind check in
RangeVarCallbackForPolicy.

Вложения

Re: remove unnecessary include in src/backend/commands/policy.c

От
Chao Li
Дата:


On Sep 14, 2025, at 14:37, jian he <jian.universality@gmail.com> wrote:

hi.

in src/backend/commands/policy.c, i found that
#include "access/htup.h"
#include "access/htup_details.h"
#include "catalog/catalog.h"
#include "nodes/pg_list.h"
#include "parser/parse_node.h"
#include "utils/array.h"

is not necessary "include", so I removed it.

we can also remove
#include "access/relation.h"
replace relation_open to table_open, since we already did relkind check in
RangeVarCallbackForPolicy.
<v1-0001-remove-unnecessary-include-in-policy.c.patch>

LGTM. I built the patch on MacOS M4, and build passed without warning.

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




Re: remove unnecessary include in src/backend/commands/policy.c

От
Shinya Kato
Дата:
Hi,

On Sun, Sep 14, 2025 at 3:38 PM jian he <jian.universality@gmail.com> wrote:
>
> hi.
>
> in src/backend/commands/policy.c, i found that
> #include "access/htup.h"
> #include "access/htup_details.h"
> #include "catalog/catalog.h"
> #include "nodes/pg_list.h"
> #include "parser/parse_node.h"
> #include "utils/array.h"
>
> is not necessary "include", so I removed it.
>
> we can also remove
> #include "access/relation.h"
> replace relation_open to table_open, since we already did relkind check in
> RangeVarCallbackForPolicy.

Thanks for the patch!
I can confirm that it builds successfully and passes the regression tests.

However, the changes make policy.c rely on transitive includes. For
example, policy.c uses GETSTRUCT(), which is defined in
access/htup_details.h. Instead of being included directly, that header
is currently pulled in via a fairly long chain:
catalog/indexing.h -> nodes/execnodes.h -> access/tupconvert.h ->
executor/tuptable.h -> access/htup_details.h

While this works for now, the dependency is fragile and could break if
header files are rearranged in the future. I'm not sure this is a good
practice, and although I couldn't find a specific rule against it in
PostgreSQL's coding conventions, it seems risky.

--
Best regards,
Shinya Kato
NTT OSS Center