Search code examples
ssasmdxolap

Logical order an MDX query is processed


What is the order of evaluation of the clauses within an MDX script?

WITH 
  MEMBER measures.A AS ...
  MEMBER measures.B AS ...
  SET S1 AS ...
SELECT 
  {
    measures.A
   ,measures.B
   ,measures.x
  } ON COLUMNS
  {S1} HAVING <condition> on ROWS
FROM [Cube]
WHERE ({S2})
  1. FROM
  2. WHERE
  3. WITH
  4. SELECT
  5. HAVING

?

But maybe not that simple as a MEMBER and a SET are dealt with differently in terms of context - so if this order is correct how does context tie in?


Solution

  • I would say:

    1. FROM (including potential subselects)
    2. WHERE
    3. SETs and MEMBER location in the WITH clause
    4. Build the list of tuples for all query axes (columns, rows, ...) in parallel, ignoring NON EMPTY and HAVING
    5. Cell values for all axis intersections
    6. Remove tuples from the axes as requested by NON EMPTY and HAVING for each axis.

    By "member location" in step 3, I mean the information that the member exists at all, and in which hierarchy and possibly under which parent it is located in the hierarchy. This does not involve the member definition expression. That will be evaluated in step 5 and 6. But the location is needed for step 4.

    The parallel evaluation of the axes means that there is no relation between axes in the query processing.

    Also note that this is the conceptual view. Physically, step 6 may happen during the processing of step 4, or whatever the optimizer decides is a proper execution order, as long as the result would be the same.