sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Angela's Avatar

How could the optimizer choose to use the MQT


Question posted by: Angela (Guest) on November 12th, 2005 06:04 AM
I had built a summary table as follow:

db2 "create table db2inst1.thirdcube as (select a,b,c,sum(fact) as
amount from db2inst1.fact1 group by cube(a,b,c) ) DATA INITIALLY
DEFERRED REFRESH DEFERRED ENABLE QUERY OPTIMIZATION"
db2 "refresh table db2inst1.thirdcube"
db2 "RUNSTATS ON table db2inst1.thirdcube WITH DISTRIBUTION"

But when I run a qurey:
select a, sum(fact) from fact1 group by a
The query still used the base table fact1 instead of the summary
table.
I also tried:
SET CURRENT REFRESH AGE ANY
SET CURRENT QUERY OPTIMIZATION 9
But it does not work.
Any one of you would help me figure it out?

Thanks a lot,
Angela
4 Answers Posted
Anton Versteeg's Avatar
Guest - n/a Posts
#2: Re: How could the optimizer choose to use the MQT

I think you should do the select straight from the MQT table , not from
fact1.

Angela wrote:
[color=blue]
>I had built a summary table as follow:
>
>db2 "create table db2inst1.thirdcube as (select a,b,c,sum(fact) as
>amount from db2inst1.fact1 group by cube(a,b,c) ) DATA INITIALLY
>DEFERRED REFRESH DEFERRED ENABLE QUERY OPTIMIZATION"
>db2 "refresh table db2inst1.thirdcube"
>db2 "RUNSTATS ON table db2inst1.thirdcube WITH DISTRIBUTION"
>
>But when I run a qurey:
>select a, sum(fact) from fact1 group by a
>The query still used the base table fact1 instead of the summary
>table.
>I also tried:
>SET CURRENT REFRESH AGE ANY
>SET CURRENT QUERY OPTIMIZATION 9
>But it does not work.
>Any one of you would help me figure it out?
>
>Thanks a lot,
>Angela
>
>[/color]

--
Anton Versteeg
IBM Certified DB2 Specialist
IBM Netherlands


AK's Avatar
Guest - n/a Posts
#3: Re: How could the optimizer choose to use the MQT

Angela,

have you tried "group by a,b,c" instead of "group by cube(a,b,c)"?
Spencer's Avatar
Guest - n/a Posts
#4: Re: How could the optimizer choose to use the MQT

One of the points of using MQT's is that the optimizer is supposed to
do query rewrite to use this table. Angela's question is valid and
warrants an answer not a workaround.


Anton Versteeg <anton_versteeg@nnll.iibbmm.com> wrote in message news:<3FDDA71D.9030103@nnll.iibbmm.com>...[color=blue]
> I think you should do the select straight from the MQT table , not from
> fact1.
>
> Angela wrote:
>[color=green]
> >I had built a summary table as follow:
> >
> >db2 "create table db2inst1.thirdcube as (select a,b,c,sum(fact) as
> >amount from db2inst1.fact1 group by cube(a,b,c) ) DATA INITIALLY
> >DEFERRED REFRESH DEFERRED ENABLE QUERY OPTIMIZATION"
> >db2 "refresh table db2inst1.thirdcube"
> >db2 "RUNSTATS ON table db2inst1.thirdcube WITH DISTRIBUTION"
> >
> >But when I run a qurey:
> >select a, sum(fact) from fact1 group by a
> >The query still used the base table fact1 instead of the summary
> >table.
> >I also tried:
> >SET CURRENT REFRESH AGE ANY
> >SET CURRENT QUERY OPTIMIZATION 9
> >But it does not work.
> >Any one of you would help me figure it out?
> >
> >Thanks a lot,
> >Angela
> >
> >[/color][/color]
miro flasza's Avatar
Guest - n/a Posts
#5: Re: How could the optimizer choose to use the MQT

Angela wrote:
[color=blue]
> I had built a summary table as follow:
>
> db2 "create table db2inst1.thirdcube as (select a,b,c,sum(fact) as
> amount from db2inst1.fact1 group by cube(a,b,c) ) DATA INITIALLY
> DEFERRED REFRESH DEFERRED ENABLE QUERY OPTIMIZATION"
> db2 "refresh table db2inst1.thirdcube"
> db2 "RUNSTATS ON table db2inst1.thirdcube WITH DISTRIBUTION"
>
> But when I run a qurey:
> select a, sum(fact) from fact1 group by a
> The query still used the base table fact1 instead of the summary
> table.
> I also tried:
> SET CURRENT REFRESH AGE ANY
> SET CURRENT QUERY OPTIMIZATION 9
> But it does not work.
> Any one of you would help me figure it out?
>
> Thanks a lot,
> Angela[/color]

This query should route to your MQT. Are the columns A,B,C nullable?
If yes, we usually recommend including the GROUPING() function for
each nullable column that is part of the cube in the MQT definition.
Otherwise we might not be able to uniquely identify the row in the
cube representing the rollup by A.

Regards,
Miro

 
Not the answer you were looking for? Post your question . . .
196,844 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,844 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors