Delete a tuple from this BTreeFile. May cause pages to merge or redistribute entries/tuples if the pages become less than half full. @param tid - the transaction id @param t - the tuple to delete @return a list of all pages that were dirtied by this operation. Could include many pages since parent
(TransactionId tid, Tuple t)
| 1049 | * @see #handleMinOccupancyPage(TransactionId, Map, BTreePage) |
| 1050 | */ |
| 1051 | public List<Page> deleteTuple(TransactionId tid, Tuple t) |
| 1052 | throws DbException, IOException, TransactionAbortedException { |
| 1053 | Map<PageId, Page> dirtypages = new HashMap<>(); |
| 1054 | |
| 1055 | BTreePageId pageId = new BTreePageId(tableid, t.getRecordId().getPageId().getPageNumber(), |
| 1056 | BTreePageId.LEAF); |
| 1057 | BTreeLeafPage page = (BTreeLeafPage) getPage(tid, dirtypages, pageId, Permissions.READ_WRITE); |
| 1058 | page.deleteTuple(t); |
| 1059 | |
| 1060 | // if the page is below minimum occupancy, get some tuples from its siblings |
| 1061 | // or merge with one of the siblings |
| 1062 | int maxEmptySlots = page.getMaxTuples() - page.getMaxTuples()/2; // ceiling |
| 1063 | if(page.getNumEmptySlots() > maxEmptySlots) { |
| 1064 | handleMinOccupancyPage(tid, dirtypages, page); |
| 1065 | } |
| 1066 | |
| 1067 | return new ArrayList<>(dirtypages.values()); |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * Get a read lock on the root pointer page. Create the root pointer page and root page |