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
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
Angela,
have you tried "group by a,b,c" instead of "group by cube(a,b,c)"?
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]
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
|
|
|
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.
Top Community Contributors
|