Beginning SQL
Beginning SQL Beginning SQL
The slots are often implemented as a doubly linked list (illustrated in Figure 13-4). A doubly linked list is a structure where each container holding data has two pointers to other containers, one to the previous container and another to the next container. This structure allows very fast movement or sorting of data since the data itself is never physically moved; rather the two links are simply modified to point to different neighbors. Of course, the old neighbors’ pointers also have to be modified since they no longer point to this data item, and the new neighbors’ links have to be updated to point to this data item. Figure 13-4 Index Item Data Item Pointer to Prev Pointer to Next Pointer to Rec Data Table Index Item Data Item Pointer to Prev Pointer to Next Pointer to Rec Database Tuning Index Item Data Item Pointer Prev Pointer Next Pointer Data Implementing a doubly linked list means finding the two slots that the new data belongs between, adjusting the pointers of each of these neighbor slots to point to the new data item, and then adjusting the pointers of the empty slot into which the data was placed to point to the data slots on either side. All of this is just grunt work that the DBMS has to go through, and it isn’t a reason not to build an index where one is needed, but just keep in mind that every index causes these data shuffles any time the data in that indexed column changes or is deleted. Perhaps you’ve heard the advice, “It may be faster to drop an index and rebuild it after a bulk insert.” This data shuffle is exactly the reason why that may be the case. If the number of records added, deleted, or modified is a very high percentage of the number of records already in the table, then moving the index items around may be slower than just deleting the index and rebuilding it from scratch. This is also the reason why you want to do large bulk imports during off hours (if any) so that the overhead of shuffling index items or rebuilding indexes does not impact the users. If you are going to be doing large inserts or other modifications of data to indexed tables, it can be beneficial to drop the indexes before doing the insert and then rebuild the index after the data is inserted. Obviously, given the example database used in this book, you will not be able to really see the effects. However, in a production database with millions of records already in a table and deletes or inserts of large quantities of records, you may find dropping indexes very beneficial. 359
- Page 708: Chapter 12 ❑ You can assign a dif
- Page 712: Chapter 12 Privileges Privileges ar
- Page 716: Chapter 12 338 You could then give
- Page 720: Chapter 12 You might implement this
- Page 724: Chapter 12 Another shortcut, using
- Page 728: Chapter 12 As you can imagine, givi
- Page 732: Chapter 12 The situation gets a lit
- Page 736: Chapter 12 Summary Database securit
- Page 740: Chapter 13 robust, fault-tolerant m
- Page 744: Chapter 13 Gigahertz Networks or Co
- Page 748: Chapter 13 Database Cache 354 In ad
- Page 752: Chapter 13 Again, the shotgun appro
- Page 756: Chapter 13 358 Figure 13-3 Leaf Ind
- Page 762: On the other hand, an index on a tr
- Page 766: Tuning Tips The following list cont
- Page 770: Database Tuning Exercises 1. Create
- Page 776: Appendix A Exercise 2 Solution 368
- Page 780: Appendix A ( 8, ‘Jack’, ‘John
- Page 784: Appendix A ZipCode, Email, DateOfJo
- Page 788: Appendix A Exercise 3 Solution Firs
- Page 792: Appendix A 376 Figure A-1 ISBN is a
- Page 796: Appendix A Chapter 5 Exercise 1 Sol
- Page 800: Appendix A 380 You might receive sl
- Page 804: Appendix A 382 You should use the f
The slots are often implemented as a doubly linked list (illustrated in Figure 13-4). A doubly linked list is<br />
a structure where each container holding data has two pointers to other containers, one to the previous<br />
container and another to the next container. This structure allows very fast movement or sorting of data<br />
since the data itself is never physically moved; rather the two links are simply modified to point to different<br />
neighbors. Of course, the old neighbors’ pointers also have to be modified since they no longer<br />
point to this data item, and the new neighbors’ links have to be updated to point to this data item.<br />
Figure 13-4<br />
Index Item<br />
Data Item<br />
Pointer to Prev<br />
Pointer to Next<br />
Pointer to Rec<br />
Data Table<br />
Index Item<br />
Data Item<br />
Pointer to Prev<br />
Pointer to Next<br />
Pointer to Rec<br />
Database Tuning<br />
Index Item<br />
Data Item<br />
Pointer Prev<br />
Pointer Next<br />
Pointer Data<br />
Implementing a doubly linked list means finding the two slots that the new data belongs between,<br />
adjusting the pointers of each of these neighbor slots to point to the new data item, and then adjusting<br />
the pointers of the empty slot into which the data was placed to point to the data slots on either side. All<br />
of this is just grunt work that the DBMS has to go through, and it isn’t a reason not to build an index<br />
where one is needed, but just keep in mind that every index causes these data shuffles any time the data<br />
in that indexed column changes or is deleted.<br />
Perhaps you’ve heard the advice, “It may be faster to drop an index and rebuild it after a bulk insert.”<br />
This data shuffle is exactly the reason why that may be the case. If the number of records added, deleted,<br />
or modified is a very high percentage of the number of records already in the table, then moving the<br />
index items around may be slower than just deleting the index and rebuilding it from scratch. This is<br />
also the reason why you want to do large bulk imports during off hours (if any) so that the overhead of<br />
shuffling index items or rebuilding indexes does not impact the users.<br />
If you are going to be doing large inserts or other modifications of data to indexed tables, it can be beneficial<br />
to drop the indexes before doing the insert and then rebuild the index after the data is inserted.<br />
Obviously, given the example database used in this book, you will not be able to really see the effects.<br />
However, in a production database with millions of records already in a table and deletes or inserts of<br />
large quantities of records, you may find dropping indexes very beneficial.<br />
359