mirror of
https://github.com/postgres/postgres.git
synced 2025-11-29 23:43:17 +03:00
Repair bug noticed by Deepak Bhole: a shell type should have a dependency
on its namespace, so that it will go away if the schema is dropped.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.82 2002/09/04 20:31:14 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.82.2.1 2003/01/08 21:40:49 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@@ -105,6 +105,21 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
|
|||||||
|
|
||||||
CatalogUpdateIndexes(pg_type_desc, tup);
|
CatalogUpdateIndexes(pg_type_desc, tup);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create dependencies. We can/must skip this in bootstrap mode.
|
||||||
|
*/
|
||||||
|
if (!IsBootstrapProcessingMode())
|
||||||
|
GenerateTypeDependencies(typeNamespace,
|
||||||
|
typoid,
|
||||||
|
InvalidOid,
|
||||||
|
0,
|
||||||
|
InvalidOid,
|
||||||
|
InvalidOid,
|
||||||
|
InvalidOid,
|
||||||
|
InvalidOid,
|
||||||
|
NULL,
|
||||||
|
false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* clean up and return the type-oid
|
* clean up and return the type-oid
|
||||||
*/
|
*/
|
||||||
@@ -129,7 +144,7 @@ Oid
|
|||||||
TypeCreate(const char *typeName,
|
TypeCreate(const char *typeName,
|
||||||
Oid typeNamespace,
|
Oid typeNamespace,
|
||||||
Oid assignedTypeOid,
|
Oid assignedTypeOid,
|
||||||
Oid relationOid, /* only for 'c'atalog typeType */
|
Oid relationOid, /* only for 'c'atalog types */
|
||||||
char relationKind, /* ditto */
|
char relationKind, /* ditto */
|
||||||
int16 internalSize,
|
int16 internalSize,
|
||||||
char typeType,
|
char typeType,
|
||||||
@@ -139,7 +154,7 @@ TypeCreate(const char *typeName,
|
|||||||
Oid elementType,
|
Oid elementType,
|
||||||
Oid baseType,
|
Oid baseType,
|
||||||
const char *defaultTypeValue, /* human readable rep */
|
const char *defaultTypeValue, /* human readable rep */
|
||||||
const char *defaultTypeBin, /* cooked rep */
|
char *defaultTypeBin, /* cooked rep */
|
||||||
bool passedByValue,
|
bool passedByValue,
|
||||||
char alignment,
|
char alignment,
|
||||||
char storage,
|
char storage,
|
||||||
@@ -149,6 +164,7 @@ TypeCreate(const char *typeName,
|
|||||||
{
|
{
|
||||||
Relation pg_type_desc;
|
Relation pg_type_desc;
|
||||||
Oid typeObjectId;
|
Oid typeObjectId;
|
||||||
|
bool rebuildDeps = false;
|
||||||
HeapTuple tup;
|
HeapTuple tup;
|
||||||
char nulls[Natts_pg_type];
|
char nulls[Natts_pg_type];
|
||||||
char replaces[Natts_pg_type];
|
char replaces[Natts_pg_type];
|
||||||
@@ -268,6 +284,8 @@ TypeCreate(const char *typeName,
|
|||||||
simple_heap_update(pg_type_desc, &tup->t_self, tup);
|
simple_heap_update(pg_type_desc, &tup->t_self, tup);
|
||||||
|
|
||||||
typeObjectId = HeapTupleGetOid(tup);
|
typeObjectId = HeapTupleGetOid(tup);
|
||||||
|
|
||||||
|
rebuildDeps = true; /* get rid of shell type's dependencies */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -290,10 +308,55 @@ TypeCreate(const char *typeName,
|
|||||||
* Create dependencies. We can/must skip this in bootstrap mode.
|
* Create dependencies. We can/must skip this in bootstrap mode.
|
||||||
*/
|
*/
|
||||||
if (!IsBootstrapProcessingMode())
|
if (!IsBootstrapProcessingMode())
|
||||||
|
GenerateTypeDependencies(typeNamespace,
|
||||||
|
typeObjectId,
|
||||||
|
relationOid,
|
||||||
|
relationKind,
|
||||||
|
inputProcedure,
|
||||||
|
outputProcedure,
|
||||||
|
elementType,
|
||||||
|
baseType,
|
||||||
|
(defaultTypeBin ?
|
||||||
|
stringToNode(defaultTypeBin) :
|
||||||
|
(void *) NULL),
|
||||||
|
rebuildDeps);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* finish up
|
||||||
|
*/
|
||||||
|
heap_close(pg_type_desc, RowExclusiveLock);
|
||||||
|
|
||||||
|
return typeObjectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GenerateTypeDependencies: build the dependencies needed for a type
|
||||||
|
*
|
||||||
|
* If rebuild is true, we remove existing dependencies and rebuild them
|
||||||
|
* from scratch. This is needed for ALTER TYPE, and also when replacing
|
||||||
|
* a shell type.
|
||||||
|
*
|
||||||
|
* NOTE: a shell type will have a dependency to its namespace, and no others.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
GenerateTypeDependencies(Oid typeNamespace,
|
||||||
|
Oid typeObjectId,
|
||||||
|
Oid relationOid, /* only for 'c'atalog types */
|
||||||
|
char relationKind, /* ditto */
|
||||||
|
Oid inputProcedure,
|
||||||
|
Oid outputProcedure,
|
||||||
|
Oid elementType,
|
||||||
|
Oid baseType,
|
||||||
|
Node *defaultExpr,
|
||||||
|
bool rebuild)
|
||||||
{
|
{
|
||||||
ObjectAddress myself,
|
ObjectAddress myself,
|
||||||
referenced;
|
referenced;
|
||||||
|
|
||||||
|
if (rebuild)
|
||||||
|
deleteDependencyRecordsFor(RelOid_pg_type,
|
||||||
|
typeObjectId);
|
||||||
|
|
||||||
myself.classId = RelOid_pg_type;
|
myself.classId = RelOid_pg_type;
|
||||||
myself.objectId = typeObjectId;
|
myself.objectId = typeObjectId;
|
||||||
myself.objectSubId = 0;
|
myself.objectSubId = 0;
|
||||||
@@ -309,15 +372,21 @@ TypeCreate(const char *typeName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Normal dependencies on the I/O functions */
|
/* Normal dependencies on the I/O functions */
|
||||||
|
if (OidIsValid(inputProcedure))
|
||||||
|
{
|
||||||
referenced.classId = RelOid_pg_proc;
|
referenced.classId = RelOid_pg_proc;
|
||||||
referenced.objectId = inputProcedure;
|
referenced.objectId = inputProcedure;
|
||||||
referenced.objectSubId = 0;
|
referenced.objectSubId = 0;
|
||||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (OidIsValid(outputProcedure))
|
||||||
|
{
|
||||||
referenced.classId = RelOid_pg_proc;
|
referenced.classId = RelOid_pg_proc;
|
||||||
referenced.objectId = outputProcedure;
|
referenced.objectId = outputProcedure;
|
||||||
referenced.objectSubId = 0;
|
referenced.objectSubId = 0;
|
||||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the type is a rowtype for a relation, mark it as internally
|
* If the type is a rowtype for a relation, mark it as internally
|
||||||
@@ -364,14 +433,10 @@ TypeCreate(const char *typeName,
|
|||||||
referenced.objectSubId = 0;
|
referenced.objectSubId = 0;
|
||||||
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/* Normal dependency on the default expression. */
|
||||||
* finish up
|
if (defaultExpr)
|
||||||
*/
|
recordDependencyOnExpr(&myself, defaultExpr, NIL, DEPENDENCY_NORMAL);
|
||||||
heap_close(pg_type_desc, RowExclusiveLock);
|
|
||||||
|
|
||||||
return typeObjectId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: pg_type.h,v 1.134 2002/09/24 21:26:44 tgl Exp $
|
* $Id: pg_type.h,v 1.134.2.1 2003/01/08 21:40:49 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
* the genbki.sh script reads this file and generates .bki
|
* the genbki.sh script reads this file and generates .bki
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
#ifndef PG_TYPE_H
|
#ifndef PG_TYPE_H
|
||||||
#define PG_TYPE_H
|
#define PG_TYPE_H
|
||||||
|
|
||||||
|
#include "nodes/nodes.h"
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* postgres.h contains the system type definitions and the
|
* postgres.h contains the system type definitions and the
|
||||||
* CATALOG(), BOOTSTRAP and DATA() sugar words so this file
|
* CATALOG(), BOOTSTRAP and DATA() sugar words so this file
|
||||||
@@ -550,7 +552,7 @@ extern Oid TypeCreate(const char *typeName,
|
|||||||
Oid elementType,
|
Oid elementType,
|
||||||
Oid baseType,
|
Oid baseType,
|
||||||
const char *defaultTypeValue,
|
const char *defaultTypeValue,
|
||||||
const char *defaultTypeBin,
|
char *defaultTypeBin,
|
||||||
bool passedByValue,
|
bool passedByValue,
|
||||||
char alignment,
|
char alignment,
|
||||||
char storage,
|
char storage,
|
||||||
@@ -558,9 +560,20 @@ extern Oid TypeCreate(const char *typeName,
|
|||||||
int32 typNDims,
|
int32 typNDims,
|
||||||
bool typeNotNull);
|
bool typeNotNull);
|
||||||
|
|
||||||
|
extern void GenerateTypeDependencies(Oid typeNamespace,
|
||||||
|
Oid typeObjectId,
|
||||||
|
Oid relationOid,
|
||||||
|
char relationKind,
|
||||||
|
Oid inputProcedure,
|
||||||
|
Oid outputProcedure,
|
||||||
|
Oid elementType,
|
||||||
|
Oid baseType,
|
||||||
|
Node *defaultExpr,
|
||||||
|
bool rebuild);
|
||||||
|
|
||||||
extern void TypeRename(const char *oldTypeName, Oid typeNamespace,
|
extern void TypeRename(const char *oldTypeName, Oid typeNamespace,
|
||||||
const char *newTypeName);
|
const char *newTypeName);
|
||||||
|
|
||||||
extern char *makeArrayTypeName(const char *typeName);
|
extern char *makeArrayTypeName(const char *typeName);
|
||||||
|
|
||||||
#endif /* PG_TYPE_H */
|
#endif /* PG_TYPE_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user