dbTalk Databases Forums  

Optimize Foodmart query

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss Optimize Foodmart query in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Milind
 
Posts: n/a

Default Optimize Foodmart query - 06-14-2006 , 05:20 AM






Hi,

I have a query similar to the below Foodmart query. The below query
takes around 2 minutes to run. Can anyone make the execution time down
to less than 10 seconds?

With Set [TestExtract] as
'Generate(NonEmptyCrossJoin(
[Customers].[City].Members),
Generate(NonEmptyCrossJoin(
[Customers].Children),
Extract(Tail(NonEmptyCrossJoin(
{[Customers].CurrentMember},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members)),
[Customers], [Promotions])))'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Please help!

Thanks

Milind


Reply With Quote
  #2  
Old   
Chris Webb
 
Posts: n/a

Default RE: Optimize Foodmart query - 06-15-2006 , 08:43 AM






Hi Milind,

Although your original query runs in around 30 seconds on my machine on
AS2K, the following version (which I'm fairly certain returns the same
results) runs in just a few seconds, so hopefully it'll do the trick for you:

With Set [TestExtract] as
'Extract(
Generate(NonEmptyCrossJoin([Customers].[City].MEMBERS),
Filter(
NonEmptyCrossJoin(
{[Customers].CurrentMember.CHILDREN},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members
) as myset
, not(myset.current.item(0) is myset.item(rank(myset.current,
myset)).item(0)))
)
, [Customers], [Promotions])
'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Rather than use the TAIL function to get the last Promotion for each
Customer, I've created a set of tuples of each Customer by Month and by
Promotion, then filtered it to only contain the tuples where the Customer is
different from the Customer in the next tuple in the set. I've used this
technique in the past and once again it seems to be significantly faster
here.

HTH,

Chris

--
I blog about Microsoft BI here:
http://spaces.msn.com/cwebbbi/
Do you need help with Analysis Services or MDX? I''m available for hire:
http://www.crossjoin.co.uk/


"Milind" wrote:

Quote:
Hi,

I have a query similar to the below Foodmart query. The below query
takes around 2 minutes to run. Can anyone make the execution time down
to less than 10 seconds?

With Set [TestExtract] as
'Generate(NonEmptyCrossJoin(
[Customers].[City].Members),
Generate(NonEmptyCrossJoin(
[Customers].Children),
Extract(Tail(NonEmptyCrossJoin(
{[Customers].CurrentMember},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members)),
[Customers], [Promotions])))'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Please help!

Thanks

Milind



Reply With Quote
  #3  
Old   
Milind
 
Posts: n/a

Default Re: Optimize Foodmart query - 06-15-2006 , 10:33 AM



My query which is similar to the Foodmart query below used to take 1
min 17 sec. With your mdx, it just got down to 4 sec!!!

Hats off to you, Chris!!!! Thanks alot

Milind

Chris Webb wrote:
Quote:
Hi Milind,

Although your original query runs in around 30 seconds on my machine on
AS2K, the following version (which I'm fairly certain returns the same
results) runs in just a few seconds, so hopefully it'll do the trick for you:

With Set [TestExtract] as
'Extract(
Generate(NonEmptyCrossJoin([Customers].[City].MEMBERS),
Filter(
NonEmptyCrossJoin(
{[Customers].CurrentMember.CHILDREN},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members
) as myset
, not(myset.current.item(0) is myset.item(rank(myset.current,
myset)).item(0)))
)
, [Customers], [Promotions])
'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Rather than use the TAIL function to get the last Promotion for each
Customer, I've created a set of tuples of each Customer by Month and by
Promotion, then filtered it to only contain the tuples where the Customer is
different from the Customer in the next tuple in the set. I've used this
technique in the past and once again it seems to be significantly faster
here.

HTH,

Chris

--
I blog about Microsoft BI here:
http://spaces.msn.com/cwebbbi/
Do you need help with Analysis Services or MDX? I''m available for hire:
http://www.crossjoin.co.uk/


"Milind" wrote:

Hi,

I have a query similar to the below Foodmart query. The below query
takes around 2 minutes to run. Can anyone make the execution time down
to less than 10 seconds?

With Set [TestExtract] as
'Generate(NonEmptyCrossJoin(
[Customers].[City].Members),
Generate(NonEmptyCrossJoin(
[Customers].Children),
Extract(Tail(NonEmptyCrossJoin(
{[Customers].CurrentMember},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members)),
[Customers], [Promotions])))'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Please help!

Thanks

Milind




Reply With Quote
  #4  
Old   
Chris Webb
 
Posts: n/a

Default Re: Optimize Foodmart query - 06-15-2006 , 12:23 PM



Interesting problem, and this advice is still relevant for AS2005 too. I've
just blogged about it here:
http://cwebbbi.spaces.msn.com/blog/cns!7B84B0F2C239489A!755.entry

Chris
--
I blog about Microsoft BI here:
http://spaces.msn.com/cwebbbi/
Do you need help with Analysis Services or MDX? I''m available for hire:
http://www.crossjoin.co.uk/


"Milind" wrote:

Quote:
My query which is similar to the Foodmart query below used to take 1
min 17 sec. With your mdx, it just got down to 4 sec!!!

Hats off to you, Chris!!!! Thanks alot

Milind

Chris Webb wrote:
Hi Milind,

Although your original query runs in around 30 seconds on my machine on
AS2K, the following version (which I'm fairly certain returns the same
results) runs in just a few seconds, so hopefully it'll do the trick for you:

With Set [TestExtract] as
'Extract(
Generate(NonEmptyCrossJoin([Customers].[City].MEMBERS),
Filter(
NonEmptyCrossJoin(
{[Customers].CurrentMember.CHILDREN},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members
) as myset
, not(myset.current.item(0) is myset.item(rank(myset.current,
myset)).item(0)))
)
, [Customers], [Promotions])
'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Rather than use the TAIL function to get the last Promotion for each
Customer, I've created a set of tuples of each Customer by Month and by
Promotion, then filtered it to only contain the tuples where the Customer is
different from the Customer in the next tuple in the set. I've used this
technique in the past and once again it seems to be significantly faster
here.

HTH,

Chris

--
I blog about Microsoft BI here:
http://spaces.msn.com/cwebbbi/
Do you need help with Analysis Services or MDX? I''m available for hire:
http://www.crossjoin.co.uk/


"Milind" wrote:

Hi,

I have a query similar to the below Foodmart query. The below query
takes around 2 minutes to run. Can anyone make the execution time down
to less than 10 seconds?

With Set [TestExtract] as
'Generate(NonEmptyCrossJoin(
[Customers].[City].Members),
Generate(NonEmptyCrossJoin(
[Customers].Children),
Extract(Tail(NonEmptyCrossJoin(
{[Customers].CurrentMember},
[Time].[Month].Members,
[Promotions].[Promotion Name].Members)),
[Customers], [Promotions])))'

Select {[Measures].[Unit Sales]} on columns,
[TestExtract] on rows
from Sales
where [Product].[All Products].[Food]

Please help!

Thanks

Milind





Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.