Skip to content

Commit ffb087c

Browse files
committed
This patch refactors execTuples.c in two ways.
Neil Conway
1 parent 8f61184 commit ffb087c

File tree

1 file changed

+26
-62
lines changed

1 file changed

+26
-62
lines changed

src/backend/executor/execTuples.c

Lines changed: 26 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.73 2003/11/29 19:51:48 pgsql Exp $
18+
* $PostgreSQL: pgsql/src/backend/executor/execTuples.c,v 1.74 2003/12/01 23:09:02 momjian Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -112,6 +112,8 @@
112112
#include "executor/executor.h"
113113
#include "utils/lsyscache.h"
114114

115+
static TupleDesc ExecTypeFromTLInternal(List *targetList,
116+
bool hasoid, bool skipjunk);
115117

116118
/* ----------------------------------------------------------------
117119
* tuple table create/delete functions
@@ -469,13 +471,6 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */
469471
* is used for initializing special-purpose slots.
470472
* --------------------------------
471473
*/
472-
#define INIT_SLOT_DEFS \
473-
TupleTable tupleTable; \
474-
TupleTableSlot* slot
475-
476-
#define INIT_SLOT_ALLOC \
477-
tupleTable = (TupleTable) estate->es_tupleTable; \
478-
slot = ExecAllocTableSlot(tupleTable);
479474

480475
/* ----------------
481476
* ExecInitResultTupleSlot
@@ -484,9 +479,7 @@ ExecSetSlotDescriptorIsNew(TupleTableSlot *slot, /* slot to change */
484479
void
485480
ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
486481
{
487-
INIT_SLOT_DEFS;
488-
INIT_SLOT_ALLOC;
489-
planstate->ps_ResultTupleSlot = slot;
482+
planstate->ps_ResultTupleSlot = ExecAllocTableSlot(estate->es_tupleTable);
490483
}
491484

492485
/* ----------------
@@ -496,9 +489,7 @@ ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
496489
void
497490
ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
498491
{
499-
INIT_SLOT_DEFS;
500-
INIT_SLOT_ALLOC;
501-
scanstate->ss_ScanTupleSlot = slot;
492+
scanstate->ss_ScanTupleSlot = ExecAllocTableSlot(estate->es_tupleTable);
502493
}
503494

504495
/* ----------------
@@ -508,9 +499,7 @@ ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
508499
TupleTableSlot *
509500
ExecInitExtraTupleSlot(EState *estate)
510501
{
511-
INIT_SLOT_DEFS;
512-
INIT_SLOT_ALLOC;
513-
return slot;
502+
return ExecAllocTableSlot(estate->es_tupleTable);
514503
}
515504

516505
/* ----------------
@@ -560,34 +549,7 @@ ExecInitNullTupleSlot(EState *estate, TupleDesc tupType)
560549
TupleDesc
561550
ExecTypeFromTL(List *targetList, bool hasoid)
562551
{
563-
TupleDesc typeInfo;
564-
List *tlitem;
565-
int len;
566-
567-
/*
568-
* allocate a new typeInfo
569-
*/
570-
len = ExecTargetListLength(targetList);
571-
typeInfo = CreateTemplateTupleDesc(len, hasoid);
572-
573-
/*
574-
* scan list, generate type info for each entry
575-
*/
576-
foreach(tlitem, targetList)
577-
{
578-
TargetEntry *tle = lfirst(tlitem);
579-
Resdom *resdom = tle->resdom;
580-
581-
TupleDescInitEntry(typeInfo,
582-
resdom->resno,
583-
resdom->resname,
584-
resdom->restype,
585-
resdom->restypmod,
586-
0,
587-
false);
588-
}
589-
590-
return typeInfo;
552+
return ExecTypeFromTLInternal(targetList, hasoid, false);
591553
}
592554

593555
/* ----------------------------------------------------------------
@@ -599,30 +561,32 @@ ExecTypeFromTL(List *targetList, bool hasoid)
599561
TupleDesc
600562
ExecCleanTypeFromTL(List *targetList, bool hasoid)
601563
{
602-
TupleDesc typeInfo;
603-
List *tlitem;
604-
int len;
605-
int cleanresno;
564+
return ExecTypeFromTLInternal(targetList, hasoid, true);
565+
}
606566

607-
/*
608-
* allocate a new typeInfo
609-
*/
610-
len = ExecCleanTargetListLength(targetList);
567+
static TupleDesc
568+
ExecTypeFromTLInternal(List *targetList, bool hasoid, bool skipjunk)
569+
{
570+
TupleDesc typeInfo;
571+
List *l;
572+
int len;
573+
int cur_resno = 1;
574+
575+
if (skipjunk)
576+
len = ExecCleanTargetListLength(targetList);
577+
else
578+
len = ExecTargetListLength(targetList);
611579
typeInfo = CreateTemplateTupleDesc(len, hasoid);
612580

613-
/*
614-
* scan list, generate type info for each entry
615-
*/
616-
cleanresno = 1;
617-
foreach(tlitem, targetList)
581+
foreach(l, targetList)
618582
{
619-
TargetEntry *tle = lfirst(tlitem);
620-
Resdom *resdom = tle->resdom;
583+
TargetEntry *tle = lfirst(l);
584+
Resdom *resdom = tle->resdom;
621585

622-
if (resdom->resjunk)
586+
if (skipjunk && resdom->resjunk)
623587
continue;
624588
TupleDescInitEntry(typeInfo,
625-
cleanresno++,
589+
cur_resno++,
626590
resdom->resname,
627591
resdom->restype,
628592
resdom->restypmod,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy