B-tree index balance?

Started by Ronabout 2 years ago3 messagesgeneral
Jump to latest
#1Ron
ronljohnsonjr@gmail.com

On an RDMS which I used in the 1990s and 2000s, b-tree indices of sequences
would get unbalanced, since every new leaf was added to the far right
corner of the tree.
Sure, they would auto-balance *to a degree* during node splits, but all
those "far-right corner" inserts still left them pretty lopsided.
Thus, they provided a utility which we could use to determine the
lopsidedness, and thus decide when to rebuild an index.

Does Postgresql keep b-tree indexes on sequences fully balanced? If not,
how do I see how unbalanced they are? (Assume PG12+.)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ron (#1)
Re: B-tree index balance?

Ron Johnson <ronljohnsonjr@gmail.com> writes:

On an RDMS which I used in the 1990s and 2000s, b-tree indices of sequences
would get unbalanced, since every new leaf was added to the far right
corner of the tree.
Sure, they would auto-balance *to a degree* during node splits, but all
those "far-right corner" inserts still left them pretty lopsided.
Thus, they provided a utility which we could use to determine the
lopsidedness, and thus decide when to rebuild an index.

Does Postgresql keep b-tree indexes on sequences fully balanced? If not,
how do I see how unbalanced they are? (Assume PG12+.)

As far as I know, we don't have a problem of that sort. Continued
insertions will eventually force a split of the root node, which will
rebalance the tree.

regards, tom lane

#3Ron
ronljohnsonjr@gmail.com
In reply to: Tom Lane (#2)
Re: B-tree index balance?

On Fri, Jan 19, 2024 at 11:37 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Ron Johnson <ronljohnsonjr@gmail.com> writes:

On an RDMS which I used in the 1990s and 2000s, b-tree indices of

sequences

would get unbalanced, since every new leaf was added to the far right
corner of the tree.
Sure, they would auto-balance *to a degree* during node splits, but all
those "far-right corner" inserts still left them pretty lopsided.
Thus, they provided a utility which we could use to determine the
lopsidedness, and thus decide when to rebuild an index.

Does Postgresql keep b-tree indexes on sequences fully balanced? If not,
how do I see how unbalanced they are? (Assume PG12+.)

As far as I know, we don't have a problem of that sort. Continued
insertions will eventually force a split of the root node, which will
rebalance the tree.

Thanks for the explanation.