00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef Fennel_BTreeSearchExecStream_Included
00025 #define Fennel_BTreeSearchExecStream_Included
00026
00027 #include "fennel/ftrs/BTreeReadExecStream.h"
00028 #include "fennel/exec/ConduitExecStream.h"
00029 #include "fennel/exec/DynamicParam.h"
00030 #include "fennel/common/SearchEndpoint.h"
00031
00032 FENNEL_BEGIN_NAMESPACE
00033
00038 struct FENNEL_FTRS_EXPORT BTreeSearchKeyParameter
00039 {
00043 DynamicParamId dynamicParamId;
00044
00048 uint keyOffset;
00049
00050 BTreeSearchKeyParameter(
00051 DynamicParamId id,
00052 uint offset) :
00053 dynamicParamId(id),
00054 keyOffset(offset)
00055 {
00056 }
00057 };
00058
00063 struct FENNEL_FTRS_EXPORT BTreeSearchExecStreamParams
00064 : public BTreeReadExecStreamParams, public ConduitExecStreamParams
00065 {
00069 bool outerJoin;
00070
00075 TupleProjection inputKeyProj;
00076
00081 TupleProjection inputJoinProj;
00082
00088 TupleProjection inputDirectiveProj;
00089
00094 std::vector<BTreeSearchKeyParameter> searchKeyParams;
00095 };
00096
00105 class FENNEL_FTRS_EXPORT BTreeSearchExecStream
00106 : public BTreeReadExecStream, public ConduitExecStream
00107 {
00111 enum DirectiveOrdinal {
00112 LOWER_BOUND_DIRECTIVE = 0,
00113 UPPER_BOUND_DIRECTIVE = 1
00114 };
00115
00116 protected:
00117 TupleProjectionAccessor inputKeyAccessor;
00118 TupleProjectionAccessor inputJoinAccessor;
00119 TupleProjectionAccessor readerKeyAccessor;
00120 TupleProjectionAccessor directiveAccessor;
00121 TupleProjectionAccessor upperBoundAccessor;
00122 TupleDescriptor inputKeyDesc, upperBoundDesc;
00123 TupleData inputKeyData,upperBoundData,readerKeyData,directiveData,
00124 *pSearchKey;
00125 bool outerJoin;
00126 bool preFilterNulls;
00127 uint nJoinAttributes;
00128 SearchEndpoint lowerBoundDirective;
00129 SearchEndpoint upperBoundDirective;
00130 bool leastUpper;
00131 std::vector<BTreeSearchKeyParameter> searchKeyParams;
00132 boost::scoped_array<FixedBuffer> searchKeyBuffer;
00133 bool dynamicKeysRead;
00134 TupleProjection searchKeyProj, upperBoundKeyProj;
00135
00136 bool innerSearchLoop();
00137 ExecStreamResult innerFetchLoop(
00138 ExecStreamQuantum const &quantum,
00139 uint &nTuples);
00140 void readDirectives();
00141 bool testInterval();
00142
00146 void readSearchKey();
00147
00152 void readUpperBoundKey();
00153
00160 bool checkNextKey();
00161
00169 virtual bool reachedTupleLimit(uint nTuples);
00170
00176 bool searchForKey();
00177
00178 public:
00179
00180 void prepare(BTreeSearchExecStreamParams const ¶ms);
00181 virtual void open(bool restart);
00182 virtual ExecStreamResult execute(ExecStreamQuantum const &quantum);
00183 virtual void closeImpl();
00184 };
00185
00186 FENNEL_END_NAMESPACE
00187
00188 #endif
00189
00190