This commit is contained in:
Hongze Cheng 2022-03-23 08:21:09 +00:00
parent 7b89447239
commit 09833d2244
1 changed files with 32 additions and 17 deletions

View File

@ -710,28 +710,43 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
if (nNewCells < infoNews[iNew].cnt) { if (nNewCells < infoNews[iNew].cnt) {
tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0); tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0);
nNewCells++; nNewCells++;
// insert parent page
if (!childNotLeaf && nNewCells == infoNews[iNew].cnt) {
SIntHdr *pIntHdr = (SIntHdr *)pParent->pData;
if (iNew == nNews - 1 && pIntHdr->pgno == 0) {
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]);
} else { } else {
if (childNotLeaf) { // TODO:
// Insert to parent ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]);
// TODO: pCell here may be inserted as an overflow cell, handle it
tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0);
}
// move to next new page
iNew++;
nNews = 0;
}
} else {
ASSERT(childNotLeaf);
// set current new page right-most child // set current new page right-most child
((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0]; ((SIntHdr *)pNews[iNew]->pData)->pgno = ((SPgno *)pCell)[0];
// move to next new page // insert to parent as divider cell
iNew++; SIntHdr *pIntHdr = (SIntHdr *)pParent->pData;
nNewCells = 0;
if (iNew == nNews - 1 && pIntHdr->pgno == 0) {
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]);
} else { } else {
// TODO: Insert to parent max key and current page number or the right most child ((SPgno *)pCell)[0] = TDB_PAGE_PGNO(pNews[iNew]);
tdbPageInsertCell(pParent, sIdx++, pCell, szCell, 0);
}
// move to next new page // move to next new page
iNew++; iNew++;
nNewCells = 0; nNewCells = 0;
// insert the cell to the new page
ASSERT(nNewCells < infoNews[iNew].cnt);
tdbPageInsertCell(pNews[iNew], nNewCells, pCell, szCell, 0);
nNewCells++;
}
} }
} }
} }