use of org.apache.hyracks.storage.am.common.ophelpers.FindTupleMode in project asterixdb by apache.
the class BTreeNSMInteriorFrame method getChildPageId.
@Override
public int getChildPageId(RangePredicate pred) throws HyracksDataException {
// Trivial case where there is only a child pointer (and no key).
if (buf.getInt(Constants.TUPLE_COUNT_OFFSET) == 0) {
return buf.getInt(RIGHT_LEAF_OFFSET);
}
// Trivial cases where no low key or high key was given (e.g. during an
// index scan).
ITupleReference tuple = null;
FindTupleMode fsm = null;
// The target comparator may be on a prefix of the BTree key fields.
MultiComparator targetCmp = pred.getLowKeyComparator();
tuple = pred.getLowKey();
if (tuple == null) {
return getLeftmostChildPageId();
}
if (pred.isLowKeyInclusive()) {
fsm = FindTupleMode.INCLUSIVE;
} else {
fsm = FindTupleMode.EXCLUSIVE;
}
// Search for a matching key.
int tupleIndex = slotManager.findTupleIndex(tuple, frameTuple, targetCmp, fsm, FindTupleNoExactMatchPolicy.HIGHER_KEY);
int slotOff = slotManager.getSlotOff(tupleIndex);
// Follow the rightmost (greatest) child pointer.
if (tupleIndex == slotManager.getGreatestKeyIndicator()) {
return buf.getInt(RIGHT_LEAF_OFFSET);
}
// Deal with prefix searches.
// slotManager.findTupleIndex() will return an arbitrary tuple matching
// the given field prefix (according to the target comparator).
// To make sure we traverse the right path, we must find the
// leftmost or rightmost tuple that matches the prefix.
int origTupleOff = slotManager.getTupleOff(slotOff);
cmpFrameTuple.resetByTupleOffset(buf.array(), origTupleOff);
int cmpTupleOff = origTupleOff;
// The answer set begins with the lowest key matching the prefix.
// We must follow the child pointer of the lowest (leftmost) key
// matching the given prefix.
int maxSlotOff = buf.capacity();
slotOff += slotManager.getSlotSize();
while (slotOff < maxSlotOff) {
cmpTupleOff = slotManager.getTupleOff(slotOff);
frameTuple.resetByTupleOffset(buf.array(), cmpTupleOff);
if (targetCmp.compare(cmpFrameTuple, frameTuple) != 0) {
break;
}
slotOff += slotManager.getSlotSize();
}
slotOff -= slotManager.getSlotSize();
frameTuple.resetByTupleOffset(buf.array(), slotManager.getTupleOff(slotOff));
int childPageOff = getLeftChildPageOff(frameTuple);
return buf.getInt(childPageOff);
}
Aggregations