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

Commitb1a5f87

Browse files
committed
Tom Lane wrote:
> There's no longer a separate call to heap_storage_create in that routine> --- the right place to make the test is now in the storage_create> boolean parameter being passed to heap_create. A simple change, but> it passeth patch's understanding ...Thanks.Attached is a patch against cvs tip as of 8:30 PM PST or so. Turned outthat even after fixing the failed hunks, there was a new spot inbufmgr.c which needed to be fixed (related to temp relations;RelationUpdateNumberOfBlocks). But thankfully the regression test codecaught it :-)Joe Conway
1 parent38294db commitb1a5f87

File tree

27 files changed

+434
-58
lines changed

27 files changed

+434
-58
lines changed

‎doc/src/sgml/ref/create_type.sgml‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.30 2002/07/24 19:11:07 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_type.sgml,v 1.31 2002/08/15 16:36:00 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -30,6 +30,13 @@ CREATE TYPE <replaceable class="parameter">typename</replaceable> ( INPUT = <rep
3030
[ , ALIGNMENT = <replaceable class="parameter">alignment</replaceable> ]
3131
[ , STORAGE = <replaceable class="parameter">storage</replaceable> ]
3232
)
33+
34+
CREATE TYPE <replaceable class="parameter">typename</replaceable> AS
35+
( <replaceable class="PARAMETER">column_definition_list</replaceable> )
36+
37+
where <replaceable class="PARAMETER">column_definition_list</replaceable> can be:
38+
39+
( <replaceable class="PARAMETER">column_name</replaceable> <replaceable class="PARAMETER">data_type</replaceable> [, ... ] )
3340
</synopsis>
3441

3542
<refsect2 id="R2-SQL-CREATETYPE-1">
@@ -138,6 +145,25 @@ CREATE TYPE <replaceable class="parameter">typename</replaceable> ( INPUT = <rep
138145
</para>
139146
</listitem>
140147
</varlistentry>
148+
149+
<varlistentry>
150+
<term><replaceable class="PARAMETER">column_name</replaceable></term>
151+
<listitem>
152+
<para>
153+
The name of a column of the composite type.
154+
</para>
155+
</listitem>
156+
</varlistentry>
157+
158+
<varlistentry>
159+
<term><replaceable class="PARAMETER">data_type</replaceable></term>
160+
<listitem>
161+
<para>
162+
The name of an existing data type.
163+
</para>
164+
</listitem>
165+
</varlistentry>
166+
141167
</variablelist>
142168
</para>
143169
</refsect2>
@@ -191,9 +217,9 @@ CREATE TYPE
191217
</para>
192218

193219
<para>
194-
<command>CREATE TYPE</command> requires theregistration of two functions
195-
(using CREATE FUNCTION) before defining the type. The
196-
representationof anewbasetypeisdetermined by
220+
The first form of<command>CREATE TYPE</command> requires the
221+
registration of two functions(using CREATE FUNCTION) before defining the
222+
type. The representationofanew base type is determined by
197223
<replaceable class="parameter">input_function</replaceable>, which
198224
converts the type's external representation to an internal
199225
representation usable by the
@@ -288,6 +314,14 @@ CREATE TYPE
288314
<literal>extended</literal> and <literal>external</literal> items.)
289315
</para>
290316

317+
<para>
318+
The second form of <command>CREATE TYPE</command> requires a column
319+
definition list in the form ( <replaceable class="PARAMETER">column_name</replaceable>
320+
<replaceable class="PARAMETER">data_type</replaceable> [, ... ] ). This
321+
creates a composite type, similar to that of a TABLE or VIEW relation.
322+
A stand-alone composite type is useful as the return type of FUNCTION.
323+
</para>
324+
291325
<refsect2>
292326
<title>Array Types</title>
293327

@@ -370,6 +404,15 @@ CREATE TYPE box (INTERNALLENGTH = 16,
370404
CREATE TYPE bigobj (INPUT = lo_filein, OUTPUT = lo_fileout,
371405
INTERNALLENGTH = VARIABLE);
372406
CREATE TABLE big_objs (id int4, obj bigobj);
407+
</programlisting>
408+
</para>
409+
410+
<para>
411+
This example creates a composite type and uses it in
412+
a table function definition:
413+
<programlisting>
414+
CREATE TYPE compfoo AS (f1 int, f2 int);
415+
CREATE FUNCTION getfoo() RETURNS SETOF compfoo AS 'SELECT fooid, foorefid FROM foo' LANGUAGE SQL;
373416
</programlisting>
374417
</para>
375418
</refsect1>

‎src/backend/catalog/heap.c‎

Lines changed: 12 additions & 9 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.220 2002/08/11 21:17:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.221 2002/08/15 16:36:00 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -357,9 +357,10 @@ CheckAttributeNames(TupleDesc tupdesc, bool relhasoids, char relkind)
357357
/*
358358
* first check for collision with system attribute names
359359
*
360-
* Skip this for a view, since it doesn't have system attributes.
360+
* Skip this for a view and type relation, since it doesn't have system
361+
* attributes.
361362
*/
362-
if (relkind!=RELKIND_VIEW)
363+
if (relkind!=RELKIND_VIEW&&relkind!=RELKIND_COMPOSITE_TYPE)
363364
{
364365
for (i=0;i<natts;i++)
365366
{
@@ -473,10 +474,10 @@ AddNewAttributeTuples(Oid new_rel_oid,
473474

474475
/*
475476
* Next we add the system attributes. Skip OID if rel has no OIDs.
476-
* Skip all for a view. We don't bother with making datatype
477-
* dependencies here, since presumably all these types are pinned.
477+
* Skip all for a view or type relation. We don't bother with making
478+
*datatypedependencies here, since presumably all these types are pinned.
478479
*/
479-
if (relkind!=RELKIND_VIEW)
480+
if (relkind!=RELKIND_VIEW&&relkind!=RELKIND_COMPOSITE_TYPE)
480481
{
481482
dpp=SysAtt;
482483
for (i=0;i<-1-FirstLowInvalidHeapAttributeNumber;i++)
@@ -689,13 +690,14 @@ heap_create_with_catalog(const char *relname,
689690
* physical disk file. (If we fail further down, it's the smgr's
690691
* responsibility to remove the disk file again.)
691692
*
692-
* NB: create a physical file only if it's not a view.
693+
* NB: create a physical file only if it's not a view or type relation.
693694
*/
694695
new_rel_desc=heap_create(relname,
695696
relnamespace,
696697
tupdesc,
697698
shared_relation,
698-
(relkind!=RELKIND_VIEW),
699+
(relkind!=RELKIND_VIEW&&
700+
relkind!=RELKIND_COMPOSITE_TYPE),
699701
allow_system_table_mods);
700702

701703
/* Fetch the relation OID assigned by heap_create */
@@ -1131,7 +1133,8 @@ heap_drop_with_catalog(Oid rid)
11311133
/*
11321134
* unlink the relation's physical file and finish up.
11331135
*/
1134-
if (rel->rd_rel->relkind!=RELKIND_VIEW)
1136+
if (rel->rd_rel->relkind!=RELKIND_VIEW&&
1137+
rel->rd_rel->relkind!=RELKIND_COMPOSITE_TYPE)
11351138
smgrunlink(DEFAULT_SMGR,rel);
11361139

11371140
/*

‎src/backend/catalog/namespace.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.30 2002/08/09 16:45:14 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.31 2002/08/15 16:36:01 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1585,6 +1585,7 @@ RemoveTempRelations(Oid tempNamespaceId)
15851585
caseRELKIND_RELATION:
15861586
caseRELKIND_SEQUENCE:
15871587
caseRELKIND_VIEW:
1588+
caseRELKIND_COMPOSITE_TYPE:
15881589
AssertTupleDescHasOid(pgclass->rd_att);
15891590
object.classId=RelOid_pg_class;
15901591
object.objectId=HeapTupleGetOid(tuple);

‎src/backend/catalog/pg_type.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.77 2002/08/05 03:29:16 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.78 2002/08/15 16:36:01 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -311,15 +311,28 @@ TypeCreate(const char *typeName,
311311

312312
/*
313313
* If the type is a rowtype for a relation, mark it as internally
314-
* dependent on the relation. This allows it to be auto-dropped
315-
* when the relation is, and not otherwise.
314+
* dependent on the relation, *unless* it is a stand-alone composite
315+
* type relation. For the latter case, we have to reverse the
316+
* dependency.
317+
*
318+
* In the former case, this allows the type to be auto-dropped
319+
* when the relation is, and not otherwise. And in the latter,
320+
* of course we get the opposite effect.
316321
*/
317322
if (OidIsValid(relationOid))
318323
{
324+
Relationrel=relation_open(relationOid,AccessShareLock);
325+
charrelkind=rel->rd_rel->relkind;
326+
relation_close(rel,AccessShareLock);
327+
319328
referenced.classId=RelOid_pg_class;
320329
referenced.objectId=relationOid;
321330
referenced.objectSubId=0;
322-
recordDependencyOn(&myself,&referenced,DEPENDENCY_INTERNAL);
331+
332+
if (relkind!=RELKIND_COMPOSITE_TYPE)
333+
recordDependencyOn(&myself,&referenced,DEPENDENCY_INTERNAL);
334+
else
335+
recordDependencyOn(&referenced,&myself,DEPENDENCY_INTERNAL);
323336
}
324337

325338
/*

‎src/backend/commands/copy.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.162 2002/08/02 18:15:06 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.163 2002/08/15 16:36:02 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -398,6 +398,9 @@ DoCopy(const CopyStmt *stmt)
398398
if (rel->rd_rel->relkind==RELKIND_VIEW)
399399
elog(ERROR,"You cannot copy view %s",
400400
RelationGetRelationName(rel));
401+
elseif (rel->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
402+
elog(ERROR,"You cannot copy type relation %s",
403+
RelationGetRelationName(rel));
401404
elseif (rel->rd_rel->relkind==RELKIND_SEQUENCE)
402405
elog(ERROR,"You cannot change sequence relation %s",
403406
RelationGetRelationName(rel));
@@ -443,6 +446,9 @@ DoCopy(const CopyStmt *stmt)
443446
if (rel->rd_rel->relkind==RELKIND_VIEW)
444447
elog(ERROR,"You cannot copy view %s",
445448
RelationGetRelationName(rel));
449+
elseif (rel->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
450+
elog(ERROR,"You cannot copy type relation %s",
451+
RelationGetRelationName(rel));
446452
elseif (rel->rd_rel->relkind==RELKIND_SEQUENCE)
447453
elog(ERROR,"You cannot copy sequence %s",
448454
RelationGetRelationName(rel));

‎src/backend/commands/tablecmds.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.28 2002/08/07 21:45:01 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.29 2002/08/15 16:36:02 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -345,6 +345,10 @@ TruncateRelation(const RangeVar *relation)
345345
elog(ERROR,"TRUNCATE cannot be used on views. '%s' is a view",
346346
RelationGetRelationName(rel));
347347

348+
if (rel->rd_rel->relkind==RELKIND_COMPOSITE_TYPE)
349+
elog(ERROR,"TRUNCATE cannot be used on type relations. '%s' is a type",
350+
RelationGetRelationName(rel));
351+
348352
if (!allowSystemTableMods&&IsSystemRelation(rel))
349353
elog(ERROR,"TRUNCATE cannot be used on system tables. '%s' is a system table",
350354
RelationGetRelationName(rel));
@@ -3210,12 +3214,13 @@ CheckTupleType(Form_pg_class tuple_class)
32103214
caseRELKIND_RELATION:
32113215
caseRELKIND_INDEX:
32123216
caseRELKIND_VIEW:
3217+
caseRELKIND_COMPOSITE_TYPE:
32133218
caseRELKIND_SEQUENCE:
32143219
caseRELKIND_TOASTVALUE:
32153220
/* ok to change owner */
32163221
break;
32173222
default:
3218-
elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table, TOAST table, index, view, or sequence",
3223+
elog(ERROR,"ALTER TABLE: relation \"%s\" is not a table, TOAST table, index, view,type,or sequence",
32193224
NameStr(tuple_class->relname));
32203225
}
32213226
}

‎src/backend/commands/typecmds.c‎

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.8 2002/07/24 19:11:09 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/typecmds.c,v 1.9 2002/08/15 16:36:02 momjian Exp $
1212
*
1313
* DESCRIPTION
1414
* The "DefineFoo" routines take the parse tree and pick out the
@@ -38,6 +38,7 @@
3838
#include"catalog/namespace.h"
3939
#include"catalog/pg_type.h"
4040
#include"commands/defrem.h"
41+
#include"commands/tablecmds.h"
4142
#include"miscadmin.h"
4243
#include"parser/parse_func.h"
4344
#include"parser/parse_type.h"
@@ -50,7 +51,6 @@
5051

5152
staticOidfindTypeIOFunction(List*procname,boolisOutput);
5253

53-
5454
/*
5555
* DefineType
5656
*Registers a new type.
@@ -666,3 +666,42 @@ findTypeIOFunction(List *procname, bool isOutput)
666666

667667
returnprocOid;
668668
}
669+
670+
/*-------------------------------------------------------------------
671+
* DefineCompositeType
672+
*
673+
* Create a Composite Type relation.
674+
* `DefineRelation' does all the work, we just provide the correct
675+
* arguments!
676+
*
677+
* If the relation already exists, then 'DefineRelation' will abort
678+
* the xact...
679+
*
680+
* DefineCompositeType returns relid for use when creating
681+
* an implicit composite type during function creation
682+
*-------------------------------------------------------------------
683+
*/
684+
Oid
685+
DefineCompositeType(constRangeVar*typevar,List*coldeflist)
686+
{
687+
CreateStmt*createStmt=makeNode(CreateStmt);
688+
689+
if (coldeflist==NIL)
690+
elog(ERROR,"attempted to define composite type relation with"
691+
" no attrs");
692+
693+
/*
694+
* now create the parameters for keys/inheritance etc. All of them are
695+
* nil...
696+
*/
697+
createStmt->relation= (RangeVar*)typevar;
698+
createStmt->tableElts=coldeflist;
699+
createStmt->inhRelations=NIL;
700+
createStmt->constraints=NIL;
701+
createStmt->hasoids= false;
702+
703+
/*
704+
* finally create the relation...
705+
*/
706+
returnDefineRelation(createStmt,RELKIND_COMPOSITE_TYPE);
707+
}

‎src/backend/executor/execMain.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.173 2002/08/07 21:45:02tgl Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.174 2002/08/15 16:36:02momjian Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -786,6 +786,10 @@ initResultRelInfo(ResultRelInfo *resultRelInfo,
786786
elog(ERROR,"You can't change view relation %s",
787787
RelationGetRelationName(resultRelationDesc));
788788
break;
789+
caseRELKIND_COMPOSITE_TYPE:
790+
elog(ERROR,"You can't change type relation %s",
791+
RelationGetRelationName(resultRelationDesc));
792+
break;
789793
}
790794

791795
MemSet(resultRelInfo,0,sizeof(ResultRelInfo));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp