Information Technology Reference
In-Depth Information
Algorithm 11.2 Secondary-index update in procedure insert .T;x;y; v /
insert-into-page .T;p;x;y; v /
if the secondary index is under construction then
n 1 U NDO -N EXT -LSN.T /
if x< Cursor then
unlatch-and-unfix .p; p 0 /
unlock .T; x 0 ; X; short-duration/
q the last page of the side file (allocating one if needed)
fix-and-write-latch .q/
append the record . ix-I ;y;x;p/into page q
log .n 2 ;hT; append-to-side-file ;q; ix-I ;y;x;p;n 1 i/
P AGE -LSN.q/ n 2
unlatch-and-unfix .q/
else {x> Cursor }
unlatch-and-unfix .p; p 0 /
unlock .T; x 0 ; X; short-duration/
log .n 2 ;hT; no-append-to-side-file ; ix-I ;y;x;p;n 1 i/
end if
U NDO -N EXT -LSN.T / n 2
else if the secondary index is available then
unlatch-and-unfix .p; p 0 /
unlock .T; x 0 ; X; short-duration/
insert-index-record .T;y;x;p/
else {the secondary index is neither available nor under construction}
unlatch-and-unfix .p; p 0 /
unlock .T; x 0 ; X; short-duration/
end if
To accomplish the above, the sequence of calls
insert-into-page .T;p;x;y; v /
unlatch-and-unfix .p; p 0 /
unlock .T; x 0 ; X; short-duration/
at the end of the call insert .T;x;y; v / must be replaced by the statements given
as Algorithm 11.2 . Here the short-duration X lock on the key x 0 next to x can
be released immediately after unlatching the page p and the next page p 0 ,before
performing the actions specific to the secondary index.
In Algorithm 11.2 , it is essential that the data page p that receives the inserted
tuple is kept write-latched during the reading of the current value of Cursor , because
then the extraction process cannot advance its scan past page p, if it has not done so
before the page was write-latched for the insert action by T .IfT observes that x>
Cursor , it unlatches p and writes a no-append-to-side-file log record, after which the
extraction process will in due time get a read latch on p when the scan has advanced
at that page and hence will capture the insertion. On the other hand, it is also correct
to unlatch p immediately after observing that x< Cursor before appending the
record to the side file, because in that case the scan has already advanced past the
page. We also note that the case x D Cursor is impossible.
 
Search WWH ::




Custom Search