Skip to content

Commit

Permalink
Use the correct fill factor for splits.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauzo committed Dec 3, 2011
1 parent 15c7db9 commit 6779850
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions btree.sql
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ CREATE FUNCTION insert(
n.ks := n.ks[1:n.ix-1] || k || n.ks[n.ix:n.nk];
n := reset(n);

IF n.nk < 8 THEN
IF n.nk < m.fill THEN
PERFORM update(n);
ELSE
s.ks := n.ks[1:4];
s.ks := n.ks[1:m.fill/2];
s.leaf := n.leaf;
n.ks := n.ks[5:8];
n.ks := n.ks[(m.fill/2 + 1):m.fill];

s := update(s);
n := update(n);
Expand Down
17 changes: 17 additions & 0 deletions t/btree.pg
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,22 @@ SELECT btree_is(11, 8, $$
(11, '{10,17,1}', false)
$$, 'overflow splits rather than stealing');

SELECT reset_btree(256);
SELECT btree_is(1, 256, $$
(1, '{}', true)
$$, 'initial btree (order 256)');

SELECT perform(insert(null)) FROM generate_series(1,255);
SELECT bag_eq(
$$ SELECT id FROM btree $$,
$$ VALUES (0), (1) $$,
'order-256 btree will take 255 values without splitting');

SELECT perform(insert(null));
SELECT bag_eq(
$$ SELECT id FROM btree $$,
$$ VALUES (0), (1), (258), (259) $$,
'order-256 btree splits at 256 entries');

SELECT * FROM finish();
ROLLBACK;

0 comments on commit 6779850

Please sign in to comment.