head	1.20;
access;
symbols
	release_4_2:1.20
	aix_ok:1.20
	Version_2_1:1.14
	C_Demo_1:1.9
	Retrieve_x_qual:1.7
	Retrieve_x_all:1.5
	Retrieve_x_1:1.4;
locks; strict;
comment	@ * @;


1.20
date	92.07.04.04.03.42;	author mao;	state Exp;
branches;
next	1.19;

1.19
date	91.11.17.21.13.34;	author mer;	state Exp;
branches;
next	1.18;

1.18
date	91.11.17.20.39.50;	author mer;	state Exp;
branches;
next	1.17;

1.17
date	91.11.15.16.27.20;	author hong;	state Exp;
branches;
next	1.16;

1.16
date	91.11.02.21.42.33;	author hong;	state Exp;
branches;
next	1.15;

1.15
date	91.05.08.15.09.41;	author hong;	state Exp;
branches;
next	1.14;

1.14
date	91.03.06.16.54.24;	author hong;	state Exp;
branches;
next	1.13;

1.13
date	90.10.15.14.54.09;	author choi;	state Exp;
branches;
next	1.12;

1.12
date	90.09.25.16.36.02;	author kemnitz;	state Exp;
branches;
next	1.11;

1.11
date	89.11.14.11.17.14;	author hong;	state Exp;
branches;
next	1.10;

1.10
date	89.10.13.17.59.33;	author hong;	state Exp;
branches;
next	1.9;

1.9
date	89.09.05.17.17.33;	author mao;	state C_Demo_1;
branches;
next	1.8;

1.8
date	89.08.23.16.02.44;	author ong;	state Exp;
branches;
next	1.7;

1.7
date	89.08.04.14.29.03;	author goh;	state Exp;
branches;
next	1.6;

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

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

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

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

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

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


desc
@stuff to compute joins
@


1.20
log
@fixes for arrays, array refs, and nested dots
@
text
@
/*     
 *      FILE
 *     	joinutils
 *     
 *      DESCRIPTION
 *     	Utilities for matching and building join and path keys
 *     
 */

/*  RcsId("$Header: /private/mao/postgres/src/planner/path/RCS/joinutils.c,v 1.19 1991/11/17 21:13:34 mer Exp mao $");   */

/*     
 *      EXPORTS
 *     		match-pathkeys-joinkeys
 *     		match-paths-joinkeys
 *     		extract-path-keys
 *     		new-join-pathkeys
 */

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

#include "planner/internal.h"
#include "planner/joinutils.h"
#include "planner/var.h"
#include "planner/keys.h"
#include "planner/tlist.h"
#include "planner/joininfo.h"


/*     	===============
 *     	KEY COMPARISONS
 *     	===============
 */

/*    
 *    	match-pathkeys-joinkeys
 *    
 *    	Attempts to match the keys of a path against the keys of join clauses.
 *    	This is done by looking for a matching join key in 'joinkeys' for
 *    	every path key in the list 'pathkeys'. If there is a matching join key
 *    	(not necessarily unique) for every path key, then the list of 
 *    	corresponding join keys and join clauses are returned in the order in 
 *    	which the keys matched the path keys.
 *    
 *    	'pathkeys' is a list of path keys:
 *    		( ( (var) (var) ... ) ( (var) ... ) )
 *    	'joinkeys' is a list of join keys:
 *    		( (outer inner) (outer inner) ... )
 *    	'joinclauses' is a list of clauses corresponding to the join keys in
 *    		'joinkeys'
 *    	'which-subkey' is a flag that selects the desired subkey of a join key
 *    		in 'joinkeys'
 *    
 *    	Returns the join keys and corresponding join clauses in a list if all
 *    	of the path keys were matched:
 *    		( 
 *    		 ( (outerkey0 innerkey0) ... (outerkeyN innerkeyN) )
 *    		 ( clause0 ... clauseN ) 
 *    		)
 *    	and nil otherwise.
 *    
 */

/*  .. match-unsorted-inner, match-unsorted-outer    */

LispValue
match_pathkeys_joinkeys(pathkeys,joinkeys,joinclauses,which_subkey)
     LispValue pathkeys,joinkeys,joinclauses;
     int which_subkey ;
{
     LispValue matched_joinkeys = LispNil;
     LispValue matched_joinclauses = LispNil;
     LispValue pathkey = LispNil;
     LispValue t_list = LispNil;
     LispValue i = LispNil;
     int matched_joinkey_index = -1;

     foreach(i, pathkeys) {
	 pathkey = CAR(i);
	 matched_joinkey_index = 
	   match_pathkey_joinkeys(pathkey,joinkeys,which_subkey);
	 
	 if(matched_joinkey_index != -1 ) {
	     LispValue xjoinkey = nth(matched_joinkey_index,joinkeys);
	     LispValue joinclause = nth(matched_joinkey_index,joinclauses);

	     /* XXX was "push" function */
	     
	     matched_joinkeys = nappend1(matched_joinkeys,xjoinkey);
	     matched_joinkeys = nreverse(matched_joinkeys);

	     matched_joinclauses = nappend1(matched_joinclauses,joinclause);
	     matched_joinclauses = nreverse(matched_joinclauses);
	     joinkeys = LispRemove(xjoinkey,joinkeys);
	     
	 } 
	 else {
	     return(LispNil);
	 } 
		
     }
     if(!lispNullp(matched_joinkeys) &&
	length(matched_joinkeys) == length(pathkeys)) {
	 t_list = lispCons(nreverse(matched_joinkeys),
			    lispCons(nreverse(matched_joinclauses),
				     LispNil));
     } 
     return(t_list);

}  /* function end  */

/*    
 *    	match-pathkey-joinkeys
 *    
 *    	Returns the 0-based index into 'joinkeys' of the first joinkey whose
 *    	outer or inner subkey matches any subkey of 'pathkey'.
 *    
 */

/*  .. match-pathkeys-joinkeys	 */

int
match_pathkey_joinkeys(pathkey,joinkeys,which_subkey)
     LispValue pathkey,joinkeys;
     int which_subkey ;
{
    Var path_subkey;
    int pos;
    LispValue i = LispNil;
    LispValue x = LispNil;
    JoinKey jk;

    foreach(i,pathkey) {
	path_subkey = (Var)CAR(i);
	pos = 0;
	foreach(x,joinkeys) {
	    jk = (JoinKey)CAR(x);
	    if(var_equal((LispValue)path_subkey, (LispValue)extract_subkey(jk, which_subkey)))
		return(pos);
	    pos++;
	}
    }
    return(-1);    /* no index found   */

}  /* function end   */

/*    
 *    	match-paths-joinkeys
 *    
 *    	Attempts to find a path in 'paths' whose keys match a set of join
 *    	keys 'joinkeys'.  To match,
 *    	1. the path node ordering must equal 'ordering'.
 *    	2. each subkey of a given path must match(i.e., be(var_equal) to) the
 *    	   appropriate subkey of the corresponding join key in 'joinkeys',
 *    	   i.e., the Nth path key must match its subkeys against the subkey of
 *    	   the Nth join key in 'joinkeys'.
 *    
 *    	'joinkeys' is the list of key pairs to which the path keys must be 
 *    		matched
 *    	'ordering' is the ordering of the(outer) path to which 'joinkeys'
 *    		must correspond
 *    	'paths' is a list of(inner) paths which are to be matched against
 *    		each join key in 'joinkeys'
 *    	'which-subkey' is a flag that selects the desired subkey of a join key
 *    		in 'joinkeys'
 *    
 *    	Returns the matching path node if one exists, nil otherwise.
 *    
 */

/*  function used by match_paths_joinkeys */
bool
every_func(joinkeys, pathkey, which_subkey)
     LispValue joinkeys, pathkey;
     int which_subkey;
{
     JoinKey xjoinkey;
     Var temp;
     LispValue tempkey = LispNil;
     bool found = false;
     LispValue i = LispNil;
     LispValue j = LispNil;

     foreach(i,joinkeys) {
	 xjoinkey = (JoinKey)CAR(i);
	 found = false;
	 foreach(j,pathkey) {
	     temp = (Var)CAR(CAR(j));
	     if(temp == NULL) continue;
	     tempkey = extract_subkey(xjoinkey,which_subkey);
	     if(var_equal((LispValue)tempkey,(LispValue)temp)) {
		 found = true;
		 break;
	     }
	 }
	 if(found == false)
	   return(false);
     }
     return(found);
}

/*  .. match-unsorted-outer	 */

Path
match_paths_joinkeys(joinkeys,ordering,paths,which_subkey)
     LispValue joinkeys,ordering,paths;
     int which_subkey ;
{
    Path path = (Path)NULL ;
    bool key_match = false;
    LispValue i = LispNil;
 
    foreach(i,paths) {
	path = (Path)CAR(i);
	key_match = every_func(joinkeys,
			       get_keys(path),
			       which_subkey);

	if(equal_path_path_ordering(ordering,
				      get_p_ordering(path)) &&
	    length(joinkeys) == length(get_keys(path)) &&
	    key_match) {
	    return(path);
	}
    }
    return((Path) LispNil);
}  /* function end  */



/*    
 *    	extract-path-keys
 *    
 *    	Builds a subkey list for a path by pulling one of the subkeys from
 *    	a list of join keys 'joinkeys' and then finding the var node in the
 *    	target list 'tlist' that corresponds to that subkey.
 *    
 *    	'joinkeys' is a list of join key pairs
 *    	'tlist' is a relation target list
 *    	'which-subkey' is a flag that selects the desired subkey of a join key
 *    		in 'joinkeys'
 *    
 *    	Returns a list of pathkeys: ((tlvar1)(tlvar2)...(tlvarN)).
 *    
 */

/*  .. hash-inner-and-outer, match-unsorted-inner, match-unsorted-outer
 *  .. sort-inner-and-outer
 */
LispValue
extract_path_keys(joinkeys,tlist,which_subkey)
     LispValue joinkeys,tlist;
     int which_subkey ;
{
    JoinKey xjoinkey = (JoinKey)NULL;
    LispValue t_list = LispNil;
    LispValue temp_node = LispNil;
    LispValue i = LispNil;

    foreach(i,joinkeys) {
	xjoinkey = (JoinKey)CAR(i);
	temp_node =
	  lispCons((LispValue)matching_tlvar((Var)extract_subkey(xjoinkey,
						    which_subkey),tlist),
		    LispNil);
	t_list = nappend1(t_list,temp_node);
    }
    return(t_list);
} /* function end  */

/*     	=====================
 *     	NEW PATHKEY FORMATION
 *     	=====================
 */

/*    
 *    	new-join-pathkeys
 *    
 *    	Find the path keys for a join relation by finding all vars in the list
 *    	of join clauses 'joinclauses' such that:
 *    		(1) the var corresponding to the outer join relation is a
 *    		    key on the outer path
 *    		(2) the var appears in the target list of the join relation
 *    	In other words, add to each outer path key the inner path keys that
 *    	are required for qualification.
 *    
 *    	'outer-pathkeys' is the list of the outer path's path keys
 *    	'join-rel-tlist' is the target list of the join relation
 *    	'joinclauses' is the list of restricting join clauses
 *    
 *    	Returns the list of new path keys. 
 *    
 */

/*  .. hash-inner-and-outer, match-unsorted-inner, match-unsorted-outer
 *  .. sort-inner-and-outer
 */
LispValue
new_join_pathkeys(outer_pathkeys,join_rel_tlist,joinclauses)
     LispValue outer_pathkeys,join_rel_tlist,joinclauses ;
{
    LispValue outer_pathkey = LispNil;
    LispValue t_list = LispNil;
    LispValue x;
    LispValue temp_node = LispNil;
    LispValue i = LispNil;

    foreach(i,outer_pathkeys) {
	outer_pathkey = CAR(i);
	x = new_join_pathkey(outer_pathkey, LispNil, 
			      join_rel_tlist,joinclauses);
	if(!lispNullp(x)) {
	    temp_node = lispCons(x, LispNil);
	    t_list = nconc(t_list,temp_node);
	  }
      }
    return(t_list);
}

/*    
 *    	new-join-pathkey
 *    
 *    	Finds new vars that become subkeys due to qualification clauses that
 *    	contain any previously considered subkeys.  These new subkeys plus the
 *    	subkeys from 'subkeys' form a new pathkey for the join relation.
 *    
 *    	Note that each returned subkey is the var node found in
 *    	'join-rel-tlist' rather than the joinclause var node.
 *    
 *    	'subkeys' is a list of subkeys for which matching subkeys are to be
 *    		found
 *    	'considered-subkeys' is the current list of all subkeys corresponding
 *    		to a given pathkey
 *    
 *    	Returns a new pathkey(list of subkeys).
 *    
 */

/*  .. new-join-pathkeys  	 */

LispValue
new_join_pathkey(subkeys,considered_subkeys,join_rel_tlist,joinclauses)
     LispValue subkeys,considered_subkeys,join_rel_tlist,joinclauses ;
{
    LispValue t_list = LispNil;
    Var subkey;
    LispValue i = LispNil;
    LispValue matched_subkeys = LispNil;
    Expr tlist_key = (Expr)NULL;
    LispValue newly_considered_subkeys = LispNil;

    foreach(i,subkeys) {
	subkey = (Var)CAR(i);
	if(subkey == NULL)
	  break;    /* XXX something is wrong */
	matched_subkeys = 
	  new_matching_subkeys(subkey,considered_subkeys,
				join_rel_tlist,joinclauses);
	tlist_key = matching_tlvar(subkey,join_rel_tlist);
	newly_considered_subkeys = LispNil;

	if( tlist_key ) {
	    if(!member((LispValue)tlist_key,matched_subkeys))
	      newly_considered_subkeys = lispCons((LispValue)tlist_key,
						  matched_subkeys);
	} 
	else {
	    newly_considered_subkeys = matched_subkeys;
	} 
	
	considered_subkeys = 
	  append(considered_subkeys,newly_considered_subkeys);
	t_list = nconc(t_list,newly_considered_subkeys);
    }
    return(t_list);
    
}  /* function end  */

/*    
 *    	new-matching-subkeys
 *    
 *    	Returns a list of new subkeys:
 *    	(1) which are not listed in 'considered-subkeys'
 *    	(2) for which the "other" variable in some clause in 'joinclauses' is
 *    	    'subkey'
 *    	(3) which are mentioned in 'join-rel-tlist'
 *    
 *    	Note that each returned subkey is the var node found in
 *    	'join-rel-tlist' rather than the joinclause var node.
 *    
 *    	'subkey' is the var node for which we are trying to find matching
 *    		clauses
 *    
 *    	Returns a list of new subkeys.
 *    
 */

/*  .. new-join-pathkey */

LispValue
new_matching_subkeys(subkey,considered_subkeys,join_rel_tlist,joinclauses)
     LispValue considered_subkeys,join_rel_tlist,joinclauses ;
     Var subkey;
{
     LispValue joinclause = LispNil;
     LispValue t_list = LispNil;
     LispValue temp = LispNil;
     LispValue i = LispNil;
     Expr tlist_other_var = (Expr)NULL;

     foreach(i,joinclauses) {
	 joinclause = CAR(i);
	 tlist_other_var = 
	   matching_tlvar(other_join_clause_var(subkey,joinclause),
			   join_rel_tlist);

	 if(tlist_other_var && 
	    !(member((LispValue)tlist_other_var,considered_subkeys))) {
	     /* XXX was "push" function  */
	     considered_subkeys = nappend1(considered_subkeys,
					   (LispValue)tlist_other_var);
	     /* considered_subkeys = nreverse(considered_subkeys); 
		XXX -- I am not sure of this. */

	     temp = lispCons((LispValue)tlist_other_var,LispNil);
	     t_list = nconc(t_list,temp);
	 } 
     }
     return(t_list);
 }  /* function end  */
@


1.19
log
@prototyping -- oops var_equal has changed on me
@
text
@d11 1
a11 1
/*  RcsId("$Header: /users/mer/postgres/src/planner/path/RCS/joinutils.c,v 1.18 1991/11/17 20:39:50 mer Exp mer $");   */
d143 1
a143 1
	    if(var_equal((LispValue)path_subkey, (LispValue)extract_subkey(jk, which_subkey), false))
d196 1
a196 1
	     if(var_equal((LispValue)tempkey,(LispValue)temp, false)) {
@


1.18
log
@prototyping
@
text
@d11 1
a11 1
/*  RcsId("$Header: /users/mer/postgres/src/planner/path/RCS/joinutils.c,v 1.17 1991/11/15 16:27:20 hong Exp mer $");   */
d143 1
a143 1
	    if(var_equal(path_subkey, (Var)extract_subkey(jk, which_subkey)))
d196 1
a196 1
	     if(var_equal((Var)tempkey,temp)) {
@


1.17
log
@planner prototyping
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.16 91/11/02 21:42:33 hong Exp $");   */
d268 1
a268 1
	  lispCons(matching_tlvar((Var)extract_subkey(xjoinkey,
d368 3
a370 2
	    if(!member(tlist_key,matched_subkeys))
	      newly_considered_subkeys = lispCons(tlist_key, matched_subkeys);
d423 1
a423 1
	    !(member(tlist_other_var,considered_subkeys))) {
d426 1
a426 1
					   tlist_other_var);
d430 1
a430 1
	     temp = lispCons(tlist_other_var,LispNil);
@


1.16
log
@cleaned up bushy tree plan generation code.
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.15 91/05/08 15:09:41 hong Exp $");   */
d32 1
d132 1
a132 1
    LispValue path_subkey = LispNil;
d139 1
a139 1
	path_subkey = CAR(i);
d143 1
a143 1
	    if(var_equal(path_subkey,extract_subkey(jk, which_subkey)))
d182 2
a183 2
     LispValue xjoinkey = LispNil;
     LispValue temp = LispNil;
d190 1
a190 1
	 xjoinkey = CAR(i);
d193 2
a194 2
	     temp = CAR(CAR(j));
	     if(temp == LispNil) continue;
d196 1
a196 1
	     if(var_equal(tempkey,temp)) {
d268 1
a268 1
	  lispCons(matching_tlvar(extract_subkey(xjoinkey,
d351 1
a351 1
    LispValue subkey = LispNil;
d358 2
a359 2
	subkey = CAR(i);
	if(null(subkey))
@


1.15
log
@fixed a problem in join_pathkey generation
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.14 91/03/06 16:54:24 hong Exp $");   */
d71 3
a73 2
match_pathkeys_joinkeys (pathkeys,joinkeys,joinclauses,which_subkey)
     LispValue pathkeys,joinkeys,joinclauses,which_subkey ;
d82 1
a82 1
     foreach (i, pathkeys) {
d85 1
a85 1
	   match_pathkey_joinkeys (pathkey,joinkeys,which_subkey);
d88 2
a89 2
	     LispValue xjoinkey = nth (matched_joinkey_index,joinkeys);
	     LispValue joinclause = nth (matched_joinkey_index,joinclauses);
d98 1
a98 1
	     joinkeys = LispRemove (xjoinkey,joinkeys);
d102 1
a102 1
	     return (LispNil);
d106 4
a109 3
     if ( length (matched_joinkeys) == length (pathkeys) ) {
	 t_list = lispCons (nreverse (matched_joinkeys),
			    lispCons(nreverse (matched_joinclauses),
d114 1
a114 1
 }  /* function end  */
d127 3
a129 2
match_pathkey_joinkeys (pathkey,joinkeys,which_subkey)
     LispValue pathkey,joinkeys,which_subkey ;
d142 1
a142 1
	    if (var_equal(path_subkey,extract_subkey(jk, which_subkey)))
d147 1
a147 1
    return (-1);    /* no index found   */
d157 1
a157 1
 *    	2. each subkey of a given path must match (i.e., be (var_equal) to) the
d164 1
a164 1
 *    	'ordering' is the ordering of the (outer) path to which 'joinkeys'
d166 1
a166 1
 *    	'paths' is a list of (inner) paths which are to be matched against
d177 3
a179 2
every_func (joinkeys, pathkey, which_subkey)
     LispValue joinkeys, pathkey, which_subkey;
d188 1
a188 1
     foreach (i,joinkeys) {
d193 1
a193 1
	     if (temp == LispNil) continue;
d195 1
a195 1
	     if (var_equal(tempkey,temp)) {
d200 1
a200 1
	 if (found == false)
d209 3
a211 2
match_paths_joinkeys (joinkeys,ordering,paths,which_subkey)
     LispValue joinkeys,ordering,paths,which_subkey ;
d220 1
a220 1
			       get_keys (path),
d223 3
a225 3
	if (equal_path_path_ordering (ordering,
				      get_p_ordering (path)) &&
	    length (joinkeys) == length (get_keys (path)) &&
d255 1
a255 1
extract_path_keys (joinkeys,tlist,which_subkey)
d267 1
a267 1
	  lispCons (matching_tlvar (extract_subkey (xjoinkey,
d303 1
a303 1
new_join_pathkeys (outer_pathkeys,join_rel_tlist,joinclauses)
d308 1
d314 7
a320 7
	temp_node = 
	  lispCons (new_join_pathkey (outer_pathkey,
				      LispNil,
				      join_rel_tlist,joinclauses),
		    LispNil);
	t_list = nconc(t_list,temp_node);
    }
a321 1
     
d339 1
a339 1
 *    	Returns a new pathkey (list of subkeys).
d346 1
a346 1
new_join_pathkey (subkeys,considered_subkeys,join_rel_tlist,joinclauses)
d358 1
a358 1
	if (null(subkey))
d361 1
a361 1
	  new_matching_subkeys (subkey,considered_subkeys,
d363 1
a363 1
	tlist_key = matching_tlvar (subkey,join_rel_tlist);
d366 2
a367 2
	if ( tlist_key ) {
	    if (!member(tlist_key,matched_subkeys))
d375 1
a375 1
	  append (considered_subkeys,newly_considered_subkeys);
d404 1
a404 1
new_matching_subkeys (subkey,considered_subkeys,join_rel_tlist,joinclauses)
d417 1
a417 1
	   matching_tlvar (other_join_clause_var (subkey,joinclause),
d421 1
a421 1
	    !(member (tlist_other_var,considered_subkeys))) {
d428 1
a428 1
	     temp = lispCons (tlist_other_var,LispNil);
@


1.14
log
@now the planner can generate mergejoins with two indexscans
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.13 90/10/15 14:54:09 choi Exp Locker: hong $");   */
d310 1
a310 1
				      outer_pathkey,
d362 2
a363 5
	    /* XXX was "adjoin" function */
	    if (member(tlist_key,matched_subkeys))
	      newly_considered_subkeys = lispCons(lispCons(tlist_key,
							   matched_subkeys),
						  LispNil);
@


1.13
log
@changed remove() to LispRemove(). (posix)
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.12 90/09/25 16:36:02 kemnitz Exp Locker: choi $");   */
d188 1
a188 1
	     temp = CAR(j);
@


1.12
log
@Updating from revision 1.11 to revision 1.12
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.12 90/08/14 11:10:04 cimarron Exp $");   */
d97 1
a97 2

	     joinkeys = remove (xjoinkey,joinkeys);
@


1.11
log
@a fix for three-way mergejoin,
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.10 89/10/13 17:59:33 hong Exp Locker: hong $");   */
d21 6
a26 1
#include "pg_lisp.h"
a27 4
#include "relation.h"
#include "relation.a.h"
#include "plannodes.h"
#include "plannodes.a.h"
@


1.10
log
@some fixes for mergejoins
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.9 89/09/05 17:17:33 mao C_Demo_1 Locker: hong $");   */
d423 2
a424 1
	     considered_subkeys = nreverse(considered_subkeys);
@


1.9
log
@Working version of C-only demo
@
text
@d11 1
a11 1
/*  RcsId("$Header: RCS/joinutils.c,v 1.8 89/08/23 16:02:44 ong Exp Locker: ong $");   */
d129 1
a129 2
    int temp = 0;
    bool flag = false;
d131 2
d136 6
a141 3
	if (temp = position(path_subkey,joinkeys,var_equal,
			    extract_subkey(joinkeys, which_subkey))) {
	    flag = true;
a142 2
	if (flag == true)
	  return(temp);
d189 1
d219 1
a219 1
				      get_ordering (path)) &&
@


1.8
log
@planner supports all but rules and mergesort
@
text
@d11 1
a11 1
/*  RcsId("$Header: /n/postgres/a/postgres/ong/postgres/src/planner/path/RCS/joinutils.c,v 1.7 89/08/04 14:29:03 goh Exp $");   */
@


1.7
log
@reorganised header files
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.6 89/08/04 14:27:24 goh Locked $");   */
d77 2
d80 23
a102 10
     foreach (pathkey, pathkeys) {
	  int matched_joinkey_index = 
	    match_pathkey_joinkeys (pathkey,joinkeys,which_subkey);
	  
	  if(integerp (matched_joinkey_index) ) {
	       LispValue xjoinkey = nth (matched_joinkey_index,joinkeys);
	       LispValue joinclause = nth (matched_joinkey_index,joinclauses);
	       push (xjoinkey,matched_joinkeys);
	       push (joinclause,matched_joinclauses);
	       joinkeys = remove (xjoinkey,joinkeys);
a103 5
	  } 
	  else {
	       return (LispNil);
	  } 
		
d106 3
a108 3
	  t_list = lispCons (nreverse (matched_joinkeys),
			     lispCons(nreverse (matched_joinclauses),
				      LispNil));
d112 1
a112 1
}  /* function end  */
d128 4
a131 12
     LispValue path_subkey = LispNil;
     int temp;
     bool flag = false;
     foreach(path_subkey,pathkey) {
	  if (temp = position(path_subkey,joinkeys,var_equal,
			      extract_subkey(joinkeys, which_subkey))) {
	       flag = true;
	  }
	  if (flag == true)
	    return(temp);
     }
     return (-1);    /* no index found   */
d133 11
d175 1
a175 1
     LispValue xjoinkey;
d179 2
d182 13
a194 11
     foreach (xjoinkey,joinkeys) {
	  found = false;
	  foreach(temp,pathkey) {
	       tempkey = extract_subkey(xjoinkey,which_subkey);
	       if (var_equal(tempkey,temp)) {
		    found = true;
		    break;
	       }
	  }
	  if (found == false)
	    return(false);
d205 9
a213 7
     LispValue path ;
     bool key_match ;
     
     foreach(path,paths) {
	  key_match = every_func(joinkeys,
				 get_keys (path),
				 which_subkey);
d215 8
a222 8
	  if (equal_path_path_ordering (ordering,
					get_ordering (path)) &&
	      length (joinkeys) == length (get_keys (path)) &&
	      key_match) {
	       return((Path)path);
	  }
     }
     return((Path) LispNil);
d248 2
a249 1
     LispValue joinkeys,tlist,which_subkey ;
d251 4
a254 3
     LispValue xjoinkey = LispNil;
     LispValue t_list = LispNil;
     LispValue temp_node = LispNil;
d256 9
a264 8
     foreach(xjoinkey,joinkeys) {
	  temp_node =
	    lispCons (matching_tlvar (extract_subkey (xjoinkey,
						      which_subkey),tlist),
		      LispNil);
	  t_list = nappend1(t_list,temp_node);
     }
     return(t_list);
d298 4
a301 3
     LispValue outer_pathkey = LispNil;
     LispValue t_list = LispNil;
     LispValue temp_node = LispNil;
d303 10
a312 10
     foreach(outer_pathkey,outer_pathkeys) {
	  
	  temp_node = 
	    lispCons (new_join_pathkey (outer_pathkey,
					outer_pathkey,
					join_rel_tlist,joinclauses),
		      LispNil);
	  t_list = nconc(t_list,temp_node);
     }
     return(t_list);
d341 6
a346 2
     LispValue t_list = LispNil;
     LispValue subkey = LispNil;
d348 9
a356 1
     foreach(subkey,subkeys) {
d358 17
a374 22
	  LispValue matched_subkeys = 
	    new_matching_subkeys (subkey,considered_subkeys,
				  join_rel_tlist,joinclauses);
	  Expr tlist_key = matching_tlvar (subkey,join_rel_tlist);
	  LispValue newly_considered_subkeys = LispNil;

	  if ( tlist_key ) {
	       if (member(tlist_key,matched_subkeys))
		 newly_considered_subkeys = lispCons(lispCons(tlist_key,
							      matched_subkeys),
						     LispNil);
	  } 
	  else {
	       newly_considered_subkeys = matched_subkeys;
	  } 
	  
	  considered_subkeys = 
	    append (considered_subkeys,newly_considered_subkeys);
	  t_list = nconc(t_list,newly_considered_subkeys);
     }
     return(t_list);
     
d400 2
a401 1
     LispValue subkey,considered_subkeys,join_rel_tlist,joinclauses ;
d406 2
d409 5
a413 4
     foreach(joinclause,joinclauses) {
	  Expr tlist_other_var = 
	    matching_tlvar (other_join_clause_var (subkey,joinclause),
			    join_rel_tlist);
d415 10
a424 8
	  if(tlist_other_var && 
	     !(member (tlist_other_var,considered_subkeys))) {
	       push (tlist_other_var,considered_subkeys);
	       temp = lispCons (tlist_other_var,LispNil);
	       t_list = nconc(t_list,temp);
	  } 
	  else
	    t_list = nconc(t_list,LispNil);
d427 1
a427 1
}  /* function end  */
@


1.6
log
@reorganised header files
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.5 89/08/04 13:23:25 goh Locked $");   */
d22 1
a22 1
#include "internal.h"
d27 4
a30 4
#include "joinutils.h"
#include "var.h"
#include "keys.h"
#include "tlist.h"
@


1.5
log
@checkin for retrieve (x.all)
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.4 89/08/01 14:40:07 goh Locked $");   */
@


1.4
log
@retrieve (x=1) checkin
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.3 89/07/25 17:35:34 ong Exp $");   */
@


1.3
log
@Phase III
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.2 89/07/21 12:43:22 ong Locked $");   */
d96 3
a98 2
	  t_list = list (nreverse (matched_joinkeys),
			 nreverse (matched_joinclauses));
d122 1
a122 1
	  if (temp = position(path_subkey,joinkeys,test(var_equal),
d237 3
a239 2
	    list (matching_tlvar (extract_subkey (xjoinkey,
						  which_subkey),tlist));
d283 4
a286 2
	    list (new_join_pathkey (outer_pathkey,
				    outer_pathkey,join_rel_tlist,joinclauses));
d331 3
a333 2
		 newly_considered_subkeys = list(lispCons(tlist_key,
							  matched_subkeys));
d384 1
a384 1
	       temp = list (tlist_other_var);
@


1.2
log
@Pahse II checkin.
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.1 89/07/10 15:17:01 ong Locked $");   */
d128 1
d285 1
d369 1
a369 1
     LispValue temp_node = LispNil;
a371 1
	  /* XXX - let form, maybe incorrect */
d379 2
a380 2
	       list (tlist_other_var);

d382 2
d385 1
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
/*  RcsId("$Header: joinutils.c,v 1.1 89/04/27 21:04:25 ong Locked $");   */
d21 1
d23 8
a30 1
#include "pg_lisp.h"
a31 3
extern LispValue new_join_pathkey();
extern LispValue new_matching_subkeys();
extern LispValue match_pathkey_joinkeys();
a32 2
extern Boolean var_equal();

a72 1
	/* XXX - let form, maybe incorrect */
d79 1
a79 2
	  /* XXX - let form, maybe incorrect */
	  LispValue matched_joinkey_index = 
a82 1
	       /* XXX - let form, maybe incorrect */
d113 1
a113 1
LispValue
d118 2
a119 2
     LispValue temp = LispNil;

d123 1
a123 2
	       /*  XXX fix me !  */
	       return(temp);
d125 2
d128 1
d155 25
d182 1
a182 1
LispValue
d186 7
a192 2
#ifdef 
		opus43;
d194 9
a202 4
#endif
		;
		declare (special (joinkeys,ordering,which_subkey));
		find_if (/* XXX - hash-quote */ LispValue
a203 6
		/* XXX - Move me */ 
		LAMBDA_UNKNOWN_FUNCTION (path)
		    LispValue path ;
		{
#ifdef 
			opus43;
a204 4
#endif
			;
			declare (special (joinkeys,ordering,which_subkey));
			and (equal_path_path_ordering (ordering,get_ordering (path)),length (joinkeys) == length (get_keys (path)),every (/* XXX - hash-quote */ LispValue
a205 17
			/* XXX - Move me */ 
			LAMBDA_UNKNOWN_FUNCTION (joinkey,pathkey)
			    LispValue joinkey,pathkey ;
			{
#ifdef 
				opus43;

#endif
				;
				declare (special (which_subkey));
				find (extract_subkey (joinkey,which_subkey),pathkey,test/* XXX - hash-quote */ ,var_equal);
			}
			,joinkeys,get_keys (path)));
		}
		,paths);
	}

d229 1
a229 1
     LispValue joinkey = LispNil;
d233 1
a233 1
     foreach(joinkey,joinkeys) {
d235 1
a235 1
	    list (matching_tlvar (extract_subkey (joinkey,
a312 1
     LispValue temp_node = LispNil;
d320 1
a320 1
	  LispValue tlist_key = matching_tlvar (subkey,join_rel_tlist);
d324 3
a326 1
	       newly_considered_subkeys = adjoin (tlist_key,matched_subkeys);
d334 1
a334 1
	  return(newly_considered_subkeys);
d336 2
a337 1

d371 1
a371 1
	  LispValue tlist_other_var = 
@
