nodeHashjoin.c 17.8 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * nodeHashjoin.c
4
 *	  Routines to handle hash join nodes
5 6 7 8 9
 *
 * Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
B
Bruce Momjian 已提交
10
 *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.21 1999/05/25 16:08:42 momjian Exp $
11 12 13
 *
 *-------------------------------------------------------------------------
 */
14
#include <sys/types.h>
15 16
#include <string.h>

B
Bruce Momjian 已提交
17
#include "postgres.h"
18

19
#include "executor/execdebug.h"
20
#include "executor/executor.h"
21 22 23 24
#include "executor/nodeHash.h"
#include "executor/nodeHashjoin.h"
#include "optimizer/clauses.h"	/* for get_leftop */

25
static TupleTableSlot *ExecHashJoinOuterGetTuple(Plan *node, Plan *parent,
B
Bruce Momjian 已提交
26
						  HashJoinState *hjstate);
27
static TupleTableSlot *ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
B
Bruce Momjian 已提交
28 29
						  BufFile * file,
						  TupleTableSlot *tupleSlot);
30
static int	ExecHashJoinGetBatch(int bucketno, HashJoinTable hashtable);
31
static int	ExecHashJoinNewBatch(HashJoinState *hjstate);
32 33


34
/* ----------------------------------------------------------------
35
 *		ExecHashJoin
36
 *
37 38 39 40
 *		This function implements the Hybrid Hashjoin algorithm.
 *		recursive partitioning remains to be added.
 *		Note: the relation we build hash table on is the inner
 *			  the other one is outer.
41 42
 * ----------------------------------------------------------------
 */
43
TupleTableSlot *				/* return: a tuple or NULL */
44
ExecHashJoin(HashJoin *node)
45
{
46 47 48 49 50 51 52 53
	HashJoinState *hjstate;
	EState	   *estate;
	Plan	   *outerNode;
	Hash	   *hashNode;
	List	   *hjclauses;
	Expr	   *clause;
	List	   *qual;
	ScanDirection dir;
54
	TupleTableSlot *inntuple;
55 56 57 58 59
	Var		   *outerVar;
	ExprContext *econtext;
	HashJoinTable hashtable;
	HeapTuple	curtuple;
	bool		qualResult;
60 61
	TupleTableSlot *outerTupleSlot;
	TupleTableSlot *innerTupleSlot;
62 63 64
	Var		   *innerhashkey;
	int			i;
	bool		hashPhaseDone;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

	/* ----------------
	 *	get information from HashJoin node
	 * ----------------
	 */
	hjstate = node->hashjoinstate;
	hjclauses = node->hashclauses;
	clause = lfirst(hjclauses);
	estate = node->join.state;
	qual = node->join.qual;
	hashNode = (Hash *) innerPlan(node);
	outerNode = outerPlan(node);
	hashPhaseDone = node->hashdone;

	dir = estate->es_direction;

81
	/* -----------------
82
	 * get information from HashJoin state
83 84
	 * -----------------
	 */
85
	hashtable = hjstate->hj_HashTable;
86

87 88 89
	/* --------------------
	 * initialize expression context
	 * --------------------
90
	 */
91 92 93 94 95
	econtext = hjstate->jstate.cs_ExprContext;

	if (hjstate->jstate.cs_TupFromTlist)
	{
		TupleTableSlot *result;
96
		bool		isDone;
97 98 99 100

		result = ExecProject(hjstate->jstate.cs_ProjInfo, &isDone);
		if (!isDone)
			return result;
101
	}
102

103
	/* ----------------
104
	 *	if this is the first call, build the hash table for inner relation
105 106
	 * ----------------
	 */
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	if (!hashPhaseDone)
	{							/* if the hash phase not completed */
		if (hashtable == NULL)
		{						/* if the hash table has not been created */
			/* ----------------
			 * create the hash table
			 * ----------------
			 */
			hashtable = ExecHashTableCreate(hashNode);
			hjstate->hj_HashTable = hashtable;
			innerhashkey = hashNode->hashkey;
			hjstate->hj_InnerHashKey = innerhashkey;

			/* ----------------
			 * execute the Hash node, to build the hash table
			 * ----------------
			 */
124
			hashNode->hashstate->hashtable = hashtable;
125 126 127
			innerTupleSlot = ExecProcNode((Plan *) hashNode, (Plan *) node);
		}
		node->hashdone = true;
128 129 130 131
		/* ----------------
		 * Open temp files for outer batches, if needed.
		 * Note that file buffers are palloc'd in regular executor context.
		 * ----------------
132
		 */
133
		for (i = 0; i < hashtable->nbatch; i++)
134
		{
B
Bruce Momjian 已提交
135 136
			File		tfile = OpenTemporaryFile();

137 138
			Assert(tfile >= 0);
			hashtable->outerBatchFile[i] = BufFileCreate(tfile);
139 140
		}
	}
141 142
	else if (hashtable == NULL)
		return NULL;
143

144
	/* ----------------
145
	 *	Now get an outer tuple and probe into the hash table for matches
146 147
	 * ----------------
	 */
148 149 150
	outerTupleSlot = hjstate->jstate.cs_OuterTupleSlot;
	outerVar = get_leftop(clause);

151
	for (;;)
152
	{
B
Bruce Momjian 已提交
153

154
		/*
155
		 * if the current outer tuple is nil, get a new one
156
		 */
157
		if (TupIsNull(outerTupleSlot))
158
		{
159 160 161 162
			outerTupleSlot = ExecHashJoinOuterGetTuple(outerNode,
													   (Plan *) node,
													   hjstate);
			if (TupIsNull(outerTupleSlot))
163
			{
B
Bruce Momjian 已提交
164

165
				/*
166
				 * when the last batch runs out, clean up and exit
167 168 169 170 171 172 173
				 */
				ExecHashTableDestroy(hashtable);
				hjstate->hj_HashTable = NULL;
				return NULL;
			}

			/*
B
Bruce Momjian 已提交
174 175
			 * now we have an outer tuple, find the corresponding bucket
			 * for this tuple from the hash table
176
			 */
177 178 179 180
			econtext->ecxt_outertuple = outerTupleSlot;
			hjstate->hj_CurBucketNo = ExecHashGetBucket(hashtable, econtext,
														outerVar);
			hjstate->hj_CurTuple = NULL;
181

182 183 184 185 186 187 188 189
			/* ----------------
			 *	Now we've got an outer tuple and the corresponding hash bucket,
			 *	but this tuple may not belong to the current batch.
			 *	This need only be checked in the first pass.
			 * ----------------
			 */
			if (hashtable->curbatch == 0)
			{
B
Bruce Momjian 已提交
190 191 192
				int			batch = ExecHashJoinGetBatch(hjstate->hj_CurBucketNo,
														 hashtable);

193
				if (batch > 0)
194
				{
B
Bruce Momjian 已提交
195

196
					/*
197 198
					 * Need to postpone this outer tuple to a later batch.
					 * Save it in the corresponding outer-batch file.
199
					 */
B
Bruce Momjian 已提交
200 201
					int			batchno = batch - 1;

202 203
					hashtable->outerBatchSize[batchno]++;
					ExecHashJoinSaveTuple(outerTupleSlot->val,
B
Bruce Momjian 已提交
204
									 hashtable->outerBatchFile[batchno]);
205
					ExecClearTuple(outerTupleSlot);
B
Bruce Momjian 已提交
206
					continue;	/* loop around for a new outer tuple */
207 208 209 210
				}
			}
		}

211 212
		/*
		 * OK, scan the selected hash bucket for matches
213
		 */
214
		for (;;)
215
		{
216 217 218 219 220
			curtuple = ExecScanHashBucket(hjstate,
										  hjclauses,
										  econtext);
			if (curtuple == NULL)
				break;			/* out of matches */
B
Bruce Momjian 已提交
221

222
			/*
223
			 * we've got a match, but still need to test qpqual
224
			 */
225 226 227 228 229 230 231 232 233 234 235 236 237
			inntuple = ExecStoreTuple(curtuple,
									  hjstate->hj_HashTupleSlot,
									  InvalidBuffer,
									  false);	/* don't pfree this tuple */
			econtext->ecxt_innertuple = inntuple;
			qualResult = ExecQual(qual, econtext);
			/* ----------------
			 * if we pass the qual, then save state for next call and
			 * have ExecProject form the projection, store it
			 * in the tuple table, and return the slot.
			 * ----------------
			 */
			if (qualResult)
238
			{
239 240 241 242 243 244 245 246 247
				ProjectionInfo *projInfo;
				TupleTableSlot *result;
				bool		isDone;

				hjstate->jstate.cs_OuterTupleSlot = outerTupleSlot;
				projInfo = hjstate->jstate.cs_ProjInfo;
				result = ExecProject(projInfo, &isDone);
				hjstate->jstate.cs_TupFromTlist = !isDone;
				return result;
248 249 250 251
			}
		}

		/* ----------------
252 253
		 *	 Now the current outer tuple has run out of matches,
		 *	 so we free it and loop around to get a new outer tuple.
254 255
		 * ----------------
		 */
256
		ExecClearTuple(outerTupleSlot);
257
	}
258 259 260
}

/* ----------------------------------------------------------------
261
 *		ExecInitHashJoin
262
 *
263
 *		Init routine for HashJoin node.
264 265
 * ----------------------------------------------------------------
 */
266
bool							/* return: initialization status */
267
ExecInitHashJoin(HashJoin *node, EState *estate, Plan *parent)
268
{
269 270 271
	HashJoinState *hjstate;
	Plan	   *outerNode;
	Hash	   *hashNode;
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

	/* ----------------
	 *	assign the node's execution state
	 * ----------------
	 */
	node->join.state = estate;

	/* ----------------
	 * create state structure
	 * ----------------
	 */
	hjstate = makeNode(HashJoinState);

	node->hashjoinstate = hjstate;

	/* ----------------
288
	 *	Miscellaneous initialization
289 290 291 292 293 294 295 296 297
	 *
	 *		 +	assign node's base_id
	 *		 +	assign debugging hooks and
	 *		 +	create expression context for node
	 * ----------------
	 */
	ExecAssignNodeBaseInfo(estate, &hjstate->jstate, parent);
	ExecAssignExprContext(estate, &hjstate->jstate);

298
#define HASHJOIN_NSLOTS 2
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
	/* ----------------
	 *	tuple table initialization
	 * ----------------
	 */
	ExecInitResultTupleSlot(estate, &hjstate->jstate);
	ExecInitOuterTupleSlot(estate, hjstate);

	/* ----------------
	 * initializes child nodes
	 * ----------------
	 */
	outerNode = outerPlan((Plan *) node);
	hashNode = (Hash *) innerPlan((Plan *) node);

	ExecInitNode(outerNode, estate, (Plan *) node);
	ExecInitNode((Plan *) hashNode, estate, (Plan *) node);

	/* ----------------
	 *	now for some voodoo.  our temporary tuple slot
	 *	is actually the result tuple slot of the Hash node
	 *	(which is our inner plan).	we do this because Hash
	 *	nodes don't return tuples via ExecProcNode() -- instead
	 *	the hash join node uses ExecScanHashBucket() to get
	 *	at the contents of the hash table.	-cim 6/9/91
	 * ----------------
	 */
	{
326
		HashState  *hashstate = hashNode->hashstate;
327
		TupleTableSlot *slot = hashstate->cstate.cs_ResultTupleSlot;
328 329 330

		hjstate->hj_HashTupleSlot = slot;
	}
331
	hjstate->hj_OuterTupleSlot->ttc_tupleDescriptor = ExecGetTupType(outerNode);
332

333
/*
334
	hjstate->hj_OuterTupleSlot->ttc_execTupDescriptor = ExecGetExecTupDesc(outerNode);
335
*/
336 337 338 339 340 341 342 343 344

	/* ----------------
	 *	initialize tuple type and projection info
	 * ----------------
	 */
	ExecAssignResultTypeFromTL((Plan *) node, &hjstate->jstate);
	ExecAssignProjectionInfo((Plan *) node, &hjstate->jstate);

	/* ----------------
345
	 *	initialize hash-specific info
346 347 348 349 350 351
	 * ----------------
	 */

	node->hashdone = false;

	hjstate->hj_HashTable = (HashJoinTable) NULL;
352 353
	hjstate->hj_CurBucketNo = 0;
	hjstate->hj_CurTuple = (HashJoinTuple) NULL;
354 355 356 357 358 359
	hjstate->hj_InnerHashKey = (Var *) NULL;

	hjstate->jstate.cs_OuterTupleSlot = (TupleTableSlot *) NULL;
	hjstate->jstate.cs_TupFromTlist = (bool) false;

	return TRUE;
360 361 362
}

int
363
ExecCountSlotsHashJoin(HashJoin *node)
364
{
365
	return ExecCountSlotsNode(outerPlan(node)) +
366
	ExecCountSlotsNode(innerPlan(node)) +
367
	HASHJOIN_NSLOTS;
368 369 370
}

/* ----------------------------------------------------------------
371
 *		ExecEndHashJoin
372
 *
373
 *		clean up routine for HashJoin node
374 375 376
 * ----------------------------------------------------------------
 */
void
377
ExecEndHashJoin(HashJoin *node)
378
{
379
	HashJoinState *hjstate;
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422

	/* ----------------
	 *	get info from the HashJoin state
	 * ----------------
	 */
	hjstate = node->hashjoinstate;

	/* ----------------
	 * free hash table in case we end plan before all tuples are retrieved
	 * ---------------
	 */
	if (hjstate->hj_HashTable)
	{
		ExecHashTableDestroy(hjstate->hj_HashTable);
		hjstate->hj_HashTable = NULL;
	}

	/* ----------------
	 *	Free the projection info and the scan attribute info
	 *
	 *	Note: we don't ExecFreeResultType(hjstate)
	 *		  because the rule manager depends on the tupType
	 *		  returned by ExecMain().  So for now, this
	 *		  is freed at end-transaction time.  -cim 6/2/91
	 * ----------------
	 */
	ExecFreeProjectionInfo(&hjstate->jstate);

	/* ----------------
	 * clean up subtrees
	 * ----------------
	 */
	ExecEndNode(outerPlan((Plan *) node), (Plan *) node);
	ExecEndNode(innerPlan((Plan *) node), (Plan *) node);

	/* ----------------
	 *	clean out the tuple table
	 * ----------------
	 */
	ExecClearTuple(hjstate->jstate.cs_ResultTupleSlot);
	ExecClearTuple(hjstate->hj_OuterTupleSlot);
	ExecClearTuple(hjstate->hj_HashTupleSlot);

423 424 425
}

/* ----------------------------------------------------------------
426
 *		ExecHashJoinOuterGetTuple
427
 *
428 429 430
 *		get the next outer tuple for hashjoin: either by
 *		executing a plan node as in the first pass, or from
 *		the tmp files for the hashjoin batches.
431 432 433 434
 * ----------------------------------------------------------------
 */

static TupleTableSlot *
435
ExecHashJoinOuterGetTuple(Plan *node, Plan *parent, HashJoinState *hjstate)
436
{
B
Bruce Momjian 已提交
437 438
	HashJoinTable hashtable = hjstate->hj_HashTable;
	int			curbatch = hashtable->curbatch;
439 440 441 442 443
	TupleTableSlot *slot;

	if (curbatch == 0)
	{							/* if it is the first pass */
		slot = ExecProcNode(node, parent);
B
Bruce Momjian 已提交
444
		if (!TupIsNull(slot))
445
			return slot;
B
Bruce Momjian 已提交
446

447
		/*
B
Bruce Momjian 已提交
448 449
		 * We have just reached the end of the first pass. Try to switch
		 * to a saved batch.
450 451
		 */
		curbatch = ExecHashJoinNewBatch(hjstate);
452 453 454
	}

	/*
B
Bruce Momjian 已提交
455 456
	 * Try to read from a temp file. Loop allows us to advance to new
	 * batch as needed.
457
	 */
458 459 460
	while (curbatch <= hashtable->nbatch)
	{
		slot = ExecHashJoinGetSavedTuple(hjstate,
B
Bruce Momjian 已提交
461
								 hashtable->outerBatchFile[curbatch - 1],
462
										 hjstate->hj_OuterTupleSlot);
B
Bruce Momjian 已提交
463
		if (!TupIsNull(slot))
464 465 466 467 468 469
			return slot;
		curbatch = ExecHashJoinNewBatch(hjstate);
	}

	/* Out of batches... */
	return NULL;
470 471 472
}

/* ----------------------------------------------------------------
473
 *		ExecHashJoinGetSavedTuple
474
 *
475
 *		read the next tuple from a tmp file
476 477 478 479
 * ----------------------------------------------------------------
 */

static TupleTableSlot *
480
ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
B
Bruce Momjian 已提交
481
						  BufFile * file,
482
						  TupleTableSlot *tupleSlot)
483
{
B
Bruce Momjian 已提交
484 485 486
	HeapTupleData htup;
	size_t		nread;
	HeapTuple	heapTuple;
487 488 489 490 491 492 493 494

	nread = BufFileRead(file, (void *) &htup, sizeof(HeapTupleData));
	if (nread == 0)
		return NULL;			/* end of file */
	if (nread != sizeof(HeapTupleData))
		elog(ERROR, "Read from hashjoin temp file failed");
	heapTuple = palloc(HEAPTUPLESIZE + htup.t_len);
	memcpy((char *) heapTuple, (char *) &htup, sizeof(HeapTupleData));
B
Bruce Momjian 已提交
495 496
	heapTuple->t_data = (HeapTupleHeader)
		((char *) heapTuple + HEAPTUPLESIZE);
497 498 499 500
	nread = BufFileRead(file, (void *) heapTuple->t_data, htup.t_len);
	if (nread != (size_t) htup.t_len)
		elog(ERROR, "Read from hashjoin temp file failed");
	return ExecStoreTuple(heapTuple, tupleSlot, InvalidBuffer, true);
501 502 503
}

/* ----------------------------------------------------------------
504
 *		ExecHashJoinNewBatch
505
 *
506
 *		switch to a new hashjoin batch
507 508
 * ----------------------------------------------------------------
 */
509
static int
510
ExecHashJoinNewBatch(HashJoinState *hjstate)
511
{
512 513 514 515 516
	HashJoinTable hashtable = hjstate->hj_HashTable;
	int			nbatch = hashtable->nbatch;
	int			newbatch = hashtable->curbatch + 1;
	long	   *innerBatchSize = hashtable->innerBatchSize;
	long	   *outerBatchSize = hashtable->outerBatchSize;
B
Bruce Momjian 已提交
517
	BufFile    *innerFile;
518
	TupleTableSlot *slot;
519
	ExprContext *econtext;
520
	Var		   *innerhashkey;
521 522 523

	if (newbatch > 1)
	{
B
Bruce Momjian 已提交
524

525
		/*
B
Bruce Momjian 已提交
526 527
		 * We no longer need the previous outer batch file; close it right
		 * away to free disk space.
528
		 */
529 530
		BufFileClose(hashtable->outerBatchFile[newbatch - 2]);
		hashtable->outerBatchFile[newbatch - 2] = NULL;
531 532 533
	}

	/* --------------
534 535
	 *	We can skip over any batches that are empty on either side.
	 *	Release associated temp files right away.
536
	 * --------------
537
	 */
538 539 540
	while (newbatch <= nbatch &&
		   (innerBatchSize[newbatch - 1] == 0L ||
			outerBatchSize[newbatch - 1] == 0L))
541
	{
542 543 544 545
		BufFileClose(hashtable->innerBatchFile[newbatch - 1]);
		hashtable->innerBatchFile[newbatch - 1] = NULL;
		BufFileClose(hashtable->outerBatchFile[newbatch - 1]);
		hashtable->outerBatchFile[newbatch - 1] = NULL;
546
		newbatch++;
547
	}
548

549
	if (newbatch > nbatch)
550
		return newbatch;		/* no more batches */
551

552
	/*
B
Bruce Momjian 已提交
553 554
	 * Rewind inner and outer batch files for this batch, so that we can
	 * start reading them.
555 556 557 558 559 560
	 */
	if (BufFileSeek(hashtable->outerBatchFile[newbatch - 1], 0L,
					SEEK_SET) != 0L)
		elog(ERROR, "Failed to rewind hash temp file");

	innerFile = hashtable->innerBatchFile[newbatch - 1];
561

562 563 564 565 566 567 568
	if (BufFileSeek(innerFile, 0L, SEEK_SET) != 0L)
		elog(ERROR, "Failed to rewind hash temp file");

	/*
	 * Reload the hash table with the new inner batch
	 */
	ExecHashTableReset(hashtable, innerBatchSize[newbatch - 1]);
569 570 571 572 573

	econtext = hjstate->jstate.cs_ExprContext;
	innerhashkey = hjstate->hj_InnerHashKey;

	while ((slot = ExecHashJoinGetSavedTuple(hjstate,
574 575
											 innerFile,
											 hjstate->hj_HashTupleSlot))
576 577 578
		   && !TupIsNull(slot))
	{
		econtext->ecxt_innertuple = slot;
579
		ExecHashTableInsert(hashtable, econtext, innerhashkey);
580 581 582
	}

	/*
B
Bruce Momjian 已提交
583 584
	 * after we build the hash table, the inner batch file is no longer
	 * needed
585
	 */
586 587
	BufFileClose(innerFile);
	hashtable->innerBatchFile[newbatch - 1] = NULL;
588

589
	hashtable->curbatch = newbatch;
590 591 592 593
	return newbatch;
}

/* ----------------------------------------------------------------
594
 *		ExecHashJoinGetBatch
595
 *
596 597 598 599
 *		determine the batch number for a bucketno
 *		+----------------+-------+-------+ ... +-------+
 *		0			  nbuckets						 totalbuckets
 * batch		 0			 1		 2	   ...
600 601
 * ----------------------------------------------------------------
 */
602
static int
603
ExecHashJoinGetBatch(int bucketno, HashJoinTable hashtable)
604
{
605
	int			b;
606

607
	if (bucketno < hashtable->nbuckets || hashtable->nbatch == 0)
608 609
		return 0;

610 611
	b = (hashtable->nbatch * (bucketno - hashtable->nbuckets)) /
		(hashtable->totalbuckets - hashtable->nbuckets);
612
	return b + 1;
613 614 615
}

/* ----------------------------------------------------------------
616
 *		ExecHashJoinSaveTuple
617
 *
618 619 620 621 622
 *		save a tuple to a tmp file.
 *
 * The data recorded in the file for each tuple is an image of its
 * HeapTupleData (with meaningless t_data pointer) followed by the
 * HeapTupleHeader and tuple data.
623 624 625
 * ----------------------------------------------------------------
 */

626
void
627
ExecHashJoinSaveTuple(HeapTuple heapTuple,
B
Bruce Momjian 已提交
628
					  BufFile * file)
629
{
B
Bruce Momjian 已提交
630
	size_t		written;
631 632 633 634 635 636 637

	written = BufFileWrite(file, (void *) heapTuple, sizeof(HeapTupleData));
	if (written != sizeof(HeapTupleData))
		elog(ERROR, "Write to hashjoin temp file failed");
	written = BufFileWrite(file, (void *) heapTuple->t_data, heapTuple->t_len);
	if (written != (size_t) heapTuple->t_len)
		elog(ERROR, "Write to hashjoin temp file failed");
638
}
V
Vadim B. Mikheev 已提交
639 640 641 642

void
ExecReScanHashJoin(HashJoin *node, ExprContext *exprCtxt, Plan *parent)
{
643
	HashJoinState *hjstate = node->hashjoinstate;
V
Vadim B. Mikheev 已提交
644 645 646

	if (!node->hashdone)
		return;
647

V
Vadim B. Mikheev 已提交
648
	node->hashdone = false;
649 650 651 652

	/*
	 * Unfortunately, currently we have to destroy hashtable in all
	 * cases...
V
Vadim B. Mikheev 已提交
653 654 655 656 657 658
	 */
	if (hjstate->hj_HashTable)
	{
		ExecHashTableDestroy(hjstate->hj_HashTable);
		hjstate->hj_HashTable = NULL;
	}
659 660 661

	hjstate->hj_CurBucketNo = 0;
	hjstate->hj_CurTuple = (HashJoinTuple) NULL;
V
Vadim B. Mikheev 已提交
662 663 664 665
	hjstate->hj_InnerHashKey = (Var *) NULL;

	hjstate->jstate.cs_OuterTupleSlot = (TupleTableSlot *) NULL;
	hjstate->jstate.cs_TupFromTlist = (bool) false;
666 667 668 669

	/*
	 * if chgParam of subnodes is not null then plans will be re-scanned
	 * by first ExecProcNode.
V
Vadim B. Mikheev 已提交
670
	 */
671 672 673 674
	if (((Plan *) node)->lefttree->chgParam == NULL)
		ExecReScan(((Plan *) node)->lefttree, exprCtxt, (Plan *) node);
	if (((Plan *) node)->righttree->chgParam == NULL)
		ExecReScan(((Plan *) node)->righttree, exprCtxt, (Plan *) node);
V
Vadim B. Mikheev 已提交
675
}