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 > Views and performance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-07, 14:12
svrider svrider is offline
Registered User
 
Join Date: Jul 2002
Posts: 39
Question Views and performance

Hey all,

I'm pretty sure of what you're gonna say, but I have to ask anyways.

Is it possible to index a view?

As I understand it, when used in a query, the view is generated then used as a table and joined with the other tables/views in the query. So it is easy to optimize the generation of the view, but when used in a query with other tables/views, I can't index the view for better response, can I?

Thanks.

JFS.
Reply With Quote
  #2 (permalink)  
Old 12-18-07, 15:02
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Nope, no index on a view.

Andy
Reply With Quote
  #3 (permalink)  
Old 12-18-07, 15:54
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by svrider
Hey all,

I'm pretty sure of what you're gonna say, but I have to ask anyways.

Is it possible to index a view?

As I understand it, when used in a query, the view is generated then used as a table and joined with the other tables/views in the query. So it is easy to optimize the generation of the view, but when used in a query with other tables/views, I can't index the view for better response, can I?

Thanks.

JFS.
You are not understanding how DB2 works with views. Views are not materialized and it would not help to index them. When you have a view, the SQL is re-written (and optimized) by DB2 when the statement is compiled to a new SQL statement without the view against the base tables, and any indexes on the base tables will be used.
__________________
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
  #4 (permalink)  
Old 12-18-07, 16:45
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
A view in SQL (not just DB2's dialect) is just like a macro. You can think of it as being some simple text replacement occurring to resolve the view before the actual execution of the statement starts. (It is not that simple because of things like privileges, but you should get the idea.)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 12-23-07, 17:07
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by svrider
Is it possible to index a view?
Yes, it is. That is to say, "it depends":
With DB2 9 for z/OS you can define an index on an expression, hence a view having a column which is not just a base table column cannot be indexed in earlier versions of DB2 but can be in DB2 9.
(So it's not the view itself which gets indexed, but the result is the same when the view is going to be queried.)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
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