Record SPSegment::lookup(TID tid) { // TODO assert(tid.getPage() is part of this segment); BufferFrame frame = bm->fixPage(tid.getPage(), false); SlottedPage* page = reinterpret_cast<SlottedPage*>(frame.getData()); Slot* slot = page->getSlot(tid.getSlot()); if (slot->isMoved()) { // Slot was indirected: Lookup that TID the slot points to recursively. bm->unfixPage(frame, false); return this->lookup(TID(slot->slot)); } else if (slot->length() == 0 && slot->offset() == 0) { // Slot is empty: Return empty record bm->unfixPage(frame, false); return Record(0, nullptr); } else { // Slot has content: Return record with content. bm->unfixPage(frame, false); return Record(slot->length(), slot->getRecord()->getData()); } }
Record SPSegment::inPlaceLookup(TID tid) { // TODO assert(tid.getPage() is part of this segment); BufferFrame frame = bm->fixPage(tid.getPage(), false); SlottedPage* page = reinterpret_cast<SlottedPage*>(frame.getData()); Slot* slot = page->getSlot(tid.getSlot()); if (slot->isMoved() || slot->isEmpty()) { // Slot is empty: Return empty record bm->unfixPage(frame, false); return Record(0, nullptr); } else { // Slot has content: Return record with content. bm->unfixPage(frame, false); return Record(slot->length(), slot->getRecord()->getData()); } }