00001 /* 00002 // $Id: //open/dev/fennel/lucidera/bitmap/LbmSearchExecStream.cpp#7 $ 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 #include "fennel/common/CommonPreamble.h" 00023 #include "fennel/tuple/StandardTypeDescriptor.h" 00024 #include "fennel/lucidera/colstore/LcsClusterNode.h" 00025 #include "fennel/lucidera/bitmap/LbmSearchExecStream.h" 00026 00027 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSearchExecStream.cpp#7 $"); 00028 00029 void LbmSearchExecStream::prepare(LbmSearchExecStreamParams const ¶ms) 00030 { 00031 BTreePrefetchSearchExecStream::prepare(params); 00032 00033 rowLimitParamId = params.rowLimitParamId; 00034 ignoreRowLimit = (rowLimitParamId == DynamicParamId(0)); 00035 if (!ignoreRowLimit) { 00036 // tupledatum for dynamic parameter 00037 rowLimitDatum.pData = (PConstBuffer) &rowLimit; 00038 rowLimitDatum.cbData = sizeof(rowLimit); 00039 } 00040 00041 startRidParamId = params.startRidParamId; 00042 ridInKey = (startRidParamId > DynamicParamId(0)); 00043 if (ridInKey) { 00044 startRidDatum.pData = (PConstBuffer) &startRid; 00045 startRidDatum.cbData = sizeof(startRid); 00046 00047 // add on the rid to the btree search key if the key hasn't already 00048 // been setup 00049 TupleDescriptor ridKeyDesc = inputKeyDesc; 00050 if (inputKeyDesc.size() == treeDescriptor.keyProjection.size() - 1) { 00051 StandardTypeDescriptorFactory stdTypeFactory; 00052 TupleAttributeDescriptor attrDesc( 00053 stdTypeFactory.newDataType(STANDARD_TYPE_RECORDNUM)); 00054 ridKeyDesc.push_back(attrDesc); 00055 ridKeySetup = false; 00056 } else { 00057 assert( 00058 inputKeyDesc.size() == 1 && 00059 inputKeyDesc.size() == treeDescriptor.keyProjection.size()); 00060 ridKeySetup = true; 00061 } 00062 00063 savedLowerBoundAccessor.compute(ridKeyDesc); 00064 ridSearchKeyData.compute(ridKeyDesc); 00065 pfLowerBoundData.compute(ridKeyDesc); 00066 00067 // need to look for greatest lower bound if searching on rid 00068 leastUpper = false; 00069 } 00070 } 00071 00072 bool LbmSearchExecStream::reachedTupleLimit(uint nTuples) 00073 { 00074 if (ignoreRowLimit) { 00075 return false; 00076 } 00077 00078 // read the parameter the first time through 00079 if (nTuples == 0) { 00080 pDynamicParamManager->readParam(rowLimitParamId, rowLimitDatum); 00081 } 00082 // a row limit of 0 indicates that the scan should read till EOS 00083 if (rowLimit == 0) { 00084 return false; 00085 } 00086 return (nTuples >= rowLimit); 00087 } 00088 00089 void LbmSearchExecStream::setAdditionalKeys() 00090 { 00091 if (ridInKey) { 00092 // If the rid key was not setup in farrago, need to copy the keys 00093 // that precede the rid. Also make sure that in this case, the search 00094 // is an equality one. Otherwise, in the case where the key was setup, 00095 // the search is a greater than equal search. 00096 assert(lowerBoundDirective == SEARCH_CLOSED_LOWER); 00097 if (ridKeySetup) { 00098 assert(upperBoundDirective == SEARCH_UNBOUNDED_UPPER); 00099 } else { 00100 assert(upperBoundDirective == SEARCH_CLOSED_UPPER); 00101 00102 for (uint i = 0; i < inputKeyData.size(); i++) { 00103 ridSearchKeyData[i] = inputKeyData[i]; 00104 } 00105 } 00106 // rid is the last key; note that this needs to be reset each time 00107 // because the rid key value originates from a dynamic parameter 00108 // rather than the key buffer passed into setLowerBoundKey() 00109 ridSearchKeyData[ridSearchKeyData.size() - 1].pData = 00110 (PConstBuffer) &startRid; 00111 pDynamicParamManager->readParam(startRidParamId, startRidDatum); 00112 pSearchKey = &ridSearchKeyData; 00113 00114 } else { 00115 pSearchKey = &inputKeyData; 00116 } 00117 } 00118 00119 void LbmSearchExecStream::setLowerBoundKey(PConstBuffer buf) 00120 { 00121 savedLowerBoundAccessor.setCurrentTupleBuf(buf); 00122 if (ridInKey) { 00123 savedLowerBoundAccessor.unmarshal(ridSearchKeyData); 00124 pSearchKey = &ridSearchKeyData; 00125 } else { 00126 savedLowerBoundAccessor.unmarshal(inputKeyData); 00127 pSearchKey = &inputKeyData; 00128 } 00129 } 00130 00131 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/lucidera/bitmap/LbmSearchExecStream.cpp#7 $"); 00132 00133 // End LbmSearchExecStream.cpp