[Mondrian] NON EMPTY crossjoin not optimized anymore

Robin Tharappel rtharappel at gmail.com
Fri Oct 5 16:20:22 EDT 2007

In Mondrian 2.2.2 there was a optimization made to the evaluation of
the non empty cross join. In the CrossJoinFunDef.crosJoin() method the
following comment in the code describes the optimization:

        // Optimize nonempty(crossjoin(a,b)) ==
        //  nonempty(crossjoin(nonempty(a),nonempty(b))

In the current Mondrian tip this comment is in the code however it
does not appear the optimization is being made. Previously there was
the following in 2.2.2 to allow this type of optimization:

if (useOptimizer && size > opSize && evaluator.isNonEmpty()) {

      list1 = nonEmptyList(evaluator, list1);
      list2 = nonEmptyList(evaluator, list2);


size = (long)list1.size() * (long)list2.size();

List result = new ArrayList((int) size);

// Code to perform cross join …

Performing the nonempty check on dimension set A and B can help
substantially where there is a large volume of dimension members but
the data is sparse. For example if there was a non empty cross join
between two dimension each having 100,000 members the cross product
would be 10 billion. However if a non empty check was performed on
each dimension set before the cross product is made the cross product
can be reduced substantially depending on how sparse the data is.
Using a native.nonempty could help here however depending on the MDX
query it is not always guaranteed to be used (as described in previous

This issue was originally discussed in tracker 1675585 (NON EMPTY
cross join not optimized anymore) where the code change above is
described.  I would like to add this optimization back in but wanted
to check if there were any known issues for it being removed. It looks
like it was removed in revision 45 of CrossJoinFunDef due to a test
case failure. I think that might have been the case because there is
not a check to determine if the evaluator is nonempty (since the
crossJoin method is used by NonEmptyCrossJoin and CrossJoin



More information about the Mondrian mailing list