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

Commita376a46

Browse files
committed
Fix oversight in optimization that avoids an unnecessary projection step
when scanning a table that we need all the columns from. In case ofSELECT INTO, we have to check that the hasoids flag matches the desiredoutput type, too. Per report from Mike Mascari.
1 parentbb9f663 commita376a46

File tree

6 files changed

+94
-49
lines changed

6 files changed

+94
-49
lines changed

‎src/backend/executor/execMain.c

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.227 2004/01/1423:01:54 tgl Exp $
29+
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.228 2004/01/22 02:23:21 tgl Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -591,7 +591,8 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
591591
if (operation==CMD_SELECT&&parseTree->into!=NULL)
592592
{
593593
do_select_into= true;
594-
estate->es_force_oids=parseTree->intoHasOids;
594+
estate->es_select_into= true;
595+
estate->es_into_oids=parseTree->intoHasOids;
595596
}
596597

597598
/*
@@ -897,6 +898,63 @@ initResultRelInfo(ResultRelInfo *resultRelInfo,
897898
ExecOpenIndices(resultRelInfo);
898899
}
899900

901+
/*
902+
*ExecContextForcesOids
903+
*
904+
* This is pretty grotty: when doing INSERT, UPDATE, or SELECT INTO,
905+
* we need to ensure that result tuples have space for an OID iff they are
906+
* going to be stored into a relation that has OIDs. In other contexts
907+
* we are free to choose whether to leave space for OIDs in result tuples
908+
* (we generally don't want to, but we do if a physical-tlist optimization
909+
* is possible). This routine checks the plan context and returns TRUE if the
910+
* choice is forced, FALSE if the choice is not forced. In the TRUE case,
911+
* *hasoids is set to the required value.
912+
*
913+
* One reason this is ugly is that all plan nodes in the plan tree will emit
914+
* tuples with space for an OID, though we really only need the topmost node
915+
* to do so. However, node types like Sort don't project new tuples but just
916+
* return their inputs, and in those cases the requirement propagates down
917+
* to the input node. Eventually we might make this code smart enough to
918+
* recognize how far down the requirement really goes, but for now we just
919+
* make all plan nodes do the same thing if the top level forces the choice.
920+
*
921+
* We assume that estate->es_result_relation_info is already set up to
922+
* describe the target relation. Note that in an UPDATE that spans an
923+
* inheritance tree, some of the target relations may have OIDs and some not.
924+
* We have to make the decisions on a per-relation basis as we initialize
925+
* each of the child plans of the topmost Append plan.
926+
*
927+
* SELECT INTO is even uglier, because we don't have the INTO relation's
928+
* descriptor available when this code runs; we have to look aside at a
929+
* flag set by InitPlan().
930+
*/
931+
bool
932+
ExecContextForcesOids(PlanState*planstate,bool*hasoids)
933+
{
934+
if (planstate->state->es_select_into)
935+
{
936+
*hasoids=planstate->state->es_into_oids;
937+
return true;
938+
}
939+
else
940+
{
941+
ResultRelInfo*ri=planstate->state->es_result_relation_info;
942+
943+
if (ri!=NULL)
944+
{
945+
Relationrel=ri->ri_RelationDesc;
946+
947+
if (rel!=NULL)
948+
{
949+
*hasoids=rel->rd_rel->relhasoids;
950+
return true;
951+
}
952+
}
953+
}
954+
955+
return false;
956+
}
957+
900958
/* ----------------------------------------------------------------
901959
*ExecEndPlan
902960
*
@@ -2058,7 +2116,8 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
20582116
palloc0(estate->es_topPlan->nParamExec*sizeof(ParamExecData));
20592117
epqstate->es_rowMark=estate->es_rowMark;
20602118
epqstate->es_instrument=estate->es_instrument;
2061-
epqstate->es_force_oids=estate->es_force_oids;
2119+
epqstate->es_select_into=estate->es_select_into;
2120+
epqstate->es_into_oids=estate->es_into_oids;
20622121
epqstate->es_topPlan=estate->es_topPlan;
20632122

20642123
/*

‎src/backend/executor/execScan.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.29 2003/11/29 19:51:48 pgsql Exp $
15+
* $PostgreSQL: pgsql/src/backend/executor/execScan.c,v 1.30 2004/01/22 02:23:21 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -23,7 +23,7 @@
2323
#include"utils/memutils.h"
2424

2525

26-
staticbooltlist_matches_tupdesc(List*tlist,Indexvarno,TupleDesctupdesc);
26+
staticbooltlist_matches_tupdesc(PlanState*ps,List*tlist,Indexvarno,TupleDesctupdesc);
2727

2828

2929
/* ----------------------------------------------------------------
@@ -180,7 +180,8 @@ ExecAssignScanProjectionInfo(ScanState *node)
180180
{
181181
Scan*scan= (Scan*)node->ps.plan;
182182

183-
if (tlist_matches_tupdesc(scan->plan.targetlist,
183+
if (tlist_matches_tupdesc(&node->ps,
184+
scan->plan.targetlist,
184185
scan->scanrelid,
185186
node->ss_ScanTupleSlot->ttc_tupleDescriptor))
186187
node->ps.ps_ProjInfo=NULL;
@@ -189,11 +190,13 @@ ExecAssignScanProjectionInfo(ScanState *node)
189190
}
190191

191192
staticbool
192-
tlist_matches_tupdesc(List*tlist,Indexvarno,TupleDesctupdesc)
193+
tlist_matches_tupdesc(PlanState*ps,List*tlist,Indexvarno,TupleDesctupdesc)
193194
{
194195
intnumattrs=tupdesc->natts;
195196
intattrno;
197+
boolhasoid;
196198

199+
/* Check the tlist attributes */
197200
for (attrno=1;attrno <=numattrs;attrno++)
198201
{
199202
Form_pg_attributeatt_tup=tupdesc->attrs[attrno-1];
@@ -219,5 +222,13 @@ tlist_matches_tupdesc(List *tlist, Index varno, TupleDesc tupdesc)
219222
if (tlist)
220223
return false;/* tlist too long */
221224

225+
/*
226+
* If the plan context requires a particular hasoid setting, then
227+
* that has to match, too.
228+
*/
229+
if (ExecContextForcesOids(ps,&hasoid)&&
230+
hasoid!=tupdesc->tdhasoid)
231+
return false;
232+
222233
return true;
223234
}

‎src/backend/executor/execUtils.c

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.108 2003/12/18 20:21:37 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.109 2004/01/22 02:23:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -201,7 +201,8 @@ CreateExecutorState(void)
201201
estate->es_rowMark=NIL;
202202

203203
estate->es_instrument= false;
204-
estate->es_force_oids= false;
204+
estate->es_select_into= false;
205+
estate->es_into_oids= false;
205206

206207
estate->es_exprcontexts=NIL;
207208

@@ -446,43 +447,17 @@ ExecAssignResultTypeFromOuterPlan(PlanState *planstate)
446447
void
447448
ExecAssignResultTypeFromTL(PlanState*planstate)
448449
{
449-
boolhasoid= false;
450+
boolhasoid;
450451
TupleDesctupDesc;
451452

452-
/*
453-
* This is pretty grotty: we need to ensure that result tuples have
454-
* space for an OID iff they are going to be stored into a relation
455-
* that has OIDs. We assume that estate->es_result_relation_info is
456-
* already set up to describe the target relation.One reason this is
457-
* ugly is that all plan nodes in the plan tree will emit tuples with
458-
* space for an OID, though we really only need the topmost plan to do
459-
* so.
460-
*
461-
* It would be better to have InitPlan adjust the topmost plan node's
462-
* output descriptor after plan tree initialization. However, that
463-
* doesn't quite work because in an UPDATE that spans an inheritance
464-
* tree, some of the target relations may have OIDs and some not. We
465-
* have to make the decision on a per-relation basis as we initialize
466-
* each of the child plans of the topmost Append plan.So, this is
467-
* ugly but it works, for now ...
468-
*
469-
* SELECT INTO is also pretty grotty, because we don't yet have the INTO
470-
* relation's descriptor at this point; we have to look aside at a
471-
* flag set by InitPlan().
472-
*/
473-
if (planstate->state->es_force_oids)
474-
hasoid= true;
453+
if (ExecContextForcesOids(planstate,&hasoid))
454+
{
455+
/* context forces OID choice; hasoid is now set correctly */
456+
}
475457
else
476458
{
477-
ResultRelInfo*ri=planstate->state->es_result_relation_info;
478-
479-
if (ri!=NULL)
480-
{
481-
Relationrel=ri->ri_RelationDesc;
482-
483-
if (rel!=NULL)
484-
hasoid=rel->rd_rel->relhasoids;
485-
}
459+
/* given free choice, don't leave space for OIDs in result tuples */
460+
hasoid= false;
486461
}
487462

488463
/*

‎src/backend/executor/nodeAppend.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.55 2003/11/29 19:51:48 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeAppend.c,v 1.56 2004/01/22 02:23:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -208,7 +208,7 @@ ExecInitAppend(Append *node, EState *estate)
208208
* call ExecInitNode on each of the plans to be executed and save the
209209
* results into the array "appendplans". Note we *must* set
210210
* estate->es_result_relation_info correctly while we initialize each
211-
* sub-plan;ExecAssignResultTypeFromTL depends on that!
211+
* sub-plan;ExecContextForcesOids depends on that!
212212
*/
213213
for (i=appendstate->as_firstplan;i <=appendstate->as_lastplan;i++)
214214
{

‎src/include/executor/executor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.105 2004/01/1423:01:55 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.106 2004/01/22 02:23:21 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -93,6 +93,7 @@ extern void ExecutorEnd(QueryDesc *queryDesc);
9393
externvoidExecutorRewind(QueryDesc*queryDesc);
9494
externvoidExecCheckRTPerms(List*rangeTable);
9595
externvoidExecEndPlan(PlanState*planstate,EState*estate);
96+
externboolExecContextForcesOids(PlanState*planstate,bool*hasoids);
9697
externvoidExecConstraints(ResultRelInfo*resultRelInfo,
9798
TupleTableSlot*slot,EState*estate);
9899
externTupleTableSlot*EvalPlanQual(EState*estate,Indexrti,

‎src/include/nodes/execnodes.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.110 2004/01/06 04:31:01 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.111 2004/01/22 02:23:21 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -311,9 +311,8 @@ typedef struct EState
311311
List*es_rowMark;/* not good place, but there is no other */
312312

313313
booles_instrument;/* true requests runtime instrumentation */
314-
booles_force_oids;/* true forces result tuples to have
315-
* (space for) OIDs --- used for SELECT
316-
* INTO */
314+
booles_select_into;/* true if doing SELECT INTO */
315+
booles_into_oids;/* true to generate OIDs in SELECT INTO */
317316

318317
List*es_exprcontexts;/* List of ExprContexts within EState */
319318

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp