head 1.32; access; symbols release_4_2:1.32 aix_ok:1.31 Version_2_1:1.15 C_Demo_1:1.10 Retrieve_x_qual:1.7 Retrieve_x_all:1.6 Retrieve_x_1:1.5; locks; strict; comment @ * @; 1.32 date 93.11.01.08.00.35; author aoki; state Exp; branches; next 1.31; 1.31 date 93.04.14.00.59.24; author sunita; state Exp; branches; next 1.30; 1.30 date 92.07.09.03.57.32; author hong; state Exp; branches; next 1.29; 1.29 date 92.07.08.20.56.48; author joey; state Exp; branches; next 1.28; 1.28 date 92.07.04.04.03.51; author mao; state Exp; branches; next 1.27; 1.27 date 92.07.01.05.13.01; author mer; state Exp; branches; next 1.26; 1.26 date 91.11.17.21.13.02; author mer; state Exp; branches; next 1.25; 1.25 date 91.11.17.20.36.34; author mer; state Exp; branches; next 1.24; 1.24 date 91.11.15.16.28.21; author hong; state Exp; branches; next 1.23; 1.23 date 91.08.18.01.57.25; author caetta; state Exp; branches; next 1.22; 1.22 date 91.08.16.15.47.31; author caetta; state Exp; branches; next 1.21; 1.21 date 91.08.15.18.05.19; author caetta; state Exp; branches; next 1.20; 1.20 date 91.05.23.18.42.02; author kemnitz; state Exp; branches; next 1.19; 1.19 date 91.03.31.20.41.01; author kemnitz; state Exp; branches; next 1.18; 1.18 date 91.03.29.02.39.59; author kemnitz; state Exp; branches; next 1.17; 1.17 date 91.03.28.22.25.42; author kemnitz; state Exp; branches; next 1.16; 1.16 date 91.03.18.19.51.57; author sp; state Exp; branches; next 1.15; 1.15 date 90.10.10.18.57.27; author hong; state Exp; branches; next 1.14; 1.14 date 90.09.25.16.39.22; author kemnitz; state Exp; branches; next 1.13; 1.13 date 90.05.25.12.15.48; author kemnitz; state Exp; branches; next 1.12; 1.12 date 90.03.16.15.28.23; author ong; state Exp; branches; next 1.11; 1.11 date 89.10.04.13.42.59; author ong; state Exp; branches; next 1.10; 1.10 date 89.09.05.17.19.39; author mao; state C_Demo_1; branches; next 1.9; 1.9 date 89.08.30.16.57.14; author ong; state Exp; branches; next 1.8; 1.8 date 89.08.23.16.02.00; author ong; state Exp; branches; next 1.7; 1.7 date 89.08.04.14.31.31; author goh; state Exp; branches; next 1.6; 1.6 date 89.08.04.13.30.10; author goh; state Exp; branches; next 1.5; 1.5 date 89.08.01.14.33.54; author goh; state Exp; branches; next 1.4; 1.4 date 89.07.20.18.13.58; author goh; state Exp; branches; next 1.3; 1.3 date 89.07.19.20.01.07; author goh; state Exp; branches; next 1.2; 1.2 date 89.07.19.13.26.39; author goh; state Exp; branches; next 1.1; 1.1 date 89.06.29.10.42.44; author goh; state Exp; branches; next ; desc @@ 1.32 log @added lib/copyfuncs.h @ text @/* ---------------------------------------------------------------- * FILE * tlist.c * * DESCRIPTION * Target list manipulation routines * * INTERFACE ROUTINES * tlistentry-member * matching_tlvar * add_tl_element * create_tl_element * get-actual-tlist * tlist-member * match_varid * new-unsorted-tlist * targetlist-resdom-numbers * copy-vars * flatten-tlist * flatten-tlist-vars * * NOTES * * IDENTIFICATION * $Header$ * ---------------------------------------------------------------- */ #include "tmp/c.h" RcsId("$Header: /usr/local/devel/postgres/src/backend/planner/util/RCS/tlist.c,v 1.31 1993/04/14 00:59:24 sunita Exp aoki $"); #include "nodes/relation.h" #include "nodes/relation.a.h" #include "planner/internal.h" #include "nodes/primnodes.h" #include "nodes/primnodes.a.h" #include "nodes/pg_lisp.h" #include "planner/var.h" #include "planner/tlist.h" #include "planner/clauses.h" #include "utils/log.h" #include "lib/copyfuncs.h" /* XXX - find these references */ extern LispValue copy_seq_tree(); static TLE flatten_tlistentry(); /* ---------- RELATION node target list routines ---------- */ /* * tlistentry-member * * RETURNS: the leftmost member of sequence "targetlist" that satisfies * the predicate "var_equal" * MODIFIES: nothing * REQUIRES: test = function which can operate on a lispval union * var = valid var-node * targetlist = valid sequence */ LispValue tlistentry_member (var,targetlist) Var var; List targetlist; { extern LispValue lambda1(); if ( var) { LispValue temp = LispNil; foreach (temp,targetlist) { if ( var_equal((LispValue)var, (LispValue)get_expr(get_entry(CAR(temp))))) return(CAR(temp)); } } return (LispNil); } /* * matching_tlvar * * RETURNS: var node in a target list which is var_equal to 'var', * if one exists. * REQUIRES: "test" operates on lispval unions, * */ /* .. add_tl_element, collect-index-pathkeys, extract-path-keys * .. new-join-pathkey, new-matching-subkeys */ Expr matching_tlvar (var,targetlist) Var var; List targetlist; { LispValue tlentry; tlentry = tlistentry_member (var,targetlist); if ( tlentry ) return((Expr)get_expr (get_entry (tlentry)) ); return((Expr) NULL); } /* * add_tl_element * * Creates a targetlist entry corresponding to the supplied var node * 'var' and adds the new targetlist entry to the targetlist field of * 'rel' with the joinlist field set to 'joinlist'. * * RETURNS: nothing * MODIFIES: vartype and varid fields of leftmost varnode that matches * argument "var" (sometimes). * CREATES: new var-node iff no matching var-node exists in targetlist */ /* .. add-vars-to-rels, initialize-targetlist */ LispValue add_tl_element (rel,var,joinlist) Rel rel; Var var; List joinlist ; { Expr oldvar = (Expr)NULL; oldvar = matching_tlvar (var,get_targetlist (rel)); /* If 'var' is not already in 'rel's target list, add a new node. * Otherwise, put the var with fewer nestings into the target list. */ if ( null( oldvar ) ) { LispValue tlist = get_targetlist(rel); Var newvar = MakeVar (get_varno (var), get_varattno (var), get_vartype (var), get_varid (var),0); set_targetlist (rel,nappend1 (tlist, (LispValue)create_tl_element( newvar, length(tlist) + 1, joinlist))); } else if (length (get_varid ((Var)oldvar)) > length (get_varid (var))) { set_vartype ((Var)oldvar,get_vartype (var)); set_varid ((Var)oldvar,get_varid (var)); } } /* * create_tl_element * * Creates a target list entry node and its associated (resdom var) pair * with its resdom number equal to 'resdomno' and the joinlist field set * to 'joinlist'. * * RETURNS: newly created tlist-entry * CREATES: new targetlist entry (always). */ /* .. add_tl_element, new-join-tlist */ TL create_tl_element (var,resdomno,joinlist) Var var; int resdomno; List joinlist; { TL tlelement; tlelement = lispList(); set_entry (tlelement, MakeTLE (MakeResdom (resdomno, get_vartype (var), ((typeid_get_relid(get_vartype(var))) ? true : false), get_typlen (get_vartype (var)), (Name)LispNil, (Index)0, (OperatorTupleForm)NULL,0), var)); set_joinlist (tlelement,joinlist); return(tlelement); } /* * get-actual-tlist * * Returns the targetlist elements from a relation tlist. * */ /* .. compute-rel-width, create_plan */ LispValue get_actual_tlist (tlist) LispValue tlist ; { LispValue element = LispNil; LispValue result = LispNil; if (null(tlist)) { elog(DEBUG,"calling get_actual_tlist with empty tlist"); return(LispNil); } /* XXX - it is unclear to me what exactly get_entry should be doing, as it is unclear to me the exact relationship between "TL" "TLE" and joinlists */ foreach(element,tlist) result = nappend1 (result, get_entry (CAR(element))); return(result); } /* ---------- GENERAL target list routines ---------- */ /* * tlist-member * * Determines whether a var node is already contained within a * target list. * * 'var' is the var node * 'tlist' is the target list * 'dots' is t if we must match dotfields to determine uniqueness * * Returns the resdom entry of the matching var node. * */ /* .. flatten-tlist, replace-joinvar-refs, replace-nestvar-refs * .. set-temp-tlist-operators */ Resdom tlist_member (var,tlist) Var var; List tlist; { LispValue i = LispNil; TLE temp_tle = (TLE)NULL; TLE tl_elt = (TLE)NULL; if ( var) { foreach (i,tlist) { temp_tle = (TLE)CAR(i); if (var_equal((LispValue)var, (LispValue)get_expr(temp_tle))) { tl_elt = temp_tle; break; } } if ( consp (tl_elt) ) return(get_resdom (tl_elt)); else return((Resdom)NULL); } return ((Resdom)NULL); } /* * Routine to get the resdom out of a targetlist. */ Resdom tlist_resdom(tlist,resnode) LispValue tlist; Resdom resnode; { Resdom resdom = (Resdom)NULL; LispValue i = LispNil; TLE temp_tle = (TLE)NULL; foreach(i,tlist) { temp_tle = (TLE)CAR(i); resdom = get_resdom(temp_tle); /* Since resnos are supposed to be unique */ if (get_resno(resnode) == get_resno(resdom)) return(resdom); } return((Resdom)NULL); } /* * match_varid * * Searches a target list for an entry with some desired varid. * * 'varid' is the desired id * 'tlist' is the target list that is searched * * Returns the target list entry (resdom var) of the matching var. * * Now checks to make sure array references (in addition to range * table indices) are identical - retrieve (a.b[1],a.b[2]) should * not be turned into retrieve (a.b[1],a.b[1]). * */ /* .. flatten-tlistentry, replace-resultvar-refs */ LispValue match_varid (test_var,tlist) Var test_var; LispValue tlist; { LispValue i; TLE entry = (TLE)NULL; oid type_var, type_entry; List test_varid; test_varid = (List) get_varid(test_var); type_var = (oid) get_vartype(test_var); foreach (i,tlist) { entry = CAR(i); if (equal((Node)get_varid(get_expr(entry)), (Node)test_varid)) { if (get_vartype(get_expr(entry)) == type_var) return(entry); } } return (LispNil); } /* * new-unsorted-tlist * * Creates a copy of a target list by creating new resdom nodes * without sort information. * * 'targetlist' is the target list to be copied. * * Returns the resulting target list. * */ /* .. make_temp, sort-level-result */ List new_unsorted_tlist (targetlist) List targetlist ; { List new_targetlist = (List)CopyObject (targetlist); List x = LispNil; foreach (x, new_targetlist) { set_reskey (get_resdom (CAR(x)),0); set_reskeyop (get_resdom (CAR(x)),(OperatorTupleForm)NULL); } return(new_targetlist); } /* * targetlist-resdom-numbers * * Returns a list containing all resdom numbers in 'targetlist'. * */ /* .. expand-targetlist, write-decorate */ LispValue targetlist_resdom_numbers (targetlist) LispValue targetlist ; { LispValue element; LispValue result = LispNil; foreach (element,targetlist) result = nappend1 (result, lispInteger(get_resno(get_resdom(CAR(element))))); return (result); } /* * copy-vars * * Replaces the var nodes in the first target list with those from * the second target list. The two target lists are assumed to be * identical except their actual resdoms and vars are different. * * 'target' is the target list to be replaced * 'source' is the target list to be copied * * Returns a new target list. * */ /* .. set-temp-tlist-references */ LispValue copy_vars (target,source) LispValue target,source ; { LispValue result = LispNil; LispValue src = LispNil; LispValue dest = LispNil; for ( src = source, dest = target; src != LispNil && dest != LispNil; src = CDR(src), dest = CDR(dest)) { LispValue temp = MakeTLE(get_resdom(CAR(dest)), get_expr(CAR(src))); result = nappend1(result,temp); } return(result); } /* * flatten-tlist * * Create a target list that only contains unique variables. * -jc--also cons' the agg nodes to the var node list. * XXX Resdom nodes are numbered based on the length of the target list - * this hasn't caused problems yet, but.... * * 'tlist' is the current target list * * Returns the new target list. * */ /* .. query_planner */ LispValue flatten_tlist (tlist) LispValue tlist ; { int last_resdomno = 0; List new_tlist = LispNil; LispValue tlist_vars = LispNil; List tlist_aggs = LispNil; LispValue temp; LispValue var; LispValue tlist_thing = LispNil; LispValue tlist_rest = LispNil; LispValue temp_entry = LispNil; TLE full_agg_entry; Resdom agg_resdom; extern List MakeList(); foreach(temp,tlist) { temp_entry = CAR(temp); tlist_thing = pull_agg_clause(CADR(temp_entry)); if(tlist_thing != LispNil) { agg_resdom = get_resdom(temp_entry); full_agg_entry = MakeTLE(agg_resdom, tlist_thing); tlist_aggs = (LispValue)nappend1(tlist_aggs, full_agg_entry); } else { tlist_thing = pull_var_clause ((LispValue)get_expr(temp_entry)); if(tlist_thing != LispNil) { tlist_vars = nconc(tlist_vars, tlist_thing); } tlist_rest = nappend1(tlist_rest, temp_entry); } } /* XXX - This used to use the function push and nreverse. */ foreach (var,tlist_vars ) { if ( !(tlist_member ((Var)CAR(var),new_tlist))) { new_tlist = (LispValue)append1(new_tlist, MakeTLE (MakeResdom(++last_resdomno, get_vartype((Var)CAR(var)), ((typeid_get_relid( get_vartype((Var)CAR(var)))) ? true : false), get_typlen (get_vartype ((Var)CAR(var))), (Name)NULL, (Index)0, (OperatorTupleForm)NULL,0), CAR(var))); } } new_tlist = MakeList( new_tlist, tlist_aggs, tlist_rest, -1); /*jc */ return(new_tlist); } /* * flatten-tlist-vars * * Redoes the target list of a query with no nested attributes by * replacing vars within computational expressions with vars from * the 'flattened' target list of the query. * * 'full-tlist' is the actual target list * 'flat-tlist' is the flattened (var-only) target list * * Returns the modified actual target list. * */ /* .. query_planner */ LispValue flatten_tlist_vars (full_tlist,flat_tlist) LispValue full_tlist,flat_tlist ; { LispValue x = LispNil; LispValue result = LispNil; foreach(x,full_tlist) result = nappend1(result, MakeTLE (get_resdom (CAR(x)), flatten_tlistentry ( get_expr (CAR(x)), flat_tlist))); return(result); } /* * flatten-tlistentry * * Replaces vars within a target list entry with vars from a flattened * target list. * * 'tlistentry' is the target list entry to be modified * 'flat-tlist' is the flattened target list * * Returns the (modified) target_list entry from the target list. * */ /* .. flatten-tlist-vars, flatten-tlistentry */ static TLE flatten_tlistentry (tlistentry,flat_tlist) TLE tlistentry,flat_tlist ; { if(null (tlistentry)) { return((TLE)NULL); } else if (IsA (tlistentry,Var)) { return((TLE)get_expr (match_varid ((Var)tlistentry, flat_tlist))); } else if (IsA (tlistentry,Iter)) { LispValue temp; temp = (LispValue) flatten_tlistentry (get_iterexpr((Iter)tlistentry), flat_tlist); set_iterexpr((Iter)tlistentry, temp); return(tlistentry); } else if (single_node (tlistentry)) { return(tlistentry); } else if (is_funcclause (tlistentry)) { LispValue temp_result = LispNil; LispValue elt = LispNil; foreach(elt,get_funcargs(tlistentry)) temp_result = nappend1(temp_result, flatten_tlistentry(CAR(elt),flat_tlist)); return((TLE)make_funcclause (get_function (tlistentry), temp_result)); } else if (IsA(tlistentry,ArrayRef)) { LispValue temp = LispNil; LispValue elt = LispNil; foreach(elt, get_refupperindexpr((ArrayRef)tlistentry)) temp = nappend1(temp, flatten_tlistentry(CAR(elt), flat_tlist)); set_refupperindexpr((ArrayRef)tlistentry, temp); temp = LispNil; foreach(elt, get_reflowerindexpr((ArrayRef)tlistentry)) temp = nappend1(temp, flatten_tlistentry(CAR(elt), flat_tlist)); set_reflowerindexpr((ArrayRef)tlistentry, temp); temp = (LispValue) flatten_tlistentry(get_refexpr((ArrayRef)tlistentry), flat_tlist); set_refexpr((ArrayRef)tlistentry, temp); temp = (LispValue) flatten_tlistentry(get_refassgnexpr((ArrayRef)tlistentry), flat_tlist); set_refassgnexpr((ArrayRef)tlistentry, temp); return(tlistentry); } else { return((TLE) make_opclause( (Oper)get_op (tlistentry), (Var)flatten_tlistentry( get_leftop(tlistentry), flat_tlist), (Var)flatten_tlistentry( get_rightop(tlistentry), flat_tlist))); } } @ 1.31 log @Changes to enable a more general array support. @ text @d1 8 a8 13 /* * FILE * tlist * * DESCRIPTION * Target list manipulation routines * */ static char *rcsid = "$Header: /usr/local/devel/postgres/src/backend/planner/util/RCS/tlist.c,v 1.30 1992/07/09 03:57:32 hong Exp $"; /* * EXPORTS d21 6 d31 2 d44 2 a47 1 @ 1.30 log @changes to make arrayref nodes work @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.29 92/07/08 20:56:48 joey Exp Locker: hong $"; d575 10 a584 5 LispValue temp; temp = (LispValue)flatten_tlistentry(get_refindexpr((ArrayRef)tlistentry), flat_tlist); set_refindexpr((ArrayRef)tlistentry, temp); d589 4 @ 1.29 log @fix up call to MakeResdom to include rescomplex @ text @d10 1 a10 1 static char *rcsid = "$Header: /private/joey/pg/src/planner/util/RCS/tlist.c,v 1.28 1992/07/04 04:03:51 mao Exp joey $"; d178 1 a178 1 ((typeid_get_relid(var)) ? true : false), d476 2 a477 1 ((typeid_get_relid(var)) ? d574 11 @ 1.28 log @fixes for arrays, array refs, and nested dots @ text @d10 1 a10 1 static char *rcsid = "$Header: /private/mao/postgres/src/planner/util/RCS/tlist.c,v 1.27 1992/07/01 05:13:01 mer Exp mao $"; d178 1 d476 2 @ 1.27 log @teach tlist code about Iter nodes @ text @d10 1 a10 1 static char *rcsid = "$Header: /private/mer/pg/src/planner/util/RCS/tlist.c,v 1.26 1991/11/17 21:13:02 mer Exp mer $"; a52 2 * NOTES: normally called with test = (*var_equal)() * d54 1 a54 1 * the predicate "test" d71 1 a71 2 (LispValue)get_expr(get_entry(CAR(temp))), false)) a80 1 * NOTES: "test" should normally be var_equal() d137 1 a137 2 get_vartype (var),LispNil, get_vararraylist(var), d252 1 a252 2 (LispValue)get_expr(temp_tle), false)) { d328 1 a328 4 if ((get_vartype(get_expr(entry)) == type_var) && (equal( (Node)get_vararraylist(get_expr(entry)), (Node)get_vararraylist(test_var)))) { a329 1 } @ 1.26 log @prototyping - oops var_equal has changed on me @ text @d10 1 a10 1 static char *rcsid = "$Header: /users/mer/postgres/src/planner/util/RCS/tlist.c,v 1.25 1991/11/17 20:36:34 mer Exp mer $"; d554 2 a555 2 } else if (IsA (tlistentry,Var)) { d557 10 a566 2 } else if (single_node (tlistentry)) { d568 2 a569 2 } else if (is_funcclause (tlistentry)) { d579 1 @ 1.25 log @prototyping @ text @d10 1 a10 1 static char *rcsid = "$Header: /users/mer/postgres/src/planner/util/RCS/tlist.c,v 1.24 1991/11/15 16:28:21 hong Exp mer $"; d72 3 a74 1 if ( var_equal(var, get_expr(get_entry(CAR(temp))))) d256 3 a258 1 if (var_equal(var,get_expr(temp_tle))) { @ 1.24 log @planner prototyping @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.23 91/08/18 01:57:25 caetta Exp $"; a67 1 extern bool var_equal(); d144 1 a144 1 create_tl_element (newvar, d148 1 a148 1 } else if (length (get_varid (oldvar)) > length (get_varid (var))) { d150 2 a151 2 set_vartype (oldvar,get_vartype (var)); set_varid (oldvar,get_varid (var)); d182 3 a184 1 LispNil,0,LispNil,0), d328 1 a328 1 if (equal(get_varid(get_expr(entry)), test_varid)) d331 2 a332 2 (equal(get_vararraylist(get_expr(entry)), get_vararraylist(test_var)))) d365 1 a365 1 set_reskeyop (get_resdom (CAR(x)),LispNil); a457 1 extern List nset_difference(); d468 1 a468 1 tlist_thing = pull_var_clause (get_expr(temp_entry)); d477 1 a477 1 if ( !(tlist_member (CAR(var),new_tlist,1 ))) { d480 1 a480 1 get_vartype(CAR(var)), d483 4 a486 4 (CAR(var))), LispNil, 0, LispNil,0), d552 1 a552 1 return((TLE)get_expr (match_varid (tlistentry, flat_tlist))); d568 6 a573 5 return((TLE)make_opclause (get_op (tlistentry), flatten_tlistentry (get_leftop (tlistentry), flat_tlist), flatten_tlistentry (get_rightop (tlistentry), flat_tlist))); @ 1.23 log @adjusted to allow more efficiency and correct elogs... @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.22 91/08/16 15:47:31 caetta Exp $"; d242 1 a242 1 tlist_member (var,tlist,dots,key,test) d244 1 a244 2 List tlist,dots,key; bool (*test)(); a245 1 /* declare (special (dots)); */ @ 1.22 log @aggregate fix.. @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.21 91/08/15 18:05:19 caetta Exp $"; d450 1 a450 1 LispValue tlist_aggs = LispNil; d454 4 a457 1 LispValue tlist_rest = tlist; d462 15 a476 13 tlist_thing = pull_var_clause (get_expr(CAR(temp))); if(tlist_thing != LispNil) { tlist_vars = nconc(tlist_vars, tlist_thing); } else { tlist_thing = pull_agg_clause(get_expr(CAR(temp))); if(tlist_thing != LispNil) { tlist_aggs = nconc(tlist_aggs, tlist_thing); tlist_rest = nset_difference(temp, tlist_rest); } } } a492 1 @ 1.21 log @for the alternate flattening... @ text @d10 1 a10 1 static char *rcsid = "$Header: planner/util/RCS/tlist.c,v 1.20 91/05/23 18:42:02 kemnitz Exp Locker: caetta $"; d464 1 a464 1 tlist_thing = pull_agg_clause(CAR(temp)); @ 1.20 log @got rid of lint warning "has return(e); and return;" @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.19 91/03/31 20:41:01 kemnitz Exp Locker: kemnitz $"; d431 1 a431 1 * d450 1 d453 4 d458 13 a470 4 foreach(temp,tlist) tlist_vars = nconc(tlist_vars, pull_var_clause (get_expr(CAR(temp)))); d489 1 @ 1.19 log @oops - need to check vararraylist for equality after all... @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.18 91/03/29 02:39:59 kemnitz Exp Locker: kemnitz $"; d103 2 @ 1.18 log @true fixes for match_varid - now compares varid's and vartypes. @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.17 91/03/28 22:25:42 kemnitz Exp Locker: kemnitz $"; d312 2 a313 2 match_varid (var_to_test,tlist) Var var_to_test; d321 2 a322 2 test_varid = (List) get_varid(var_to_test); type_var = (oid) get_vartype(var_to_test); d329 3 a331 1 if (get_vartype(get_expr(entry)) == type_var) @ 1.17 log @match_varid now checks to make sure both array indirection lists AND varids are equal - (a.b[1], a.b[2]) in the targetlist should not be the same as (a.b[1], a.b[1]) @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.16 91/03/18 19:51:57 sp Exp Locker: kemnitz $"; d318 2 a319 1 List var1; d321 5 a325 1 foreach (i,tlist) { d327 7 a333 3 if (equal(get_varid(get_expr(entry)),get_varid(var_to_test)) && equal(get_vararraylist(get_expr(entry)), get_vararraylist(var_to_test))) return(entry); @ 1.16 log @replaced elog NOTICE with DEBUG... @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.15 90/10/10 18:57:27 hong Exp Locker: sp $"; d139 1 a139 3 (consider_vararrayindex(var) ? varid_array_index(var) : 0 ), d301 4 d312 3 a314 2 match_varid (varid,tlist) LispValue varid,tlist; d318 1 d322 2 a323 1 if (equal(get_varid(get_expr(entry)),varid)) d522 1 a522 2 return((TLE)get_expr (match_varid (get_varid (tlistentry), flat_tlist))); @ 1.15 log @added a new field in Resdom node @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.14 90/09/25 16:39:22 kemnitz Exp Locker: hong $"; d207 1 a207 1 elog(NOTICE,"calling get_actual_tlist with empty tlist"); @ 1.14 log @Updating from revision 1.13 to revision 1.16 @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.16 90/08/14 13:17:33 cimarron Exp $"; d183 1 a183 1 LispNil,0,LispNil), d451 1 a451 1 LispNil), @ 1.13 log @Added entry for new varnode element in MakeVar. @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.12 90/03/16 15:28:23 ong Exp Locker: kemnitz $"; d28 4 a31 3 #include "c.h" #include "relation.h" #include "relation.a.h" d33 3 a35 3 #include "primnodes.h" #include "primnodes.a.h" #include "pg_lisp.h" d39 1 a39 1 #include "log.h" d343 1 a343 1 List new_targetlist = copy_seq_tree (targetlist); @ 1.12 log @added tlist_resdom() @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.11 89/10/04 13:42:59 ong Exp Locker: ong $"; d141 1 a141 1 get_varid (var)); @ 1.11 log @bug fix for targetlist_resdom_numbers @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.10 89/09/05 17:19:39 mao C_Demo_1 $"; d265 1 d268 24 @ 1.10 log @Working version of C-only demo @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.9 89/08/30 16:57:14 ong Exp Locker: ong $"; d341 1 a341 1 LispValue result; d343 1 a343 1 for(element = targetlist; element != LispNil; element = CDR(element)) d345 1 a345 1 lispInteger(get_resno (get_resdom (CAR(element))))); @ 1.9 log @changed make_clause to make opclause @ text @d10 1 a10 1 static char *rcsid = "$Header: RCS/tlist.c,v 1.8 89/08/23 16:02:00 ong Exp Locker: ong $"; @ 1.8 log @planner supports all but rules and mergesort @ text @d10 1 a10 1 static char *rcsid = "$Header: /n/postgres/a/postgres/ong/postgres/src/planner/util/RCS/tlist.c,v 1.7 89/08/04 14:31:31 goh Exp $"; d508 1 a508 1 return((TLE)make_clause (get_op (tlistentry), @ 1.7 log @reorganised header files @ text @d10 1 a10 1 static char *rcsid = "$Header: tlist.c,v 1.6 89/08/04 13:30:10 goh Locked $"; d125 1 a125 1 Expr oldvar; d134 1 d136 6 a141 6 get_varattno (var), get_vartype (var),LispNil, (consider_vararrayindex(var) ? varid_array_index(var) : 0 ), get_varid (var)); d143 4 a146 4 set_targetlist (rel,nappend1 (get_targetlist (rel), create_tl_element (newvar, get_size(rel) -1, joinlist))); d149 1 a149 1 d173 1 a173 1 Resdom resdomno; d176 11 a186 11 TL tlelement; tlelement = lispList(); set_entry (tlelement, MakeTLE (MakeResdom (resdomno, get_vartype (var), get_typlen (get_vartype (var)), LispNil,0,LispNil), var)); set_joinlist (tlelement,joinlist); return(tlelement); d247 4 a250 1 /* d252 8 a259 3 TLE tl_elt = (TLE)find (var,tlist, key , get_expr , test, var_equal ); d265 1 a265 1 */ d317 2 a318 2 List new_targetlist = copy_seq_tree (targetlist); List x = NULL; d320 5 a324 4 foreach (x, new_targetlist) { set_reskey (get_resdom (CAR(x)),0); set_reskeyop (get_resdom (CAR(x)),LispNil); } d370 3 a372 1 LispValue result, src, dest; d409 1 a409 2 return(tlist); /* d414 1 d417 11 a427 5 push (MakeTLE ( MakeResdom(last_resdomno++ , get_vartype (var), get_typlen (get_vartype (var)), LispNil,0,LispNil),var), new_tlist); d430 3 a432 3 return(nreverse(new_tlist)); */ @ 1.6 log @checkin for retrieve (x.all) @ text @d10 1 a10 1 static char *rcsid = "$Header: tlist.c,v 1.5 89/08/01 14:33:54 goh Locked $"; d31 1 a31 1 #include "internal.h" d35 3 a37 3 #include "var.h" #include "tlist.h" #include "clauses.h" @ 1.5 log @retrieve (x=1) checkin @ text @d10 1 a10 1 static char *rcsid = "$Header: tlist.c,v 1.4 89/07/20 18:13:58 goh Locked $"; d38 1 d63 1 a63 1 tlistentry_member (var,targetlist,var_equal) a65 1 bool (*var_equal)(); d67 1 d69 8 a76 2 if ( var) return ( find(var,targetlist,var_equal,lambda1)); a78 9 /* called by tlistentry-member */ static LispValue lambda1 (x) LispValue x ; { get_expr (get_entry (x)); } d94 1 a94 1 matching_tlvar (var,targetlist,test) a96 1 bool (*test)(); d98 4 a101 5 LispValue tlentry; tlentry = tlistentry_member (var,targetlist,test); if ( tlentry ) return((Expr)get_expr (get_entry (tlentry)) ); d121 3 a123 1 LispValue rel,var,joinlist ; d177 1 a177 1 /* d184 1 a184 1 */ d201 10 a210 2 LispValue element; LispValue result; d212 4 a215 4 for (element = tlist; element != LispNil; element = CDR(element) ) result = nappend1 (result, get_entry (element)); return(result); a272 6 static LispValue lambda2(x) LispValue x ; { get_varid (get_expr (x)); } d275 2 a276 2 match_varid (varid,tlist,key) LispValue varid,tlist,key ; d278 9 a286 1 return( find (varid,tlist,key, lambda2)); d312 2 a313 2 set_reskey (get_resdom (x),0); set_reskeyop (get_resdom (x),LispNil); d330 8 a337 8 LispValue element; LispValue result; for(element = targetlist; element != LispNil; element = CDR(element)) result = nappend1 (result, lispInteger(get_resno (get_resdom (element)))); return (result); d364 2 a365 2 LispValue temp = MakeTLE(get_resdom(dest), get_expr(src)); d437 8 a444 2 LispValue x = LispNil; LispValue result = LispNil; d446 1 a446 5 foreach(x,full_tlist) result = nappend1(result, MakeTLE (get_resdom (x), flatten_tlistentry (get_expr (x), flat_tlist))); d469 19 a487 19 if(null (tlistentry)) { return((TLE)NULL); } else if (IsA (tlistentry,Var)) { return((TLE)get_expr (match_varid (get_varid (tlistentry), flat_tlist))); } else if (single_node (tlistentry)) { return(tlistentry); } else if (is_funcclause (tlistentry)) { LispValue temp_result = LispNil; LispValue elt = LispNil; foreach(elt,get_funcargs(tlistentry)) temp_result = nappend1(temp_result, flatten_tlistentry(elt,flat_tlist)); return((TLE)make_funcclause (get_function (tlistentry), d489 7 a495 7 } else { return((TLE)make_clause (get_op (tlistentry), flatten_tlistentry (get_leftop (tlistentry), flat_tlist), flatten_tlistentry (get_rightop (tlistentry), flat_tlist))); } @ 1.4 log @phase 3 checkin @ text @d10 1 a10 1 static char *rcsid = "$Header: tlist.c,v 1.3 89/07/19 20:01:07 goh Locked $"; d34 1 a40 2 extern LispValue tlist_varsnreverse(); extern Var make_var(); d42 1 d62 1 a62 1 tlistentry_member (var,targetlist,test) d65 1 a65 1 bool (*test)(); d68 2 a69 2 if ( var) return ( find (var,targetlist,lambda1,test)); d77 1 a77 1 tl_expr (get_tlelement (x)); d105 1 a105 1 return((Expr)get_expr (get_tlelement (tlentry)) ); d129 1 a129 1 oldvar = matching_tlvar (var,get_tlist (rel)); d136 1 a136 1 Var newvar = make_var (get_varno (var), d144 1 a144 1 set_tlist (rel,append1 (get_tlist (rel), d146 1 a146 1 tlist_size(rel) -1, d178 2 a179 2 tlelement = CreateNode(TL); d181 4 a184 3 list (make_resdom (resdomno, get_vartype (var), get_typlen (get_vartype (var)), LispNil,0,LispNil),var)); d186 1 a186 1 d207 1 a207 1 result = nappend1 (result, get_tlelement (element)); d240 1 a240 1 d243 2 a244 2 key , tl_expr /* func */, test, var_equal /* func */); d250 1 d271 1 a271 1 get_varid (tl_expr (x)); d304 2 a305 2 set_reskey (tl_resdom (x),0); set_reskeyop (tl_resdom (x),LispNil); d326 2 a327 1 result = nappend1 (result, get_resno (tl_Resdom (element))); d352 9 a360 7 LispValue result, src, dest; for ( src = source, dest = target; src != LispNil && dest != LispNil; src = CDR(src), dest = CDR(dest)) result = nappend1(result,list(tl_resdom(dest),tl_expr(src))); return(result); d388 6 d395 7 a401 9 foreach(temp,tlist) pull_var_clause (tl_expr(temp)); foreach (var,tlist_varsnreverse (new_tlist)) { if ( !(tlist_member (var,new_tlist,1 /* XXX - true */))) { push (new_tl (make_resdom(last_resdomno++ , get_vartype (var), get_typlen (get_vartype (var)), LispNil,0,LispNil),var),new_tlist); d404 3 d434 2 a435 2 new_tl (tl_resdom (x), flatten_tlistentry (tl_expr (x), d462 1 a462 1 else if (var_p (tlistentry)) { @ 1.3 log @phase 2 checkin @ text @d10 1 a10 1 static char *rcsid = "$Header: tlist.c,v 1.2 89/07/19 13:26:39 goh Locked $"; d32 2 d43 1 a43 1 static LispValue flatten_tlistentry(); d63 2 a64 1 LispValue var,targetlist; d67 3 a69 3 extern LispValue lambda1(); if ( var != LispNil ) return ( find (var,targetlist,lambda1,test) ); d94 2 a95 1 LispValue d97 2 a98 1 LispValue var,targetlist; d105 1 a105 1 return(tl_expr (get_tlelement (tlentry)) ); d127 1 a127 1 LispValue oldvar; d232 1 a232 1 LispValue d234 2 a235 1 LispValue var,tlist,dots,key; d238 11 a248 11 /* declare (special (dots)); */ if ( var != LispNil ) { LispValue tl_elt = find (var,tlist, key , tl_expr /* func */, test, var_equal /* func */); if ( consp (tl_elt) ) return(tl_resdom (tl_elt)); else return(LispNil); } d436 1 a436 1 * Returns the (modified) node from the target list. d442 2 a443 1 static LispValue d445 1 a445 1 LispValue tlistentry,flat_tlist ; d448 1 a448 1 return(LispNil); d451 1 a451 1 return(tl_expr (match_varid (get_varid (tlistentry), d465 1 a465 1 return(make_funcclause (get_function (tlistentry), d468 1 a468 1 return(make_clause (get_op (tlistentry), @ 1.2 log @*** empty log message *** @ text @d10 1 a10 1 static char *rcsid = "$Header: /usr6/postgres/goh/newpost/src/planner/util/RCS/tlist.c,v 1.1 89/06/29 10:42:44 goh Exp $"; d33 2 d36 4 d41 1 a41 3 extern LispValue flatten_tlistentry(); extern LispValue tl_expr(); extern LispValue create_tl_element(); d122 16 a137 1 LispValue oldvar; d139 4 a142 1 oldvar = matching_tlvar (var,get_tlist (rel)); d144 1 a144 3 /* If 'var' is not already in 'rel's target list, add a new node. * Otherwise, put the var with fewer nestings into the target list. */ d146 4 a149 16 if ( null( oldvar ) ) { LispValue newvar = make_var (get_varno (var), get_varattno (var), get_vartype (var),LispNil, (consider_vararrayindex(var) ? varid_array_index(var) : LispNil ), get_varid (var)); set_tlist (rel,append1 (get_tlist (rel), create_tl_element (newvar, tlist_size(rel) -1, joinlist))); } else if (length (get_varid (oldvar)) > length (get_varid (var))) { set_vartype (oldvar,get_vartype (var)); set_varid (oldvar,get_varid (var)); } d165 2 a166 1 LispValue d168 3 a170 1 LispValue var,resdomno,joinlist ; d172 2 a173 2 LispValue tlelement; tlelement = create_node ("TargetList"); d175 1 a175 1 set_tlelement (tlelement, d179 2 a180 1 set_join_list (tlelement,joinlist); a231 1 static LispValue dots; d288 1 a288 1 LispValue d290 1 a290 1 LispValue targetlist ; d292 2 a293 2 LispValue new_targetlist = copy_seq_tree (targetlist); LispValue x = LispNil; d372 15 a386 17 int last_resdomno = 0; LispValue new_tlist = LispNil; LispValue tlist_vars = LispNil; LispValue temp; LispValue var; foreach(temp,tlist) pull_var_clause (tl_expr(temp)); for (var = tlist_varsnreverse (new_tlist); var != LispNil; var = CDR(var)) { if ( !(tlist_member (var,new_tlist,1 /* XXX - true */))) { push (new_tl (make_resdom(last_resdomno++ , get_vartype (var), get_typlen (get_vartype (var)), LispNil,0,LispNil),var),new_tlist); } d388 1 d390 1 a390 1 @ 1.1 log @Initial revision @ text @d10 1 a10 1 static char *rcsid = "$Header:$"; d28 3 a31 1 #include "c.h" d34 1 d45 8 a52 5 * Determines whether a var node 'var' is already contained within a list * of target list entry nodes 'targetlist'. * * Returns the corresponding tlist entry node. * d55 9 a63 2 /* .. add-vars-to-rels, matching_tlvar */ d65 1 a72 8 LispValue tlistentry_member (var,targetlist,key,test) LispValue var,targetlist,key ; bool (*test)(); { if ( var != LispNil ) return ( find (var,targetlist,key,test,test) ); } d75 1 a75 1 * matching_tlvar d77 5 a81 3 * Returns the var node in a target list which is var_equal to 'var', * if one exists. * d88 2 a89 2 matching_tlvar (var,targetlist,key,test) LispValue var,targetlist,key ; d92 3 a94 1 LispValue tlentry = tlistentry_member (var,targetlist,test,test); d106 4 a109 2 * Returns nothing of interest. * d118 1 a118 1 LispValue oldvar = matching_tlvar (var,get_tlist (rel)); d120 2 d126 1 a126 1 if(null (oldvar)) { d151 2 a152 2 * Returns the newly created targetlist entry. * d161 3 a163 1 LispValue tlelement = create_node ("TargetList"); d217 2 a218 1 LispValue var,tlist,dots,key,test ; d361 1 a362 1 LispValue last_resdomno = 0; d373 1 a373 1 push (new_tl (make_resdom(incf (last_resdomno), @