| Thomas 的个人资料Thomas Kejsers Blog日志列表网络 | 帮助 |
|
2006/8/7 Factors to consider when performance tuning cubes and MDXBefore we move on the the wonders of subselects I would like to give you a few pointers on tuning MDX queries and cubes in general. During my time as a performance tuner on Analysis Services - these are the most important factors you should consider in a 2005 environment:
2006/8/5 Doing Multi-Selects in Analysis Services 2000 and 2005One of the major challenges for users of Analysis Services 2000 are queries that answer question of the form:
For example. Your interface has a product drop down list like this:
You allow you user to select one or more subcategories at the same time. For the purposes of illustration, lets assume the users selects "Bike Racks" and "Bike Stands". The user then asks for the order count of the hierarchized product dimension - but filtered by his selection. Put differently, the users wants:
Naïvely you execute this MDX statement: [Measures].[Internet Order Count] ON 0, HIERARCHIZE (GENERATE( {[Product].[Product Categories].[Subcategory].&[26], [Product].[Product Categories].[Subcategory].&[27]} , ASCENDANTS([Product].[Product Categories])) ) ON 1FROM [Direct Sales](Try it out in Adventureworks) What happens?... You get:
The values for All Products and Accessories are not right! You want the value for accessories and All Products to be 328 + 249 (the sum of the selected descendants), not 18208 and 27659. This is the essence of the visual totals problem: Analysis Services will happily scan the cube space for you and return the values of the parent. But you get the Order Count for the entire parent member - not the sum of the values you have selected. Why? Because this is the value that has been preaggregated in the cube. There is something intuitively wrong with the MDX query above. You are essentially mixing up two different questións:
Aha!... You need to seperate shape and subspace - just like you seperate the columns and WHERE parts of an SQL statement. Applying our SQL knowledge to MDX (generally a bad idea) we try: [Measures].[Internet Order Count] ON 0, DESCENDANTS ([Product].[Product Categories].[All Products], [Product].[Product Categories].[Subcategory], SELF_AND_BEFORE) ON 1FROM [Direct Sales]WHERE {[Product].[Product Categories].[Subcategory].&[26], [Product].[Product Categories].[Subcategory].&[27]}This generates an error. Even if we reduced our WHERE critieria to a single select (simplifying the problem): ([Product].[Product Categories].[Subcategory].&[26]) ... we still get the infamous error:
This, deceptively simple, multi-select problem have caused many headaches for MDX programmers. There ARE workarounds in Analysis Services 2000 - but they take a syntactic form that is disgusting to behold and I will not quote them here. Analysis Services 2005 to the rescue! Finally, we are able to seperate shape and subspace in our query. The above query can be written, correctly, like this in AS2005; [Measures].[Internet Order Count] ON 0, DESCENDANTS ([Product].[Product Categories].[All Products], [Product].[Product Categories].[Subcategory], SELF_AND_BEFORE) ON 1FROM (SELECT {[Product].[Product Categories].[Subcategory].&[26] , [Product].[Product Categories].[Subcategory].&[27]} ON 0 FROM [Direct Sales]) Notice the user of the "subselect". The outer select specifies the shape of space to return - the inner select specifies the subspace that is the scope of the query. Syntactically elegant - and we get the desired result:
Now, every coin has a back side. Allowing the user to specify any subspace in his query has som implications on how aggregations are being accessed. Programmers familiar with visual totals will probably have spotted this by now. My next post will deal with the subspaces you can define and how they affect your queries. |
|
|