head	1.15;
access;
symbols
	release_4_2:1.15
	aix_ok:1.15
	Version_2_1:1.10
	C_Demo_1:1.8
	Retrieve_x_qual:1.6
	Retrieve_x_all:1.5
	Retrieve_x_1:1.4;
locks; strict;
comment	@ * @;


1.15
date	92.07.12.10.57.31;	author joey;	state Exp;
branches;
next	1.14;

1.14
date	92.03.31.23.12.56;	author mer;	state Exp;
branches;
next	1.13;

1.13
date	91.11.17.20.39.50;	author mer;	state Exp;
branches;
next	1.12;

1.12
date	91.11.15.16.27.00;	author hong;	state Exp;
branches;
next	1.11;

1.11
date	91.04.11.14.26.05;	author kemnitz;	state Exp;
branches;
next	1.10;

1.10
date	90.09.25.16.35.32;	author kemnitz;	state Exp;
branches;
next	1.9;

1.9
date	90.05.30.18.56.42;	author cimarron;	state Exp;
branches;
next	1.8;

1.8
date	89.09.05.17.17.17;	author mao;	state C_Demo_1;
branches;
next	1.7;

1.7
date	89.08.23.16.02.35;	author ong;	state Exp;
branches;
next	1.6;

1.6
date	89.08.04.14.27.14;	author goh;	state Exp;
branches;
next	1.5;

1.5
date	89.08.04.13.23.06;	author goh;	state Exp;
branches;
next	1.4;

1.4
date	89.08.01.14.39.45;	author goh;	state Exp;
branches;
next	1.3;

1.3
date	89.07.25.17.35.21;	author ong;	state Exp;
branches;
next	1.2;

1.2
date	89.07.21.14.55.46;	author ong;	state Exp;
branches;
next	1.1;

1.1
date	89.07.10.15.15.35;	author ong;	state Exp;
branches;
next	;


desc
@stuff to do hashjoins
@


1.15
log
@CInfo->clause is now a LispValue, not an Expr
@
text
@
/*     
 *      FILE
 *     	hashutils
 *     
 *      DESCRIPTION
 *     	Utilities for finding applicable merge clauses and pathkeys
 *     
 */
/* RcsId ("$Header: /private/joey/pg/src/planner/path/RCS/hashutils.c,v 1.14 1992/03/31 23:12:56 mer Exp joey $"); */

/*     
 *      EXPORTS
 *     		group-clauses-by-hashop
 *     		match-hashop-hashinfo
 */

#include "nodes/pg_lisp.h"
#include "nodes/relation.h"
#include "nodes/relation.a.h"

#include "planner/internal.h"
#include "planner/hashutils.h"
#include "planner/clauses.h"

/*    
 *    	group-clauses-by-hashop
 *    
 *    	If a join clause node in 'clauseinfo-list' is hashjoinable, store
 *    	it within a hashinfo node containing other clause nodes with the same
 *    	hash operator.
 *    
 *    	'clauseinfo-list' is the list of clauseinfo nodes
 *    	'inner-relid' is the relid of the inner join relation
 *    
 *    	Returns the new list of hashinfo nodes.
 *    
 */

/*  .. find-all-join-paths */

LispValue
group_clauses_by_hashop (clauseinfo_list,inner_relid)
     LispValue clauseinfo_list,inner_relid ;
{
    LispValue hashinfo_list = LispNil;
    CInfo clauseinfo = (CInfo)NULL;
    LispValue i = LispNil;
    LispValue temp = LispNil;
    LispValue temp2 = LispNil;
    ObjectId hashjoinop = 0;
    
    foreach (i,clauseinfo_list) {
	clauseinfo = (CInfo)CAR(i);
	hashjoinop = get_hashjoinoperator(clauseinfo);
	
	/*    Create a new hashinfo node and add it to */
	/*    'hashinfo-list' if one does not yet */
	/*    exist for this hash operator.   */
	
	if (hashjoinop ) {
	    HInfo xhashinfo = (HInfo)NULL;
	    LispValue clause = get_clause (clauseinfo);
	    Var leftop = get_leftop(clause);
	    Var rightop = get_rightop(clause);
	    JoinKey keys = (JoinKey)NULL;
	    
	    xhashinfo = 
	      match_hashop_hashinfo (hashjoinop,hashinfo_list);
	    
	    if (CInteger(inner_relid) == get_varno (leftop)){
		keys = MakeJoinKey((LispValue)rightop,
				   (LispValue)leftop);
	    }
	    else {
		keys = MakeJoinKey((LispValue)leftop,
				   (LispValue)rightop);
	    }
	    
	    if ( null(xhashinfo)) {
		xhashinfo = RMakeHInfo();
		set_hashop(xhashinfo,
			   hashjoinop);

		set_jmkeys((JoinMethod)xhashinfo,LispNil);
		set_clauses((JoinMethod)xhashinfo,LispNil);

/*		set_clause(xhashinfo,NULL);
		set_selectivity(xhashinfo,0);
		set_notclause(xhashinfo,false);
		set_indexids(xhashinfo,LispNil);
		set_mergesortorder(xhashinfo,(MergeOrder)NULL);
 */

		/* XXX was push  */
		hashinfo_list = nappend1(hashinfo_list,(LispValue)xhashinfo);
		hashinfo_list = nreverse(hashinfo_list);
	    }

	    /* XXX was "push" function  */
	    /* push (clause,joinmethod_clauses (xhashinfo));
	     *  push (keys,joinmethod_keys (xhashinfo));
	     */
	    
	    if (null(get_clauses((JoinMethod)xhashinfo)))
	    {
	      set_clauses((JoinMethod)xhashinfo,lispCons((LispValue)clause, LispNil));
	    }
	    else {
		temp = lispList();
		CAR(temp) = CAR(get_clauses((JoinMethod)xhashinfo));
		CDR(temp) = CDR(get_clauses((JoinMethod)xhashinfo));
		CDR(get_clauses((JoinMethod)xhashinfo)) = temp;
		CAR(get_clauses((JoinMethod)xhashinfo)) = clause;
	    }
	    if (null(get_jmkeys((JoinMethod)xhashinfo)))
	    {
	      set_jmkeys((JoinMethod)xhashinfo,lispCons((LispValue)keys, LispNil));
	    }
	    else {
		temp2 = lispList();
	    
		CAR(temp2) = CAR(get_jmkeys((JoinMethod)xhashinfo));
		CDR(temp2) = CDR(get_jmkeys((JoinMethod)xhashinfo));
		CDR(get_jmkeys((JoinMethod)xhashinfo)) = temp2;
		CAR(get_jmkeys((JoinMethod)xhashinfo)) = (LispValue)keys;
	    }

/*	    temp2 = get_jmkeys(xhashinfo);
	    temp2 = nappend1(temp2,keys);
	    temp2 = nreverse(temp2);
 */	    
	}
    }
    return(hashinfo_list);
} /* function end */


/*    
 *    	match-hashop-hashinfo
 *    
 *    	Searches the list 'hashinfo-list' for a hashinfo node whose hash op
 *    	field equals 'hashop'.
 *    
 *    	Returns the node if it exists.
 *    
 */

/*  .. group-clauses-by-hashop */

HInfo
match_hashop_hashinfo (hashop,hashinfo_list)
     LispValue hashinfo_list ;
     ObjectId hashop;
{
    ObjectId key = 0;
    HInfo xhashinfo = (HInfo)NULL;
    LispValue i = LispNil;
    
    /* XXX -- Lisp find and lambda function --- maybe wrong */
    foreach( i, hashinfo_list) {
	xhashinfo = (HInfo)CAR(i);
	key = get_hashop(xhashinfo);
	if (hashop == key) {  /* found */
	    return(xhashinfo);    /* should be a hashinfo node ! */
	}
    }
    return((HInfo)LispNil);
}
@


1.14
log
@change accessor functions into macros
@
text
@d10 1
a10 1
/* RcsId ("$Header: /users/mer/pg/src/planner/path/RCS/hashutils.c,v 1.13 1991/11/17 20:39:50 mer Exp mer $"); */
d63 3
a65 3
	    Expr clause = get_clause (clauseinfo);
	    Var leftop = get_leftop((LispValue)clause);
	    Var rightop = get_rightop((LispValue)clause);
d88 1
a88 1
/*		set_clause(xhashinfo,(Expr)NULL);
d114 1
a114 1
		CAR(get_clauses((JoinMethod)xhashinfo)) = (LispValue)clause;
@


1.13
log
@prototyping
@
text
@d10 1
a10 1
/* RcsId ("$Header: /users/mer/postgres/src/planner/path/RCS/hashutils.c,v 1.12 1991/11/15 16:27:00 hong Exp mer $"); */
d106 3
a108 2
	      set_clauses((JoinMethod)xhashinfo,lispCons((LispValue)clause,
							 LispNil));
d117 3
a119 2
	      set_jmkeys((JoinMethod)xhashinfo,lispCons((LispValue)keys,
							LispNil));
@


1.12
log
@planner prototyping
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/hashutils.c,v 1.11 91/04/11 14:26:05 kemnitz Exp $"); */
d96 1
a96 1
		hashinfo_list = nappend1(hashinfo_list,xhashinfo);
d106 2
a107 1
	      set_clauses((JoinMethod)xhashinfo,lispCons(clause,LispNil));
d116 2
a117 1
	      set_jmkeys((JoinMethod)xhashinfo,lispCons(keys,LispNil));
@


1.11
log
@change "equal(key,...)" to "key == ..."
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/hashutils.c,v 1.10 90/09/25 16:35:32 kemnitz Exp Locker: kemnitz $"); */
a25 6
/* ----------------
 *	HInfo creator declaration
 * ----------------
 */
extern HInfo RMakeHInfo();

d64 2
a65 2
	    Var leftop = get_leftop (clause);
	    Var rightop = get_rightop (clause);
d72 2
a73 2
		keys = MakeJoinKey(rightop,
				   leftop);
d76 2
a77 2
		keys = MakeJoinKey(leftop,
				   rightop);
d85 2
a86 2
		set_jmkeys(xhashinfo,LispNil);
		set_clauses(xhashinfo,LispNil);
d105 2
a106 2
	    if (null(get_clauses(xhashinfo)))
	      set_clauses(xhashinfo,lispCons(clause,LispNil));
d109 4
a112 4
		CAR(temp) = CAR(get_clauses(xhashinfo));
		CDR(temp) = CDR(get_clauses(xhashinfo));
		CDR(get_clauses(xhashinfo)) = temp;
		CAR(get_clauses(xhashinfo)) = (LispValue)clause;
d114 2
a115 2
	    if (null(get_jmkeys(xhashinfo)))
	      set_jmkeys(xhashinfo,lispCons(keys,LispNil));
d119 4
a122 4
		CAR(temp2) = CAR(get_jmkeys(xhashinfo));
		CDR(temp2) = CDR(get_jmkeys(xhashinfo));
		CDR(get_jmkeys(xhashinfo)) = temp2;
		CAR(get_jmkeys(xhashinfo)) = (LispValue)keys;
@


1.10
log
@Updating from revision 1.9 to revision 1.10
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/hashutils.c,v 1.10 90/08/14 11:09:51 cimarron Exp $"); */
d166 1
a166 1
	if (equal(hashop,key)) {  /* found */
@


1.9
log
@CreateNode(Foo) --> RMakeFoo() change
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/hashutils.c,v 1.8 89/09/05 17:17:17 mao C_Demo_1 $"); */
d18 4
a21 3
#include "pg_lisp.h"
#include "relation.h"
#include "relation.a.h"
@


1.8
log
@Working version of C-only demo
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/hashutils.c,v 1.7 89/08/23 16:02:35 ong Exp Locker: ong $"); */
d25 5
a30 1

d86 1
a86 1
		xhashinfo = CreateNode(HInfo);
a98 2
		xhashinfo->printFunc = PrintHInfo;
		xhashinfo->equalFunc = EqualHInfo;
@


1.7
log
@planner supports all but rules and mergesort
@
text
@d10 1
a10 1
/* RcsId ("$Header: /usr6/postgres/ong/postgres/src/planner/path/RCS/hashutils.c,v 1.6 89/08/04 14:27:14 goh Exp $"); */
@


1.6
log
@reorganised header files
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.5 89/08/04 13:23:06 goh Locked $"); */
a24 1
/* extern LispValue match_hashop_hashinfo(); */
d26 1
d47 38
a84 10
     /* XXX - let form, maybe incorrect */
     LispValue hashinfo_list = LispNil;
     LispValue clauseinfo = LispNil;
     foreach (clauseinfo,clauseinfo_list) {
	  
	  ObjectId hashjoinop = get_hashjoinoperator(clauseinfo);
	  
	  /*    Create a new hashinfo node and add it to */
	  /*    'hashinfo-list' if one does not yet */
	  /*    exist for this hash operator.   */
d86 49
a134 30
	  if (hashjoinop ) {
	       CInfo xhashinfo;
	       Expr clause = get_clause (clauseinfo);
	       Var leftop = get_leftop (clause);
	       Var rightop = get_rightop (clause);
	       JoinKey keys;
	       xhashinfo = 
		 match_hashop_hashinfo (hashjoinop,hashinfo_list);
	       
	       if (equal(inner_relid,get_varno (leftop))) {
		    keys = MakeJoinKey(rightop,
					leftop);
	       }
	       else {
		    keys = MakeJoinKey(leftop,
					rightop);
	       }
		     
	       if ( null(xhashinfo)) {
		    xhashinfo = CreateNode(CInfo);
		    set_hashjoinoperator(xhashinfo,
					 MakeCInfo(hashjoinop));
		    push (xhashinfo,hashinfo_list);
	       }
	       push (clause,joinmethod_clauses (xhashinfo));
	       push (keys,joinmethod_keys (xhashinfo));
	       
		}
     }
     return(hashinfo_list);
d150 1
a150 1
CInfo
d152 2
a153 1
     LispValue hashop,hashinfo_list ;
d155 10
a164 9
     ObjectId key ;
     LispValue xhashinfo;

	/* XXX -- Lisp find and lambda function --- maybe wrong */
     foreach( xhashinfo, hashinfo_list) {
	  key = get_hashjoinoperator((CInfo)xhashinfo);
	  if (equal(hashop,key)) {  /* found */
	       return((CInfo)xhashinfo);    /* should be a hashinfo node ! */
		}
d166 2
a167 1
	return((CInfo)LispNil);
@


1.5
log
@checkin for retrieve (x.all)
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.4 89/08/01 14:39:45 goh Locked $"); */
a18 1
#include "internal.h"
d21 3
a23 2
#include "hashutils.h"
#include "clauses.h"
@


1.4
log
@retrieve (x=1) checkin
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.3 89/07/25 17:35:21 ong Exp $"); */
@


1.3
log
@Phase III
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.2 89/07/21 14:55:46 ong Locked $"); */
d61 2
a62 2
	       LispValue leftop = get_leftop (clause);
	       LispValue rightop = get_rightop (clause);
d79 1
a79 1
					 make_hashinfo(op(hashjoinop)));
@


1.2
log
@Phase II
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.1 89/07/10 15:15:35 ong Locked $"); */
d19 1
a19 1
#include "internal.h
@


1.1
log
@Initial revision
@
text
@d10 1
a10 1
/* RcsId ("$Header: hashutils.c,v 1.1 89/04/27 21:04:17 ong Locked $"); */
d19 5
a23 1
#include "internal.h"
d25 1
a25 1
extern LispValue match_hashop_hashinfo();
d47 10
a56 6
	/* XXX - let form, maybe incorrect */
	LispValue hashinfo_list = LispNil;
	LispValue clauseinfo;
	for (clauseinfo = car(clauseinfo_list); clauseinfo_list != LispNil;
	     clauseinfo_list = cdr(clauseinfo_list)) {
		/* XXX - let form, maybe incorrect */
d58 27
a84 29
		LispValue hashjoinop = get_hashjoinoperator(clauseinfo);

		/*    Create a new hashinfo node and add it to */
		/*    'hashinfo-list' if one does not yet */
		/*    exist for this hash operator.   */

		if (hashjoinop == LispTrue ) {
			LispValue hashinfo = 
			  match_hashop_hashinfo (hashjoinop,hashinfo_list);
			LispValue clause = get_clause (clauseinfo);
			LispValue leftop = get_leftop (clause);
			LispValue rightop = get_rightop (clause);
			LispValue keys = LispNil;
			if (equal(inner_relid,get_varno (leftop))) {
				keys = make_joinkey(outer(rightop),
						    inner(leftop));
			}
			else {
				keys = make_joinkey(outer(leftop),
						    inner(rightop));
			}
			
			if ( null(hashinfo)) {
				hashinfo = make_hashinfo(op(hashjoinop));
				push (hashinfo,hashinfo_list);
			}
			push (clause,joinmethod_clauses (hashinfo));
			push (keys,joinmethod_keys (hashinfo));

d86 2
a87 2
	}
	return(hashinfo_list);
d103 1
a103 1
LispValue
d107 2
a108 2
	LispValue key = LispNil;
	LispValue hashinfo = LispNil;
d111 4
a114 5
	for( hashinfo = car(hashinfo_list); hashinfo_list != LispNil;
	    hashinfo_list = cdr (hashinfo_list)) {
		key = hashinfo_op(hashinfo);
		if (equal(hashop,key)) {  /* found */
			return(hashinfo);    /* should be a hashinfo node ! */
d117 1
a117 1
	return(LispNil);
@
