If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Making views

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-15-11, 13:18
Onsightfree Onsightfree is offline
Banned
 
Join Date: May 2010
Posts: 5
Making views

Hi all,

I have got the following (beginner) question regarding views:

I have a machine, that inserts data into a db2 table, using the same user, that queries the table. So, sometimes the query can take a while, as the insert is still ongoing. (2-3 minutes sometimes)

The table has now ~3mil rows.

I thought that I build a View for the table, and redirect the query to the view, as the insert remains on the original table.

Q1: Would it solve my problem with the sometimes long waiting times?
Q2: Is the view always up-to-date with the original table, or how long does it "lag" ?
Q3: Is it a huge workload for the db, or like nothing? (db itself is like 30Gb in size)

Hope i was clear with the situation, and unfortunately i cannot change the users, so this is not really an option

Thank you very much for your responses and time in advance !
Reply With Quote
  #2 (permalink)  
Old 02-15-11, 15:34
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
It makes no difference if you create a view. The view doesn't actually exist as a separate physical table in the database, and will not eliminate contention (if there is any).

To solve the contention problem, there are two options.

1. On all the select statements, put "WITH UR" at the end of the statement to eliminate locking.

2. Issue the following commands and restart the instance:
db2set DB2_SKIPINSERTED=ON
db2set DB2_SKIPDELETED=ON (optional, but recommended if you ever delete rows).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 02-17-11, 10:04
Onsightfree Onsightfree is offline
Banned
 
Join Date: May 2010
Posts: 5
Hi,

Thanks for your reply, I start experimenting with the UR option.
In the last days I read a lot about views and locks, but I still do not really understand.

If I create a view, based only on one table, which consists only the last 1000 inserted rows (based on timestamp), would it make the queries faster? Plus if I could query this view with another user , not the one that inserts the table, then the insert and the query could happen parallel. Am I right?

If i am not mistaken and correctly informed, than DB2 lockouts are row-based, so logic dictates me it should work.

Still havent found what happens if 2 separate users are querying/inserting the same table.

Regards
Reply With Quote
  #4 (permalink)  
Old 02-17-11, 12:53
JAYANTA_DATTA JAYANTA_DATTA is offline
Registered User
 
Join Date: Oct 2004
Location: DELHI INDIA
Posts: 336
having a view even on selecting the 1000 rows, is not going to help in terms of avoiding locks. Instead try to have good indexes ( e.g. on timestamp in your case) based on which the SELECT queries are fired. Having the right index for your queries are definitely going to reduce contention with other concurrent queries on the same table and also with faster response. WITH UR too is going to help avoid lock escalation.
__________________

Jayanta Datta
DB2 UDB DBA
IBM India, Global Delivery
New Delhi
Reply With Quote
  #5 (permalink)  
Old 02-18-11, 03:48
Onsightfree Onsightfree is offline
Banned
 
Join Date: May 2010
Posts: 5
Thanks,

I am getting closer to understand and - through this - solving my problem.

Thanks for your responses
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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