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.94.2) (envelope-from ) id 1t1jdY-00063h-VD for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Oct 2024 09:51:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t1jdX-001ZaZ-28 for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Oct 2024 09:51:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1jdW-001ZaR-N4 for pgsql-hackers@lists.postgresql.org; Fri, 18 Oct 2024 09:51:11 +0000 Received: from fhigh-a1-smtp.messagingengine.com ([103.168.172.152]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1jdT-001grP-Cf for pgsql-hackers@lists.postgresql.org; Fri, 18 Oct 2024 09:51:10 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 2B8B911401E1 for ; Fri, 18 Oct 2024 05:51:05 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Fri, 18 Oct 2024 05:51:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm2; t=1729245065; x=1729331465; bh=+ywMOXMRDkoYCt2Mq1CSUIT658yERcgd xq14EaXtWLs=; b=3UjRyQ6oJzCFxJEchygFg5FFDHxXSrRkYhx4noUZDSw6MuYP jqrb6o2S8sh0L5OMy9N3YVtK1RybU1QDaqD7L9AJvPODgdGGYZ1AwlJSbNQQJMve 28UAhoJkG4APXKOvLE3ZR+N85+q/hOmAFyifp5tJu3Q1v0lmGhh3u7ZtNV8a/i5F aYYDt3uB/9Knq05gJC8IfxXUWuRLCcslm9Oj7fZ2XPseMDfQTthQDY2CKLC1dA6s LLQeW4OFDPMa93vvbpyJBZO14RRuBIrs+vVG0bsYu3wH690coAv7P3d7wjXe3rvV KOWxw8CLmHKdBbQX30x7xiye4THxzLOzGlCIeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1729245065; x=1729331465; bh=+ywMOXMRDkoYCt2Mq1CSUIT658yERcgdxq1 4EaXtWLs=; b=BiwqFNtIuGVN/VtoasS6neyxqAQ2IpL+QHD/wRoeXCyw/zsgN83 OlrS7A8X3hmE0qkcReLpGNj/deE5Zm+dfyTRrTMKITQUFIgGu6J7OJ+O/44lRnbv WYRbDQgUphZ/VZCzNs80tnwfk0BXYNspaZNmI9WTRnEULuJqDQScLnKouFmfhJpO sVx/8eE+S2rDZzYPLiCsxrM0K+LPXR5epxc6r5Zk1wAraIn6JXWPpivWPMGNVQB4 XNmBqFepALV0Y61dX15vFJCE4OTY9Y8UH+YFlpXAopARsyCmuU0XnX8fGhhmRiP5 IEPAQJM0MMdlGAF37d8zUWS+rPH17lG/+cg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdehfedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkgggt ugesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmih gthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvtdffteeg tdfhuefgvedvtdejgfeugfeggfejgfdvhefgfeevieektdelkefhgfenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghq uhhivghrrdighiiipdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprh gtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhq lhdrohhrgh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 18 Oct 2024 05:51:04 -0400 (EDT) Date: Fri, 18 Oct 2024 18:50:50 +0900 From: Michael Paquier To: Postgres hackers Subject: Use more CppAsString2() in pg_amcheck.c Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8TfolDqCc+9o6BPe" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --8TfolDqCc+9o6BPe Content-Type: multipart/mixed; boundary="FC/Jkgou1n86+SaJ" Content-Disposition: inline --FC/Jkgou1n86+SaJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, pg_amcheck.c is one of these places where relkind and relpersistence values are hardcoded in queries based on the contents of pg_class_d.h. Similarly to other places in src/bin/, let's sprinkle some CppAsString2() and feed to the binary the values from the header. The patch attached does that. Thoughts or comments? -- Michael --FC/Jkgou1n86+SaJ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Use-more-CppAsString2-in-pg_amcheck.c.patch" Content-Transfer-Encoding: quoted-printable =46rom 9f56c8befb5b59b6c8013c3f7d58d62e5e42c30a Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Fri, 18 Oct 2024 18:49:45 +0900 Subject: [PATCH] Use more CppAsString2() in pg_amcheck.c --- src/bin/pg_amcheck/pg_amcheck.c | 42 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/bin/pg_amcheck/pg_amcheck.c b/src/bin/pg_amcheck/pg_amchec= k.c index 0c05cf58bc..e74a0af1f8 100644 --- a/src/bin/pg_amcheck/pg_amcheck.c +++ b/src/bin/pg_amcheck/pg_amcheck.c @@ -16,6 +16,7 @@ #include =20 #include "catalog/pg_am_d.h" +#include "catalog/pg_class_d.h" #include "catalog/pg_namespace_d.h" #include "common/logging.h" #include "common/username.h" @@ -857,7 +858,7 @@ prepare_heap_command(PQExpBuffer sql, RelationInfo *rel= , PGconn *conn) =20 appendPQExpBuffer(sql, "\n) v WHERE c.oid =3D %u " - "AND c.relpersistence !=3D 't'", + "AND c.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP), rel->reloid); } =20 @@ -890,7 +891,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *re= l, PGconn *conn) "\nFROM pg_catalog.pg_class c, pg_catalog.pg_index i " "WHERE c.oid =3D %u " "AND c.oid =3D i.indexrelid " - "AND c.relpersistence !=3D 't' " + "AND c.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP) " " "AND i.indisready AND i.indisvalid AND i.indislive", rel->datinfo->amcheck_schema, (opts.heapallindexed ? "true" : "false"), @@ -905,7 +906,7 @@ prepare_btree_command(PQExpBuffer sql, RelationInfo *re= l, PGconn *conn) "\nFROM pg_catalog.pg_class c, pg_catalog.pg_index i " "WHERE c.oid =3D %u " "AND c.oid =3D i.indexrelid " - "AND c.relpersistence !=3D 't' " + "AND c.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP) " " "AND i.indisready AND i.indisvalid AND i.indislive", rel->datinfo->amcheck_schema, (opts.heapallindexed ? "true" : "false"), @@ -1952,7 +1953,8 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, * until firing off the amcheck command, as the state of an index may * change by then. */ - appendPQExpBufferStr(&sql, "\nWHERE c.relpersistence !=3D 't'"); + appendPQExpBufferStr(&sql, "\nWHERE c.relpersistence !=3D " + CppAsString2(RELPERSISTENCE_TEMP) " "); if (opts.excludetbl || opts.excludeidx || opts.excludensp) appendPQExpBufferStr(&sql, "\nAND ep.pattern_id IS NULL"); =20 @@ -1972,15 +1974,29 @@ compile_relation_list_one_db(PGconn *conn, SimplePt= rList *relations, if (opts.allrel) appendPQExpBuffer(&sql, " AND c.relam =3D %u " - "AND c.relkind IN ('r', 'S', 'm', 't') " + "AND c.relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_SEQUENCE) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ") " "AND c.relnamespace !=3D %u", HEAP_TABLE_AM_OID, PG_TOAST_NAMESPACE); else appendPQExpBuffer(&sql, " AND c.relam IN (%u, %u)" - "AND c.relkind IN ('r', 'S', 'm', 't', 'i') " - "AND ((c.relam =3D %u AND c.relkind IN ('r', 'S', 'm', 't')) OR " - "(c.relam =3D %u AND c.relkind =3D 'i'))", + "AND c.relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_SEQUENCE) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ", " + CppAsString2(RELKIND_INDEX) ") " + "AND ((c.relam =3D %u AND c.relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_SEQUENCE) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_TOASTVALUE) ")) OR " + "(c.relam =3D %u AND c.relkind =3D " + CppAsString2(RELKIND_INDEX) "))", HEAP_TABLE_AM_OID, BTREE_AM_OID, HEAP_TABLE_AM_OID, BTREE_AM_OID); =20 @@ -2007,7 +2023,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, "\nAND (t.relname ~ ep.rel_regex OR ep.rel_regex IS NULL)" "\nAND ep.heap_only" "\nWHERE ep.pattern_id IS NULL" - "\nAND t.relpersistence !=3D 't'"); + "\nAND t.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP)); appendPQExpBufferStr(&sql, "\n)"); } @@ -2026,7 +2042,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, "ON r.oid =3D i.indrelid " "INNER JOIN pg_catalog.pg_class c " "ON i.indexrelid =3D c.oid " - "AND c.relpersistence !=3D 't'"); + "AND c.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP)); if (opts.excludeidx || opts.excludensp) appendPQExpBufferStr(&sql, "\nINNER JOIN pg_catalog.pg_namespace n " @@ -2041,7 +2057,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, "\nWHERE true"); appendPQExpBuffer(&sql, " AND c.relam =3D %u " - "AND c.relkind =3D 'i'", + "AND c.relkind =3D " CppAsString2(RELKIND_INDEX), BTREE_AM_OID); if (opts.no_toast_expansion) appendPQExpBuffer(&sql, @@ -2065,7 +2081,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, "ON t.oid =3D i.indrelid" "\nINNER JOIN pg_catalog.pg_class c " "ON i.indexrelid =3D c.oid " - "AND c.relpersistence !=3D 't'"); + "AND c.relpersistence !=3D " CppAsString2(RELPERSISTENCE_TEMP)); if (opts.excludeidx) appendPQExpBufferStr(&sql, "\nLEFT OUTER JOIN exclude_pat ep " @@ -2078,7 +2094,7 @@ compile_relation_list_one_db(PGconn *conn, SimplePtrL= ist *relations, "\nWHERE true"); appendPQExpBuffer(&sql, " AND c.relam =3D %u" - " AND c.relkind =3D 'i')", + " AND c.relkind =3D " CppAsString2(RELKIND_INDEX) ")", BTREE_AM_OID); } =20 --=20 2.45.2 --FC/Jkgou1n86+SaJ-- --8TfolDqCc+9o6BPe Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmcSL3oACgkQnvQgOdby QH3GPBAAi7lYWo73Raq8g3AZMJi9Arp9IDdxUaBB2k5eOrAHyBhZfq6zeFwlyreg stGcYjUq3dRCoYmJ3UfH/I7ZQHG0uU/kslrCFXbsAYDuSf84iDHg1TJv89oxmAVo 9/JDatbhZDLnqdGwlB3P21OJkIZokYujW/IsHSJwFeNaJB2/rPuHkvDfpTtwyXbl pYyZ2ibdRAqhvPq9OHwBaapDZKmkDCY/QPkNL/1WBOvOeK3bYHTA5TvT680vm5zg oMUimrvWXoNA19fofwSaATPVJCFutrK8gCMke0BkxfDIpNd+GeJSJsiWxW7pjxiU dScVqSmwLGIy4+euge3vwWOxkgZRSsEEAwpabU5jZWLXA97FuWFktIUTt+OXG1J2 /1wTIURdsgUxBxTRNgJjarUthfX2mqoqBLYw0+5h4klCnhGnT2ify9O805ou8ZhL 1e/aIo8TH3Q/fDHKzew9Dth67Cxib8WwezAe+D6vLDC7Wlayr6V0+egC+jtuhd0C n9ActS1KwppfPZfBPgnJmmvLsGwbMHLlzsSxXgAoR/20olRS+IGi0AVQqf9YLRK5 35SFMVEVdBqkq8h1bFv3pj0EpMZnDla5lAe57zLDPAf2a+2aqX3R1nImM7kTVNe9 jcBvyLYEJoYfpe0r5M+S6xwIh4X5wL+WD2lRg90tdouGb1xz0Xk= =VRh1 -----END PGP SIGNATURE----- --8TfolDqCc+9o6BPe--