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

Commitc541bb8

Browse files
committed
Infrastructure for I/O of composite types: arrange for the I/O routines
of a composite type to get that type's OID as their second parameter,in place of typelem which is useless. The actual changes are mostlycentralized in getTypeInputInfo and siblings, but I had to fix a fewplaces that were fetching pg_type.typelem for themselves instead ofusing the lsyscache.c routines. Also, I renamed all the related variablesfrom 'typelem' to 'typioparam' to discourage people from assuming thatthey necessarily contain array element types.
1 parentc3a153a commitc541bb8

File tree

25 files changed

+332
-382
lines changed

25 files changed

+332
-382
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.50 2004/05/16 23:22:07 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_type.sgml,v 1.51 2004/06/06 00:41:25 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -102,13 +102,15 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
102102
or as taking three arguments of types
103103
<type>cstring</type>, <type>oid</type>, <type>integer</type>.
104104
The first argument is the input text as a C string, the second
105-
argument is the element type in case this is an array type,
105+
argument is the element type's OID in case this is an array type
106+
(or the type's own OID for a composite type),
106107
and the third is the <literal>typmod</> of the destination column, if known.
107108
The input function should return a value of the data type itself.
108109
The output function may be
109110
declared as taking one argument of the new data type, or as taking
110111
two arguments of which the second is type <type>oid</type>.
111-
The second argument is again the array element type for array types.
112+
The second argument is again the array element type OID for array types
113+
or the type OID for composite types.
112114
The output function should return type <type>cstring</type>.
113115
</para>
114116

@@ -128,14 +130,16 @@ CREATE TYPE <replaceable class="parameter">name</replaceable> (
128130
and <type>oid</type>. It must return a value of the data type itself.
129131
(The first argument is a pointer to a <type>StringInfo</type> buffer
130132
holding the received byte string; the optional second argument is the
131-
element type in case this is an array type.) Similarly, the optional
133+
element type OID in case this is an array type, or the type's own OID for a
134+
composite type.) Similarly, the optional
132135
<replaceable class="parameter">send_function</replaceable> converts
133136
from the internal representation to the external binary representation.
134137
If this function is not supplied, the type cannot participate in binary
135138
output. The send function may be
136139
declared as taking one argument of the new data type, or as taking
137140
two arguments of which the second is type <type>oid</type>.
138-
The second argument is again the array element type for array types.
141+
The second argument is again the array element type OID for array types
142+
or the type OID for composite types.
139143
The send function must return type <type>bytea</type>.
140144
</para>
141145

‎src/backend/access/common/printtup.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.82 2004/06/04 20:35:21 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/access/common/printtup.c,v 1.83 2004/06/06 00:41:25 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -51,7 +51,7 @@ typedef struct
5151
{/* Per-attribute information */
5252
Oidtypoutput;/* Oid for the type's text output fn */
5353
Oidtypsend;/* Oid for the type's binary output fn */
54-
Oidtypelem;/*typelem value to pass to the output fn */
54+
Oidtypioparam;/*param to pass to the output fn */
5555
booltypisvarlena;/* is it varlena (ie possibly toastable)? */
5656
int16format;/* format code for this column */
5757
FmgrInfofinfo;/* Precomputed call info for output fn */
@@ -278,15 +278,15 @@ printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
278278
{
279279
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
280280
&thisState->typoutput,
281-
&thisState->typelem,
281+
&thisState->typioparam,
282282
&thisState->typisvarlena);
283283
fmgr_info(thisState->typoutput,&thisState->finfo);
284284
}
285285
elseif (format==1)
286286
{
287287
getTypeBinaryOutputInfo(typeinfo->attrs[i]->atttypid,
288288
&thisState->typsend,
289-
&thisState->typelem,
289+
&thisState->typioparam,
290290
&thisState->typisvarlena);
291291
fmgr_info(thisState->typsend,&thisState->finfo);
292292
}
@@ -356,7 +356,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
356356

357357
outputstr=DatumGetCString(FunctionCall3(&thisState->finfo,
358358
attr,
359-
ObjectIdGetDatum(thisState->typelem),
359+
ObjectIdGetDatum(thisState->typioparam),
360360
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
361361
pq_sendcountedtext(&buf,outputstr,strlen(outputstr), false);
362362
pfree(outputstr);
@@ -368,7 +368,7 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
368368

369369
outputbytes=DatumGetByteaP(FunctionCall2(&thisState->finfo,
370370
attr,
371-
ObjectIdGetDatum(thisState->typelem)));
371+
ObjectIdGetDatum(thisState->typioparam)));
372372
/* We assume the result will not have been toasted */
373373
pq_sendint(&buf,VARSIZE(outputbytes)-VARHDRSZ,4);
374374
pq_sendbytes(&buf,VARDATA(outputbytes),
@@ -458,7 +458,7 @@ printtup_20(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
458458

459459
outputstr=DatumGetCString(FunctionCall3(&thisState->finfo,
460460
attr,
461-
ObjectIdGetDatum(thisState->typelem),
461+
ObjectIdGetDatum(thisState->typioparam),
462462
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
463463
pq_sendcountedtext(&buf,outputstr,strlen(outputstr), true);
464464
pfree(outputstr);
@@ -557,7 +557,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
557557
char*value;
558558
boolisnull;
559559
Oidtypoutput,
560-
typelem;
560+
typioparam;
561561
booltypisvarlena;
562562

563563
for (i=0;i<natts;++i)
@@ -566,7 +566,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
566566
if (isnull)
567567
continue;
568568
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
569-
&typoutput,&typelem,&typisvarlena);
569+
&typoutput,&typioparam,&typisvarlena);
570570

571571
/*
572572
* If we have a toasted datum, forcibly detoast it here to avoid
@@ -579,7 +579,7 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
579579

580580
value=DatumGetCString(OidFunctionCall3(typoutput,
581581
attr,
582-
ObjectIdGetDatum(typelem),
582+
ObjectIdGetDatum(typioparam),
583583
Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
584584

585585
printatt((unsigned)i+1,typeinfo->attrs[i],value);
@@ -672,7 +672,7 @@ printtup_internal_20(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
672672

673673
outputbytes=DatumGetByteaP(FunctionCall2(&thisState->finfo,
674674
attr,
675-
ObjectIdGetDatum(thisState->typelem)));
675+
ObjectIdGetDatum(thisState->typioparam)));
676676
/* We assume the result will not have been toasted */
677677
pq_sendint(&buf,VARSIZE(outputbytes)-VARHDRSZ,4);
678678
pq_sendbytes(&buf,VARDATA(outputbytes),

‎src/backend/bootstrap/bootstrap.c

Lines changed: 43 additions & 33 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-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.183 2004/06/03 02:08:02 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.184 2004/06/06 00:41:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -803,61 +803,71 @@ InsertOneTuple(Oid objectid)
803803
void
804804
InsertOneValue(char*value,inti)
805805
{
806-
inttypeindex;
806+
Oidtypoid;
807+
Oidtypioparam;
808+
Oidtypinput;
809+
Oidtypoutput;
807810
char*prt;
808-
structtypmap**app;
809811

810812
AssertArg(i >=0||i<MAXATTR);
811813

812814
elog(DEBUG4,"inserting column %d value \"%s\"",i,value);
813815

814816
if (Typ!=NULL)
815817
{
818+
structtypmap**app;
816819
structtypmap*ap;
817820

818-
elog(DEBUG4,"Typ != NULL");
821+
elog(DEBUG5,"Typ != NULL");
822+
typoid=boot_reldesc->rd_att->attrs[i]->atttypid;
819823
app=Typ;
820-
while (*app&& (*app)->am_oid!=boot_reldesc->rd_att->attrs[i]->atttypid)
824+
while (*app&& (*app)->am_oid!=typoid)
821825
++app;
822826
ap=*app;
823827
if (ap==NULL)
824-
{
825-
elog(FATAL,"could not find atttypid %u in Typ list",
826-
boot_reldesc->rd_att->attrs[i]->atttypid);
827-
}
828-
values[i]=OidFunctionCall3(ap->am_typ.typinput,
829-
CStringGetDatum(value),
830-
ObjectIdGetDatum(ap->am_typ.typelem),
831-
Int32GetDatum(-1));
832-
prt=DatumGetCString(OidFunctionCall3(ap->am_typ.typoutput,
833-
values[i],
834-
ObjectIdGetDatum(ap->am_typ.typelem),
835-
Int32GetDatum(-1)));
836-
elog(DEBUG4," -> %s",prt);
837-
pfree(prt);
828+
elog(ERROR,"could not find atttypid %u in Typ list",typoid);
829+
830+
/* XXX this should match getTypeIOParam() */
831+
if (ap->am_typ.typtype=='c')
832+
typioparam=typoid;
833+
else
834+
typioparam=ap->am_typ.typelem;
835+
836+
typinput=ap->am_typ.typinput;
837+
typoutput=ap->am_typ.typoutput;
838838
}
839839
else
840840
{
841+
inttypeindex;
842+
843+
/* XXX why is typoid determined differently in this path? */
844+
typoid=attrtypes[i]->atttypid;
841845
for (typeindex=0;typeindex<n_types;typeindex++)
842846
{
843-
if (TypInfo[typeindex].oid==attrtypes[i]->atttypid)
847+
if (TypInfo[typeindex].oid==typoid)
844848
break;
845849
}
846850
if (typeindex >=n_types)
847-
elog(ERROR,"type oid %u not found",attrtypes[i]->atttypid);
848-
elog(DEBUG4,"Typ == NULL, typeindex = %u",typeindex);
849-
values[i]=OidFunctionCall3(TypInfo[typeindex].inproc,
850-
CStringGetDatum(value),
851-
ObjectIdGetDatum(TypInfo[typeindex].elem),
852-
Int32GetDatum(-1));
853-
prt=DatumGetCString(OidFunctionCall3(TypInfo[typeindex].outproc,
854-
values[i],
855-
ObjectIdGetDatum(TypInfo[typeindex].elem),
856-
Int32GetDatum(-1)));
857-
elog(DEBUG4," -> %s",prt);
858-
pfree(prt);
851+
elog(ERROR,"type oid %u not found",typoid);
852+
elog(DEBUG5,"Typ == NULL, typeindex = %u",typeindex);
853+
854+
/* XXX there are no composite types in TypInfo */
855+
typioparam=TypInfo[typeindex].elem;
856+
857+
typinput=TypInfo[typeindex].inproc;
858+
typoutput=TypInfo[typeindex].outproc;
859859
}
860-
elog(DEBUG4,"inserted");
860+
861+
values[i]=OidFunctionCall3(typinput,
862+
CStringGetDatum(value),
863+
ObjectIdGetDatum(typioparam),
864+
Int32GetDatum(-1));
865+
prt=DatumGetCString(OidFunctionCall3(typoutput,
866+
values[i],
867+
ObjectIdGetDatum(typioparam),
868+
Int32GetDatum(-1)));
869+
elog(DEBUG4,"inserted -> %s",prt);
870+
pfree(prt);
861871
}
862872

863873
/* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp