changing file creation mode from 777 to 644
[csql.git] / include / PredicateImpl.h
blob2dd78d0f2edb26fa8615e4b6751377ac94cbfb10
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef PREDICATE_IMPL_H
17 #define PREDICATE_IMPL_H
18 #include<DataType.h>
19 #include<Predicate.h>
20 #include<ErrorType.h>
21 class TableImpl;
22 class Table;
23 class List;
24 class AggTableImpl;
25 class PredicateImpl:public Predicate
27 //Members set during initialization of the term
28 char fldName1[IDENTIFIER_LENGTH];
29 char fldName2[IDENTIFIER_LENGTH];
30 ComparisionOp compOp;
31 void *operand;
32 void **operandPtr;
33 LogicalOp logicalOp;
34 PredicateImpl *lhs;
35 PredicateImpl *rhs;
36 PredicateImpl *parent;
37 int offset1,offset2;
38 DataType type;
39 int length;
40 bool isNullable;
41 int fldPos;
42 //Members set during execution
43 void *tuple; //pointer to the tuple
44 List *projList;
45 bool isPushedDown;
46 AggType aggType;
48 //optimization:caching val1 and val2 for evaluation
49 char *val1;
50 char *val2;
51 char *val3;
52 bool isBindBufSet;
53 bool isNoLeftRight;
54 bool dontEvaluate;
56 //opt for between queries
57 ComparisionOp comp2Op;
58 void *operand2;
59 void **operand2Ptr;
60 //This will be set before calling evaluate
61 Table *table;
62 bool isNull;
63 public:
64 PredicateImpl()
66 strcpy(fldName1, ""); strcpy(fldName2, "");
67 lhs = rhs = NULL;
68 tuple = NULL; table = NULL;
69 projList = NULL;
70 parent = NULL;
71 offset1 = -1; offset2 =-1;
72 type = typeUnknown; length = 0;
73 isPushedDown=false;
74 isBindBufSet = false;
75 val1= NULL; val2=NULL; val3=NULL;
76 isNoLeftRight=false;
77 dontEvaluate=false;
78 aggType = AGG_UNKNOWN;
79 operand2 = operand = NULL;
80 operand2Ptr = operandPtr= NULL;
81 compOp = comp2Op = OpInvalidComparisionOp;
82 logicalOp = OpInvalidLogicalOp;
83 isNull=false;
85 ~PredicateImpl();
87 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
89 //Operand should be of the same type of the field.This is must
90 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
92 void setTerm(const char* fName1, ComparisionOp op, void **opnd);
93 void setTerm(const char* fName1, ComparisionOp op, void **opnd, AggType aggType);
94 void setTerm(const char* fName1, ComparisionOp op, void **opnd,
95 ComparisionOp op2, void **opnd2 );
98 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
99 void setTerm(const char* fName1, ComparisionOp op,bool nullFlag);
100 void* valPtrForIndexField(const char *name, bool isUnique);
101 ComparisionOp opForIndexField(const char *name);
102 void* opAndValPtrForIndexField(const char *name, bool isUnique,ComparisionOp &op);
103 DbRetVal evaluate(bool &result);
104 void evaluateForTable(bool &result, char*tuple);
105 DbRetVal evaluateForHaving(bool &result, AggTableImpl *aImpl, void* elem);
107 DbRetVal evaluateLogical(bool &result);
108 DbRetVal evaluateLogicalForTable(bool &result, char *tuple);
109 DbRetVal evaluateLogicalForHaving(bool &result, AggTableImpl *aImpl, void* elem);
111 void setTable(Table *tbl);
112 void setTuple(void *tpl);
113 void setProjectionList(List *list); //used by JoinTableImpl
114 void setOffsetAndType();
115 bool isSingleTerm();
116 bool isNotOrInvolved();
117 bool isIsNullInvolved();
118 //check predicate, whether it has field name and == operator
119 //and does not have OR, NOT operator
120 // TODO:: expression like !(f1 !=100) wont be optimized for now
121 bool pointLookupInvolved(const char *fName);
122 bool rangeQueryInvolved(const char *fName);
123 bool isBetweenInvolved(const char *fname);
124 PredicateImpl *getTablePredicate();
125 PredicateImpl *getJoinPredicate();
126 void removeIfNotNecessary();
127 bool isDummyPredicate();
128 PredicateImpl* getIfOneSidedPredicate();
129 void setParent(PredicateImpl *pImpl);
130 char* getFldName1(){ return fldName1; }
131 char* getFldName2(){ return fldName2; }
132 ComparisionOp getCompOp() {return compOp; }
133 void print(int space);
134 void setIfNoLeftRight();
135 void setDontEvaluate(){dontEvaluate = true;}
136 bool appendIfSameFld(char *fname, ComparisionOp op, void* buf);
137 void* getValIfPointLookupOnInt(int &offset);
138 void* getVal1IfBetweenOnInt(int &offset);
139 void* getVal2IfBetweenOnInt(int &offset);
140 void solveForProjList(Table *tab);
143 #endif