|
|
@ -7104,45 +7104,38 @@ mdb_node_shrink(MDB_page *mp, indx_t indx) |
|
|
|
MDB_node *node; |
|
|
|
MDB_node *node; |
|
|
|
MDB_page *sp, *xp; |
|
|
|
MDB_page *sp, *xp; |
|
|
|
char *base; |
|
|
|
char *base; |
|
|
|
int nsize, delta; |
|
|
|
indx_t delta, nsize, len, ptr; |
|
|
|
indx_t i, numkeys, ptr; |
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
node = NODEPTR(mp, indx); |
|
|
|
node = NODEPTR(mp, indx); |
|
|
|
sp = (MDB_page *)NODEDATA(node); |
|
|
|
sp = (MDB_page *)NODEDATA(node); |
|
|
|
delta = SIZELEFT(sp); |
|
|
|
delta = SIZELEFT(sp); |
|
|
|
xp = (MDB_page *)((char *)sp + delta); |
|
|
|
nsize = NODEDSZ(node) - delta; |
|
|
|
|
|
|
|
|
|
|
|
/* shift subpage upward */ |
|
|
|
/* Prepare to shift upward, set len = length(subpage part to shift) */ |
|
|
|
if (IS_LEAF2(sp)) { |
|
|
|
if (IS_LEAF2(sp)) { |
|
|
|
nsize = NUMKEYS(sp) * sp->mp_pad; |
|
|
|
len = nsize; |
|
|
|
if (nsize & 1) |
|
|
|
if (nsize & 1) |
|
|
|
return; /* do not make the node uneven-sized */ |
|
|
|
return; /* do not make the node uneven-sized */ |
|
|
|
memmove(METADATA(xp), METADATA(sp), nsize); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
int i; |
|
|
|
xp = (MDB_page *)((char *)sp + delta); /* destination subpage */ |
|
|
|
numkeys = NUMKEYS(sp); |
|
|
|
for (i = NUMKEYS(sp); --i >= 0; ) |
|
|
|
for (i=numkeys-1; i>=0; i--) |
|
|
|
|
|
|
|
xp->mp_ptrs[i] = sp->mp_ptrs[i] - delta; |
|
|
|
xp->mp_ptrs[i] = sp->mp_ptrs[i] - delta; |
|
|
|
|
|
|
|
len = PAGEHDRSZ; |
|
|
|
} |
|
|
|
} |
|
|
|
xp->mp_upper = sp->mp_lower; |
|
|
|
sp->mp_upper = sp->mp_lower; |
|
|
|
xp->mp_lower = sp->mp_lower; |
|
|
|
COPY_PGNO(sp->mp_pgno, mp->mp_pgno); |
|
|
|
xp->mp_flags = sp->mp_flags; |
|
|
|
|
|
|
|
xp->mp_pad = sp->mp_pad; |
|
|
|
|
|
|
|
COPY_PGNO(xp->mp_pgno, mp->mp_pgno); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsize = NODEDSZ(node) - delta; |
|
|
|
|
|
|
|
SETDSZ(node, nsize); |
|
|
|
SETDSZ(node, nsize); |
|
|
|
|
|
|
|
|
|
|
|
/* shift lower nodes upward */ |
|
|
|
/* Shift <lower nodes...initial part of subpage> upward */ |
|
|
|
|
|
|
|
base = (char *)mp + mp->mp_upper + PAGEBASE; |
|
|
|
|
|
|
|
memmove(base + delta, base, (char *)sp + len - base); |
|
|
|
|
|
|
|
|
|
|
|
ptr = mp->mp_ptrs[indx]; |
|
|
|
ptr = mp->mp_ptrs[indx]; |
|
|
|
numkeys = NUMKEYS(mp); |
|
|
|
for (i = NUMKEYS(mp); --i >= 0; ) { |
|
|
|
for (i = 0; i < numkeys; i++) { |
|
|
|
|
|
|
|
if (mp->mp_ptrs[i] <= ptr) |
|
|
|
if (mp->mp_ptrs[i] <= ptr) |
|
|
|
mp->mp_ptrs[i] += delta; |
|
|
|
mp->mp_ptrs[i] += delta; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
base = (char *)mp + mp->mp_upper + PAGEBASE; |
|
|
|
|
|
|
|
memmove(base + delta, base, ptr - mp->mp_upper + NODESIZE + NODEKSZ(node)); |
|
|
|
|
|
|
|
mp->mp_upper += delta; |
|
|
|
mp->mp_upper += delta; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|