head 1.20; access; symbols release_4_2:1.20 aix_ok:1.20 Version_2_1:1.10 C_Demo_1:1.8 Retrieve_x_qual:1.6 Retrieve_x_all:1.5 Retrieve_x_1:1.4; locks; strict; comment @ * @; 1.20 date 93.01.16.03.14.59; author aoki; state Exp; branches; next 1.19; 1.19 date 92.08.16.03.30.20; author mer; state Exp; branches; next 1.18; 1.18 date 92.07.24.21.19.44; author mao; state Exp; branches; next 1.17; 1.17 date 91.11.17.20.36.34; author mer; state Exp; branches; next 1.16; 1.16 date 91.11.15.16.27.59; author hong; state Exp; branches; next 1.15; 1.15 date 91.08.18.01.57.07; author caetta; state Exp; branches; next 1.14; 1.14 date 91.08.16.15.46.29; author caetta; state Exp; branches; next 1.13; 1.13 date 91.08.16.10.13.16; author caetta; state Exp; branches; next 1.12; 1.12 date 91.08.15.18.04.56; author caetta; state Exp; branches; next 1.11; 1.11 date 91.05.23.18.39.27; author kemnitz; state Exp; branches; next 1.10; 1.10 date 90.09.25.16.38.25; author kemnitz; state Exp; branches; next 1.9; 1.9 date 89.10.13.18.01.53; author hong; state Exp; branches; next 1.8; 1.8 date 89.09.05.17.19.03; author mao; state C_Demo_1; branches; next 1.7; 1.7 date 89.08.23.16.01.33; author ong; state Exp; branches; next 1.6; 1.6 date 89.08.04.14.30.29; author goh; state Exp; branches; next 1.5; 1.5 date 89.08.04.13.29.40; author goh; state Exp; branches; next 1.4; 1.4 date 89.08.01.14.32.46; author goh; state Exp; branches; next 1.3; 1.3 date 89.07.19.18.43.33; author goh; state Exp; branches; next 1.2; 1.2 date 89.07.19.18.09.55; author goh; state Exp; branches; next 1.1; 1.1 date 89.06.30.11.34.43; author goh; state Exp; branches; next ; desc @phase 1 of conversion, compiles (but with warnings, since some functions still undefined @ 1.20 log @removed references to utils/fmgr.h and parser/parse.h @ text @ /* * clauses * * Clause access and manipulation routines * $Header: /home2/aoki/postgres/src/backend/planner/util/RCS/clauses.c,v 1.19 1992/08/16 03:30:20 mer Exp aoki $ */ /* * clause-type * make-clause * is_opclause * make_opclause * get_opargs * get_op * get_leftop * get_rightop * is_funcclause * make_funcclause * get_funcargs * get_function * or_clause * make_orclause * get_orclauseargs * not_clause * make_notclause * get_notclausearg * and_clause * make_andclauseargs * get_andclauseargs */ #include "tmp/c.h" #include "parse.h" #include "utils/log.h" #include "nodes/pg_lisp.h" #include "catalog/pg_aggregate.h" #include "catalog/syscache.h" #include "planner/clauses.h" /* * clause_head * * Returns the first element of a clause, if it is a clause * */ /* .. and_clause, clause-type, is_funcclause, is_opclause, not_clause * .. or_clause */ LispValue clause_head (clause) LispValue clause ; { if ( consp (clause) ) { return(CAR (clause)); } else { return(LispNil); } } /* .. clause-args, fix-indxqual-references */ LispValue clause_type (clause) LispValue clause ; { LispValue clauseand = lispInteger(AND); LispValue clauseor = lispInteger(OR); LispValue clausenot = lispInteger(NOT); if ( consp (clause) ) { LispValue type = clause_head (clause); if (type == LispNil) return(LispNil); if ( member (type,lispCons(clauseand, lispCons(clauseor, lispCons(clausenot, LispNil)))) || IsA (type,Func) || IsA (type,Oper)) return(type); } else return(LispNil); return(LispNil); } /* .. clause-subclauses */ LispValue clause_args (clause) LispValue clause ; { LispValue clauseand = lispInteger(AND); LispValue clauseor = lispInteger(OR); LispValue clausenot = lispInteger(NOT); if ( consp (clause) ) { LispValue type = clause_type (clause); if ( member (type,lispCons(clauseand, lispCons(clauseor, lispCons(clausenot, LispNil)))) || IsA (type,Func) || IsA(type,Oper) ) return(CDR (clause)); } else return(LispNil); return(LispNil); } LispValue make_clause (type,args) LispValue type,args ; { LispValue clauseand = lispInteger(AND); LispValue clauseor = lispInteger(OR); LispValue clausenot = lispInteger(NOT); if (null(type)) return(args); else if (IsA(type,LispInt) ) { int actual = CInteger(type); if (actual == AND || actual == OR || actual == NOT) return(lispCons(type,args)); } else if (IsA(type,Func) || IsA(type,Oper)) { return(lispCons(type,args)); } else return (args); return (args); } /* .. fix-indxqual-references */ LispValue clause_subclauses (type,clause) LispValue type,clause ; { if(type) { return(clause_args (clause)); } else if (consp (clause)) { return(clause); } else return(LispNil); } /* -------- OPERATOR clause macros */ /* * is_opclause * * Returns t iff the clause is an operator clause: * (op expr expr) or (op expr). * */ /* .. fix-indxqual-references */ bool is_opclause (clause) LispValue clause ; { if (clause_head(clause)) return((bool)IsA (clause_head (clause),Oper)); return(false); } /* * make_opclause * * Creates a clause given its operator left operand and right * operand (if it is non-null). * */ /* .. fix-indxqual-references */ LispValue make_opclause (op,leftop,rightop) Oper op; Var leftop,rightop ; { if(rightop) { return(lispCons ((LispValue)op, lispCons((LispValue)leftop, lispCons((LispValue)rightop, LispNil)))); } else { return(lispCons ((LispValue)op, lispCons((LispValue)leftop,LispNil))); } } /* * get_opargs * * Returns the argument exprs of an op clause. * */ LispValue get_opargs (clause) LispValue clause ; { return(CDR (clause)); } /* * get_op * * Returns the operator in a clause of the form (op expr expr) or * (op expr) * */ LispValue get_op (clause) LispValue clause ; { return(nth (0,clause)); } /* * get_leftop * * Returns the left operand of a clause of the form (op expr expr) * or (op expr) * NB: it is assumed (for now) that all expr must be Var nodes */ Var get_leftop (clause) LispValue clause ; { return((Var)nth (1,clause)); } /* * get_rightop * * Returns the right operand in a clause of the form (op expr expr). * */ Var get_rightop (clause) LispValue clause ; { clause = CDR(CDR(clause)); return( (Var)((clause) ? CAR(clause) : LispNil) ); } /* ----Agg clause macros */ bool agg_clause(clause) LispValue clause; { char *keyword = "agg"; LispValue temp; int tempstring; if(listp(clause)){ temp = CAR(clause); if(stringp(temp)) { tempstring = (strcmp(keyword, CString(temp))); if(!tempstring) return(true); } } /* if it is not a list, we're not dealing with aggregates * anyway. */ return(false); } /* -------- FUNC clause macros */ /* * is_funcclause * * Returns t iff the clause is a function clause: (func { expr }). * */ /* .. ExecEvalExpr, fix-indxqual-references, fix-opid, flatten-tlistentry * .. nested-clause-p, print_clause, pull_var_clause * .. replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ bool is_funcclause (clause) LispValue clause ; { if (clause_head(clause)) return((bool)IsA (clause_head (clause),Func)); return(false); } /* * make_funcclause * * Creates a function clause given the FUNC node and the functional * arguments. * */ /* .. flatten-tlistentry, replace-clause-joinvar-refs * .. replace-clause-nestvar-refs, replace-clause-resultvar-refs */ LispValue make_funcclause (func,funcargs) LispValue func,funcargs ; { return(lispCons (func,funcargs)); } /* * get_function * * Returns the FUNC node from a function clause. * */ /* .. ExecEvalFunc, fix-indxqual-references, flatten-tlistentry * .. print_clause, replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ LispValue get_function (func) LispValue func ; { return(CAR (func)); } /* * get_funcargs * * Returns the functional arguments from a function clause. * */ /* .. fix-opid, flatten-tlistentry, initialize-qualification * .. nested-clause-p, print_clause, pull_var_clause * .. replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ LispValue get_funcargs (func) LispValue func ; { return(CDR (func)); } /* -------- OR clause macros */ /* * or_clause * * Returns t iff the clause is an 'or' clause: (OR { expr }). * */ /* .. ExecEvalExpr, cleanup, compute_clause_selec, contains-not * .. create_indexscan_node, find-nots, fix-opid, nested-clause-p * .. normalize, print_clause, pull-args, pull-ors, pull_var_clause * .. push-nots, relation-level-clause-p, remove-ands * .. replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs, valid-or-clause * XXX - should be called or_clause_p instead */ bool or_clause (clause) LispValue clause ; { if (consp (clause)) return(bool) ( equal((Node)lispInteger(OR),(Node)clause_head(clause))); /* return(equal ("OR",clause_head (clause))); */ return(false); } /* * make_orclause * * Creates an 'or' clause given a list of its subclauses. * */ /* .. cleanup, distribute-args, find-nots, normalize, pull-args * .. push-nots, remove-ands, replace-clause-joinvar-refs * .. replace-clause-nestvar-refs, replace-clause-resultvar-refs */ LispValue make_orclause (orclauses) LispValue orclauses ; { return(lispCons (lispInteger(OR),orclauses)); } /* * get_orclauseargs * * Retrieves the subclauses of an 'or' clause. * */ /* .. ExecEvalExpr, cleanup, compute_clause_selec, contains-not * .. create-or-index-paths, create_indexscan_node, find-nots, fix-opid * .. match-index-orclauses, nested-clause-p, normalize, print_clause * .. pull-args, pull-ors, pull_var_clause, push-nots * .. relation-level-clause-p, remove-ands, replace-clause-joinvar-refs * .. replace-clause-nestvar-refs, replace-clause-resultvar-refs */ LispValue get_orclauseargs (orclause) LispValue orclause ; { if ( consp (orclause)) return(CDR (orclause)); return(NULL); } /* -------- NOT clause macros */ /* * not_clause * * Returns t iff this is a 'not' clause: (NOT expr). * */ /* .. ExecEvalExpr, cleanup, compute_clause_selec, contains-not * .. find-nots, fix-opid, nested-clause-p, normalize, print_clause * .. pull-args, pull_var_clause, push-nots, relation-level-clause-p * .. remove-ands, replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ bool not_clause (clause) LispValue clause ; { if (consp (clause)) return(bool) ( equal((Node)lispInteger(NOT),(Node)clause_head(clause))); return(false); } /* * make_notclause * * Create a 'not' clause given the expression to be negated. * */ /* .. cleanup, normalize, pull-args, push-nots, remove-ands * .. replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ LispValue make_notclause (notclause) LispValue notclause ; { return(lispCons (lispInteger(NOT), lispCons(notclause,LispNil))); } /* * get_notclausearg * * Retrieve the clause within a 'not' clause * */ /* .. ExecEvalNot, cleanup, compute_clause_selec, find-nots, fix-opid * .. nested-clause-p, normalize, print_clause, pull-args * .. pull_var_clause, push-nots, relation-level-clause-p, remove-ands * .. replace-clause-joinvar-refs, replace-clause-nestvar-refs * .. replace-clause-resultvar-refs */ LispValue get_notclausearg (notclause) LispValue notclause ; { return( CAR(CDR( (notclause)))) ; } /* -------- AND clause macros */ /* * and_clause * * Returns t iff its argument is an 'and' clause: (AND { expr }). * */ /* .. cleanup, cnfify, find-nots, normalize, pull-ands, pull-args * .. push-nots, remove-ands */ bool and_clause (clause) LispValue clause ; { if (consp (clause)) return(bool) ( equal((Node)lispInteger(AND),(Node)clause_head(clause))); return(false); } /* * make_andclause * * Create an 'and' clause given its arguments in a list. * */ /* .. cleanup, cnfify, distribute-args, find-nots, normalize * .. pull-args, push-nots */ LispValue make_andclause (andclauses) LispValue andclauses ; { return(lispCons (lispInteger(AND),andclauses)); } /* * get_andclauseargs * * Retrieve the arguments of an 'and' clause. * */ /* .. cleanup, find-nots, normalize, or-normalize, pull-ands * .. pull-args, push-nots, remove-ands */ LispValue get_andclauseargs (andclause) LispValue andclause ; { return(CDR (andclause)); } @ 1.19 log @handle unary operator clauses correctly @ text @d6 1 a6 1 * $Header: /users/mer/pg/src/planner/util/RCS/clauses.c,v 1.18 1992/07/24 21:19:44 mao Exp mer $ d37 1 a37 1 #include "parser/parse.h" @ 1.18 log @*** empty log message *** @ text @d6 1 a6 1 * $Header: /private/mao/postgres/src/planner/util/RCS/clauses.c,v 1.17 1991/11/17 20:36:34 mer Exp $ d260 3 a262 1 return((Var)nth (2,clause)); @ 1.17 log @prototyping @ text @d6 1 a6 1 * $Header: /users/mer/postgres/src/planner/util/RCS/clauses.c,v 1.16 1991/11/15 16:27:59 hong Exp mer $ a558 15 @ 1.16 log @planner prototyping @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.15 91/08/18 01:57:07 caetta Exp $ d195 3 a197 3 return(lispCons (op, lispCons(leftop, lispCons(rightop, d200 2 a201 2 return(lispCons (op, lispCons(leftop,LispNil))); d391 1 a391 1 return(bool) ( equal(lispInteger(OR),clause_head(clause))); d459 1 a459 1 return(bool) ( equal(lispInteger(NOT),clause_head(clause))); d521 1 a521 1 return(bool) ( equal(lispInteger(AND),clause_head(clause))); @ 1.15 log @to aid parser revision.. @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.14 91/08/16 15:46:29 caetta Exp $ d191 2 a192 1 LispValue op,leftop,rightop ; @ 1.14 log @stupid syntax fix... @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.13 91/08/16 10:13:16 caetta Exp $ d267 1 a267 1 char *keyword = "aggregate"; @ 1.13 log @to check for non-aggregates as well.. @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.12 91/08/15 18:04:56 caetta Exp $ d268 3 a270 2 LispValue temp, tempstring; if(listp(clause){ d281 1 a281 1 else return(false); @ 1.12 log @for finding agg clauses @ text @d6 1 a6 1 * $Header: planner/util/RCS/clauses.c,v 1.11 91/05/23 18:39:27 kemnitz Exp Locker: caetta $ d268 13 a280 3 LispValue temp; temp = CAR(clause); return !(strcmp(keyword, CString(temp))); @ 1.11 log @got rid of lint warnings "has return(e); and return;" @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.10 90/09/25 16:38:25 kemnitz Exp Locker: kemnitz $ d41 2 d261 12 @ 1.10 log @Updating from revision 1.9 to revision 1.10 @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.10 90/08/14 13:17:39 cimarron Exp $ d87 1 d109 2 a133 1 } d135 2 d138 1 d173 2 d282 1 d367 1 d408 2 d434 2 d496 2 @ 1.9 log @fixes for mergejoins @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.8 89/09/05 17:19:03 mao C_Demo_1 Locker: hong $ d35 1 a35 5 #include "c.h" #include "planner/clauses.h" #include "pg_lisp.h" #include "parse.h" #include "log.h" d37 2 d40 3 @ 1.8 log @Working version of C-only demo @ text @d6 1 a6 1 * $Header: RCS/clauses.c,v 1.7 89/08/23 16:01:33 ong Exp Locker: ong $ d76 1 @ 1.7 log @planner supports all but rules and mergesort @ text @d6 1 a6 1 * $Header: /n/postgres/a/postgres/ong/postgres/src/planner/util/RCS/clauses.c,v 1.6 89/08/04 14:30:29 goh Exp $ @ 1.6 log @reorganised header files @ text @d6 1 a6 1 * $Header: clauses.c,v 1.5 89/08/04 13:29:40 goh Locked $ a73 1 elog(WARN, "calls member"); a95 1 elog(WARN,"clause_args, uses member"); d108 1 a108 1 /* d110 2 a111 2 make_clause (type,rest,args) LispValue type,rest,args ; d117 8 a124 1 elog(WARN,"make_clause, uses member"); d126 3 a128 8 if ( member (type,lispCons(clauseand, lispCons(clauseor, lispCons(clausenot, LispNil)))) || IsA (type,Func) || IsA (type,Oper)) { return(lispCons (type,args)); } else return(args); a129 1 */ d131 1 d438 2 a439 2 return(lispCons (lispInteger(NOT), lispCons(notclause,LispNil))); @ 1.5 log @checkin for retrieve (x.all) @ text @d6 1 a6 1 * $Header: clauses.c,v 1.4 89/08/01 14:32:46 goh Locked $ a32 1 /* require ("nodeDefs");*/ d34 1 a34 1 /* declare (localf (clause_head)); */ d36 1 a36 1 #include "clauses.h" a40 1 extern LispValue clause_head(); @ 1.4 log @retrieve (x=1) checkin @ text @d6 1 a6 1 * $Header: clauses.c,v 1.3 89/07/19 18:43:33 goh Locked $ d39 2 d59 5 a63 5 if ( consp (clause) ) { return(CAR (clause)); } else { return(LispNil); } d75 2 a76 1 d83 1 a83 1 IsA (type,Func) || IsA (type,Oper)) d99 1 d121 2 d166 2 a167 1 return((bool)IsA (clause_head (clause),Oper)); d273 2 a274 1 return((bool)IsA (clause_head (clause),Func)); d356 3 a358 1 return(equal ("OR",clause_head (clause))); d376 1 a376 1 return(lispCons ("OR",orclauses)); d397 2 a398 1 return(CDR (orclause)); d421 2 a422 1 return(equal ("NOT",clause_head (clause))); d440 1 a440 1 return(lispCons (lispString("NOT"), d481 2 a482 1 return(equal ("AND",clause_head (clause))); d499 1 a499 1 return(lispCons ("AND",andclauses)); @ 1.3 log @more fixes, almost Phase III @ text @d6 1 a6 1 * $Header: clauses.c,v 1.2 89/07/19 18:09:55 goh Locked $ d70 14 a83 8 if ( consp (clause) ) { LispValue type = clause_head (clause); if ( member (type,list(AND,OR,NOT)) || func_p (type) || oper_p (type)) return(type); } else return(LispNil); } d85 1 d92 14 a105 7 if ( consp (clause) ) { LispValue type = clause_type (clause); if ( member (type,list(AND,OR,NOT)) || func_p (type) || oper_p (type) ) return(CDR (clause)); } else return(LispNil); d113 12 a124 5 if ( member (type,list(AND,OR,NOT)) || func_p (type) || oper_p (type)) { return(lispCons (type,args)); } else return(args); d160 1 a160 1 return((bool)oper_p (clause_head (clause))); d178 4 a181 1 return(list (op,leftop,rightop)); d183 2 a184 1 return(list (op,leftop)); d266 1 a266 1 return((bool)func_p (clause_head (clause))); d428 2 a429 1 return(list ("NOT",notclause)); d505 15 @ 1.2 log @phase II checkin @ text @d6 1 a6 1 * $Header: clauses.c,v 1.1 89/06/30 11:34:43 goh Locked $ d36 1 d197 1 a197 1 * d200 1 a200 1 LispValue d204 1 a204 1 return(nth (1,clause)); d214 1 a214 1 LispValue d218 1 a218 1 return(nth (2,clause)); @ 1.1 log @Initial revision @ text @d6 1 a6 1 * $Header$ d134 1 a134 1 LispValue d138 1 a138 1 return(oper_p (clause_head (clause))); d171 1 a171 1 LispValue clause ; d236 1 a236 1 LispValue d238 1 a238 1 LispValue clause ; d240 1 a240 1 return(func_p (clause_head (clause))); d315 1 d317 2 a318 1 LispValue d320 1 a320 1 LispValue clause ; d322 1 a322 1 equal ("OR",clause_head (clause)); d380 1 a380 1 LispValue d438 1 a438 1 LispValue d440 1 a440 1 LispValue clause ; @