performance fixes
[csql.git] / include / PredicateImpl.h
blob15d5bdb05833e79dc5118c63e47163248b385f68
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 PredicateImpl:public Predicate
26 //Members set during initialization of the term
27 char fldName1[IDENTIFIER_LENGTH];
28 char fldName2[IDENTIFIER_LENGTH];
29 ComparisionOp compOp;
30 void *operand;
31 void **operandPtr;
32 LogicalOp logicalOp;
33 PredicateImpl *lhs;
34 PredicateImpl *rhs;
35 PredicateImpl *parent;
36 int offset1,offset2;
37 DataType type;
38 int length;
39 //Members set during execution
40 void *tuple; //pointer to the tuple
41 List *projList;
42 bool isPushedDown;
44 //optimization:caching val1 and val2 for evaluation
45 char *val1;
46 char *val2;
47 char *val3;
48 bool isBindBufSet;
49 bool isNoLeftRight;
50 bool dontEvaluate;
52 //opt for between queries
53 ComparisionOp comp2Op;
54 void *operand2;
55 void **operand2Ptr;
56 //This will be set before calling evaluate
57 TableImpl *table;
59 public:
60 PredicateImpl()
62 strcpy(fldName1, ""); strcpy(fldName2, "");
63 operand = NULL; operandPtr = NULL; lhs = rhs = NULL;
64 tuple = NULL; table = NULL;
65 projList = NULL;
66 parent = NULL;
67 offset1 = -1; offset2 =-1;
68 type = typeUnknown;
69 length = 0;
70 isPushedDown=false;
71 isBindBufSet = false;
72 val1= NULL;
73 val2=NULL;
74 val3=NULL;
75 isNoLeftRight=false;
76 dontEvaluate=false;
78 ~PredicateImpl(){}
80 void setTerm(const char* fName1, ComparisionOp op, const char *fName2);
82 //Operand should be of the same type of the field.This is must
83 void setTerm(const char* fName1, ComparisionOp op, void *opnd);
85 void setTerm(const char* fName1, ComparisionOp op, void **opnd);
86 void setTerm(const char* fName1, ComparisionOp op, void **opnd,
87 ComparisionOp op2, void **opnd2 );
90 void setTerm(Predicate *p1, LogicalOp op, Predicate *p2 = NULL);
92 void* valPtrForIndexField(const char *name);
93 ComparisionOp opForIndexField(const char *name);
95 DbRetVal evaluate(bool &result);
96 void evaluateForTable(bool &result, char*tuple);
98 DbRetVal evaluateLogical(bool &result);
99 DbRetVal evaluateLogicalForTable(bool &result, char *tuple);
101 void setTable(Table *tbl);
102 void setTuple(void *tpl);
103 void setProjectionList(List *list); //used by JoinTableImpl
104 void setOffsetAndType();
105 bool isSingleTerm();
106 bool isNotOrInvolved();
107 //check predicate, whether it has field name and == operator
108 //and does not have OR, NOT operator
109 // TODO:: expression like !(f1 !=100) wont be optimized for now
110 bool pointLookupInvolved(const char *fName);
111 bool rangeQueryInvolved(const char *fName);
112 bool isBetweenInvolved(const char *fname);
113 PredicateImpl *getTablePredicate();
114 PredicateImpl *getJoinPredicate();
115 void removeIfNotNecessary();
116 bool isDummyPredicate();
117 PredicateImpl* getIfOneSidedPredicate();
118 void setParent(PredicateImpl *pImpl);
119 char* getFldName1(){ return fldName1; }
120 char* getFldName2(){ return fldName2; }
121 ComparisionOp getCompOp() {return compOp; }
122 void print(int space);
123 void setIfNoLeftRight();
124 void setDontEvaluate(){dontEvaluate = true;}
125 bool appendIfSameFld(char *fname, ComparisionOp op, void* buf);
128 #endif