00001 /* 00002 // $Id: //open/dev/fennel/lucidera/colstore/LcsClusterReader.h#11 $ 00003 // Fennel is a library of data storage and processing components. 00004 // Copyright (C) 2005-2009 LucidEra, Inc. 00005 // Copyright (C) 2005-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_LcsClusterReader_Included 00023 #define Fennel_LcsClusterReader_Included 00024 00025 #include "fennel/lucidera/colstore/LcsClusterAccessBase.h" 00026 #include "fennel/lucidera/colstore/LcsClusterNode.h" 00027 #include "fennel/lucidera/colstore/LcsColumnReader.h" 00028 #include "fennel/btree/BTreeReader.h" 00029 #include "fennel/tuple/TupleDescriptor.h" 00030 #include "fennel/segment/SegPageEntryIter.h" 00031 #include "fennel/segment/SegPageEntryIterSource.h" 00032 #include <boost/scoped_array.hpp> 00033 00034 FENNEL_BEGIN_NAMESPACE 00035 00039 struct LcsRidRun 00040 { 00044 LcsRid startRid; 00045 00050 RecordNum nRids; 00051 }; 00052 00084 class FENNEL_LCS_EXPORT LcsClusterReader : 00085 public LcsClusterAccessBase, public SegPageEntryIterSource<LcsRid> 00086 { 00087 friend class LcsColumnReader; 00088 00092 SharedBTreeReader bTreeReader; 00093 00097 PLcsBatchDir pRangeBatches; 00098 00102 LcsRid rangeStartRid; 00103 00107 LcsRid rangeEndRid; 00108 00112 uint nRangePos; 00113 00117 PBuffer pLeaf; 00118 00122 PConstLcsClusterNode pLHdr; 00123 00127 PLcsBatchDir pBatches; 00128 00132 bool noPrefetch; 00133 00137 CircularBufferIter<LcsRidRun> ridRunIter; 00138 00142 SegPageEntryIter<LcsRid> prefetchQueue; 00143 00147 LcsRid nextRid; 00148 00153 std::pair<PageId, LcsRid> nextBTreeEntry; 00154 00158 std::pair<PageId, LcsRid> nextPrefetchEntry; 00159 00163 bool dumbPrefetch; 00164 00168 LcsRid currRid; 00169 00176 void moveToBlock(PageId clusterPageId); 00177 00186 bool moveToBlockWithRid(LcsRid rid); 00187 00196 bool positionInBlock(LcsRid rid); 00197 00203 void positionInRange(uint pos) 00204 { 00205 nRangePos = pos; 00206 } 00207 00212 void setUpBlock(); 00213 00219 LcsClusterNode const &readClusterPage(); 00220 00227 bool searchForRid(LcsRid rid); 00228 00232 void getNextBTreeEntry(); 00233 00234 public: 00238 uint nColsToRead; 00239 00243 boost::scoped_array<LcsColumnReader> clusterCols; 00244 00253 explicit LcsClusterReader( 00254 BTreeDescriptor const &treeDescriptor, 00255 CircularBuffer<LcsRidRun> *pRidRuns = NULL); 00256 00257 virtual ~LcsClusterReader(); 00258 00265 void setRootPageId(PageId rootPageId); 00266 00275 void initColumnReaders( 00276 uint nClusterColsInit, 00277 TupleProjection const &clusterProj); 00278 00282 void open(); 00283 00287 void close(); 00288 00296 bool getFirstClusterPageForRead(PConstLcsClusterNode &pBlock); 00297 00305 bool getNextClusterPageForRead(PConstLcsClusterNode &pBlock); 00306 00310 inline bool isPositioned() const; 00311 00315 inline LcsRid getRangeStartRid() const; 00316 00320 inline LcsRid getRangeEndRid() const; 00321 00325 inline uint getRangeSize() const; 00326 00331 inline uint getRangePos() const; 00332 00336 inline LcsRid getCurrentRid() const; 00337 00342 inline uint getRangeRowsLeft() const; 00343 00351 bool position(LcsRid rid); 00352 00356 inline bool nextRange(); 00357 00366 bool advance(uint nRids); 00367 00373 inline void advanceWithinBatch(uint nRids); 00374 00386 virtual PageId getNextPageForPrefetch(LcsRid &rid, bool &found); 00387 00403 static LcsRid getFetchRids( 00404 CircularBufferIter<LcsRidRun> &ridRunIter, 00405 LcsRid &nextRid, 00406 bool remove); 00407 00416 void catchUp(uint parentBufPos, LcsRid parentNextRid); 00417 00421 RecordNum getNumRows(); 00422 }; 00423 00424 inline bool LcsClusterReader::isPositioned() const 00425 { 00426 return pRangeBatches != NULL; 00427 } 00428 00429 inline LcsRid LcsClusterReader::getRangeStartRid() const 00430 { 00431 return rangeStartRid; 00432 } 00433 00434 inline LcsRid LcsClusterReader::getRangeEndRid() const 00435 { 00436 return rangeEndRid; 00437 } 00438 00439 inline uint LcsClusterReader::getRangeSize() const 00440 { 00441 return pRangeBatches->nRow; 00442 } 00443 00444 inline uint LcsClusterReader::getRangePos() const 00445 { 00446 return nRangePos; 00447 } 00448 00449 inline LcsRid LcsClusterReader::getCurrentRid() const 00450 { 00451 return getRangeStartRid() + getRangePos(); 00452 } 00453 00454 inline uint LcsClusterReader::getRangeRowsLeft() const 00455 { 00456 return getRangeSize() - getRangePos(); 00457 } 00458 00459 inline bool LcsClusterReader::nextRange() 00460 { 00461 return position(getRangeEndRid()); 00462 } 00463 00464 inline void LcsClusterReader::advanceWithinBatch(uint nRids) 00465 { 00466 nRangePos = nRangePos + nRids; 00467 } 00468 00469 FENNEL_END_NAMESPACE 00470 00471 #endif 00472 00473 // End LcsClusterReader.h