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 DllExport 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
47 //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
;
84 lExp
= NULL
; rExp
= NULL
;
88 void setTerm(const char* fName1
, ComparisionOp op
, const char *fName2
);
90 //Operand should be of the same type of the field.This is must
91 void setTerm(const char* fName1
, ComparisionOp op
, void *opnd
);
93 void setTerm(const char* fName1
, ComparisionOp op
, void **opnd
);
94 void setTerm(const char* fName1
, ComparisionOp op
, void **opnd
, AggType aggType
);
95 void setTerm(const char* fName1
, ComparisionOp op
, void **opnd
,
96 ComparisionOp op2
, void **opnd2
);
99 void setTerm(Predicate
*p1
, LogicalOp op
, Predicate
*p2
= NULL
);
100 void setTerm(Expression
*exp
, ComparisionOp op
, void **opnd
);
101 void setTerm(Expression
*exp
, ComparisionOp op
, const char *fName2
);
102 void setTerm(Expression
*exp1
, ComparisionOp op
, Expression
*exp2
);
103 void setTerm(const char* fName1
, ComparisionOp op
,bool nullFlag
);
104 void* valPtrForIndexField(const char *name
, bool isUnique
);
105 ComparisionOp
opForIndexField(const char *name
);
106 void* opAndValPtrForIndexField(const char *name
, bool isUnique
,ComparisionOp
&op
);
107 DbRetVal
evaluate(bool &result
);
108 void evaluateForTable(bool &result
, char*tuple
);
109 DbRetVal
evaluateForHaving(bool &result
, AggTableImpl
*aImpl
, void* elem
);
111 DbRetVal
evaluateLogical(bool &result
);
112 DbRetVal
evaluateLogicalForTable(bool &result
, char *tuple
);
113 DbRetVal
evaluateLogicalForHaving(bool &result
, AggTableImpl
*aImpl
, void* elem
);
115 void setTable(Table
*tbl
);
116 void setTuple(void *tpl
);
117 void setProjectionList(List
*list
); //used by JoinTableImpl
118 void setOffsetAndType();
120 bool isNotOrInvolved();
121 bool isIsNullInvolved();
122 //check predicate, whether it has field name and == operator
123 //and does not have OR, NOT operator
124 // TODO:: expression like !(f1 !=100) wont be optimized for now
125 bool pointLookupInvolved(const char *fName
);
126 bool rangeQueryInvolved(const char *fName
);
127 bool isBetweenInvolved(const char *fname
);
128 PredicateImpl
*getTablePredicate();
129 PredicateImpl
*getJoinPredicate();
130 void removeIfNotNecessary();
131 bool isDummyPredicate();
132 PredicateImpl
* getIfOneSidedPredicate();
133 void setParent(PredicateImpl
*pImpl
);
134 char* getFldName1(){ return fldName1
; }
135 char* getFldName2(){ return fldName2
; }
136 ComparisionOp
getCompOp() {return compOp
; }
137 void print(int space
);
138 void setIfNoLeftRight();
139 void setDontEvaluate(){dontEvaluate
= true;}
140 bool appendIfSameFld(char *fname
, ComparisionOp op
, void* buf
);
141 void* getValIfPointLookupOnInt(int &offset
);
142 void* getVal1IfBetweenOnInt(int &offset
);
143 void* getVal2IfBetweenOnInt(int &offset
);
144 void solveForProjList(Table
*tab
);