| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: ATPrepCmd: cleanup unreachable AT_AddIndexConstraint handling |
| Date: | 2026-01-29 02:00:04 |
| Message-ID: | 6FD51FD0-0D42-431B-8864-4217C0F2B140@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
> On Jan 28, 2026, at 14:14, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
> Hi Hackers,
>
> While working on the patch [1], I was looking at the handling of AT_AddIndexConstraint in ATPrepCmd():
> ```
> ATPrepCmd()
> {
> case AT_AddIndexConstraint: /* ADD CONSTRAINT USING INDEX */
> ATSimplePermissions(cmd->subtype, rel, ATT_TABLE | ATT_PARTITIONED_TABLE);
> /* This command never recurses */
> /* No command-specific prep needed */
> pass = AT_PASS_ADD_INDEXCONSTR;
> }
> ```
>
> I initially thought the comment about “never recurses” was stale, but after some debugging, I found that this branch is actually unreachable. So leaving the code and comments in an unreachable branch would be confusing for readers.
>
> This patch cleans up the handling by putting an Assert(false) there and adding a comment to explain why this code path is unreachable. I did think about just deleting the branch, but decided to keep it: if it were removed entirely, readers might wonder why AT_AddIndexConstraint is not handled in ATPrepCmd() and end up spending time debugging this themselves.
>
I thought over and decided to delete AT_AddIndexConstraint from ATPrepCmd, which should be cleaner.
PFA v2:
* Deleted AT_AddIndexConstraint from ATPrepCmd
* Added a comment under AT_AddConstraint to explain how AT_AddIndexConstraint is handled
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v2-0001-tablecmds-cleanup-unreachable-AT_AddIndexConstrai.patch | application/octet-stream | 4.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-01-29 02:41:18 | Re: pg_plan_advice |
| Previous Message | David G. Johnston | 2026-01-29 01:59:45 | Re: docs: clarify ALTER TABLE behavior on partitioned tables |