dbTalk Databases Forums  

question about locking...

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss question about locking... in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
shorti
 
Posts: n/a

Default question about locking... - 11-10-2010 , 10:47 AM






DB2 V9.5 on AIX,
This would be running on C code..The following query:

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY

or

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY FOR
UPDATE OF col2, col3

If the table actually has 100,000 records that match these queries, is
there any locking done on the rows other than the first 10....will DB2
only lock the first 10 rows?

Reply With Quote
  #2  
Old   
Mark A
 
Posts: n/a

Default Re: question about locking... - 11-10-2010 , 01:42 PM






"shorti" <lbryan21 (AT) juno (DOT) com> wrote

Quote:
DB2 V9.5 on AIX,
This would be running on C code..The following query:

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY

or

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY FOR
UPDATE OF col2, col3

If the table actually has 100,000 records that match these queries, is
there any locking done on the rows other than the first 10....will DB2
only lock the first 10 rows?
Depends on the access plan. If a table scan is needed, all rows may be
locked. If the rows are accessed via an index, then only rows accessed have
to be locked.

Reply With Quote
  #3  
Old   
shorti
 
Posts: n/a

Default Re: question about locking... - 11-10-2010 , 02:45 PM



On Nov 10, 12:42*pm, "Mark A" <no... (AT) nowhere (DOT) com> wrote:

Quote:
Depends on the access plan. If a table scan is needed, all rows may be
locked. If the rows are accessed via an index, then only rows accessed have
to be locked.
index scan is what I was interested in. Are the other 99,990 rows
that match the query not considered "accessed" if it is an index scan?

Reply With Quote
  #4  
Old   
Mark A
 
Posts: n/a

Default Re: question about locking... - 11-10-2010 , 02:52 PM



"shorti" <lbryan21 (AT) juno (DOT) com> wrote

Quote:
index scan is what I was interested in. Are the other 99,990 rows
that match the query not considered "accessed" if it is an index scan?
Assuming that there is no sort required to determine which 10 rows to
return, then I would think that only the first 10 rows will be locked. But
you can easily do a test on that by submitting SQL via the command line and
turn auto-commit off, to see how many rows (or which rows) are locked.

Reply With Quote
  #5  
Old   
Serge Rielau
 
Posts: n/a

Default Re: question about locking... - 11-10-2010 , 06:21 PM



On 11/10/2010 5:47 PM, shorti wrote:
Quote:
DB2 V9.5 on AIX,
This would be running on C code..The following query:

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY

or

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY FOR
UPDATE OF col2, col3

If the table actually has 100,000 records that match these queries, is
there any locking done on the rows other than the first 10....will DB2
only lock the first 10 rows?
Only the first 10 rows will be locked. This is even true for a table scan.
What comes into play here is the quality of the predicate.
DB2 will avoid locking rows as long as it can and a simple predicate
such as col1 = 3 will be evaluated before the row is even brought into
the bufferpool.
The FFnR property will also cut of the scan once 10 rows have been
qualified.
So you will not see overlocking here.

Cheers
Serge


--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

Reply With Quote
  #6  
Old   
shorti
 
Posts: n/a

Default Re: question about locking... - 11-15-2010 , 05:46 PM



On Nov 10, 5:21*pm, Serge Rielau <srie... (AT) ca (DOT) ibm.com> wrote:
Quote:
On 11/10/2010 5:47 PM, shorti wrote:> DB2 V9.5 on AIX,
This would be running on C code..The following query:

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY

or

SELECT * FROM table1 WHERE col1 = 3 FETCH FIRST 10 ROWS ONLY FOR
UPDATE OF col2, col3

If the table actually has 100,000 records that match these queries, is
there any locking done on the rows other than the first 10....will DB2
only lock the first 10 rows?

Only the first 10 rows will be locked. This is even true for a table scan..
What comes into play here is the quality of the predicate.
DB2 will avoid locking rows as long as it can and a simple predicate
such as col1 = 3 will be evaluated before the row is even brought into
the bufferpool.
The FFnR property will also cut of the scan once 10 rows have been
qualified.
So you will not see overlocking here.

Cheers
Serge

--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: * *tinyurl.com/SQLTips4DB2
Wiki: * *tinyurl.com/Oracle2DB2Wiki
Twitter: srielau
Thanks for the help.

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.