Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ead2e98

Browse files
committed
Lab2 finished. (?)
1 parent 64c47e4 commit ead2e98

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/backend/executor/nodeNestloop.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@
5656
* are prepared to return the first tuple.
5757
* ----------------------------------------------------------------
5858
*/
59+
60+
static inline TupleTableSlot **fetchNextBlock(PlanState *plan) {
61+
/* NEVER set outerTupleSlots[BLOCK_SIZE] to value other than NULL, it's the terimiator of the loop! */
62+
static TupleTableSlot *blockData[BLOCK_SIZE + 1] = { NULL };
63+
for (unsigned long idx = 0; idx < BLOCK_SIZE; ++ idx) {
64+
blockData[idx] = ExecProcNode(plan);
65+
if (TupIsNull(blockData[idx])) {
66+
if (idx == 0) {
67+
ENL1_printf("no outer tuple, ending join");
68+
return NULL;
69+
} else {
70+
return blockData;
71+
}
72+
}
73+
}
74+
return blockData;
75+
}
76+
5977
TupleTableSlot *
6078
ExecNestLoop(NestLoopState *node)
6179
{
@@ -119,8 +137,15 @@ ExecNestLoop(NestLoopState *node)
119137
*/
120138
if (node->nl_NeedNewOuter)
121139
{
122-
ENL1_printf("getting new outer tuple");
123-
outerTupleSlot = ExecProcNode(outerPlan);
140+
ENL1_printf("getting new outer tuples");
141+
outerTupleSlot = *(++ econtext->ecxt_outertuples);
142+
if (TupIsNull(outerTupleSlot)) {
143+
if ((econtext->ecxt_outertuples = fetchNextBlock(outerPlan)) == NULL) {
144+
ENL1_printf("no outer tuple, ending join");
145+
return NULL;
146+
}
147+
outerTupleSlot = *econtext->ecxt_outertuples;
148+
}
124149

125150
/*
126151
* if there are no more outer tuples, then the join is complete..
@@ -132,7 +157,6 @@ ExecNestLoop(NestLoopState *node)
132157
}
133158

134159
ENL1_printf("saving new outer tuple information");
135-
econtext->ecxt_outertuple = outerTupleSlot;
136160
node->nl_NeedNewOuter = false;
137161
node->nl_MatchedOuter = false;
138162

@@ -439,3 +463,5 @@ ExecReScanNestLoop(NestLoopState *node)
439463
node->nl_NeedNewOuter = true;
440464
node->nl_MatchedOuter = false;
441465
}
466+
467+

src/include/executor/nodeNestloop.h

+2
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ extern TupleTableSlot *ExecNestLoop(NestLoopState *node);
2121
extern void ExecEndNestLoop(NestLoopState *node);
2222
extern void ExecReScanNestLoop(NestLoopState *node);
2323

24+
#define BLOCK_SIZE 1024
25+
2426
#endif /* NODENESTLOOP_H */

src/include/nodes/execnodes.h

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ typedef struct ExprContext
116116
TupleTableSlot *ecxt_scantuple;
117117
TupleTableSlot *ecxt_innertuple;
118118
TupleTableSlot *ecxt_outertuple;
119+
TupleTableSlot **ecxt_outertuples;
119120

120121
/* Memory contexts for expression evaluation --- see notes above */
121122
MemoryContext ecxt_per_query_memory;

0 commit comments

Comments
 (0)