00001 /* 00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmGeneratorExecStream.h#15 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2006-2009 LucidEra, Inc. 00005 // Copyright (C) 2006-2009 The Eigenbase Project 00006 // 00007 // This program is free software; you can redistribute it and/or modify it 00008 // under the terms of the GNU General Public License as published by the Free 00009 // Software Foundation; either version 2 of the License, or (at your option) 00010 // any later version approved by The Eigenbase Project. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef Fennel_LbmGeneratorExecStream_Included 00023 #define Fennel_LbmGeneratorExecStream_Included 00024 00025 #include "fennel/tuple/TupleDataWithBuffer.h" 00026 #include "fennel/exec/DynamicParam.h" 00027 #include "fennel/lucidera/colstore/LcsRowScanBaseExecStream.h" 00028 #include "fennel/lucidera/bitmap/LbmEntry.h" 00029 00030 FENNEL_BEGIN_NAMESPACE 00031 00032 enum LbmPendingProduceType { 00033 LBM_TABLEFLUSH_PENDING, 00034 LBM_ENTRYFLUSH_PENDING, 00035 LBM_NOFLUSH_PENDING 00036 }; 00037 00042 struct LbmEntryInfo 00043 { 00044 SharedLbmEntry pBitmap; 00045 00049 PBuffer bufferPtr; 00050 00054 bool inuse; 00055 }; 00056 00057 struct LbmGeneratorExecStreamParams : 00058 public BTreeExecStreamParams, public LcsRowScanBaseExecStreamParams 00059 { 00064 DynamicParamId insertRowCountParamId; 00065 00070 bool createIndex; 00071 }; 00072 00092 class FENNEL_LBM_EXPORT LbmGeneratorExecStream 00093 : public BTreeExecStream, LcsRowScanBaseExecStream 00094 { 00099 uint numMiscScratchPages; 00100 00105 uint maxNumScratchPages; 00106 00110 DynamicParamId insertRowCountParamId; 00111 00115 bool createIndex; 00116 00121 std::vector<DynamicParamId> parameterIds; 00122 00126 uint scratchPageSize; 00127 00131 uint entrySize; 00132 00136 uint maxBitmapSize; 00137 00141 uint minBitmapSize; 00142 00146 ClusterPageLock scratchLock; 00147 00151 TupleData inputTuple; 00152 00156 RecordNum numRowsToLoad; 00157 00161 RecordNum rowCount; 00162 00166 LcsRid startRid; 00167 00171 LcsRid currRid; 00172 00176 TupleDataWithBuffer bitmapTuple; 00177 00181 TupleDescriptor bitmapTupleDesc; 00182 00186 TupleData outputTuple; 00187 00191 uint nIdxKeys; 00192 00196 bool batchRead; 00197 00201 uint currBatch; 00202 00206 std::vector<uint16_t> keyCodes; 00207 00211 std::vector<LbmEntryInfo> bitmapTable; 00212 00216 uint nBitmapEntries; 00217 00221 uint flushIdx; 00222 00226 uint nBitmapBuffers; 00227 00231 uint nScratchPagesAllocated; 00232 00236 std::vector<PBuffer> scratchPages; 00237 00242 LbmPendingProduceType producePending; 00243 00248 uint flushStart; 00249 00254 bool skipRead; 00255 00259 bool doneReading; 00260 00266 bool revertToSingletons; 00267 00275 ExecStreamResult generateSingleKeyBitmaps(ExecStreamQuantum const &quantum); 00276 00284 ExecStreamResult generateMultiKeyBitmaps(ExecStreamQuantum const &quantum); 00285 00290 void createSingletonBitmapEntry(); 00291 00299 bool generateBitmaps(); 00300 00308 bool generateSingletons(); 00309 00319 bool advanceReader(SharedLcsClusterReader &pScan); 00320 00331 bool initBitmapTable(uint nEntries); 00332 00341 void initRidAndBitmap(TupleData &bitmapTuple, LcsRid* pCurrRid); 00342 00359 bool addRidToBitmap(uint keycode, TupleData &keyvalue, LcsRid rid); 00360 00370 PBuffer flushBuffer(LcsRid addRid); 00371 00380 bool flushTable(uint start); 00381 00390 bool flushEntry(uint keycode); 00391 00392 public: 00393 virtual void prepare(LbmGeneratorExecStreamParams const ¶ms); 00394 virtual void open(bool restart); 00395 virtual ExecStreamResult execute(ExecStreamQuantum const &quantum); 00396 virtual void getResourceRequirements( 00397 ExecStreamResourceQuantity &minQuantity, 00398 ExecStreamResourceQuantity &optQuantity, 00399 ExecStreamResourceSettingType &optType); 00400 virtual void setResourceAllocation(ExecStreamResourceQuantity &quantity); 00401 virtual void closeImpl(); 00402 }; 00403 00404 FENNEL_END_NAMESPACE 00405 00406 #endif 00407 00408 // End LbmGeneratorExecStream.h