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

Commitb325dab

Browse files
committed
new_relation_targetlist used to cause about 8 separate (and
redundant) SearchSysCache searches per table column in an INSERT, whichaccounted for a good percentage of the CPU time for INSERT ... VALUES().Now it only does two searches in the typical case.
1 parentce2586d commitb325dab

File tree

1 file changed

+74
-58
lines changed

1 file changed

+74
-58
lines changed

‎src/backend/optimizer/prep/preptlist.c

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.21 1999/05/25 16:09:46 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.22 1999/05/29 01:48:06 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -23,6 +23,7 @@
2323
#include"nodes/makefuncs.h"
2424

2525
#include"utils/builtins.h"
26+
#include"utils/syscache.h"
2627
#include"utils/lsyscache.h"
2728
#include"utils/palloc.h"
2829
#include"parser/parse_type.h"
@@ -286,80 +287,95 @@ replace_matching_resname(List *new_tlist, List *old_tlist)
286287
staticList*
287288
new_relation_targetlist(Oidrelid,Indexrt_index,NodeTagnode_type)
288289
{
289-
AttrNumberattno;
290290
List*t_list=NIL;
291-
char*attname;
292-
inttyplen;
293-
Oidatttype=0;
294-
boolattisset= false;
291+
intnatts=get_relnatts(relid);
292+
AttrNumberattno;
295293

296-
for (attno=1;attno <=get_relnatts(relid);attno++)
294+
for (attno=1;attno <=natts;attno++)
297295
{
298-
attname=get_attname(relid,attno);
299-
atttype=get_atttype(relid,attno);
300-
301-
/*
302-
* Since this is an append or replace, the size of any set
303-
* attribute is the size of the OID used to represent it.
304-
*/
305-
attisset=get_attisset(relid,attname);
306-
if (attisset)
307-
typlen=typeLen(typeidType(OIDOID));
308-
else
309-
typlen=get_typlen(atttype);
296+
HeapTupletp;
297+
Form_pg_attributeatt_tup;
298+
char*attname;
299+
Oidatttype;
300+
int32atttypmod;
301+
boolattisset;
302+
303+
tp=SearchSysCacheTuple(ATTNUM,
304+
ObjectIdGetDatum(relid),
305+
UInt16GetDatum(attno),
306+
0,0);
307+
if (!HeapTupleIsValid(tp))
308+
{
309+
elog(ERROR,"new_relation_targetlist: no attribute tuple %u %d",
310+
relid,attno);
311+
}
312+
att_tup= (Form_pg_attribute)GETSTRUCT(tp);
313+
attname=pstrdup(att_tup->attname.data);
314+
atttype=att_tup->atttypid;
315+
atttypmod=att_tup->atttypmod;
316+
attisset=att_tup->attisset;
310317

311318
switch (node_type)
312319
{
313-
caseT_Const:
320+
caseT_Const:/* INSERT command */
314321
{
315322
structvarlena*typedefault=get_typdefault(atttype);
316-
inttemp=0;
317-
Const*temp2= (Const*)NULL;
318-
TargetEntry*temp3= (TargetEntry*)NULL;
323+
inttyplen;
324+
Const*temp_const;
325+
TargetEntry*temp_tle;
319326

320327
if (typedefault==NULL)
321-
temp=0;
328+
typlen=0;
322329
else
323-
temp=typlen;
324-
325-
temp2=makeConst(atttype,
326-
temp,
327-
(Datum)typedefault,
328-
(typedefault== (structvarlena*)NULL),
329-
/* XXX ? */
330-
false,
331-
false,/* not a set */
332-
false);
333-
334-
temp3=makeTargetEntry(makeResdom(attno,
335-
atttype,
336-
-1,
337-
attname,
338-
0,
339-
(Oid)0,
340-
false),
341-
(Node*)temp2);
342-
t_list=lappend(t_list,temp3);
330+
{
331+
/*
332+
* Since this is an append or replace, the size of
333+
* any set attribute is the size of the OID used to
334+
* represent it.
335+
*/
336+
if (attisset)
337+
typlen=get_typlen(OIDOID);
338+
else
339+
typlen=get_typlen(atttype);
340+
}
341+
342+
temp_const=makeConst(atttype,
343+
typlen,
344+
(Datum)typedefault,
345+
(typedefault==NULL),
346+
/* XXX ? */
347+
false,
348+
false,/* not a set */
349+
false);
350+
351+
temp_tle=makeTargetEntry(makeResdom(attno,
352+
atttype,
353+
-1,
354+
attname,
355+
0,
356+
(Oid)0,
357+
false),
358+
(Node*)temp_const);
359+
t_list=lappend(t_list,temp_tle);
343360
break;
344361
}
345-
caseT_Var:
362+
caseT_Var:/* UPDATE command */
346363
{
347-
Var*temp_var= (Var*)NULL;
348-
TargetEntry*temp_list=NULL;
364+
Var*temp_var;
365+
TargetEntry*temp_tle;
349366

350-
temp_var=makeVar(rt_index,attno,atttype,
351-
get_atttypmod(relid,attno),
367+
temp_var=makeVar(rt_index,attno,atttype,atttypmod,
352368
0,rt_index,attno);
353369

354-
temp_list=makeTargetEntry(makeResdom(attno,
355-
atttype,
356-
get_atttypmod(relid,attno),
357-
attname,
358-
0,
359-
(Oid)0,
360-
false),
361-
(Node*)temp_var);
362-
t_list=lappend(t_list,temp_list);
370+
temp_tle=makeTargetEntry(makeResdom(attno,
371+
atttype,
372+
atttypmod,
373+
attname,
374+
0,
375+
(Oid)0,
376+
false),
377+
(Node*)temp_var);
378+
t_list=lappend(t_list,temp_tle);
363379
break;
364380
}
365381
default:/* do nothing */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp