20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13<br />

358<br />

Figure 13-3<br />

Leaf<br />

Index Item<br />

Index Item<br />

Index Item<br />

Leaf Leaf Leaf<br />

Index Item<br />

Index Item<br />

Top Page<br />

Index Item<br />

As mentioned, an index holds a copy of the data being searched for. This has a couple of implications<br />

that you need to be aware of. The first is that every index created increases the storage requirements of<br />

the database by the amount of data in the indexed column plus the pointers to the real data. The next is<br />

that, as mentioned, indexes cause issues with updating or deleting data.<br />

Deleting a record causes its slot in the index page to be emptied. If there are a lot of deletes, you end up<br />

with lots of empty slots in the pages, which of course causes the DBMS to look through empty slots on<br />

its way to finding the requested data. As data is deleted, the DBMS tracks these empty slots, and if they<br />

pile up, eventually the DBMS has to do a compact or balance of the tree. Any maintenance of that nature<br />

requires locks on the index pages, which will slow down accesses to the indexes by the application while<br />

the balance is in progress.<br />

Updating data causes a similar issue, perhaps even larger in terms of performance hit. As you can visualize<br />

from knowing the tree structure, if an indexed data item changes, the item has to be moved from<br />

one position in the tree to another. If the movement causes the item to move from one index page to<br />

another, then a hole is left in the old page, but even worse, the data has to be muscled into the new page<br />

where it now belongs. Even if there are “holes” in the destination page, the existing slots have to be<br />

relinked to insert the data in the correct place. If there are no holes in the destination page, a major rebalance<br />

has to be performed, which involves moving items out of the page to other pages to open up holes.<br />

Leaf<br />

Leaf<br />

Index Item

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!