ErrorDB » Latest News » News » Programmers Only: The Mystery of the DB2 SIX Lock

News Get the latest Technology News

Post New Thread Reply
  Programmers Only: The Mystery of the DB2 SIX Lock
LinkBack Thread Tools
  #1 (permalink)  
Old 06-24-2008, 01:20 PM
Member
 
Join Date: Jun 2008
Posts: 72
Default Programmers Only: The Mystery of the DB2 SIX Lock

The SIX lock is one of DB2's many mysteries. What is it, and how do we acquire it? Another mystery is the index_only flag on the plan_table: How can it be a Y for an UPDATE or a DELETE? Excuse me, but exactly how can an UPDATE or DELETE be "index-only?" A third mystery is the fact that adding an ORDER BY to an SQL statement might eliminate a sort. And even more mysterious and perverse is the fact that removing an ORDER BY clause can actually introduce a sort into your access path. For the next few columns I will be writing about these mysteries and trying to solve them for you. So, for all of you Nancy Drew fans, let's start with "The Mystery of the SIX Lock."
SIX Locks
In a previous column ("Table Spaces and Locking Levels, Part 1," Issue 1, 2005; see Resources, page 51), I explained DB2 locking using an analogy that equated buildings to table spaces, floors to tables, and rooms to pages. You must first get into the building, then onto the right floor, and then, finally, you may enter the room. Likewise, with page-level locking, you can't immediately get into a page. You must first get into the table space (our building), then into the table (the right floor), and then into the page (the room). A typical updater would first ask for a table space lock, and then for a table lock, and finally for a page lock. The outer (or higher-level) locks are called "Intent Locks." You intend to do page-level locking if you ever get into the page. For example, you may have to acquire an IX lock on the table space (you Intend to do something eXclusive), followed by an IX lock on the table, before you even think about your X (exclusive) lock on a page.

Usually you acquire IX locks on table spaces and tables for users doing maintenance, and IS (Intend to Share) locks for those who are just reading. However, every now and then we see SIX locks at these levels. What is this type of lock and what does it mean?
I'll Let You Read But Not Update

Suppose the table space that holds our table is defined with LOCKSIZE PAGE. I have a program that must run during a window when no one else is doing maintenance. I want my program to be the only one that is doing INSERTs, UPDATEs, DELETEs, and MERGEs. I don't mind if other programs are reading. SELECTs and read-only CURSORs are just fine. How do I enforce this scenario?

What I plan to do is this: I will override the table space page-level locking rule with my own lock rule. In my program's initialization section, I will execute a statement to tell DB2 to LOCK TABLE mytablename IN SHARE MODE. This statement will cause DB2 to acquire an IS lock on the table space (the building) and an S lock on the table (the floor). The S lock on the table will allow other users to read. In fact, my S lock will be quite happy to share with two types of users, those who are just reading using the three-level IS/IS/S protocol, as well as those who issue the LOCK TABLE ... IN SHARE MODE statement. I am happy with the former but not so happy with the latter. But hang in there and let's see if we can solve the problem.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!jeqqit! Wong this Post!
Reply With Quote
Post New Thread Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:57 PM.

Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41