head	1.24;
access;
symbols
	release_4_2:1.24
	aix_ok:1.24
	Version_2_1:1.13
	C_Demo_1:1.8
	Retrieve_x_qual:1.5
	Retrieve_x_all:1.4
	Retrieve_x_1:1.3;
locks; strict;
comment	@ * @;


1.24
date	93.06.24.03.54.50;	author aoki;	state Exp;
branches;
next	1.23;

1.23
date	92.07.15.04.33.11;	author mer;	state Exp;
branches;
next	1.22;

1.22
date	92.07.12.10.59.19;	author joey;	state Exp;
branches;
next	1.21;

1.21
date	92.07.04.04.03.43;	author mao;	state Exp;
branches;
next	1.20;

1.20
date	92.06.18.17.52.43;	author hong;	state Exp;
branches;
next	1.19;

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

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

1.17
date	92.03.31.23.13.39;	author mer;	state Exp;
branches;
next	1.16;

1.16
date	91.11.17.20.46.19;	author mer;	state Exp;
branches;
next	1.15;

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

1.14
date	91.03.26.17.09.47;	author sp;	state Exp;
branches;
next	1.13;

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

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

1.11
date	90.05.30.18.56.53;	author cimarron;	state Exp;
branches;
next	1.10;

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

1.9
date	89.10.01.16.54.39;	author hirohama;	state Exp;
branches;
next	1.8;

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

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

1.6
date	89.08.23.16.04.11;	author ong;	state Exp;
branches;
next	1.5;

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

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

1.3
date	89.08.01.14.36.11;	author goh;	state Exp;
branches;
next	1.2;

1.2
date	89.07.21.13.35.42;	author goh;	state Exp;
branches;
next	1.1;

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


desc
@routines to handle target list, quals, 
and joininfo initialization.
@


1.24
log
@bogus cast of expression lval makes hpux cc complain.
remapped into cast of rval.
@
text
@/*     
 *      FILE
 *     	initsplan
 *     
 *      DESCRIPTION
 *     	Target list, qualification, joininfo initialization routines
 *     
 */

/* RcsId("$Header: /usr/local/devel/postgres/src/backend/planner/plan/RCS/initsplan.c,v 1.23 1992/07/15 04:33:11 mer Exp $");  */

/*     
 *      EXPORTS
 *     		initialize-targetlist
 *     		initialize-qualification
 *     		initialize-join-clause-info
 *     
 *      NOTES
 *     	These routines are called by(subplanner) and modify global state of
 *     	the planner(adding entries to *query-relation-list* or modifying an
 *     	existing entry).
 */

#include "tmp/c.h"

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

#include "utils/lsyscache.h"

#include "planner/internal.h"
#include "planner/clause.h"
#include "planner/clauses.h"
#include "planner/clausesel.h"
#include "planner/initsplan.h"
#include "planner/joininfo.h"
#include "planner/relnode.h"
#include "planner/tlist.h"
#include "planner/var.h"

extern bool _enable_mergesort_;
extern bool _enable_hashjoin_;
extern int Quiet;

/*     	============
 *     	TARGET LISTS
 *     	============
 */

/*    
 *    	initialize-targetlist
 *    
 *    	Creates rel nodes for every relation mentioned in the target list
 *    	'tlist' (if a node hasn't already been created) and adds them to
 *    	*query-relation-list*.  Creates targetlist entries for each member of
 *    	'tlist' and adds them to the tlist field of the appropriate rel node.
 *    
 *    	Returns nothing.
 *    
 */

/*  .. subplanner      */

void 
initialize_targetlist(tlist)
     List tlist ;
{
    List tlist_vars = LispNil;
    List xtl = LispNil;
    List tvar = LispNil;
    
#ifdef NO_PLEASE
    if(!Quiet) {
    lispDisplay(tlist,0);
    printf("\n");
    fflush(stdout);
    }
#endif NO_PLEASE

    foreach (xtl,tlist) {
	TLE entry = (TLE) CAR(xtl);

#ifdef NO_PLEASE
        if(!Quiet) {
	lispDisplay((LispValue) entry,0);
	fflush(stdout);
	}
#endif NO_PLEASE
	tlist_vars = nconc(tlist_vars,pull_var_clause( (LispValue)
						get_expr(entry) ));
    }

    foreach (tvar, tlist_vars) {
	Var 	var;
	Index   varno;
	Rel	result;
	
	var = (Var)CAR(tvar);
	varno = get_varno(var);
	result = get_rel(lispInteger(varno));

	add_tl_element(result,var,LispNil);
    }
    
}  /* function end   */

/*     	==============
 *     	QUALIFICATIONS
 *     	==============
 */

/*    
 *    	initialize-qualification
 *    
 *    	Initializes ClauseInfo and JoinInfo fields of relation entries for all
 *    	relations appearing within clauses.  Creates new relation entries if
 *    	necessary, adding them to *query-relation-list*.
 *    
 *    	Returns nothing of interest.
 *    
 */

/*  .. initialize-qualification, subplanner      */

void
initialize_qualification(clauses)
     LispValue clauses ;
{
     LispValue clause = LispNil;

     foreach (clause, clauses) {
	 if(consp(CAR(clause)) && IsA(CAR(clause),Func))
	    initialize_qualification(get_funcargs(CAR(clause)));
	  else 
	    if(consp(CAR(clause)) && IsA(CAR(clause),Oper))
	      initialize_qualification(get_opargs(CAR(clause)));
	  add_clause_to_rels(CAR(clause));
     }
}  /* function end   */

/*    
 *    	add-clause-to-rels
 *    
 *    	Add clause information to either the 'ClauseInfo' or 'JoinInfo' field
 *    	of a relation entry(depending on whether or not the clause is a join)
 *    	by creating a new ClauseInfo node and setting appropriate fields
 *    	within the nodes.
 *    
 *    	Returns nothing of interest.
 *    
 */

/*  .. initialize-qualification		 */

void
add_clause_to_rels(clause)
     LispValue clause ;
{
     
    /* Retrieve all relids and vars contained within the clause in the form */
    /* ((relid relid ...) (var var ...)) */
    
    LispValue relids_vars = clause_relids_vars(clause);
    LispValue relids = nth(0,relids_vars);
    LispValue vars = nth(1,relids_vars);
    
    if(relation_level_clause_p(clause)) 
      /*
       * Ignore quals containing relation level clauses, but place the vars
       * in the target list so their values can be referenced later.
       */
      add_vars_to_rels(vars,LispNil);
    else {
	CInfo clauseinfo = RMakeCInfo();
	set_clause(clauseinfo,clause);
	set_notclause(clauseinfo,contains_not(clause));
	set_selectivity(clauseinfo,0);
	set_indexids(clauseinfo,LispNil);
	set_mergesortorder(clauseinfo,(MergeOrder)NULL);
	set_hashjoinoperator(clauseinfo,(ObjectId)0);
	
	if(1 == length(relids)) {
	    
	    /* There is only one relation participating in 'clause', */
	    /* so 'clause' must be a restriction clause. */
	    /* XXX - let form, maybe incorrect */
	    Rel rel = get_rel(CAR(relids));
	    set_clauseinfo(rel,cons((LispValue)clauseinfo,
				    (LispValue)get_clauseinfo(rel)));
	} 
	else {
	    /* 'clause' is a join clause, since there is more than one */
	    /*  atom in the relid list. */
	    
	    /*
	     * XXX If we have a func clause set selectivity to 1/3, really
	     *     need a true selectivity function.
	     */
	    if (is_funcclause(clause))
	    {
		set_selectivity(clauseinfo,(Cost)0.3333333);
	    }
	    else
	    {
		set_selectivity(clauseinfo,compute_clause_selec(clause,
								LispNil));
	    }
	    add_join_clause_info_to_rels(clauseinfo,relids);
	    add_vars_to_rels(vars,relids);
	}
    }
}  /* function end   */

/*    
 *    	add-join-clause-info-to-rels
 *    
 *    	For every relation participating in a join clause, add 'clauseinfo' to
 *    	the appropriate joininfo node(creating a new one and adding it to the
 *    	appropriate rel node if necessary).
 *    
 *    	'clauseinfo' describes the join clause
 *    	'join-relids' is the list of relations participating in the join clause
 *    
 *    	Returns nothing.
 *    
 */

/*  .. add-clause-to-rels		 */

void
add_join_clause_info_to_rels(clauseinfo,join_relids)
     CInfo clauseinfo;
     List join_relids ;
{
    LispValue join_relid = LispNil;
    foreach (join_relid, join_relids) {
	JInfo joininfo = 
	  find_joininfo_node(get_rel(CAR(join_relid)),
			      LispRemove(CAR(join_relid),join_relids));
	set_jinfoclauseinfo(joininfo,
			     lispCons((LispValue)clauseinfo,
				   get_jinfoclauseinfo(joininfo)));

     }
} /* function end  */

/*    
 *    	add-vars-to-rels
 *    
 *    	For each variable appearing in a clause,
 *    	(1) If a targetlist entry for the variable is not already present in
 *    	    the appropriate relation's target list, add one.
 *    	(2) If a targetlist entry is already present, but the var is part of a
 *    	    join clause, add the relids of the join relations to the JoinList
 *    	    entry of the targetlist entry.
 *    
 *    	'vars' is the list of var nodes
 *    	'join-relids' is the list of relids appearing in the join clause
 *    		(if this is a join clause)
 *    
 *    	Returns nothing.
 *    
 */

/*  .. add-clause-to-rels     */
 
void
add_vars_to_rels(vars,join_relids)
     List vars,join_relids ;
{
    Var var;
    LispValue temp = LispNil;
    Rel rel = (Rel)NULL;
    LispValue tlistentry = LispNil;
    LispValue other_join_relids = LispNil;
    
    foreach (temp, vars) {
	var = (Var)CAR(temp);
	rel = get_rel(lispInteger(get_varno(var)));
	tlistentry = tlistentry_member(var,get_targetlist(rel));
	other_join_relids = LispRemove(lispInteger(get_varno(var)),
				    join_relids);
	if(null(tlistentry))
	  /*   add a new entry */
	  add_tl_element(rel,var,other_join_relids);
	else 
	  if(get_joinlist(tlistentry)) {
	      set_joinlist(tlistentry,
			    /*   modify an existing entry */
			    LispUnion(get_joinlist(tlistentry),
				       other_join_relids));
	  } 
    }
} /* function end   */

/*     	========
 *     	JOININFO
 *     	========
 */

/*    
 *    	initialize-join-clause-info
 *    
 *    	Set the MergeSortable or HashJoinable field for every joininfo node
 *    	(within a rel node) and the MergeSortOrder or HashJoinOp field for
 *    	each clauseinfo node(within a joininfo node) for all relations in a
 *    	query.
 *    
 *    	Returns nothing.
 *    
 */

/*  .. subplanner    */
 
void
initialize_join_clause_info(rel_list)
     LispValue rel_list ;
{
    LispValue x;
    Rel rel;
    LispValue y;
    JInfo joininfo;
    LispValue z;
    CInfo clauseinfo;
    LispValue clause;
    foreach (x, rel_list) {
	rel = (Rel)CAR(x);
	foreach (y, get_joininfo(rel)) {
	    joininfo = (JInfo)CAR(y);
	    foreach (z, get_jinfoclauseinfo(joininfo)) {
		clauseinfo = (CInfo)CAR(z);
		clause = (LispValue)get_clause(clauseinfo);
		if( join_clause_p(clause) ) {
		    MergeOrder sortop = (MergeOrder)NULL;
		    ObjectId hashop = (ObjectId)NULL;

		    if( _enable_mergesort_ ) 
		      sortop = mergesortop(clause);
		    if( _enable_hashjoin_ ) 
		      hashop = hashjoinop(clause);

		    if( sortop) {
			set_mergesortorder(clauseinfo, sortop);
			set_mergesortable(joininfo,true);
		    }
		    if( hashop) {
			set_hashjoinoperator(clauseinfo,hashop);
			set_hashjoinable(joininfo,true);
		    }
		}
	    }
	}
    }
}  /* function end   */

/*    
 *    	mergesortop			=== MERGE
 *    
 *    	Returns the mergesort operator of an operator iff 'clause' is
 *    	mergesortable, i.e., both operands are single vars and the operator is
 *    	a mergesortable operator.
 *    
 */
MergeOrder
mergesortop(clause)
     LispValue clause;
{
     LispValue sortops = op_mergesortable(get_opno((Oper)get_op(clause)),
					   get_vartype(get_leftop(clause)),
					   get_vartype(get_rightop(clause)));
     if( consp(sortops) ) {
	  return(MakeMergeOrder(get_opno((Oper)get_op(clause)),
				(ObjectId)nth(0,sortops),
				(ObjectId)nth(1,sortops),
				get_vartype(get_leftop(clause)),
				get_vartype(get_rightop(clause))));
     }
     else 
       return(NULL);
}  /* function end  */

/*    
 *    	hashjoinop			===  HASH
 *    
 *    	Returns the hashjoin operator of an operator iff 'clause' is
 *    	hashjoinable, i.e., both operands are single vars and the operator is
 *    	a hashjoinable operator.
 *    
 */

/*  .. initialize-join-clause-info   */
 
ObjectId
hashjoinop(clause)
     LispValue clause ;
{
     return(op_hashjoinable(get_opno((Oper)get_op(clause)),
			      get_vartype(get_leftop(clause)),
			      get_vartype(get_rightop(clause))));
}
@


1.23
log
@ changed Cost from double to float
@
text
@d10 1
a10 1
/* RcsId("$Header: /users/mer/pg/src/planner/plan/RCS/initsplan.c,v 1.22 1992/07/12 10:59:19 joey Exp mer $");  */
d84 1
a84 2
	TLE entry;
	(LispValue)entry = CAR(xtl);
d88 1
a88 1
	lispDisplay(entry,0);
@


1.22
log
@CInfo->clause is now a LispValue, not an Expr
@
text
@d10 1
a10 1
/* RcsId("$Header: /private/joey/pg/src/planner/plan/RCS/initsplan.c,v 1.21 1992/07/04 04:03:43 mao Exp $");  */
d205 1
a205 1
		set_selectivity(clauseinfo,(double)0.3333333);
@


1.21
log
@fixes for arrays, array refs, and nested dots
@
text
@d10 1
a10 1
/* RcsId("$Header: /private/mao/postgres/src/planner/plan/RCS/initsplan.c,v 1.20 1992/06/18 17:52:43 hong Exp mao $");  */
d179 1
a179 1
	set_clause(clauseinfo,(Expr)clause);
@


1.20
log
@fixed an uninitialized variable problem
@
text
@d10 1
a10 1
/* RcsId("$Header: RCS/initsplan.c,v 1.19 92/05/11 06:54:04 mer Exp $");  */
d171 5
a175 6
    if(nested_clause_p(clause) || 
       relation_level_clause_p(clause)) 
      /* Ignore quals containing dot fields or relation level clauses, */
      /* but place the vars in the target list so their values can be  */
      /* referenced later. */
      
@


1.19
log
@previous "fix" botched joins with functions in them
@
text
@d10 1
a10 1
/* RcsId("$Header: /users/mer/pg/src/planner/plan/RCS/initsplan.c,v 1.18 1992/05/08 08:55:30 mer Exp mer $");  */
d339 2
a340 2
		    MergeOrder sortop;
		    ObjectId hashop;
@


1.18
log
@hack to avoid doing join selectivity for function clauses.
@
text
@d10 1
a10 1
/* RcsId("$Header: /u/mer/pg/src/planner/plan/RCS/initsplan.c,v 1.17 1992/03/31 23:13:39 mer Exp mer $");  */
d187 1
a187 5
	/*
	 * XXX If we have a funtion treat it as a restriction, really
	 *     need a true selectivity function.
	 */
	if((1 == length(relids)) || IsA(CAR(clause),Func)) {
d200 13
a212 2
	    set_selectivity(clauseinfo,compute_clause_selec(clause,
							      LispNil));
d215 1
a215 1
	} 
@


1.17
log
@change accessor functions into macros
@
text
@d10 1
a10 1
/* RcsId("$Header: /users/mer/pg/src/planner/plan/RCS/initsplan.c,v 1.16 1991/11/17 20:46:19 mer Exp mer $");  */
d187 5
a191 1
	if(1 == length(relids)) {
@


1.16
log
@prototyping
@
text
@d10 1
a10 1
/* RcsId("$Header: /users/mer/postgres/src/planner/plan/RCS/initsplan.c,v 1.15 1991/11/15 16:26:12 hong Exp mer $");  */
d362 1
a362 1
     LispValue sortops = op_mergesortable(get_opno(get_op(clause)),
d366 1
a366 1
	  return(MakeMergeOrder(get_opno(get_op(clause)),
d391 1
a391 1
     return(op_hashjoinable(get_opno(get_op(clause)),
@


1.15
log
@planner prototyping
@
text
@d10 1
a10 1
/* RcsId("$Header: RCS/initsplan.c,v 1.14 91/03/26 17:09:47 sp Exp $");  */
d42 1
d93 2
a94 1
	tlist_vars = nconc(tlist_vars,pull_var_clause(get_expr(entry)));
d193 2
a194 1
	    set_clauseinfo(rel,cons(clauseinfo,get_clauseinfo(rel)));
@


1.14
log
@Do not print all these target lists etc...
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.13 90/10/15 14:57:30 choi Exp Locker: sp $");  */
d19 2
a20 2
 *     	These routines are called by (subplanner) and modify global state of
 *     	the planner (adding entries to *query-relation-list* or modifying an
d36 1
a46 6
/* ----------------
 *	CInfo creator declaration
 * ----------------
 */
extern CInfo RMakeCInfo();

d67 1
a67 1
initialize_targetlist (tlist)
d75 1
a75 1
    if (!Quiet) {
d87 1
a87 1
        if (!Quiet) {
d104 1
a104 1
	add_tl_element (result,var,LispNil);
d128 1
a128 1
initialize_qualification (clauses)
d135 1
a135 1
	    initialize_qualification (get_funcargs (CAR(clause)));
d137 3
a139 3
	    if (consp(CAR(clause)) && IsA(CAR(clause),Oper))
	      initialize_qualification (get_opargs (CAR(clause)));
	  add_clause_to_rels (CAR(clause));
d147 1
a147 1
 *    	of a relation entry (depending on whether or not the clause is a join)
d158 1
a158 1
add_clause_to_rels (clause)
d165 3
a167 3
    LispValue relids_vars = clause_relids_vars (clause);
    LispValue relids = nth (0,relids_vars);
    LispValue vars = nth (1,relids_vars);
d169 2
a170 2
    if(nested_clause_p (clause) || 
       relation_level_clause_p (clause)) 
d175 1
a175 1
      add_vars_to_rels (vars,LispNil);
d178 6
a183 6
	set_clause (clauseinfo,clause);
	set_notclause (clauseinfo,contains_not (clause));
	set_selectivity (clauseinfo,0);
	set_indexids (clauseinfo,LispNil);
	set_mergesortorder (clauseinfo,(MergeOrder)NULL);
	set_hashjoinoperator (clauseinfo,LispNil);
d185 1
a185 1
	if(1 == length (relids)) {
d190 2
a191 2
	    Rel rel = get_rel (CAR (relids));
	    set_clauseinfo (rel,cons (clauseinfo,get_clauseinfo (rel)));
d197 1
a197 1
	    set_selectivity (clauseinfo,compute_clause_selec (clause,
d199 2
a200 2
	    add_join_clause_info_to_rels (clauseinfo,relids);
	    add_vars_to_rels (vars,relids);
d209 1
a209 1
 *    	the appropriate joininfo node (creating a new one and adding it to the
d222 3
a224 2
add_join_clause_info_to_rels (clauseinfo,join_relids)
     LispValue clauseinfo,join_relids ;
d229 5
a233 5
	  find_joininfo_node (get_rel (CAR(join_relid)),
			      LispRemove (CAR(join_relid),join_relids));
	set_jinfoclauseinfo (joininfo,
			     lispCons (clauseinfo,
				   get_jinfoclauseinfo (joininfo)));
d259 1
a259 1
add_vars_to_rels (vars,join_relids)
d262 1
a262 1
    LispValue var = LispNil;
d269 4
a272 4
	var = CAR(temp);
	rel = get_rel (lispInteger(get_varno (var)));
	tlistentry = tlistentry_member (var,get_targetlist (rel));
	other_join_relids = LispRemove (lispInteger(get_varno (var)),
d274 1
a274 1
	if(null (tlistentry))
d276 1
a276 1
	  add_tl_element (rel,var,other_join_relids);
d278 2
a279 2
	  if (get_joinlist (tlistentry)) {
	      set_joinlist (tlistentry,
d281 1
a281 1
			    LispUnion (get_joinlist(tlistentry),
d297 1
a297 1
 *    	each clauseinfo node (within a joininfo node) for all relations in a
d307 1
a307 1
initialize_join_clause_info (rel_list)
d310 16
a325 9
    LispValue rel = LispNil;
    LispValue joininfo = LispNil;
    LispValue clauseinfo = LispNil;
    foreach (rel, rel_list) {
	foreach (joininfo, get_joininfo (CAR(rel))) {
	    foreach (clauseinfo, get_jinfoclauseinfo (CAR(joininfo))) {
		Expr clause = get_clause (CAR(clauseinfo));
		if ( join_clause_p (clause) ) {
		    LispValue sortop = LispNil;
d328 4
a331 4
		    if ( _enable_mergesort_ ) 
		      sortop = mergesortop (clause);
		    if ( _enable_hashjoin_ ) 
		      hashop = hashjoinop (clause);
d333 3
a335 3
		    if ( sortop) {
			set_mergesortorder (CAR(clauseinfo),sortop);
			set_mergesortable (CAR(joininfo),true);
d337 3
a339 3
		    if ( hashop) {
			set_hashjoinoperator (CAR(clauseinfo),hashop);
			set_hashjoinable (CAR(joininfo),true);
d355 3
a357 3
LispValue
mergesortop (clause)
     LispValue clause ;
d359 1
a359 1
     LispValue sortops = op_mergesortable (get_opno (get_op (clause)),
d361 7
a367 7
					   get_vartype (get_rightop (clause)));
     if ( consp (sortops) ) {
	  return ((LispValue)MakeMergeOrder (get_opno (get_op (clause)),
					     nth (0,sortops),
					     nth (1,sortops),
					     get_vartype (get_leftop (clause)),
					     get_vartype (get_rightop (clause))));
d370 1
a370 1
       return(LispNil);
d385 1
a385 1
hashjoinop (clause)
d388 3
a390 3
     return (op_hashjoinable (get_opno (get_op (clause)),
			      get_vartype (get_leftop (clause)),
			      get_vartype (get_rightop (clause))));
@


1.13
log
@changed remove() to LispRemove(). (posix)
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.12 90/09/25 16:36:35 kemnitz Exp Locker: choi $");  */
d79 1
d85 1
d91 1
d96 1
@


1.12
log
@Updating from revision 1.11 to revision 1.12
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.12 90/08/14 11:40:09 cimarron Exp $");  */
d230 1
a230 1
			      remove (CAR(join_relid),join_relids));
d272 1
a272 1
	other_join_relids = remove (lispInteger(get_varno (var)),
@


1.11
log
@CreateNode(Foo) --> RMakeFoo() change
@
text
@d10 1
a10 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.10 89/11/27 20:52:09 hong Exp $");  */
d24 10
a34 1
#include "c.h"
d36 3
a38 4
#include "relation.h"
#include "relation.a.h"
#include "plannodes.h"
#include "plannodes.a.h"
a39 4
#include "planner/joininfo.h"
#include "planner/initsplan.h"
#include "pg_lisp.h"
#include "lsyscache.h"
a40 1
#include "planner/clausesel.h"
@


1.10
log
@turn off junk message output when Quiet option is given
@
text
@a0 1

d10 1
a10 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.9 89/10/01 16:54:39 hirohama Exp $");  */
d43 6
d175 1
a175 1
	CInfo clauseinfo = CreateNode(CInfo);
a181 2
	clauseinfo->printFunc = PrintCInfo;
	clauseinfo->equalFunc = EqualCInfo;
@


1.9
log
@now compiles
@
text
@d11 1
a11 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.8 89/09/05 17:17:52 mao C_Demo_1 Locker: hirohama $");  */
d42 1
d71 1
d75 1
d81 1
d84 1
@


1.8
log
@Working version of C-only demo
@
text
@d11 1
a11 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.7 89/09/02 13:42:21 ong Exp $");  */
d33 1
a33 1
#include "planner/joininfo.h
@


1.7
log
@#included costsize.h
@
text
@d11 1
a11 1
/* RcsId ("$Header: RCS/initsplan.c,v 1.6 89/08/23 16:04:11 ong Exp Locker: ong $");  */
@


1.6
log
@planner supports all but rules and mergesort
@
text
@d11 1
a11 1
/* RcsId ("$Header: /n/postgres/a/postgres/ong/postgres/src/planner/plan/RCS/initsplan.c,v 1.5 89/08/04 14:30:01 goh Exp $");  */
d38 1
@


1.5
log
@reorganised header files
@
text
@d11 1
a11 1
/* RcsId ("$Header: initsplan.c,v 1.4 89/08/04 13:28:45 goh Locked $");  */
d121 1
a121 1
	 if(consp(clause) && IsA(CAR(clause),Func))
d124 1
a124 1
	    if (consp(clause) && IsA(CAR(clause),Oper))
d149 43
a191 36
     /* Retrieve all relids and vars contained within the clause in the form */
     /* ((relid relid ...) (var var ...)) */

     LispValue relids_vars = clause_relids_vars (clause);
     LispValue relids = nth (0,relids_vars);
     LispValue vars = nth (1,relids_vars);

     if(nested_clause_p (clause) || 
	relation_level_clause_p (clause)) 
	  /* Ignore quals containing dot fields or relation level clauses, */
	  /* but place the vars in the target list so their values can be  */
	  /* referenced later. */

	  add_vars_to_rels (vars,LispNil);
     else {
	  CInfo clauseinfo = CreateNode(CInfo);
	  set_clause (clauseinfo,clause);
	  set_notclause (clauseinfo,contains_not (clause));
	  if(1 == length (relids)) {

	       /* There is only one relation participating in 'clause', */
	       /* so 'clause' must be a restriction clause. */
	       /* XXX - let form, maybe incorrect */
	       Rel rel = get_rel (CAR (relids));
	       set_clauseinfo (rel,cons (clauseinfo,get_clauseinfo (rel)));
	  } 
	  else {
	       /* 'clause' is a join clause, since there is more than one */
	       /*  atom in the relid list. */

	       set_selectivity (clauseinfo,compute_clause_selec (clause,
								 LispNil));
	       add_join_clause_info_to_rels (clauseinfo,relids);
	       add_vars_to_rels (vars,relids);
	  } 
     }
d214 8
a221 9
     LispValue join_relid = LispNil;
     foreach (join_relid, join_relids) {
	  /* XXX - let form, maybe incorrect */
	 JInfo joininfo = 
	   find_joininfo_node (get_rel (CAR(join_relid)),
			       remove (CAR(join_relid),join_relids));
	  set_jinfoclauseinfo (joininfo,
			   cons (clauseinfo,
				 get_jinfoclauseinfo (joininfo)));
d251 1
a251 1
    LispValue temp;
d260 1
a260 1
	other_join_relids = remove (get_varno (var),
d270 1
a270 1
					other_join_relids));
d272 1
a272 1
     }
d298 10
a307 10
     LispValue rel = LispNil;
     LispValue joininfo = LispNil;
     LispValue clauseinfo = LispNil;
     foreach (rel, rel_list) {
	  foreach (joininfo, get_joininfo (CAR(rel))) {
	       foreach (clauseinfo, get_clauseinfo (joininfo)) {
		    Expr clause = get_clause (CAR(clauseinfo));
		    if ( join_clause_p (clause) ) {
			 LispValue sortop = LispNil;
			 ObjectId hashop;
d309 4
a312 4
			 if ( _enable_mergesort_ ) 
			   sortop = mergesortop (clause);
			 if ( _enable_hashjoin_ ) 
			   hashop = hashjoinop (clause);
d314 3
a316 8
			 if ( sortop) {
			      set_mergesortorder (CAR(clauseinfo),sortop);
			      set_mergesortable (CAR(joininfo),true);
			 }
			 if ( hashop) {
			      set_hashjoinoperator (CAR(clauseinfo),hashop);
			      set_hashjoinable (CAR(joininfo),true);
			 }
d318 8
a325 3
	       }
	  }
     }
@


1.4
log
@checkin for retrieve (x.all)
@
text
@d11 1
a11 1
/* RcsId ("$Header: initsplan.c,v 1.3 89/08/01 14:36:11 goh Locked $");  */
d25 1
a25 1
#include "internal.h"
d27 1
a27 1
#include "clause.h"
d32 3
a34 3
#include "relnode.h"
#include "joininfo.h
#include "initsplan.h"
d37 1
a37 1
#include "tlist.h"
d39 2
a40 10
/*
extern void *add_clause_to_rels();
extern void *add_join_clause_info_to_rels();
extern void *add_vars_to_rels();
extern LispValue hashjoinop();
extern LispValue mergesortop();
*/

extern Boolean _enable_mergesort_;
extern Boolean _enable_hashjoin_;
@


1.3
log
@retrieve (x=1) checkin
@
text
@d11 1
a11 1
/* RcsId ("$Header: initsplan.c,v 1.2 89/07/21 13:35:42 goh Locked $");  */
d129 2
a130 2
	  if(IsA(clause,Func))
	    initialize_qualification (get_funcargs (clause));
d132 3
a134 3
	    if (IsA(clause,Oper))
	      initialize_qualification (get_opargs (clause));
	  add_clause_to_rels (clause);
d219 3
a221 3
	   find_joininfo_node (get_rel (join_relid),
			       remove (join_relid,join_relids));
	  set_clauseinfo (joininfo,
d223 1
a223 1
				 get_clauseinfo (joininfo)));
d252 22
a273 16
     LispValue var = LispNil;
     foreach (var, vars) {
	  Rel rel = get_rel (lispInteger(get_varno (var)));
	  LispValue  tlistentry = tlistentry_member (var,get_targetlist (rel));
	  LispValue other_join_relids = remove (get_varno (var),
						join_relids);
	  if(null (tlistentry))
	    /*   add a new entry */
	    add_tl_element (rel,var,other_join_relids);
	  else 
	    if (get_joinlist (tlistentry)) {
		 set_joinlist (tlistentry,
				/*   modify an existing entry */
				LispUnion (get_joinlist(tlistentry),
				       other_join_relids));
	    } 
@


1.2
log
@phase 2-3 of check in
@
text
@d11 1
a11 1
/* RcsId ("$Header: initsplan.c,v 1.1 89/07/18 15:15:51 goh Locked $");  */
a45 1
extern LispValue create_mergeorder(); /* XXX - where is this from ? */
d69 3
a71 3
void
*initialize_targetlist (tlist)
LispValue tlist ;
d73 7
a79 3
     LispValue tlist_vars = LispNil;
     LispValue xtl = LispNil;
     LispValue var = LispNil;
d81 3
a83 2
     foreach(xtl,tlist) 
       tlist_vars = nappend1(tlist_vars,pull_var_clause(tl_expr(xtl)));
d85 4
a88 2
     foreach (var, tlist_vars) 
       add_tl_element (get_rel (get_varno (var)),var,LispNil);
d90 12
d123 1
a123 1
*initialize_qualification (clauses)
d129 1
a129 1
	  if(func_p (clause))
d132 1
a132 1
	    if (oper_p (clause))
d153 1
a153 1
*add_clause_to_rels (clause)
d181 1
a181 1
	       set_clause_info (rel,cons (clauseinfo,get_clause_info (rel)));
d212 1
a212 1
*add_join_clause_info_to_rels (clauseinfo,join_relids)
d221 1
a221 1
	  set_clause_info (joininfo,
d223 1
a223 1
				 get_clause_info (joininfo)));
d249 1
a249 1
*add_vars_to_rels (vars,join_relids)
d254 2
a255 2
	  Rel rel = get_rel (get_varno (var));
	  LispValue  tlistentry = tlistentry_member (var,get_tlist (rel));
d262 2
a263 2
	    if (get_join_list (tlistentry)) {
		 set_join_list (tlistentry,
d265 1
a265 1
				LispUnion (get_join_list(tlistentry),
d291 1
a291 1
*initialize_join_clause_info (rel_list)
d298 1
a298 1
	  foreach (joininfo, get_joininfo (rel)) {
d300 1
a300 1
		    Expr clause = get_clause (clauseinfo);
d311 2
a312 2
			      set_mergesortorder (clauseinfo,sortop);
			      set_mergesortable (joininfo,true);
d315 2
a316 2
			      set_hashjoinoperator (clauseinfo,hashop);
			      set_hashjoinable (joininfo,true);
d340 5
a344 5
	  return (create_mergeorder (get_opno (get_op (clause)),
				     nth (0,sortops),
				     nth (1,sortops),
				     get_vartype (get_leftop (clause)),
				     get_vartype (get_rightop (clause))));
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
/* RcsId ("$Header: initsplan.c,v 1.1 89/04/27 21:04:50 ong Locked $");  */
d26 12
d39 1
a39 2
#define TRUE  1

d45 2
d154 1
a154 2
	  /* XXX - let form, maybe incorrect */
	  LispValue clauseinfo = create_node ("ClauseInfo");
d162 1
a162 1
	       LispValue rel = get_rel (car (relids));
d200 3
a202 3
	  LispValue joininfo = 
	    find_joininfo_node (get_rel (join_relid),
				remove (join_relid,join_relids));
d232 1
a232 1
     LispValue vars,join_relids ;
d236 2
a237 2
	  LispValue rel = get_rel (get_varno (var));
	  LispValue tlistentry = tlistentry_member (var,get_tlist (rel));
d280 3
a282 4
	  foreach (joininfo, get_join_info (rel)) {
	       foreach (clauseinfo, get_clause_info (joininfo)) {
		    /* XXX - let form, maybe incorrect */
		    LispValue clause = get_clause (clauseinfo);
d285 1
a285 1
			 LispValue hashop = LispNil;
d294 1
a294 1
			      set_mergesortable (joininfo,TRUE);
d298 1
a298 1
			      set_hashjoinable (joininfo,TRUE);
a317 1
     /* XXX - let form, maybe incorrect */
d343 1
a343 1
LispValue
@
