Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jBg4a-0006pp-Mk for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 14:41:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jBg4Z-0007Db-8M for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Mar 2020 14:41:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jBg4Y-0007Ct-RW for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2020 14:41:31 +0000 Received: from mail-qv1-xf41.google.com ([2607:f8b0:4864:20::f41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jBg4V-0008WF-TP for pgsql-hackers@lists.postgresql.org; Tue, 10 Mar 2020 14:41:30 +0000 Received: by mail-qv1-xf41.google.com with SMTP id u10so6195674qvi.2 for ; Tue, 10 Mar 2020 07:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Rb+xzIZlXkv1vI+gflHQ+eKNtqGE1UbnBnxNDqCVE+8=; b=faqK4CZ+TwAls1BKtKAGH/6OFSNySrPxWbxhd0S2C9qevTbO6KoTN170eHouE3F5yY eQxpEiGNwe1WY8kxRCrjd0jbtpLLkm870PjHV3GLHPWLxB+FEGEQeXSIwn48JjwOHLRs qbGnHU9Zp349giSrYOwQdA8iC1xMSCEaGAb/LDZMQgaa97woeZySzGI2SEBA7I38YM5Q /36K/+jD6VeH+/9mb0NdjTzAMkCAOaFIn2nJeIvSiHL9r2YVy0d6/ic4kkpl7YyLqVHa 9X+p7F2xVYM/w0BwofzDp9KqwzVwpaYsPA6JG95yIiRJ1dHJzV2V3a9MdPdI3FOvhURI NhLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Rb+xzIZlXkv1vI+gflHQ+eKNtqGE1UbnBnxNDqCVE+8=; b=dxVqDcW5G+I+FbGFzBVS5YKfnmtDpJ3tPFrAbTu7/GDMTB7/fOq1rAcyredlMgTYLW F9ch6vqTF8t5Q44REmYdnzIGqfTJr9FgE7VfiUENwS54lt5HvbLeQLLcarwCCdHewL/H KNRB53DoDQ/5GA68zi0PIbxd67Mx/UUUe2Q9Gks8mDM6C3Df+MLD43H9C/95t+C0ytNp esBvWQiVBzOhhGdE901RH6MsX2P6d771xUMLaJ7fehVaR1BH7VYOPAcsnPWL6aCVAIAB A1SFenvBwXPt242VXpT0wkCkdjH0nC5+MGg9CqC+9bB6ERk6xkiViWLqWeUhR4SzBjmX qVig== X-Gm-Message-State: ANhLgQ259vbbo/SUlSeIrorKbszd/C9h9WvqNYAH/jA59FghdIMpZyo+ ssaeBJrTO4ultECBrtDPUWArzSwo74QLdOXkPWGu7rDuT9jDcJaQnxmjkwCI8G20P5Z/obJL/aN NqTEGWBdG3977U4k/YPe/WQODhsDYuAABon6Ac9lgWyIVhl9QJXAwchQm3g8hmmTQWuvKN5hmHH 3dK854bgR288rLryzq X-Google-Smtp-Source: ADFU+vtIqXWW4rE+HEynSRjuTBRy17bIkX4sKtzt5bYUgZ/eqFEaTQIbYFg2G4/GbrfHI/BmfjYNYA== X-Received: by 2002:a05:6214:928:: with SMTP id dk8mr3963106qvb.170.1583851283521; Tue, 10 Mar 2020 07:41:23 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([179.56.30.174]) by smtp.gmail.com with ESMTPSA id d185sm24727270qkf.46.2020.03.10.07.41.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2020 07:41:22 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id C0F4D3008DB; Tue, 10 Mar 2020 11:41:20 -0300 (-03) Date: Tue, 10 Mar 2020 11:41:20 -0300 From: Alvaro Herrera To: Pg Hackers Subject: Re: time for catalog/pg_cast.c? Message-ID: <20200310144120.GA13226@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="huq684BweRXVnRxX" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200309211444.GA24535@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --huq684BweRXVnRxX Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit I would even say that DropCastById belongs in the new file, which is just the attached. However, none of the Drop.*ById or Remove.*ById functions seem to be in backend/catalog/ at all, and moving just a single one seems to make things even more inconsistent. I think all these catalog-accessing functions should be in backend/catalog/ but I'm not in a hurry to patch half of backend/commands/ to move them all. (I think the current arrangement is just fallout from having created the dependency.c system to drop objects, which rid us of a bunch of bespoke deletion-handling code.) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --huq684BweRXVnRxX Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="move-dropcast.patch" diff --git a/src/backend/catalog/pg_cast.c b/src/backend/catalog/pg_cast.c index 3854455637..bd2a369aad 100644 --- a/src/backend/catalog/pg_cast.c +++ b/src/backend/catalog/pg_cast.c @@ -14,7 +14,9 @@ */ #include "postgres.h" +#include "access/genam.h" #include "access/htup_details.h" +#include "access/skey.h" #include "access/table.h" #include "catalog/catalog.h" #include "catalog/dependency.h" @@ -24,6 +26,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_type.h" #include "utils/builtins.h" +#include "utils/fmgroids.h" #include "utils/rel.h" #include "utils/syscache.h" @@ -121,3 +124,29 @@ CastCreate(Oid sourcetypeid, Oid targettypeid, Oid funcid, char castcontext, return myself; } + +void +DropCastById(Oid castOid) +{ + Relation relation; + ScanKeyData scankey; + SysScanDesc scan; + HeapTuple tuple; + + relation = table_open(CastRelationId, RowExclusiveLock); + + ScanKeyInit(&scankey, + Anum_pg_cast_oid, + BTEqualStrategyNumber, F_OIDEQ, + ObjectIdGetDatum(castOid)); + scan = systable_beginscan(relation, CastOidIndexId, true, + NULL, 1, &scankey); + + tuple = systable_getnext(scan); + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "could not find tuple for cast %u", castOid); + CatalogTupleDelete(relation, &tuple->t_self); + + systable_endscan(scan); + table_close(relation, RowExclusiveLock); +} diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index 5eac55aaca..355e93840a 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -1645,33 +1645,6 @@ CreateCast(CreateCastStmt *stmt) return myself; } -void -DropCastById(Oid castOid) -{ - Relation relation; - ScanKeyData scankey; - SysScanDesc scan; - HeapTuple tuple; - - relation = table_open(CastRelationId, RowExclusiveLock); - - ScanKeyInit(&scankey, - Anum_pg_cast_oid, - BTEqualStrategyNumber, F_OIDEQ, - ObjectIdGetDatum(castOid)); - scan = systable_beginscan(relation, CastOidIndexId, true, - NULL, 1, &scankey); - - tuple = systable_getnext(scan); - if (!HeapTupleIsValid(tuple)) - elog(ERROR, "could not find tuple for cast %u", castOid); - CatalogTupleDelete(relation, &tuple->t_self); - - systable_endscan(scan); - table_close(relation, RowExclusiveLock); -} - - static void check_transform_function(Form_pg_proc procstruct) { diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h index 2620ff40f0..78ba395f17 100644 --- a/src/include/catalog/pg_cast.h +++ b/src/include/catalog/pg_cast.h @@ -95,5 +95,6 @@ extern ObjectAddress CastCreate(Oid sourcetypeid, char castcontext, char castmethod, DependencyType behavior); +extern void DropCastById(Oid castOid); #endif /* PG_CAST_H */ diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h index c77c9a6ed5..1d22cc8083 100644 --- a/src/include/commands/defrem.h +++ b/src/include/commands/defrem.h @@ -56,7 +56,6 @@ extern ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt extern void RemoveFunctionById(Oid funcOid); extern ObjectAddress AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt); extern ObjectAddress CreateCast(CreateCastStmt *stmt); -extern void DropCastById(Oid castOid); extern ObjectAddress CreateTransform(CreateTransformStmt *stmt); extern void DropTransformById(Oid transformOid); extern void IsThereFunctionInNamespace(const char *proname, int pronargs, --huq684BweRXVnRxX--