Information Technology Reference
In-Depth Information
Algorithm 10.2
Procedure
bulk-insert
.T; s
XV
/
sort the tuples in s
XV
in ascending key order
choose-locks
.s
XV
;L/
for
.f; M / 2 L
do
lock
.T;f;M;commit-duration/
end for
while
s
XV
not empty
do
.x;
v
/ thefirsttupleins
XV
find-page-for-bulk-insert
.p;h;p
0
;x;
v
/
S the longest prefix of s
XV
of tuples with keys less than h that fit in page p
y
0
the least key in page p
0
Y
0
keys
.p/[fy
0
g[f1g
W Y
0
[
keys
.S / merged in ascending order
Y the keys in Y
0
that are next keys of some tuples in S in the sequence W
for
all y 2 Y
do
if
for all i D 0;:::;m: L contains neither .g
i
.y/; IX/ nor .g
i
.y/; X/
then
for
i D 0 to m
do
conditionally-lock
.T; g
i
.y/; IX; short-duration/
end for
if
some of the requested locks were not granted
then
unlatch-and-unfix
.p; p
0
/
for
i D 0 to m
do
lock
.T; g
i
.y/; IX; short-duration/
end for
continue with the
while
loop
end if
end if
end for
insert-bulk-into-page
.T;p;S/
s
XV
s
XV
nS
unlatch-and-unfix
.p; p
0
/
release the short-duration locks if any
end while
10.5
Bulk Deletion
The call
bulk-delete
.T; s
X
;s
XV
/ (Algorithm
10.3
) implements the bulk-delete action
DŒs
X
;s
XV
for transaction T . Again, for simplicity, we consider only closed ranges
Œ
z
1
;
z
2
. As with the bulk-read action, the key ranges of s
X
are first sorted in
ascending key order, and the processing of a range Œ
z
1
;
z
2
in s
X
starts with locking
the smallest partition fragment that covers the keys
z
1
and
z
2
. The smallest covering
fragment is X-locked and the containing fragments are IX-locked, for short duration.
In processing a range Œ
z
1
;
z
2
,thevariable
z
, with initial value
z
1
, is advanced,
step by step, up to
z
2
. At each step, while holding write-latched the leaf page p that
covers
z
, as many tuples are deleted from p that is possible without the underflow of
p, after which the variable
z
is advanced to the key y next to the last tuple deleted
in the step. When y exceeds
z
2
, it is X-locked, and the containing fragments are
IX-locked, for commit duration.