Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCJQC-0006qt-TZ for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 10:19:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mCJPf-0000U8-0W for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Aug 2021 10:18:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCJPd-0000Tz-A4 for pgsql-hackers@lists.postgresql.org; Sat, 07 Aug 2021 10:18:42 +0000 Received: from new3-smtp.messagingengine.com ([66.111.4.229]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCJPT-0005B6-Sm for pgsql-hackers@postgresql.org; Sat, 07 Aug 2021 10:18:39 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.nyi.internal (Postfix) with ESMTP id 43FD9580ADC; Sat, 7 Aug 2021 06:18:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sat, 07 Aug 2021 06:18:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=TOa1h7bTJNuZ2WUOP4O2kMk4UqM c6s4RDmlb/0oDwC4=; b=twQGtX/aYAbdHEYFamTFV+Q7IFYjc+iXmuNZEczaiVA Qw54zW5BwQAX5xRfOf7Zk4MfqwrTEeB9XRW91VoZUMMalw+XD5xozETpfhmQN3rw tiZbdq0uZK6dYoNnfdRuj+U9l7sBoBEWKzB8u6TVxR6Dm/B8orhTGDOfgkPVC8lc /vpJfGoUiJ2bNFISXAUgYz/8Pqh+Vr/GkNwnZphHjQxtrInVf7w32uA8TU29E2iZ qL5wkALK6FwFu36musnjHm/ThxzK/AeCmC8s+5cfmnfwyY0Wd3pNQJXjzx/2c0N+ bh8UTy7iCAhBKetYEfpyv805AwldbS/06e6Wo0qE5TA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=TOa1h7 bTJNuZ2WUOP4O2kMk4UqMc6s4RDmlb/0oDwC4=; b=GrgDcu0DRqBElCZ2wygdB5 cYsSsTrh+rkTPCVOKb9/JYR1r79Pw5Tkw6jUOeC4UXxrYKE6/V/jdyqN1MdVOSJa Y60le5x1SYd+xZVcA98ZhrQx9S+4zYIhhQb739ONazU6kp6YYEklwYOPbnVI50rs gAt3ye8clFS8sL/6lg+hUt1HxGXCU6FremMBkCItcMGctvDFHSPfO8RQt/vz15HY PL0OmEHQko8iUwrv4kU7kVZqkMfigU6dD/ke5wkdzDBvPF4JY9v3QMgafXzzAJVL Y4EIAQpYltG6PhWsz9VPx8On4TSeQhov7IOpx+yOaE7Go0UrZ84uaDar/gjIGL7A == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrjeefgddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepvdegudeuhfdtueeltedtveejheeh ieevueeigeelteegleejleeiueeiheegvefhnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 7 Aug 2021 06:18:24 -0400 (EDT) Date: Sat, 7 Aug 2021 19:18:19 +0900 From: Michael Paquier To: Jeff Davis Cc: Justin Pryzby , vignesh C , pgsql-hackers@postgresql.org, Jacob Champion , Heikki Linnakangas , Ashwin Agrawal , Ashutosh Sharma , Andres Freund , Robert Haas , Amit Kapila , Alvaro Herrera , Dilip Kumar Subject: Re: alter table set TABLE ACCESS METHOD Message-ID: References: <20210722094154.GD19620@telsasoft.com> <10785e3e9456a5d761164d3e60d9c4981b80e321.camel@j-davis.com> <87ca2262da500df70f12bb33e992197a0c903094.camel@j-davis.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Zn31ZabWyIZd1EDd" Content-Disposition: inline In-Reply-To: <87ca2262da500df70f12bb33e992197a0c903094.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Zn31ZabWyIZd1EDd Content-Type: multipart/mixed; boundary="doAr64aZwRUGL4YW" Content-Disposition: inline --doAr64aZwRUGL4YW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jul 30, 2021 at 02:18:02PM -0700, Jeff Davis wrote: > It sounds like anything we do here should be part of a larger change to > make it consistent. So I'm fine with the patch you posted. As a matter of curiosity, I have checked how it would look to handle the no-op case for the sub-commands other than SET TABLESPACE, and one would need something like the attached, with a new flag for AlteredTableInfo. That does not really look good, but it triggers properly the object access hook when SET LOGGED/UNLOGGED/ACCESS METHOD are no-ops, so let's just handle the case using the version from upthread. I'll do that at the beginning of next week. -- Michael --doAr64aZwRUGL4YW Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="alter-table-hook-wip.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablec= mds.c index fcd778c62a..eecbde8479 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -179,6 +179,8 @@ typedef struct AlteredTableInfo Oid newAccessMethod; /* new access method; 0 means no change */ Oid newTableSpace; /* new tablespace; 0 means no change */ bool chgPersistence; /* T if SET LOGGED/UNLOGGED is used */ + bool rewriteAttempted; /* T if a rewrite operation was attempted, + * may be a no-op */ char newrelpersistence; /* if above is true */ Expr *partition_constraint; /* for attach partition validation */ /* true, if validating default due to some other attach/detach */ @@ -4593,6 +4595,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd = *cmd, break; case AT_SetLogged: /* SET LOGGED */ ATSimplePermissions(cmd->subtype, rel, ATT_TABLE); + tab->rewriteAttempted =3D true; if (tab->chgPersistence) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -4608,6 +4611,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd = *cmd, break; case AT_SetUnLogged: /* SET UNLOGGED */ ATSimplePermissions(cmd->subtype, rel, ATT_TABLE); + tab->rewriteAttempted =3D true; if (tab->chgPersistence) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), @@ -5475,6 +5479,8 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wqu= eue, LOCKMODE lockmode, RecentXmin, ReadNextMultiXactId(), persistence); + + InvokeObjectPostAlterHook(RelationRelationId, tab->relid, 0); } else { @@ -5493,6 +5499,16 @@ ATRewriteTables(AlterTableStmt *parsetree, List **wq= ueue, LOCKMODE lockmode, */ if (tab->newTableSpace) ATExecSetTableSpace(tab->relid, tab->newTableSpace, lockmode); + else if (tab->rewriteAttempted) + { + /* + * Even if no rewrite is going to happen, it may be possible + * that one has gone through SET LOGGED/UNLOGGED or ACCESS + * METHOD while being a no-op. If that's the case, invoke the + * access hook. + */ + InvokeObjectPostAlterHook(RelationRelationId, tab->relid, 0); + } } } =20 @@ -5971,6 +5987,7 @@ ATGetQueueEntry(List **wqueue, Relation rel) tab->newTableSpace =3D InvalidOid; tab->newrelpersistence =3D RELPERSISTENCE_PERMANENT; tab->chgPersistence =3D false; + tab->rewriteAttempted =3D false; =20 *wqueue =3D lappend(*wqueue, tab); =20 @@ -13660,6 +13677,7 @@ ATPrepSetAccessMethod(AlteredTableInfo *tab, Relati= on rel, const char *amname) =20 /* Check that the table access method exists */ amoid =3D get_table_am_oid(amname, false); + tab->rewriteAttempted =3D true; =20 if (rel->rd_rel->relam =3D=3D amoid) return; --doAr64aZwRUGL4YW-- --Zn31ZabWyIZd1EDd Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmEOXesACgkQnvQgOdby QH1S/hAApQvKi6Hb2C1WFeJjbpmp74G6BntzMuBSxcCT72tnlYlKJPKJtjVlhG+0 iEgO8uRNspfE5Vfx+SP00plfeix/HSaFWQX3CdDHtTcilkdE5HS98VuBvawscp0E SvTuuTAEnvMO/V6R/yNa+DiE0PZyIRnNCnmPbgdsdFHroOhIwtSMt89FtFE3Sw8l Siqw24SdPMytOjf6zl/6MfbAf98G65YQI68jCiXjRb1X6xdE1Edx7zNdUVoAZmn8 2nxHXd63GosAqr4WFExuxWVqRBZ8fC8DLokl4JfRHD65D43jq7AThQUqFuxTndIu I9kRqSItE3VADGbsMpe15DAsAsj7V/G0xnGd2+GKi9h+gGrEGae4ct+Vx/CzffEb A+tHXJKEFhaFeIdYmb/LWhyQ6sZRxJj9XHkSDWermSnzfLTXnUF5ctQWtRmF0k/G /gKI7nHbKv1DJ1jYgyxmLQM56y9cavht3eq6EvoAEctZQBmdWxHBR8H0GcAytD6y xrSJJvF7D5BzEK0ofpaQkoemGpxmn6xk0fmdL5YZrdhWdfSsjnBYDTwwIWDrjfI1 1kLT6f3KSfRcgU+pk5T7Bpt9ep4nDMViQbjzAa7uWfAfw9UULRjH4ADDy8hPVxiy 7Mk0GMthPmGBjiJb8rpsVtOrvNIAS+2VbPH6zcCgEd4ATWkpuyY= =Y2dR -----END PGP SIGNATURE----- --Zn31ZabWyIZd1EDd--