Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSX1i-003ExU-2U for pgsql-hackers@arkaria.postgresql.org; Thu, 28 May 2026 09:27:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wSX1e-00BTdR-1e for pgsql-hackers@arkaria.postgresql.org; Thu, 28 May 2026 09:27:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wSX1e-00BTdJ-0D for pgsql-hackers@lists.postgresql.org; Thu, 28 May 2026 09:27:39 +0000 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wSX1d-0000000194o-09d6 for pgsql-hackers@lists.postgresql.org; Thu, 28 May 2026 09:27:38 +0000 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-82f8b60e54dso9990460b3a.2 for ; Thu, 28 May 2026 02:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779960456; x=1780565256; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=Z+mXTBlsuF7Y8epsnCiscV2nJYN4/LIqXbdle/1wgTU=; b=HUJ1K4u1Gso3mF81r7PntmpsNjOqkJzJcmPSbBE9vQac+qPcYqxbVRtKnZ6NlSy4P6 iWlbxzrGD9/QoA9gY09UrQXVzLnZ52YlU67BRAO/hy7fAkQijyt9m4FAGLjM9cMoZNEj YEuM1Ied3+5+njtDNsd1ghcdFoUJHVohpc9MrItd/eHThTD3J0LyGgev4YwNQHuAxVtB d2gO9bOvkPP4M/TV7IHlHuJbNolEfSVhK00biVRsM6T9BLLZVR1yzZlXkl3dWvK8bnco kbbm3rKFQWIfTcXNwCPDxR2eRgke/zZo+HRKA48NVNyDjLWmBGsF6juPAQMJKpsaxvDs Hmtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779960456; x=1780565256; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z+mXTBlsuF7Y8epsnCiscV2nJYN4/LIqXbdle/1wgTU=; b=aml513ByjNO9tn8Dokqhs0uxhKX2aj+LCmri6e0y6xa2upJGj89DYK5L9K9oeJy1zf OfBnhJCjbvwb5KKe8xGJR4B40eldopbs1Tayr31gRUzjrBuhujx4Sk9GFnCWsuknzDnJ ddg2yDjVwwtUXs3A5n5OSEfZIAPVdBpLRYIhoqva2VOqm+5RIFlO1uIkuR/scZ7CiEXp P4uYrkaDRJWl47YUVnCmuTQzGtCdciCKlqaO6zvDbWC1eE9ZnenT2sMU6bCl2ph06jw4 RCrT5vW2TlLTLzoBZ1yvBmFlSHlqD1i8UAJrrwTd2cJ36DACInWoSK90nKptWUxGUko+ ncUg== X-Forwarded-Encrypted: i=1; AFNElJ/43pm7StANBW5ubM9BGl0RVkR1Dxv+sG8UYInjYCGaiDugNXi4OFrmdhBOdaYCarHnfUCEmqtRFFafOlKX@lists.postgresql.org X-Gm-Message-State: AOJu0YwpJ4nLkIzTWBMgN67qeIHIy0VVtz/iipItganyUBFyx4Ly/cbn 2lyVxs6iRyYaxsC4nGBklzGmv7NmUbU4ems61R516bmtkqW4KgK2UjpU/1dFoLrZ1fU= X-Gm-Gg: Acq92OGMGjWpqeYVKYjVqUWK8yaHNsCefIkf63EwJyPdHZoEqtDF/BzpTld64k9cUH/ aydCI1opMOAs1bbaLsJWalJv/zZ6hplG5r7Nkik7hQxCw0Aum1iw3jyDe5MlzoFsIBmcYcGUYeo quJXkSOq0paKXsHCn6qOelrYOei2vaeZhC9NXOGm+SVapxbV/1VLsyz8NvA9pZl+i1WQMr4BvBr a6reW7u7qy54NwIiryWThLD7JDVawfQQY+Ugw6I/PI9NFzSY99oc/O+BtDgPMnqYml43SqrYQOI Qwrk4sraLlTRFvo2tuXTund8I5vBETlXzNL6rjDncksD+reLVbOuDLh21wxNycnarq8hDsFqNCR cHdvrfNpKUDEME52ulH5lohxZG4ScsCsp8+jCAZ8lJRRHx4N5Dzp0MvAQzJZKS/LCQv4QlJm0Qb FFLdS1NyU5JlTl7UwD02/VmRKTdEqOIzGX0AU/f+F58A== X-Received: by 2002:a05:6a00:1944:b0:82f:5125:a327 with SMTP id d2e1a72fcca58-8415f33006amr24236932b3a.27.1779960455573; Thu, 28 May 2026 02:27:35 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-841d70f3473sm4432483b3a.44.2026.05.28.02.27.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2026 02:27:34 -0700 (PDT) From: Chao Li Message-Id: <7BF5468D-51A1-42BE-A4AD-CC8211F52D6E@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_ACFBFF33-3789-4D1E-9EF6-481935DF54F9" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: tablecmds: clarify recurse vs recusing Date: Thu, 28 May 2026 17:26:55 +0800 In-Reply-To: Cc: Peter Eisentraut , Postgres hackers To: Tom Lane References: <1078495.1768839280@sss.pgh.pa.us> <1734390.1768939652@sss.pgh.pa.us> X-Mailer: Apple Mail (2.3864.600.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_ACFBFF33-3789-4D1E-9EF6-481935DF54F9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 21, 2026, at 06:55, Chao Li wrote: >=20 >=20 >=20 >> On Jan 21, 2026, at 04:07, Tom Lane wrote: >>=20 >> Chao Li writes: >>> Enhancing the header comments also helps here. >>> PSA v2: >>=20 >> I had something more like the attached in mind. I'm not generally >> a fan of documenting only some of the arguments of a function, so >> I don't care for the way you handled the issue for other functions >> in tablecmds.c either. We can either assume that people read >> ATPrepCmd's comment and can extrapolate to the other functions, >> or we can do something similar to this for all of them. >=20 > Got it, thanks. In v4, I=E2=80=99ve limited the changes to fully = documenting all ATPrepCmd() arguments in its header comment and removed = the scattered recurse/recursing references from other functions. >=20 >>=20 >> I do agree with your 0002, but I see no point in pushing that >> separately. >=20 > Absolutely. 0002 was too trivial to be a separate commit. I have = squashed it into 0001 in v4. >=20 > Best regards, > -- > Chao Li (Evan) > HighGo Software Co., Ltd. > https://www.highgo.com/ >=20 >=20 >=20 >=20 > Trying to bump this patch because, while working on patch [1], I needed = to think about the meaning of =E2=80=9Crecurse=E2=80=9D and = =E2=80=9Crecursing=E2=80=9D. That reminded me of this patch, and it = helped me recall the distinction. So I still think this pure comment = update patch is still helpful. Attached v5 is just a rebased version, with no changes from v4. [1] = https://www.postgresql.org/message-id/E74C57FA-1DD0-4C8E-8FB1-538034752592= %40gmail.com Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_ACFBFF33-3789-4D1E-9EF6-481935DF54F9 Content-Disposition: attachment; filename=v5-0001-tablecmds-clarify-recurse-recursing-semantics-in-.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v5-0001-tablecmds-clarify-recurse-recursing-semantics-in-.patch" Content-Transfer-Encoding: quoted-printable =46rom=209108d4544a425ae8a1818e3a7dc722d00c65bb59=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Tue,=2020=20Jan=202026=2009:57:24=20+0800=0ASubject:=20[PATCH=20= v5]=20tablecmds:=20clarify=20recurse/recursing=20semantics=20in=0A=20= ATPrepCmd()=0A=0ADocument=20all=20ATPrepCmd()=20arguments=20and=20= centralize=20the=20explanation=20of=20how=0Arecurse=20and=20recursing=20= interact=20during=20ALTER=20TABLE=20recursion.=20Remove=0Ascattered=20= partial=20comments=20and=20keep=20other=20function=20comments=20= lightweight.=0A=0ANo=20functional=20changes.=0A=0AAuthor:=20Chao=20Li=20= =0AReviewed-by:=20Tom=20Lane=20=0A= Discussion:=20= https://postgr.es/m/CAEoWx2n9E6_zxPbqwMpaPuC1C_p4b3y635SjiDuCPSVm8GBjsA@ma= il.gmail.com=0A---=0A=20src/backend/commands/tablecmds.c=20|=2035=20= +++++++++++++++++++++++++-------=0A=201=20file=20changed,=2028=20= insertions(+),=207=20deletions(-)=0A=0Adiff=20--git=20= a/src/backend/commands/tablecmds.c=20b/src/backend/commands/tablecmds.c=0A= index=20a1845240a98..63cd1df71bc=20100644=0A---=20= a/src/backend/commands/tablecmds.c=0A+++=20= b/src/backend/commands/tablecmds.c=0A@@=20-4577,11=20+4577,10=20@@=20= AlterTableLookupRelation(AlterTableStmt=20*stmt,=20LOCKMODE=20lockmode)=0A= =20=20*=0A=20=20*=20The=20caller=20must=20lock=20the=20relation,=20with=20= an=20appropriate=20lock=20level=0A=20=20*=20for=20the=20subcommands=20= requested,=20using=20AlterTableGetLockLevel(stmt->cmds)=0A-=20*=20or=20= higher.=20We=20pass=20the=20lock=20level=20down=0A-=20*=20so=20that=20we=20= can=20apply=20it=20recursively=20to=20inherited=20tables.=20Note=20that=20= the=0A-=20*=20lock=20level=20we=20want=20as=20we=20recurse=20might=20= well=20be=20higher=20than=20required=20for=0A-=20*=20that=20specific=20= subcommand.=20So=20we=20pass=20down=20the=20overall=20lock=20= requirement,=0A-=20*=20rather=20than=20reassess=20it=20at=20lower=20= levels.=0A+=20*=20or=20higher.=20We=20pass=20the=20lock=20level=20down=20= so=20that=20we=20can=20apply=20it=20recursively=0A+=20*=20to=20inherited=20= tables.=20Note=20that=20the=20lock=20level=20we=20want=20as=20we=20= recurse=20might=0A+=20*=20well=20be=20higher=20than=20required=20for=20= that=20specific=20subcommand.=20So=20we=20pass=20down=0A+=20*=20the=20= overall=20lock=20requirement,=20rather=20than=20reassess=20it=20at=20= lower=20levels.=0A=20=20*=0A=20=20*=20The=20caller=20also=20provides=20a=20= "context"=20which=20is=20to=20be=20passed=20back=20to=0A=20=20*=20= utility.c=20when=20we=20need=20to=20execute=20a=20subcommand=20such=20as=20= CREATE=20INDEX.=0A@@=20-4960,8=20+4959,29=20@@=20= ATController(AlterTableStmt=20*parsetree,=0A=20=20*=20Traffic=20cop=20= for=20ALTER=20TABLE=20Phase=201=20operations,=20including=20simple=0A=20=20= *=20recursion=20and=20permission=20checks.=0A=20=20*=0A-=20*=20Caller=20= must=20have=20acquired=20appropriate=20lock=20type=20on=20relation=20= already.=0A-=20*=20This=20lock=20should=20be=20held=20until=20commit.=0A= +=20*=20*wqueue:=20resulting=20AlteredTableInfo=20structs=20are=20added=20= to=20this=20list=0A+=20*=20rel:=20the=20relation=20we=20are=20currently=20= considering=0A+=20*=20cmd:=20the=20ALTER=20TABLE=20subcommand=20we=20are=20= currently=20considering=0A+=20*=20recurse:=20true=20to=20recurse=20to=20= child=20tables=20of=20rel=20(including=20partitions)=0A+=20*=20= recursing:=20true=20if=20already=20recursing=20(rel=20is=20a=20= descendant=20of=20original=20table)=0A+=20*=20lockmode:=20lock=20level=20= held=20on=20rel,=20and=20to=20be=20acquired=20on=20children=0A+=20*=20= context:=20context=20passed=20down=20from=20ProcessUtility,=20or=20NULL=20= if=20none=0A+=20*=0A+=20*=20At=20top=20level,=20recurse=20is=20true=20= unless=20the=20command=20specified=20ONLY.=0A+=20*=20Internally,=20= recurse=20may=20be=20true=20when=20descending=20the=20inheritance=20tree=0A= +=20*=20on-the-fly,=20or=20false=20when=20the=20tree=20has=20already=20= been=20expanded=20at=20an=0A+=20*=20outer=20level=20(see=20= ATSimpleRecursion).=0A+=20*=0A+=20*=20recurse=20and=20recursing=20= together=20control=20how=20recursion=20proceeds:=0A+=20*=0A+=20*=20=20=20= recurse=3Dfalse,=20recursing=3Dfalse:=20top-level=20call,=20no=20= recursion=0A+=20*=20=20=20recurse=3Dtrue,=20=20recursing=3Dfalse:=20= top-level=20call,=20recurse=20if=20supported=0A+=20*=20=20=20= recurse=3Dtrue,=20=20recursing=3Dtrue:=20=20recursive=20call,=20continue=20= recursion=0A+=20*=20=20=20recurse=3Dfalse,=20recursing=3Dtrue:=20=20= recursive=20call,=20stop=20recursion=0A+=20*=0A+=20*=20Caller=20must=20= have=20acquired=20lockmode=20on=20rel=20already.=20This=20lock=20should=20= be=20held=0A+=20*=20until=20commit.=20If=20we=20recurse,=20the=20same=20= lockmode=20will=20be=20acquired=20on=20child=0A+=20*=20tables.=0A=20=20= */=0A=20static=20void=0A=20ATPrepCmd(List=20**wqueue,=20Relation=20rel,=20= AlterTableCmd=20*cmd,=0A@@=20-10819,6=20+10839,7=20@@=20= validateFkOnDeleteSetColumns(int=20numfks,=20const=20int16=20*fkattnums,=0A= =20=20*=20=20=20=20=20=20(...)=20clause=0A=20=20*=20fkdelsetcols:=20the=20= attnum=20array=20of=20the=20columns=20in=20the=20ON=20DELETE=20SET=0A=20=20= *=20=20=20=20=20=20NULL/DEFAULT=20clause=0A+=20*=20is_internal:=20true=20= if=20this=20is=20an=20internally=20generated=20constraint=0A=20=20*=20= with_period:=20true=20if=20this=20is=20a=20temporal=20FK=0A=20=20*/=0A=20= static=20ObjectAddress=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_ACFBFF33-3789-4D1E-9EF6-481935DF54F9--