惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
Cisco Talos Blog
Cisco Talos Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
美团技术团队
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
月光博客
月光博客
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
Recorded Future
Recorded Future
I
Intezer
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
GbyAI
GbyAI
罗磊的独立博客
V
V2EX
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
A
About on SuperTechFans
Scott Helme
Scott Helme
Vercel News
Vercel News
Spread Privacy
Spread Privacy
T
Threat Research - Cisco Blogs
Recent Announcements
Recent Announcements
Hacker News: Ask HN
Hacker News: Ask HN
C
CERT Recently Published Vulnerability Notes
G
Google Developers Blog
B
Blog
博客园 - 叶小钗
WordPress大学
WordPress大学
博客园 - 聂微东
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
IT之家
IT之家
C
Cybersecurity and Infrastructure Security Agency CISA
P
Palo Alto Networks Blog
小众软件
小众软件
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
AWS News Blog
AWS News Blog

博客园 - microsheen

[MDX学习笔记之四]Where vs. Subselect/Subcube [MDX学习笔记之三]MDX的上下文(Context) [MDX学习笔记之二]在MDX中处理边界情况 SQL Server 2005 SP2 CTP 在11月7号发布了 [MDX学习笔记之一]MDX中一些常见的计算 SSAS中Cube的结构 如何使用MDX编写同比和环比 SQL Server2005对XML的支持 2006 Tech.Ed 第二天见闻 2006 Tech.Ed 第一天见闻 C#简单命名指南 [.net泛型学习笔记之三]再测泛型的性能 [.net泛型学习笔记之二]泛型的性能 [.net泛型学习笔记之一]泛型介绍 [设计模式学习笔记之二]设计模式和量体剪衣 Note Three: studying JavaScript: The Definitive Guide, 4th Edition Note Two : studying JavaScript: The Definitive Guide, 4th Edition Note One —— studying JavaScript: The Definitive Guide, 4th Edition [设计模式学习笔记之一]面向对象是什么?
[MDX学习笔记之五]优化Set操作——SUM中的CrossJoin
microsheen · 2007-02-04 · via 博客园 - microsheen

今天看了《MDX Solutions with Microsoft SQL.Server Analysis Services 2005 and Hyperion Essbase 2nd Edition》书中关于优化SET操作的内容,并根据书中的内容作了一些测试,而测试结果有些符合书中的观点,有些则完全不同,真是让人有些意外。书中优化Set操作的主要观点是:

1. 优化Set操作的关键在于:把大的SET操作变成小的SET操作。
2. 由于CrossJoin代价(CPU、内存)巨大,所以最好用其他操作代替CrossJoin操作。

SUM中的CrossJoin
作者认为:要避免SUM一个包含多个CrossJoin的Set,你可以用其他的操作(比如嵌套SUM)进行替换。据此,我测试了一下

两组语句:

WITH MEMBER MEASURES.ABC AS 
Sum (
    CrossJoin (
        Descendants (
            
[Customer].[Customer Geography].CurrentMember,
            
[Customer].[Customer Geography].[State-Province]
        ),
        Crossjoin (
            Descendants (
                
[Date].[Calendar].CurrentMember,
                
[Date].[Calendar].[Date]
            ),
            Descendants (
                
[Product].[Product Categories].CurrentMember,
                
[Product].[Product Categories].[Product Name]
            )
        )
    )
    ,[Measures].[Internet Sales Amount]-[Measures].[Internet Tax Amount]

  )
SELECT MEASURES.ABC ON 0 ,
[Customer].[Customer Geography].[Country].Members *  
[Date].[Calendar].[Calendar Year].MEMBERS * 
[Product].[Product Categories].[Category].MEMBERS
ON 1
FROM [Adventure Works]

WITH MEMBER MEASURES.ABC AS 
Sum (
    Descendants (
        
[Customer].[Customer Geography].CurrentMember,
        
[Customer].[Customer Geography].[State-Province]
    ),        
    
SUM(
        Descendants (
            
[Product].[Product Categories].CurrentMember,
            
[Product].[Product Categories].[Product Name]
        ),
        
SUM(
            Descendants (
                
[Date].[Calendar].CurrentMember,
                
[Date].[Calendar].[Date]
            )        
            ,[Measures].[Internet Sales Amount]-[Measures].[Internet Tax Amount]

        )                
    )    
)
SELECT MEASURES.ABC ON 0 ,
{
[Customer].[Customer Geography].[Country].Members} *  
[Date].[Calendar].[Calendar Year].Members * 
[Product].[Product Categories].[Category].Members
ON 1
FROM [Adventure Works]

以上语句中,作者认为第一个语句慢于第二个语句(理由是嵌套的SUM每次操作的SET更小),可实际的结果(测了10次)恰恰相反,第一个语句平均花费的时间51.654秒,而第二个语句平均花费的时间在55.912秒,这是何故呢?此外,书中认为在第二个语句的嵌套SUM中,如果把大的Set放在里面,这样会快一些。也就是说下面的语句比上面第二个语句要慢5%-20%。

WITH MEMBER MEASURES.ABC AS 
Sum (
    Descendants (
        
[Date].[Calendar].CurrentMember,
        
[Date].[Calendar].[Date]
    ),
    
SUM(
        Descendants (
            
[Product].[Product Categories].CurrentMember,
            
[Product].[Product Categories].[Product Name]
        ),      
        
SUM(
        Descendants (
            
[Customer].[Customer Geography].CurrentMember,
            
[Customer].[Customer Geography].[State-Province]
        ),    
            
[Measures].[Internet Sales Amount]-[Measures].[Internet Tax Amount]        )                
    )    
)
SELECT MEASURES.ABC ON 0 ,
{
[Customer].[Customer Geography].[Country].Members} *  
[Date].[Calendar].[Calendar Year].Members * 
[Product].[Product Categories].[Category].Members
ON 1
FROM [Adventure Works]


以上测试语句中,关于[Date].[Calendar].[Date]的Set其Turple个数在365左右,关于[Product].[Product Categories].[Product Name]的Set其Turple个数在几十个左右,而关于[Customer].[Customer Geography].[State-Province]的Set其成员个数大多在十几个左右

经过测试发现上面这条语句平均时间在57.858秒。也就是说,测试结果和书中的观点是一致的,只是幅度没有那么大。此外,我还尝试了一下这样的写法。

WITH 
MEMBER MEASURES.ABC 
AS 
Sum (
    
    CrossJoin (
        Descendants (
            
[Customer].[Customer Geography].CurrentMember,
            
[Customer].[Customer Geography].[State-Province]
        ),
        Crossjoin (
            Descendants (
                
[Date].[Calendar].CurrentMember,
                
[Date].[Calendar].[Date]
            ),
            Descendants (
                
[Product].[Product Categories].CurrentMember,
                
[Product].[Product Categories].[Product Name]
            )
        )
    ) 
AS MYABC

    ,
[Measures].[Internet Sales Amount]
)
-
Sum (    
    MYABC
    ,
[Measures].[Internet Tax Amount]
)
SELECT MEASURES.ABC ON 0 ,
[Customer].[Customer Geography].[Country].Members *  
[Date].[Calendar].[Calendar Year].MEMBERS * 
[Product].[Product Categories].[Category].MEMBERS
ON 1
FROM [Adventure Works]

上面语句的不同之处在于,把要计算的内容分散开来了,令人惊异的是,这个语句只要2-3秒种就能运行完成。

总结
由上面两次测试我们可以得出以下结论:
1)SUM中的CrossJoin并不一定会降低速度,书中的观点可能是错误的。看来MDX解析器对CrossJoin有很多有优化,在上面的测试中CrossJoin比嵌套的SUM要快8%左右。
2)嵌套SUM中,把大的SET放在里层的SUM中,这样速度能够快一些。上面的测试中,把小的Set放在里层比把大的Set放在里层慢3.5%。
3)在做SUM等统计计算时,如果能够把计算项分解到每个单独的Measure,这个时候性能提升非常明显,速度将会大大提高。上面的测试中,速度提高了20多倍。