pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: time for catalog/pg_cast.c?
Date: Tue, 10 Mar 2020 11:41:20 -0300
Message-ID: <20200310144120.GA13226@alvherre.pgsql> (raw )
In-Reply-To: <20200309211444.GA24535@alvherre.pgsql >
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
Attachments:
[text/x-diff] move-dropcast.patch (3.4K, ../20200310144120.GA13226@alvherre.pgsql/2-move-dropcast.patch)
download | inline diff:
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,
view thread (4+ messages) latest in thread
Message-ID: <20200310144120.GA13226@alvherre.pgsql>
Permalink: ../20200310144120.GA13226@alvherre.pgsql/
Also on: postgresql.org/message-id/20200310144120.GA13226@alvherre.pgsql
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: alvherre@2ndquadrant.com, pgsql-hackers@lists.postgresql.org
Subject: Re: time for catalog/pg_cast.c?
In-Reply-To: <20200310144120.GA13226@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox