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 > Query Optimization does NOT work with MQT

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-09-06, 13:02
DBA-Jr DBA-Jr is offline
Registered User
 
Join Date: Mar 2005
Posts: 108
Query Optimization does NOT work with MQT

Hi All,
I am using DB2 V8.2 in Linux.
I want to make DB2 use MQT for better performance. By using "enable query optimization" when creating MQT, I expected DB2 to rewrite my SQL to access the MQT when my SQL references the base table. Somehow this didn't work for me. I tried to define the MQT exactly the same as my query. It still didn't work. Here are the the scripts (current query optimization = 5):

The query:
Code:
 
select columns-list
from base_table 
WHERE    (RUN_STA =6 OR RUN_STA =2) AND 
         ITM_TYP <>4                AND 
         APPL_ID =6                 AND
         (APPL_SRV_NM =108 OR APPL_SRV_NM is NULL)
The MQT and others:
Code:
 
create table query_base_table as 
(
select same-column-list-as-the-query
from base_table 
WHERE    (RUN_STA =6 OR RUN_STA =2) AND 
         ITM_TYP <>4                AND 
         APPL_ID =6                 AND
         (APPL_SRV_NM =108 OR APPL_SRV_NM is NULL)
)
data initially deferred
refresh immediate
enable query optimization
maintained by system
;
 
refresh table query_base_table;
CREATE INDEX N1_qBSAGENT_BS_AGE ON query_base_table 
  (RUN_STA,APPL_ID,APPL_SRV_NM,ITM_TYP);
 
runstats on table schema.base_table with distribution and detailed indexes all;
runstats on table schema.query_base_table with distribution and detailed indexes all;
 
db2expln -database db-name -output o.out -stmtfile q.sql -terminator ';' -graph
Output from the explain tool showed DB2 chose to access the base table directly through an index on column RUN_STA which has a cardinality of 6, while the table has 155K rows.
I don't know what I am missing and how to make DB2 "optimize" the query by using the MQT.

Thank you for advice in advance.

Last edited by DBA-Jr; 11-09-06 at 13:27.
Reply With Quote
  #2 (permalink)  
Old 11-09-06, 18:11
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Check the value of CURRENT QUERY OPTIMIZATION. As the manual says,

Quote:
REFRESH IMMEDIATE MAINTAINED BY SYSTEM materialized query tables can always be used to optimize the processing of a query if the CURRENT QUERY OPTIMIZATION special register is set to 2 or a value greater than or equal to 5.
Reply With Quote
  #3 (permalink)  
Old 11-12-06, 16:14
DBA-Jr DBA-Jr is offline
Registered User
 
Join Date: Mar 2005
Posts: 108
The Value is 5 as mentioned above.
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