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

Commitd03e987

Browse files
committed
Replace typtoout() and gettypelem() with a single routine,
so that fetching an attribute value needs only one SearchSysCacheTuple callinstead of two redundant searches. This speeds up a large SELECT by aboutten percent, and probably will help GROUP BY and SELECT DISTINCT too.
1 parent77f5428 commitd03e987

File tree

6 files changed

+74
-78
lines changed

6 files changed

+74
-78
lines changed

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

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.37 1998/12/12 22:04:09 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.38 1999/01/24 05:40:47 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -33,11 +33,15 @@
3333
*/
3434

3535
/* ----------------
36-
*typtoout - used by printtup and debugtup
36+
*getTypeOutAndElem -- get both typoutput and typelem for a type
37+
*
38+
* We used to fetch these with two separate function calls,
39+
* typtoout() and gettypelem(), which each called SearchSysCacheTuple.
40+
* This way takes half the time.
3741
* ----------------
3842
*/
39-
Oid
40-
typtoout(Oidtype)
43+
int
44+
getTypeOutAndElem(Oidtype,Oid*typOutput,Oid*typElem)
4145
{
4246
HeapTupletypeTuple;
4347

@@ -46,26 +50,18 @@ typtoout(Oid type)
4650
0,0,0);
4751

4852
if (HeapTupleIsValid(typeTuple))
49-
return (Oid) ((Form_pg_type)GETSTRUCT(typeTuple))->typoutput;
50-
51-
elog(ERROR,"typtoout: Cache lookup of type %d failed",type);
52-
returnInvalidOid;
53-
}
54-
55-
Oid
56-
gettypelem(Oidtype)
57-
{
58-
HeapTupletypeTuple;
59-
60-
typeTuple=SearchSysCacheTuple(TYPOID,
61-
ObjectIdGetDatum(type),
62-
0,0,0);
53+
{
54+
Form_pg_typept= (Form_pg_type)GETSTRUCT(typeTuple);
55+
*typOutput= (Oid)pt->typoutput;
56+
*typElem= (Oid)pt->typelem;
57+
returnOidIsValid(*typOutput);
58+
}
6359

64-
if (HeapTupleIsValid(typeTuple))
65-
return (Oid) ((Form_pg_type)GETSTRUCT(typeTuple))->typelem;
60+
elog(ERROR,"getTypeOutAndElem: Cache lookup of type %d failed",type);
6661

67-
elog(ERROR,"typtoout: Cache lookup of type %d failed",type);
68-
returnInvalidOid;
62+
*typOutput=InvalidOid;
63+
*typElem=InvalidOid;
64+
return0;
6965
}
7066

7167
/* ----------------
@@ -77,19 +73,19 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
7773
{
7874
inti,
7975
j,
80-
k;
76+
k,
77+
outputlen;
8178
char*outputstr;
8279
Datumattr;
8380
boolisnull;
84-
Oidtypoutput;
85-
81+
Oidtypoutput,
82+
typelem;
8683
#ifdefMULTIBYTE
8784
unsignedchar*p;
88-
8985
#endif
9086

9187
/* ----------------
92-
*tell the frontend to expect new tuple data
88+
*tell the frontend to expect new tuple data (in ASCII style)
9389
* ----------------
9490
*/
9591
pq_putnchar("D",1);
@@ -127,28 +123,29 @@ printtup(HeapTuple tuple, TupleDesc typeinfo)
127123
attr=heap_getattr(tuple,i+1,typeinfo,&isnull);
128124
if (isnull)
129125
continue;
130-
131-
typoutput=typtoout((Oid)typeinfo->attrs[i]->atttypid);
132-
if (OidIsValid(typoutput))
126+
if (getTypeOutAndElem((Oid)typeinfo->attrs[i]->atttypid,
127+
&typoutput,&typelem))
133128
{
134-
outputstr=fmgr(typoutput,attr,
135-
gettypelem(typeinfo->attrs[i]->atttypid),
129+
outputstr=fmgr(typoutput,attr,typelem,
136130
typeinfo->attrs[i]->atttypmod);
137131
#ifdefMULTIBYTE
138132
p=pg_server_to_client(outputstr,strlen(outputstr));
139-
pq_putint(strlen(p)+VARHDRSZ,VARHDRSZ);
140-
pq_putnchar(p,strlen(p));
133+
outputlen=strlen(p);
134+
pq_putint(outputlen+VARHDRSZ,VARHDRSZ);
135+
pq_putnchar(p,outputlen);
141136
#else
142-
pq_putint(strlen(outputstr)+VARHDRSZ,VARHDRSZ);
143-
pq_putnchar(outputstr,strlen(outputstr));
137+
outputlen=strlen(outputstr);
138+
pq_putint(outputlen+VARHDRSZ,VARHDRSZ);
139+
pq_putnchar(outputstr,outputlen);
144140
#endif
145141
pfree(outputstr);
146142
}
147143
else
148144
{
149145
outputstr="<unprintable>";
150-
pq_putint(strlen(outputstr)+VARHDRSZ,VARHDRSZ);
151-
pq_putnchar(outputstr,strlen(outputstr));
146+
outputlen=strlen(outputstr);
147+
pq_putint(outputlen+VARHDRSZ,VARHDRSZ);
148+
pq_putnchar(outputstr,outputlen);
152149
}
153150
}
154151
}
@@ -202,17 +199,18 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo)
202199
Datumattr;
203200
char*value;
204201
boolisnull;
205-
Oidtypoutput;
202+
Oidtypoutput,
203+
typelem;
206204

207205
for (i=0;i<tuple->t_data->t_natts;++i)
208206
{
209207
attr=heap_getattr(tuple,i+1,typeinfo,&isnull);
210-
typoutput=typtoout((Oid)typeinfo->attrs[i]->atttypid);
211-
212-
if (!isnull&&OidIsValid(typoutput))
208+
if (isnull)
209+
continue;
210+
if (getTypeOutAndElem((Oid)typeinfo->attrs[i]->atttypid,
211+
&typoutput,&typelem))
213212
{
214-
value=fmgr(typoutput,attr,
215-
gettypelem(typeinfo->attrs[i]->atttypid),
213+
value=fmgr(typoutput,attr,typelem,
216214
typeinfo->attrs[i]->atttypmod);
217215
printatt((unsigned)i+1,typeinfo->attrs[i],value);
218216
pfree(value);
@@ -223,7 +221,6 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo)
223221

224222
/* ----------------
225223
*printtup_internal
226-
*Protocol expects either T, D, C, E, or N.
227224
*We use a different data prefix, e.g. 'B' instead of 'D' to
228225
*indicate a tuple in internal (binary) form.
229226
*
@@ -240,7 +237,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo)
240237
boolisnull;
241238

242239
/* ----------------
243-
*tell the frontend to expect new tuple data
240+
*tell the frontend to expect new tuple data (in binary style)
244241
* ----------------
245242
*/
246243
pq_putnchar("B",1);

‎src/backend/executor/nodeGroup.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* columns. (ie. tuples from the same group are consecutive)
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.23 1998/11/27 19:52:01 vadim Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeGroup.c,v 1.24 1999/01/24 05:40:47 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -364,12 +364,14 @@ sameGroup(HeapTuple oldtuple,
364364
*val2;
365365
inti;
366366
AttrNumberatt;
367-
Oidtypoutput;
367+
Oidtypoutput,
368+
typelem;
368369

369370
for (i=0;i<numCols;i++)
370371
{
371372
att=grpColIdx[i];
372-
typoutput=typtoout((Oid)tupdesc->attrs[att-1]->atttypid);
373+
getTypeOutAndElem((Oid)tupdesc->attrs[att-1]->atttypid,
374+
&typoutput,&typelem);
373375

374376
attr1=heap_getattr(oldtuple,
375377
att,
@@ -386,11 +388,9 @@ sameGroup(HeapTuple oldtuple,
386388
if (isNull1)/* both are null, they are equal */
387389
continue;
388390

389-
val1=fmgr(typoutput,attr1,
390-
gettypelem(tupdesc->attrs[att-1]->atttypid),
391+
val1=fmgr(typoutput,attr1,typelem,
391392
tupdesc->attrs[att-1]->atttypmod);
392-
val2=fmgr(typoutput,attr2,
393-
gettypelem(tupdesc->attrs[att-1]->atttypid),
393+
val2=fmgr(typoutput,attr2,typelem,
394394
tupdesc->attrs[att-1]->atttypmod);
395395

396396
/*

‎src/backend/executor/nodeUnique.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.18 1998/11/27 19:52:03 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeUnique.c,v 1.19 1999/01/24 05:40:48 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -31,7 +31,7 @@
3131
#include"executor/nodeUnique.h"
3232
#include"optimizer/clauses.h"
3333
#include"access/heapam.h"
34-
#include"access/printtup.h"/* fortyptoout() */
34+
#include"access/printtup.h"/* forgetTypeOutAndElem() */
3535
#include"utils/builtins.h"/* for namecpy() */
3636

3737
/* ----------------------------------------------------------------
@@ -117,7 +117,8 @@ ExecUnique(Unique *node)
117117
char*uniqueAttr;
118118
AttrNumberuniqueAttrNum;
119119
TupleDesctupDesc;
120-
Oidtypoutput;
120+
Oidtypoutput,
121+
typelem;
121122

122123
/* ----------------
123124
*get information from the node
@@ -132,12 +133,14 @@ ExecUnique(Unique *node)
132133
if (uniqueAttr)
133134
{
134135
tupDesc=ExecGetResultType(uniquestate);
135-
typoutput=typtoout((Oid)tupDesc->attrs[uniqueAttrNum-1]->atttypid);
136+
getTypeOutAndElem((Oid)tupDesc->attrs[uniqueAttrNum-1]->atttypid,
137+
&typoutput,&typelem);
136138
}
137139
else
138140
{/* keep compiler quiet */
139141
tupDesc=NULL;
140-
typoutput=0;
142+
typoutput=InvalidOid;
143+
typelem=InvalidOid;
141144
}
142145

143146
/* ----------------
@@ -196,11 +199,9 @@ ExecUnique(Unique *node)
196199
{
197200
if (isNull1)/* both are null, they are equal */
198201
continue;
199-
val1=fmgr(typoutput,attr1,
200-
gettypelem(tupDesc->attrs[uniqueAttrNum-1]->atttypid),
202+
val1=fmgr(typoutput,attr1,typelem,
201203
tupDesc->attrs[uniqueAttrNum-1]->atttypmod);
202-
val2=fmgr(typoutput,attr2,
203-
gettypelem(tupDesc->attrs[uniqueAttrNum-1]->atttypid),
204+
val2=fmgr(typoutput,attr2,typelem,
204205
tupDesc->attrs[uniqueAttrNum-1]->atttypmod);
205206

206207
/*

‎src/backend/executor/spi.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* spi.c--
44
*Server Programming Interface
55
*
6-
* $Id: spi.c,v 1.29 1998/12/14 05:18:51 scrappy Exp $
6+
* $Id: spi.c,v 1.30 1999/01/24 05:40:48 tgl Exp $
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -409,7 +409,8 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
409409
{
410410
Datumval;
411411
boolisnull;
412-
Oidfoutoid;
412+
Oidfoutoid,
413+
typelem;
413414

414415
SPI_result=0;
415416
if (tuple->t_data->t_natts<fnumber||fnumber <=0)
@@ -421,15 +422,14 @@ SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
421422
val=heap_getattr(tuple,fnumber,tupdesc,&isnull);
422423
if (isnull)
423424
returnNULL;
424-
foutoid=typtoout((Oid)tupdesc->attrs[fnumber-1]->atttypid);
425-
if (!OidIsValid(foutoid))
425+
if (!getTypeOutAndElem((Oid)tupdesc->attrs[fnumber-1]->atttypid,
426+
&foutoid,&typelem))
426427
{
427428
SPI_result=SPI_ERROR_NOOUTFUNC;
428429
returnNULL;
429430
}
430431

431-
return (fmgr(foutoid,val,
432-
gettypelem(tupdesc->attrs[fnumber-1]->atttypid),
432+
return (fmgr(foutoid,val,typelem,
433433
tupdesc->attrs[fnumber-1]->atttypmod));
434434
}
435435

‎src/backend/libpq/be-dumpdata.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: be-dumpdata.c,v 1.19 1998/12/14 06:50:23 scrappy Exp $
9+
* $Id: be-dumpdata.c,v 1.20 1999/01/24 05:40:49 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -213,7 +213,8 @@ be_printtup(HeapTuple tuple, TupleDesc typeinfo)
213213
inti;
214214
Datumattr;
215215
boolisnull;
216-
Oidtypoutput;
216+
Oidtypoutput,
217+
typelem;
217218

218219
PortalEntry*entry=NULL;
219220
PortalBuffer*portal=NULL;
@@ -298,7 +299,8 @@ be_printtup(HeapTuple tuple, TupleDesc typeinfo)
298299
for (i=0;i<tuple->t_data->t_natts;i++)
299300
{
300301
attr=heap_getattr(tuple,i+1,typeinfo,&isnull);
301-
typoutput=typtoout((Oid)typeinfo->attrs[i]->atttypid);
302+
getTypeOutAndElem((Oid)typeinfo->attrs[i]->atttypid,
303+
&typoutput,&typelem);
302304

303305
lengths[i]=typeinfo->attrs[i]->attlen;
304306

@@ -311,11 +313,8 @@ be_printtup(HeapTuple tuple, TupleDesc typeinfo)
311313
}
312314

313315
if (!isnull&&OidIsValid(typoutput))
314-
{
315-
values[i]=fmgr(typoutput,attr,
316-
gettypelem(typeinfo->attrs[i]->atttypid),
316+
values[i]=fmgr(typoutput,attr,typelem,
317317
typeinfo->attrs[i]->atttypmod);
318-
}
319318
else
320319
values[i]=NULL;
321320

‎src/include/access/printtup.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: printtup.h,v 1.5 1998/09/01 04:34:22 momjian Exp $
9+
* $Id: printtup.h,v 1.6 1999/01/24 05:40:46 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -16,11 +16,10 @@
1616
#include<access/htup.h>
1717
#include<access/tupdesc.h>
1818

19-
externOidtyptoout(Oidtype);
19+
externintgetTypeOutAndElem(Oidtype,Oid*typOutput,Oid*typElem);
2020
externvoidprinttup(HeapTupletuple,TupleDesctypeinfo);
2121
externvoidshowatts(char*name,TupleDescattinfo);
2222
externvoiddebugtup(HeapTupletuple,TupleDesctypeinfo);
2323
externvoidprinttup_internal(HeapTupletuple,TupleDesctypeinfo);
24-
externOidgettypelem(Oidtype);
2524

2625
#endif/* PRINTTUP_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp