database - does incremented column makes the b-tree index on the column unbalanced? -
i have been thinking 2 questions. couldn't find resources on internet this. how dbms handle ? or ? oracle.
before questions, here example: have master table "master" , slave table "slave". master table has "id" column primary key , index created oracle.slave table has foreign key "master_id" refers master table , "slave_no". these 2 primary key of slave table, again indexed.
**master** | **slave** (p) id <------> (p)(f) master_id (p) slave_no now questions;
1- if master_id autoincremented column, , no record ever deleted, doesn't table's index unbalanced ? oracle rebuilds indexes periodically ? far know oracle balances index branches @ build time. oracle re-builds indexes automatically ever ? if level goes high levels ?
2- assuming oracle not rebuild automatically, apart scheduling job rebuilds index periodically, wiser order slave table's primary key columns reverse ? mean instead of "master_id", "slave_no" ordering "slave_no", "master_id"i, slave table's b-tree index more balanced ? (well each master table might not have exact number of slave records, still, seems better reverse order)
anyone know ? or opinions ?
if
master_idautoincremented column, , no record ever deleted, doesn't table's index unbalanced ?
oracle's indexes never "unbalanced": every leaf in index @ same depth other leaf.
no page split introduces new level itself: leaf page not become parent new pages on non-self-balancing tree.
instead, sibling split page made , new record (plus possibly of records old page) go new page. pointer new page added parent.
if parent page out of space (can't accept pointer newly created leaf page), gets split well, , on.
these splits can propagate root page, split thing increases index depth (and pages @ once).
index pages additionally organized double-linked lists, each list on own level. impossible if tree unbalanced.
if master_id auto-incremented means splits occur @ end (such called 90/10 splits) makes dense index possible.
would wiser order
slavetable's primary key columns reverse?
no, not, reasons above.
if join slave master often, may consider creating cluster of 2 tables, indexed master_id. means records both tables, sharing same master_id, go same or nearby data pages makes join between them fast.
when engine found record master, index or whatever, means has found records slave joined master. , vice versa, locating slave means locating master.
Comments
Post a Comment