MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / insertTuple

Method insertTuple

src/java/simpledb/index/BTreeFile.java:531–556  ·  view source on GitHub ↗

Insert a tuple into this BTreeFile, keeping the tuples in sorted order. May cause pages to split if the page where tuple t belongs is full. @param tid - the transaction id @param t - the tuple to insert @return a list of all pages that were dirtied by this operation. Could include many pages since

(TransactionId tid, Tuple t)

Source from the content-addressed store, hash-verified

529 * @see #splitLeafPage(TransactionId, Map, BTreeLeafPage, Field)
530 */
531 public List<Page> insertTuple(TransactionId tid, Tuple t)
532 throws DbException, IOException, TransactionAbortedException {
533 Map<PageId, Page> dirtypages = new HashMap<>();
534
535 // get a read lock on the root pointer page and use it to locate the root page
536 BTreeRootPtrPage rootPtr = getRootPtrPage(tid, dirtypages);
537 BTreePageId rootId = rootPtr.getRootId();
538
539 if(rootId == null) { // the root has just been created, so set the root pointer to point to it
540 rootId = new BTreePageId(tableid, numPages(), BTreePageId.LEAF);
541 rootPtr = (BTreeRootPtrPage) getPage(tid, dirtypages, BTreeRootPtrPage.getId(tableid), Permissions.READ_WRITE);
542 rootPtr.setRootId(rootId);
543 }
544
545 // find and lock the left-most leaf page corresponding to the key field,
546 // and split the leaf page if there are no more slots available
547 BTreeLeafPage leafPage = findLeafPage(tid, dirtypages, rootId, Permissions.READ_WRITE, t.getField(keyField));
548 if(leafPage.getNumEmptySlots() == 0) {
549 leafPage = splitLeafPage(tid, dirtypages, leafPage, t.getField(keyField));
550 }
551
552 // insert the tuple into the leaf page
553 leafPage.insertTuple(t);
554
555 return new ArrayList<>(dirtypages.values());
556 }
557
558 /**
559 * Handle the case when a B+ tree page becomes less than half full due to deletions.

Callers 4

indexIteratorMethod · 0.95
deleteTupleMethod · 0.95
addTupleMethod · 0.95
addDuplicateTuplesMethod · 0.95

Calls 11

getRootPtrPageMethod · 0.95
getRootIdMethod · 0.95
numPagesMethod · 0.95
getPageMethod · 0.95
getIdMethod · 0.95
setRootIdMethod · 0.95
findLeafPageMethod · 0.95
getNumEmptySlotsMethod · 0.95
splitLeafPageMethod · 0.95
insertTupleMethod · 0.95
getFieldMethod · 0.45

Tested by 4

indexIteratorMethod · 0.76
deleteTupleMethod · 0.76
addTupleMethod · 0.76
addDuplicateTuplesMethod · 0.76