00001 /* 00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmSplicerExecStream.h#16 $ 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_LbmSplicerExecStream_Included 00023 #define Fennel_LbmSplicerExecStream_Included 00024 00025 #include "fennel/btree/BTreeWriter.h" 00026 #include "fennel/ftrs/BTreeExecStream.h" 00027 #include "fennel/exec/DiffluenceExecStream.h" 00028 #include "fennel/exec/DynamicParam.h" 00029 #include "fennel/tuple/TupleAccessor.h" 00030 #include "fennel/tuple/TupleData.h" 00031 #include "fennel/tuple/TupleDataWithBuffer.h" 00032 #include "fennel/segment/SnapshotRandomAllocationSegment.h" 00033 #include "fennel/lucidera/bitmap/LbmEntry.h" 00034 #include "fennel/lucidera/bitmap/LbmRidReader.h" 00035 #include <boost/scoped_array.hpp> 00036 00037 FENNEL_BEGIN_NAMESPACE 00038 00039 struct LbmSplicerExecStreamParams : public DiffluenceExecStreamParams 00040 { 00041 std::vector<BTreeParams> bTreeParams; 00042 00043 DynamicParamId insertRowCountParamId; 00044 00045 DynamicParamId writeRowCountParamId; 00046 00047 bool createNewIndex; 00048 }; 00049 00078 class FENNEL_LBM_EXPORT LbmSplicerExecStream 00079 : public DiffluenceExecStream 00080 { 00084 SegmentAccessor scratchAccessor; 00085 00089 BTreeDescriptor writeBTreeDesc; 00090 00094 BTreeDescriptor deletionBTreeDesc; 00095 00099 DynamicParamId insertRowCountParamId; 00100 00104 bool createNewIndex; 00105 00112 bool newIndexCreated; 00113 00118 DynamicParamId writeRowCountParamId; 00119 00123 uint maxEntrySize; 00124 00128 boost::scoped_array<FixedBuffer> bitmapBuffer; 00129 00133 boost::scoped_array<FixedBuffer> mergeBuffer; 00134 00138 SharedLbmEntry pCurrentEntry; 00139 00143 bool currEntry; 00144 00149 bool currExistingEntry; 00150 00154 LcsRid currBTreeStartRid; 00155 00163 bool emptyTableUnknown; 00164 00169 bool emptyTable; 00170 00174 SharedBTreeWriter bTreeWriter; 00175 00182 bool bTreeWriterMoved; 00183 00187 bool isDone; 00188 00192 TupleData inputTuple; 00193 00198 TupleData singletonTuple; 00199 00203 TupleData outputTuple; 00204 00208 RecordNum numRowsLoaded; 00209 00213 TupleData bTreeTupleData; 00214 TupleData tempBTreeTupleData; 00215 00219 TupleDescriptor bitmapTupleDesc; 00220 00224 uint nIdxKeys; 00225 00230 bool computeRowCount; 00231 00235 bool uniqueKey; 00236 00240 bool currValidation; 00241 00245 bool firstValidation; 00246 00250 TupleDataWithBuffer currUniqueKey; 00251 00256 uint nKeyRows; 00257 00261 LbmDeletionIndexReader deletionReader; 00262 00266 TupleData deletionTuple; 00267 00271 LbmTupleRidReader inputRidReader; 00272 00277 bool nullUpsertRid; 00278 00283 LcsRid upsertRid; 00284 00288 SharedExecStreamBufAccessor violationAccessor; 00289 00293 TupleData violationTuple; 00294 00298 std::string errorMsg; 00299 00303 TupleDescriptor errorDesc; 00304 00308 TupleData errorTuple; 00309 00314 SnapshotRandomAllocationSegment *pSnapshotSegment; 00315 00320 PageId origRootPageId; 00321 00326 bool isEmpty(); 00327 00342 bool existingEntry(TupleData const &bitmapEntry); 00343 00360 bool findMatchingBTreeEntry( 00361 TupleData const &bitmapEntry, 00362 TupleData &bTreeTupleData, 00363 bool leastUpper); 00364 00379 bool findBTreeEntry( 00380 TupleData const &bitmapEntry, 00381 TupleData &bTreeTupleData); 00382 00395 bool ridOverlaps(LcsRid rid, TupleData &bitmapTupleData, bool firstByte); 00396 00405 void findBetterEntry(TupleData const &bitmapEntry); 00406 00415 void spliceEntry(TupleData &bitmapEntry); 00416 00420 void insertBitmapEntry(); 00421 00428 void createNewBitmapEntry(TupleData const &bitmapEntry); 00429 00435 void upsertSingleton(TupleData const &bitmapEntry); 00436 00446 ExecStreamResult getValidatedTuple(); 00447 00457 bool uniqueRequired(const TupleData &tuple); 00458 00467 uint countKeyRows(const TupleData &tuple); 00468 00475 inline void setUpsertRid(LcsRid rid); 00476 00483 inline const LcsRid *getUpsertRidPtr() const; 00484 00492 void postViolation(const TupleData &input, const TupleData &violation); 00493 00494 public: 00495 virtual void prepare(LbmSplicerExecStreamParams const ¶ms); 00496 virtual void open(bool restart); 00497 virtual ExecStreamResult execute(ExecStreamQuantum const &quantum); 00498 virtual void getResourceRequirements( 00499 ExecStreamResourceQuantity &minQuantity, 00500 ExecStreamResourceQuantity &optQuantity); 00501 virtual void closeImpl(); 00502 }; 00503 00504 /************************************************************** 00505 Definitions of inline methods for class LbmSplicerExecStream 00506 ***************************************************************/ 00507 00508 inline void LbmSplicerExecStream::setUpsertRid(LcsRid rid) 00509 { 00510 nullUpsertRid = false; 00511 upsertRid = rid; 00512 } 00513 00514 inline const LcsRid *LbmSplicerExecStream::getUpsertRidPtr() const 00515 { 00516 return (nullUpsertRid ? NULL : &upsertRid); 00517 } 00518 00519 FENNEL_END_NAMESPACE 00520 00521 #endif 00522 00523 // End LbmSplicerExecStream.h