head 1.18; access; symbols Version_2_1:1.8 C_Demo_1:1.5 Retrieve_x_qual:1.4 Retrieve_x_all:1.3 Retrieve_x_1:1.2; locks; strict; comment @ * @; 1.18 date 92.08.21.05.48.14; author mer; state Exp; branches; next 1.17; 1.17 date 92.07.09.03.57.34; author hong; state Exp; branches; next 1.16; 1.16 date 92.07.04.04.03.52; author mao; state Exp; branches; next 1.15; 1.15 date 92.07.01.05.13.54; author mer; state Exp; branches; next 1.14; 1.14 date 91.11.17.20.36.34; author mer; state Exp; branches; next 1.13; 1.13 date 91.08.18.02.01.17; author caetta; state Exp; branches; next 1.12; 1.12 date 91.08.16.15.47.46; author caetta; state Exp; branches; next 1.11; 1.11 date 91.08.15.18.05.40; author caetta; state Exp; branches; next 1.10; 1.10 date 91.03.31.20.40.38; author kemnitz; state Exp; branches; next 1.9; 1.9 date 91.03.29.02.39.23; author kemnitz; state Exp; branches; next 1.8; 1.8 date 90.09.25.16.39.28; author kemnitz; state Exp; branches; next 1.7; 1.7 date 90.06.09.18.55.13; author kemnitz; state Exp; branches; next 1.6; 1.6 date 89.10.19.17.22.29; author sp; state Exp; branches; next 1.5; 1.5 date 89.09.05.17.19.44; author mao; state C_Demo_1; branches; next 1.4; 1.4 date 89.08.04.14.31.33; author goh; state Exp; branches; next 1.3; 1.3 date 89.08.04.13.30.12; author goh; state Exp; branches; next 1.2; 1.2 date 89.08.01.14.34.00; author goh; state Exp; branches; next 1.1; 1.1 date 89.06.30.11.04.58; author goh; state Exp; branches; next ; desc @Phase 2 of conversion : compiles with no warnings @ 1.18 log @add a new support routine to look up the relid for a given Var node @ text @/* * FILE * var * * DESCRIPTION * Var node manipulation routines * $Header: /private/mer/pg/src/planner/util/RCS/var.c,v 1.17 1992/07/09 03:57:34 hong Exp mer $ */ /* * EXPORTS * pull_var_clause * var_equal * numlevels */ #include "planner/internal.h" #include "planner/var.h" #include "nodes/primnodes.h" #include "nodes/primnodes.a.h" #include "planner/clauses.h" LispValue pull_agg_clause(clause) LispValue clause; { LispValue retval = LispNil; if(null(clause)) retval=LispNil; else if(agg_clause(clause)) retval = CDR(clause); /* this brings the clause down to * (aggname, query, tlist, -1) */ else if (single_node (clause)) retval = LispNil; else if (or_clause(clause)) { LispValue temp; LispValue result = LispNil; /* mapcan */ foreach (temp,get_orclauseargs(clause) ) retval = nconc(retval, pull_agg_clause(CAR(temp))); } else if (is_funcclause (clause)) { LispValue temp; /* mapcan */ foreach(temp,get_funcargs(clause)) retval = nconc (retval,pull_agg_clause(CAR(temp))); } else if (IsA(clause,ArrayRef)) { retval = pull_agg_clause(get_refindexpr((ArrayRef)clause)); } else if (not_clause (clause)) retval = pull_agg_clause(get_notclausearg(clause)); else if (is_clause(clause)) retval = nconc (pull_agg_clause ((LispValue)get_leftop (clause)), pull_agg_clause ((LispValue)get_rightop (clause))); else retval= LispNil; return (retval); } /* * pull_var_clause * * Recursively pulls all var nodes from a clause by pulling vars from the * left and right operands of the clause. * * Returns list of varnodes found. * */ LispValue pull_var_clause (clause) LispValue clause ; { LispValue retval = LispNil; if (null (clause) ) return(LispNil); else if (IsA(clause,Var)) retval = lispCons (clause,LispNil); else if ( IsA(clause,Iter) ) retval = pull_var_clause(get_iterexpr((Iter)clause)); else if (single_node (clause)) retval = LispNil; else if (or_clause (clause)) { LispValue temp; LispValue result = LispNil; /* mapcan */ foreach (temp,get_orclauseargs(clause) ) retval = nconc(retval, pull_var_clause(CAR(temp))); } else if (is_funcclause (clause)) { LispValue temp; /* mapcan */ foreach(temp,get_funcargs(clause)) retval = nconc (retval,pull_var_clause(CAR(temp))); } else if (IsA(clause,ArrayRef)) { retval = nconc(pull_var_clause(get_refindexpr((ArrayRef)clause)), pull_var_clause(get_refexpr((ArrayRef)clause))); } else if (not_clause (clause)) retval = pull_var_clause (get_notclausearg (clause)); else if (is_clause (clause)) retval = nconc (pull_var_clause ((LispValue)get_leftop (clause)), pull_var_clause ((LispValue)get_rightop (clause))); else retval = LispNil; return (retval); } /* * var_equal * * Returns t iff two var nodes correspond to the same attribute. */ bool var_equal (var1,var2) LispValue var1,var2; { if (IsA (var1,Var) && IsA (var2,Var) && (get_varno ((Var)var1) == get_varno ((Var)var2)) && (get_vartype ((Var)var1) == get_vartype ((Var)var2)) && (get_varattno ((Var)var1) == get_varattno ((Var)var2))) { return(true); } else return(false); } /* var_equal */ /* * numlevels * * Returns the number of nesting levels in a var-node * */ /* .. replace-resultvar-refs */ int numlevels (var) Var var; { return(length (CDR ( get_varid (var)))); } ObjectId var_getrelid(var) Var var; { int rt_id; rt_id = CInteger(CAR(get_varid(var))); return (ObjectId) CInteger(getrelid(rt_id, _query_range_table_)); } @ 1.17 log @changes to make arrayref nodes work @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.16 92/07/04 04:03:52 mao Exp Locker: hong $ d146 10 @ 1.16 log @fixes for arrays, array refs, and nested dots @ text @d7 1 a7 1 * $Header: /private/mao/postgres/src/planner/util/RCS/var.c,v 1.15 1992/07/01 05:13:54 mer Exp mao $ d50 3 d98 3 @ 1.15 log @teach pull_var_clauses about Iter nodes @ text @d7 1 a7 1 * $Header: /private/mer/pg/src/planner/util/RCS/var.c,v 1.14 1991/11/17 20:36:34 mer Exp mer $ d107 1 a107 8 * Returns t iff two var nodes correspond to the same attribute (and * array element, if applicable), ignoring the dot fields (making * "foo.bar.baz" equivalent to "foo.ack.hodedo.baz") unless 'dots' is * set. * * vartype will be different in the case of array vars on the same * attribute, ie a.b[1][1] will be a different type than a.b[1]. * d110 1 a110 1 var_equal (var1,var2,dots) a111 1 bool dots; a117 23 /* comment out for now since vararrayindex is always nil until we get procedures working. if(dots != LispNil) { * Check for nested-dot equality. * if (equal (get_vardotfields (var1), get_vardotfields (var2)) && equal (get_vararrayindex (var1), get_vararrayindex (var2))); return(true); } else { * The vararrayindex field should be ignored unless 'var1' no longer has any nestings. * if (var_is_nested (var1) || equal (get_vararrayindex (var1), get_vararrayindex (var2))); return(true); } */ if (equal((Node)get_vararraylist((Var)var1), (Node)get_vararraylist((Var)var2))) d119 1 a119 4 else return(false); } else d139 1 a139 5 if(varid_indexes_into_array (var)) { return ( length (CDR (get_varid (var))) - 1); } else { return(length (CDR ( get_varid (var)))); } @ 1.14 log @prototyping @ text @d7 1 a7 1 * $Header: /users/mer/postgres/src/planner/util/RCS/var.c,v 1.13 1991/08/18 02:01:17 caetta Exp mer $ d78 1 a78 1 else if (IsA(clause,Var) && get_varattno((Var)clause)) d80 2 @ 1.13 log @more aggregate pulling... @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.12 91/08/16 15:47:46 caetta Exp $ d53 2 a54 2 retval = nconc (pull_agg_clause (get_leftop (clause)), pull_agg_clause (get_rightop (clause))); d78 1 a78 1 else if (IsA(clause,Var) && get_varattno(clause)) d96 2 a97 2 retval = nconc (pull_var_clause (get_leftop (clause)), pull_var_clause (get_rightop (clause))); d120 3 a122 3 (get_varno (var1) == get_varno (var2)) && (get_vartype (var1) == get_vartype (var2)) && (get_varattno (var1) == get_varattno (var2))) { d145 2 a146 1 if (equal(get_vararraylist(var1), get_vararraylist(var2))) @ 1.12 log @aggregate fix.. @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.11 91/08/15 18:05:40 caetta Exp $ d31 1 a31 1 retval = lispCons(CDR(clause), LispNil); @ 1.11 log @for pulling agg and var clauses @ text @d7 1 a7 1 * $Header: planner/util/RCS/var.c,v 1.10 91/03/31 20:40:38 kemnitz Exp Locker: caetta $ d24 2 a25 2 pull_agg_clause(temp) TLE temp; a26 1 LispValue clause = LispNil; a27 2 clause = CADR(temp); /* XXX breakable hack */ @ 1.10 log @oops - need to check vararraylist for equality after all... @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.9 91/03/29 02:39:23 kemnitz Exp Locker: kemnitz $ d23 40 d101 1 @ 1.9 log @var_equal now tests to make sure the type of the array is the same; it may not be in the case of array node vars. @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.8 90/09/25 16:39:28 kemnitz Exp Locker: kemnitz $ d107 4 a110 1 return(true); @ 1.8 log @Updating from revision 1.7 to revision 1.8 @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.8 90/08/14 13:17:37 cimarron Exp $ d71 4 a74 1 * d83 1 @ 1.7 log @Fixed return bug in equal_var. ., @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.6 89/10/19 17:22:29 sp Exp Locker: kemnitz $ d19 2 a20 2 #include "primnodes.h" #include "primnodes.a.h" @ 1.6 log @ lp working as sp (sorry spyros, but this is the only working tree in the universe right now) bugfix for unary operators @ text @d7 1 a7 1 * $Header: RCS/var.c,v 1.5 89/09/05 17:19:44 mao C_Demo_1 $ d103 3 a105 2 } else @ 1.5 log @Working version of C-only demo @ text @d7 1 a7 1 * $Header: /usr6/postgres/mao/postgres/src/planner/util/RCS/var.c,v 1.4 89/08/04 14:31:33 goh Exp $ d39 3 a41 1 if (IsA(clause,Var) && get_varattno(clause)) @ 1.4 log @reorganised header files @ text @d7 1 a7 1 * $Header: var.c,v 1.3 89/08/04 13:30:12 goh Locked $ @ 1.3 log @checkin for retrieve (x.all) @ text @d7 1 a7 1 * $Header: var.c,v 1.2 89/08/01 14:34:00 goh Locked $ d17 2 a18 2 #include "internal.h" #include "var.h" d21 1 a21 1 #include "clauses.h" @ 1.2 log @retrieve (x=1) checkin @ text @d7 1 a7 1 * $Header: var.c,v 1.1 89/06/30 11:04:58 goh Exp $ d48 1 a48 1 retval = nconc(retval, pull_var_clause(temp)); d53 1 a53 1 retval = nconc (retval,pull_var_clause(temp)); d59 1 a59 2 else return (LispNil); @ 1.1 log @Initial revision @ text @d7 1 a7 1 * $Header:$ d39 2 a40 2 if (var_p(clause) && get_varattno(clause)) retval = list (clause); d48 1 a48 1 retval = nconc(retval, pull_varclause(temp)); d77 15 a91 11 if (var_p (var1) && var_p (var2) && equal (get_varno (var1), get_varno (var2)) && equal (get_varattno (var1),get_varattno (var2))) { if(dots) { /* Check for nested-dot equality. */ if (equal (get_vardotfields (var1), get_vardotfields (var2)) && equal (get_vararrayindex (var1), get_vararrayindex (var2))); return(true); } else { d93 13 a105 11 /* The vararrayindex field should be ignored unless 'var1' no longer has any nestings. */ if (var_is_nested (var1) || equal (get_vararrayindex (var1), get_vararrayindex (var2))); return(true); } } else return(false); d124 1 a124 1 return ( length (cdr (get_varid (var))) - 1); d126 1 a126 1 return(length (cdr ( get_varid (var)))); @