Tables and Sets

Dimensionality of a Set

Many MDX functions take a set or sets as input, and return a set as output. A set consists of tuples. A tuple is a vector of members. Let n be the number of members in any given tuple. The value n is called as the dimensionality of the set. Note the following rules:

Table Associated with a Set

When mapping a statement in MDX, a set maps to a table. This table has n+1 columns, where n is the dimensionality of the set. There is one column for each dimension, and a RANK column that has the rank of a tuple within the set. This column is needed because sets in MDX are ordered. A table in SQL is not.

Any intermediate table in the expansion of a MDX also has a RANK column. The expansions below use this implicit column in an ORDER BY clause to preserve the order. Note that the notion of rank is somewhat similar to that of an identity column.

Use of ORDER BY

Many sections in this document deal with how to expand MDX set value expressions into equivalent SQL statements. For set value expressions that return another set (such as ORDER and CROSSJOIN), the final result of the expansion is a SELECT statement (which returns a virtual table, also known as set). This SELECT statement always contains an ORDER BY on the RANK column. This is appropriate for a section that deals only with mapping a set value expression. However, it is inefficient to do this when evaluating a full-fledged MDX statement that has multiple such functions along an axis. In that case, the ORDER BY is done at the end after evaluating the entire MDX expression.