Subject: hashdone

From: [email-masked] (Postgres System User)
Date: Thu, 17 Sep 92 14:50:34 -0700

I apologize for sending this type of thing to the mailing list but it
seems that Jeff has been removed from the face of the planet (at least
w/ respect to this subject.)

If the following is in error w/ respect to systems at Berkeley please
advise since this is a System V port of postgres v4r0r1!

In n_hashjoin.c function ExecHashJoin(node) about line 405 is the following:

	while (curbatch <= nbatch && TupIsNull((Pointer) outerTupleSlot)) {
	/*
	 * if the current batch runs out, switch to new batch
	 */
	   curbatch = ExecHashJoinNewBatch(hjstate);
	   if (curbatch > nbatch) {
	    /*
	     * when the last batch runs out, clean up
	     */

		... stuff deleted ...
		ExecHashTableDestroy(hashtable);
		set_hj_HashTable(hjstate, NULL);
		return NULL;
             }  
	    
This however leaves node->hashdone set to true.  So if the routine is
called again hashtable (which is NULL) is accessed causing a segment
violation. 

Assume that we have two classes related to each via the attribute Acct.
Consider the following innocuous but legal(???) scenario:
begin\g
retrieve portal MyPortal (j.Acct, c.Name) where j.Acct = c.Acct\g
fetch all in MyPortal\g
fetch 1 in MyPortal\g
---- segmentation violation from backend -----

This following however works fine (sort evidently doesn't use HashJoin?):
begin\g
retrieve portal MyPortal (j.Acct, c.Name) where j.Acct = c.Acct sort
by Acct\g
fetch all in MyPortal\g
fetch 1 in MyPortal\g /* Nothing is correctly returned */
end\g
----------------------------------------------

It would be easy enough to stop this particular violation but since
set_hj_HashTable() is called elsewhere I'm not sure of the scope of
the problem.  Any assistance would be greatly appreciatied.
Thanks
nmm

Neil M. McQuaig, III
344 Millicent Way
Shreveport, LA  71106
Voice: (318) 868-5611
Email: uunet!mcquaig!nmm