Running SQL Profiler while refreshing an Excel PivotTable that runs for several minutes revealed how poorly performing the MDX is that Excel is constructing. Can someone answer why the MDX is this poor? Using an example against the Adventure Works database,
the following query is used to populate a PivotTable.
SELECT {
[Measures].[Internet Sales Amount],
[Measures].[Internet Order Quantity]
} DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME
ON COLUMNS ,
NON EMPTY
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
Hierarchize({DrilldownLevel({[Customer].[Customer].[All Customers]},,,INCLUDE_CALC_MEMBERS)}),
Hierarchize({DrilldownLevel({[Customer].[Country].[All Customers]},,,INCLUDE_CALC_MEMBERS)})
),
Hierarchize({DrilldownLevel({[Customer].[State-Province].[All Customers]},,,INCLUDE_CALC_MEMBERS)})
), Hierarchize({DrilldownLevel({[Customer].[City].[All Customers]},,,INCLUDE_CALC_MEMBERS)})
), Hierarchize({DrilldownLevel({[Customer].[Postal Code].[All Customers]},,,INCLUDE_CALC_MEMBERS)})
) DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME,
[Customer].[State-Province].[State-Province].[Country],
[Customer].[Postal Code].[Postal Code].[City],
[Customer].[Customer].[Customer].[Address],
[Customer].[Customer].[Customer].[Birth Date],
[Customer].[Customer].[Customer].[Commute Distance],
[Customer].[Customer].[Customer].[Date of First Purchase],
[Customer].[Customer].[Customer].[Education],
[Customer].[Customer].[Customer].[Email Address],
[Customer].[Customer].[Customer].[Gender],
[Customer].[Customer].[Customer].[Home Owner],
[Customer].[Customer].[Customer].[Marital Status],
[Customer].[Customer].[Customer].[Number of Cars Owned],
[Customer].[Customer].[Customer].[Number of Children At Home],
[Customer].[Customer].[Customer].[Occupation],
[Customer].[Customer].[Customer].[Phone],
[Customer].[Customer].[Customer].[Postal Code],
[Customer].[Customer].[Customer].[Total Children],
[Customer].[Customer].[Customer].[Yearly Income],
[Customer].[City].[City].[State-Province]
ON ROWS
FROM [Adventure Works]
CELL PROPERTIES
VALUE,
FORMAT_STRING,
LANGUAGE,
BACK_COLOR,
FORE_COLOR,
FONT_FLAGS
If on the Display tab of the PivotTable Options dialog box, the Show Properties in Tooltips and Show calculated members from OLAP server are unchecked, the query is simplified but still extremely slow.
SELECT {
[Measures].[Internet Sales Amount],
[Measures].[Internet Order Quantity]
} DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME
ON COLUMNS ,
NON EMPTY
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
Hierarchize({DrilldownLevel({[Customer].[Customer].[All Customers]})}),
Hierarchize({DrilldownLevel({[Customer].[Country].[All Customers]})})
),
Hierarchize({DrilldownLevel({[Customer].[State-Province].[All Customers]})})
),
Hierarchize({DrilldownLevel({[Customer].[City].[All Customers]})})
),
Hierarchize({DrilldownLevel({[Customer].[Postal Code].[All Customers]})})
) DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME
ON ROWS
FROM [Adventure Works]
CELL PROPERTIES
VALUE,
FORMAT_STRING,
LANGUAGE,
BACK_COLOR,
FORE_COLOR,
FONT_FLAGS
But that's not the true performance killer. Why is the Hierarchize(DrillDownLevel(......)) construct used? It's crazy stupid. The following query is well over 10 fold faster and it's not even all that good.
SELECT {
[Measures].[Internet Sales Amount],
[Measures].[Internet Order Quantity]
} DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME
ON COLUMNS ,
NON EMPTY
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
{[Customer].[Customer].[All Customers].Children},
{[Customer].[Country].[All Customers].Children}
),
{[Customer].[State-Province].[All Customers].Children}
),
{[Customer].[City].[All Customers].Children}
),
{[Customer].[Postal Code].[All Customers].Children}
) DIMENSION PROPERTIES
PARENT_UNIQUE_NAME,
HIERARCHY_UNIQUE_NAME
ON ROWS
FROM [Adventure Works]
CELL PROPERTIES
VALUE,
FORMAT_STRING,
LANGUAGE,
BACK_COLOR,
FORE_COLOR,
FONT_FLAGS
Martin
<a href="http://martinsbiblog.spaces.live.com" target="_blank">http://martinmason.wordpress.com</a>