View previous topic :: View next topic
|
Author |
Message |
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
Hi All,
I have two DB2 tables say TAB1 and TAB2 with some common fields and I do have a view build for these tables thro the fields which are common in TAB1 and TAB2, say View1. I can pick up data from these tables directly by writing a join query for TAB1 and TAB2 or by quering the View, which of the above would take less time, fetching data from view or fetching data directly from tables.
Thanks in advance
Thamilzan. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Is the "join query" the same as the view definition? |
|
Back to top |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
Hey Bill,
Thanks for a quick reply
Quote: |
Is the "join query" the same as the view definition? |
Yups , its the same....
Thamilzan. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
I would think that once the cursor was opened, they would be the same....
If the newer fetch was dynamic, I would think the view would open quicker... |
|
Back to top |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
Bill,
I believe that View would be dynamically built when reffered to, so if you are quering a view there would be two queries executing at the background 1. the Query which builds the view 2. the query which the user gives to fetch data, considering this and the time taken for executing these two queries can't we say that quering the tables directly would be much more efficient, please correct me if i am wrong.
Thamilzan. |
|
Back to top |
|
|
Nimesh.Srivastava
New User
Joined: 30 Nov 2006 Posts: 78 Location: SINGAPORE
|
|
|
|
prav_06,
I would say using cursor when involving more than one table is faster than view as the number of records grows in the database. This is based more on what I have seen in my production system than logic I know of, but we had to remove the views involving multiple tables with cursors which were much faster and required programmer permissions rather than a DBA to create / modify the view.
Hope this helps
Nimesh |
|
Back to top |
|
|
ashok_uddaraju
New User
Joined: 21 Feb 2007 Posts: 72 Location: US
|
|
|
|
Hi all,
The main reason for creating views is for faster access of data so,I guess fetching from views would be faster
Correct me if i am wrong |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
using a view is not faster because DB2 has to deal with object management, since a created view is an object.
Views should be used mainly for security - retrieval of certain columns is excluded.
If you have access to the complete row, you should use an inline view because it is 1) faster and 2) the sql is there and to debug you don't have to go find it elsewhere.
DB2 Developer's Guide, Fourth Edition by Craig S. Mullins wrote: |
Why would you want to use an inline view instead of simply creating an actual view prior to issuing the SELECT statement? The first potential benefit is that an inline view expression can be easier to understand. Instead of attempting to query the DB2 Catalog to extract the SQL definition of a view, the SQL is clearly displayed in the body of the SELECT statement. Second, inline views do not require object management because no DB2 object is created. Finally, inline views provide direct SQL support for certain complex queries that required a view prior to DB2 V4. |
The same quote is obtainable in Craig's 5th edition. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Does anyone used Materialized Query Tables? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
stodalas,
you posts are normally coherent and contribute to the thread. Is this a 'new' question by you or a possible solution to the OP's question? |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Well as an alternative to views, don't they offer better performance if the underlying data doesn't change often? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
if the underlying data doesn't change often? |
but that is the important caveat. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
to add on to my and your comment:
if the DBs are read-only and there is no need for update during the normal business hours (e.g. marketing info which can be aggregated for tomorrow)
you are correct - that would be the way to go. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Yeah, I just created 5 new tables and asked for a MQT. My DBAs said no, execute the joins everytime on your query. It is a 5 table join and the data will change less than 100 times a year.
At least the tables are small, all under 5000 rows. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
The main reason for creating views is for faster access of data so,I guess fetching from views would be faster |
Maybe not. . .
A big reason for using views is ease of use rather than performance. This may be especially true if there are expected database changes. If the view is substantially changed, but returns the same values as the original, the code/queries that use the view will most often not need to be changed. |
|
Back to top |
|
|
|