1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
16 #ifndef PREDICATE_IMPL_H
17 #define PREDICATE_IMPL_H
25 class PredicateImpl
:public Predicate
27 //Members set during initialization of the term
28 char fldName1
[IDENTIFIER_LENGTH
];
29 char fldName2
[IDENTIFIER_LENGTH
];
36 PredicateImpl
*parent
;
42 //Members set during execution
43 void *tuple
; //pointer to the tuple
48 //optimization:caching val1 and val2 for evaluation
56 //opt for between queries
57 ComparisionOp comp2Op
;
60 //This will be set before calling evaluate
66 strcpy(fldName1
, ""); strcpy(fldName2
, "");
68 tuple
= NULL
; table
= NULL
;
71 offset1
= -1; offset2
=-1;
72 type
= typeUnknown
; length
= 0;
75 val1
= NULL
; val2
=NULL
; val3
=NULL
;
78 aggType
= AGG_UNKNOWN
;
79 operand2
= operand
= NULL
;
80 operand2Ptr
= operandPtr
= NULL
;
81 compOp
= comp2Op
= OpInvalidComparisionOp
;
82 logicalOp
= OpInvalidLogicalOp
;
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();
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
);