Information Technology Reference
In-Depth Information
Example 10.7
The partitions
sales-p1
,
sales-p2
,and
sales-p3
in Example
10.6
are
defined by the partition granularities g
1
, g
2
,andg
3
given below, where d is a date,
s is a store-id, and i is an item-id:
g
0
.d;s;i/
D
./
g
1
.d;s;i/
D
.
year
.d /;
quarter
.d //
g
2
.d;s;i/
D
.
year
.d /;
month
.d /;
day
.d //
g
3
.d;s;i/
D
.
year
.d /;
month
.d /;
day
.d /; s/
g
4
.d;s;i/
D
.
year
.d /;
month
.d /;
day
.d /; s; i /
The key of a fragment in the
sales-p1
partition is of the form .y; q/,wherey is a
year and q is a quarter number (1-4). The key of a fragment in the
sales-p3
partition
is of the form .y;m;d;s/,wherey is a year, m is a month number (1-12), d is a
day number (1-31), and s is a store-id.
t
The partitions of the above example were chosen so as to conform to the logical
structure of the primary key, but this is not a necessity. For example, for an integer
key X , we might define a partition hierarchy by g
1
.x/
D
x
100000, g
2
.x/
D
x
10000, g
3
.x/
D
x
1000.
The
partition-based key-range locking protocol
is based on locking keys of par-
tition fragments. To distinguish between locks on fragments in different relations,
each key is prefixed by the identifier of the relation. All lock names are 4-byte hash
values computed from the prefixed keys. For example, the name of a lock on the
fragment for the first quarter of year 2010 in the
sales-p1
partition is a hash value
computed from the tuple .
sales
; 2010; 1/.
The lock modes available are the conventional ones for multi-granular locking:
S, X, IS, IX, and SIX. Other lock modes, such as U (update-mode), could also be
employed. The locking granularity to be used for an operation is decided by the
query processor.
A bulk-read action RŒs
X
;s
XV
with Œ
z
1
;
z
2
2
s
X
has to S-lock the smallest
partition fragment that covers the keys
z
1
and
z
2
and to IS-lock the containing
fragments. In other words, when
k
D
max
f
i
j
0
i
m; g
i
.
z
1
/
D
g
i
.
z
2
/
g
;
the fragments g
0
.
z
1
/; g
1
.
z
1
/;:::;g
k1
.
z
1
/ are IS-locked and the fragment g
k
.
z
1
/
is S-locked. From the mapping of bulk-read actions to single-tuple read actions
discussed in the previous section, it follows that to achieve repeatable-read-level
isolation, if the tuple with the least key y greater than the keys of the tuples in the
range Œ
z
1
;
z
2
does not belong to the fragment g
k
.
z
1
/,thatis,g
k
.y/
6D
g
k
.
z
1
/,then
the key y must also be S-locked for commit duration and the containing fragments
g
i
.y/ IS-locked.