Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitda395b5

Browse files
committed
Tweak heap.c to refuse attempts to create table columns of standalone
composite types. Add a couple more lsyscache.c routines to support this,and make use of them in some other places that were doing lookups thehard way.
1 parent4a0c3a6 commitda395b5

File tree

6 files changed

+88
-53
lines changed

6 files changed

+88
-53
lines changed

‎src/backend/catalog/dependency.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.10 2002/09/11 14:48:54 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.11 2002/09/19 23:40:56 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -552,20 +552,7 @@ doDeletion(const ObjectAddress *object)
552552
{
553553
caseOCLASS_CLASS:
554554
{
555-
HeapTuplerelTup;
556-
charrelKind;
557-
558-
/*
559-
* Need the relkind to figure out how to drop.
560-
*/
561-
relTup=SearchSysCache(RELOID,
562-
ObjectIdGetDatum(object->objectId),
563-
0,0,0);
564-
if (!HeapTupleIsValid(relTup))
565-
elog(ERROR,"doDeletion: Relation %u does not exist",
566-
object->objectId);
567-
relKind= ((Form_pg_class)GETSTRUCT(relTup))->relkind;
568-
ReleaseSysCache(relTup);
555+
charrelKind=get_rel_relkind(object->objectId);
569556

570557
if (relKind==RELKIND_INDEX)
571558
{
@@ -1504,6 +1491,10 @@ getRelationDescription(StringInfo buffer, Oid relid)
15041491
appendStringInfo(buffer,"view %s",
15051492
relname);
15061493
break;
1494+
caseRELKIND_COMPOSITE_TYPE:
1495+
appendStringInfo(buffer,"composite type %s",
1496+
relname);
1497+
break;
15071498
default:
15081499
/* shouldn't get here */
15091500
appendStringInfo(buffer,"relation %s",

‎src/backend/catalog/heap.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.228 2002/09/1922:48:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.229 2002/09/1923:40:56 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -384,20 +384,33 @@ CheckAttributeNames(TupleDesc tupdesc, char relkind)
384384
* Warn user, but don't fail, if column to be created has UNKNOWN type
385385
* (usually as a result of a 'retrieve into' - jolly)
386386
*
387-
* Refuse any attempt to create a pseudo-type column.
387+
* Refuse any attempt to create a pseudo-type column or one that uses
388+
* a standalone composite type. (Eventually we should probably refuse
389+
* all references to complex types, but for now there's still some
390+
* Berkeley-derived code that thinks it can do this...)
388391
*/
389392
for (i=0;i<natts;i++)
390393
{
391394
Oidatt_type=tupdesc->attrs[i]->atttypid;
395+
charatt_typtype=get_typtype(att_type);
392396

393397
if (att_type==UNKNOWNOID)
394398
elog(WARNING,"Attribute \"%s\" has an unknown type"
395399
"\n\tProceeding with relation creation anyway",
396400
NameStr(tupdesc->attrs[i]->attname));
397-
if (get_typtype(att_type)=='p')
401+
if (att_typtype=='p')
398402
elog(ERROR,"Attribute \"%s\" has pseudo-type %s",
399403
NameStr(tupdesc->attrs[i]->attname),
400404
format_type_be(att_type));
405+
if (att_typtype=='c')
406+
{
407+
Oidtyprelid=get_typ_typrelid(att_type);
408+
409+
if (get_rel_relkind(typrelid)==RELKIND_COMPOSITE_TYPE)
410+
elog(ERROR,"Attribute \"%s\" has composite type %s",
411+
NameStr(tupdesc->attrs[i]->attname),
412+
format_type_be(att_type));
413+
}
401414
}
402415
}
403416

‎src/backend/commands/indexcmds.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.88 2002/09/18 21:35:20 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.89 2002/09/19 23:40:56 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -535,21 +535,14 @@ void
535535
RemoveIndex(RangeVar*relation,DropBehaviorbehavior)
536536
{
537537
OidindOid;
538-
HeapTupletuple;
538+
charrelkind;
539539
ObjectAddressobject;
540540

541541
indOid=RangeVarGetRelid(relation, false);
542-
tuple=SearchSysCache(RELOID,
543-
ObjectIdGetDatum(indOid),
544-
0,0,0);
545-
if (!HeapTupleIsValid(tuple))
546-
elog(ERROR,"index \"%s\" does not exist",relation->relname);
547-
548-
if (((Form_pg_class)GETSTRUCT(tuple))->relkind!=RELKIND_INDEX)
542+
relkind=get_rel_relkind(indOid);
543+
if (relkind!=RELKIND_INDEX)
549544
elog(ERROR,"relation \"%s\" is of type \"%c\"",
550-
relation->relname, ((Form_pg_class)GETSTRUCT(tuple))->relkind);
551-
552-
ReleaseSysCache(tuple);
545+
relation->relname,relkind);
553546

554547
object.classId=RelOid_pg_class;
555548
object.objectId=indOid;
@@ -616,7 +609,6 @@ void
616609
ReindexTable(RangeVar*relation,boolforce)
617610
{
618611
OidheapOid;
619-
HeapTupletuple;
620612
charrelkind;
621613

622614
/*
@@ -628,19 +620,12 @@ ReindexTable(RangeVar *relation, bool force)
628620
elog(ERROR,"REINDEX cannot run inside a BEGIN/END block");
629621

630622
heapOid=RangeVarGetRelid(relation, false);
631-
tuple=SearchSysCache(RELOID,
632-
ObjectIdGetDatum(heapOid),
633-
0,0,0);
634-
if (!HeapTupleIsValid(tuple))
635-
elog(ERROR,"table \"%s\" does not exist",relation->relname);
636-
relkind= ((Form_pg_class)GETSTRUCT(tuple))->relkind;
623+
relkind=get_rel_relkind(heapOid);
637624

638625
if (relkind!=RELKIND_RELATION&&relkind!=RELKIND_TOASTVALUE)
639626
elog(ERROR,"relation \"%s\" is of type \"%c\"",
640627
relation->relname,relkind);
641628

642-
ReleaseSysCache(tuple);
643-
644629
if (!reindex_relation(heapOid,force))
645630
elog(WARNING,"table \"%s\" wasn't reindexed",relation->relname);
646631
}

‎src/backend/utils/adt/ruleutils.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*back to source text
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.123 2002/09/1922:48:33 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.124 2002/09/1923:40:56 tgl Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -2087,24 +2087,14 @@ get_rule_expr(Node *node, deparse_context *context,
20872087
{
20882088
FieldSelect*fselect= (FieldSelect*)node;
20892089
OidargType=exprType(fselect->arg);
2090-
HeapTupletypetup;
2091-
Form_pg_typetypeStruct;
20922090
Oidtyprelid;
20932091
char*fieldname;
20942092

20952093
/* lookup arg type and get the field name */
2096-
typetup=SearchSysCache(TYPEOID,
2097-
ObjectIdGetDatum(argType),
2098-
0,0,0);
2099-
if (!HeapTupleIsValid(typetup))
2100-
elog(ERROR,"cache lookup of type %u failed",
2101-
argType);
2102-
typeStruct= (Form_pg_type)GETSTRUCT(typetup);
2103-
typrelid=typeStruct->typrelid;
2094+
typrelid=get_typ_typrelid(argType);
21042095
if (!OidIsValid(typrelid))
21052096
elog(ERROR,"Argument type %s of FieldSelect is not a tuple type",
21062097
format_type_be(argType));
2107-
ReleaseSysCache(typetup);
21082098
fieldname=get_relid_attribute_name(typrelid,
21092099
fselect->fieldnum);
21102100

‎src/backend/utils/cache/lsyscache.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.84 2002/09/18 21:35:23 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.85 2002/09/19 23:40:56 tgl Exp $
1111
*
1212
* NOTES
1313
* Eventually, the index information should go through here, too.
@@ -776,6 +776,33 @@ get_rel_type_id(Oid relid)
776776
returnInvalidOid;
777777
}
778778

779+
/*
780+
* get_rel_relkind
781+
*
782+
*Returns the relkind associated with a given relation.
783+
*/
784+
char
785+
get_rel_relkind(Oidrelid)
786+
{
787+
HeapTupletp;
788+
789+
tp=SearchSysCache(RELOID,
790+
ObjectIdGetDatum(relid),
791+
0,0,0);
792+
if (HeapTupleIsValid(tp))
793+
{
794+
Form_pg_classreltup= (Form_pg_class)GETSTRUCT(tp);
795+
charresult;
796+
797+
result=reltup->relkind;
798+
ReleaseSysCache(tp);
799+
returnresult;
800+
}
801+
else
802+
return'\0';
803+
}
804+
805+
779806
/*---------- TYPE CACHE ---------- */
780807

781808
/*
@@ -1153,6 +1180,33 @@ get_typtype(Oid typid)
11531180
return'\0';
11541181
}
11551182

1183+
/*
1184+
* get_typ_typrelid
1185+
*
1186+
*Given the type OID, get the typrelid (InvalidOid if not a complex
1187+
*type).
1188+
*/
1189+
Oid
1190+
get_typ_typrelid(Oidtypid)
1191+
{
1192+
HeapTupletp;
1193+
1194+
tp=SearchSysCache(TYPEOID,
1195+
ObjectIdGetDatum(typid),
1196+
0,0,0);
1197+
if (HeapTupleIsValid(tp))
1198+
{
1199+
Form_pg_typetyptup= (Form_pg_type)GETSTRUCT(tp);
1200+
Oidresult;
1201+
1202+
result=typtup->typrelid;
1203+
ReleaseSysCache(tp);
1204+
returnresult;
1205+
}
1206+
else
1207+
returnInvalidOid;
1208+
}
1209+
11561210
/*
11571211
* getTypeInputInfo
11581212
*

‎src/include/utils/lsyscache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: lsyscache.h,v 1.63 2002/09/18 21:35:25 tgl Exp $
9+
* $Id: lsyscache.h,v 1.64 2002/09/19 23:40:56 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -45,6 +45,7 @@ extern Oidget_system_catalog_relid(const char *catname);
4545
externchar*get_rel_name(Oidrelid);
4646
externOidget_rel_namespace(Oidrelid);
4747
externOidget_rel_type_id(Oidrelid);
48+
externcharget_rel_relkind(Oidrelid);
4849
externboolget_typisdefined(Oidtypid);
4950
externint16get_typlen(Oidtypid);
5051
externboolget_typbyval(Oidtypid);
@@ -54,6 +55,7 @@ extern void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval,
5455
externcharget_typstorage(Oidtypid);
5556
externNode*get_typdefault(Oidtypid);
5657
externcharget_typtype(Oidtypid);
58+
externOidget_typ_typrelid(Oidtypid);
5759
externvoidgetTypeInputInfo(Oidtype,Oid*typInput,Oid*typElem);
5860
externboolgetTypeOutputInfo(Oidtype,Oid*typOutput,Oid*typElem,
5961
bool*typIsVarlena);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp