<div>Here&#39;s an example query that demonstrates some of the limitations of the existing native non empty:</div><div><br></div><div>SELECT NON EMPTY </div><div> CrossJoin(  [Education Level].[Education Level].members, </div>

<div>     UNION( CrossJoin( [product].[product name].members, {gender.M}), </div><div>      { CrossJoin( { [Product].[All Products].[Food].[Frozen Foods].[Breakfast Foods].[Waffles].[Golden].[Golden Waffles] }, </div><div>

        { gender.M}) } ) ) on 0</div><div>FROM SALES</div><div>WHERE ([Time].[1997].[Q1].[3])</div><div><br></div><div>Ideally this MDX would fire a single native query to get the crossjoined members constrained by Gender.M and Time.1997.Q1.3.  With existing NNE, however, the UNION part requires ExpandNonNative, which will result in the nested CrossJoin args being evaluated separately.  If the nested crossjoins contained features requiring ExpandNonNative, the logic would continue to descend the expression, performing a bottom up evaluation.</div>

<div><br></div><div>ExpandNonNative will actually fail outright with the above query, since it only works if the expanded set is a list of members.  Even if we corrected this limitation, though, it would still fire additional native queries, which can be very expensive.</div>

<div><br></div><div>The above query is a little contrived, but here&#39;s a query generated by our reporting client (Cognos) that fails in part for the same reason--the sub-expressions require expansion, but also contain CrossJoins.</div>

<div><br></div><div>WITH </div><div>MEMBER [Product].[COG_OQP_INT_umg1] AS &#39;IIF([Measures].CURRENTMEMBER IS [Measures].[Unit Sales], ([Product].[COG_OQP_INT_m2], [Measures].[Unit Sales]), AGGREGATE({[Product].[Product Name].MEMBERS}))&#39;, SOLVE_ORDER = 4 </div>

<div>MEMBER [Product].[COG_OQP_INT_m2] AS &#39;AGGREGATE({[Product].[Product Name].MEMBERS}, [Measures].[Unit Sales])&#39;, SOLVE_ORDER = 4 SET [COG_OQP_INT_s5] AS &#39;CROSSJOIN({[Marital Status].[All Marital Status].[S]}, [COG_OQP_INT_s4])&#39; SET [COG_OQP_INT_s4] AS &#39;CROSSJOIN({[Gender].[All Gender].[F]}, [COG_OQP_INT_s2])&#39; </div>

<div>SET [COG_OQP_INT_s3] AS &#39;CROSSJOIN({[Gender].[All Gender].[F]}, {[COG_OQP_INT_s2], [COG_OQP_INT_s1]})&#39; </div><div>SET [COG_OQP_INT_s2] AS &#39;CROSSJOIN({[Product].[Product Name].MEMBERS}, {[Customers].[Name].MEMBERS})&#39; </div>

<div>SET [COG_OQP_INT_s1] AS &#39;CROSSJOIN({[Product].[COG_OQP_INT_umg1]}, {[Customers].DEFAULTMEMBER})&#39; </div><div>SELECT {[Measures].[Unit Sales]} ON AXIS(0), </div><div>GENERATE({[Education Level].[All Education Levels].[Graduate Degree]}, CROSSJOIN(HEAD({([Education Level].CURRENTMEMBER)}, IIF(COUNT([COG_OQP_INT_s5], INCLUDEEMPTY) &gt; 0, 1, 0)), GENERATE({[Marital Status].[All Marital Status].[S]}, CROSSJOIN(HEAD({([Marital Status].CURRENTMEMBER)}, IIF(COUNT([COG_OQP_INT_s4], INCLUDEEMPTY) &gt; 0, 1, 0)), [COG_OQP_INT_s3]), ALL)), ALL) ON AXIS(1) </div>

<div>FROM [Sales]  </div><div><br></div><div>In addition to the problems with ExpandNonNative, this particular query also has a calculated member on the columns.  Calculated members on a dimension will also cause NNE to fail right now.</div>

<div><br></div><div>The approach I&#39;ve been exploring attempts to tranform the starting, high cardinality set to a simpler low cardinality version.  The results of evaluating the low cardinality set can give us information for limiting the high cardinality set.  </div>

<div><br></div><br><div class="gmail_quote">On Fri, May 29, 2009 at 8:20 PM, Matt Campbell <span dir="ltr">&lt;<a href="mailto:mkambol@gmail.com">mkambol@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">ExpandNonNative does increase the number of cases native non empty can<br>
handle, but it will fail if the expanded set (non-natively) exceeds<br>
some threshold (has greater than 1k members).  Also, expandNonNative<br>
can result in *several* native queries being fired, which is far less<br>
efficient than a single native query.<br>
<br>
I&#39;ll send out some specific examples next week.<br>
<br>
On 5/29/09, Zelaine Fong &lt;<a href="mailto:zfong@lucidera.com">zfong@lucidera.com</a>&gt; wrote:<br>
</div><div><div></div><div class="h5">&gt; Matt,<br>
&gt;<br>
&gt; Doesn&#39;t the existing mondrian property &quot;mondrian.native.ExpandNonNative&quot;<br>
&gt; already do this?  The property is currently set to false by default.  I<br>
&gt; set it true in my environment ran the following query:<br>
&gt;<br>
&gt; SELECT NonEmptyCrossjoin( Product.[Product Name].members,<br>
&gt;     {Time.[1997].LastChild, Time.[1997].LastChild.PrevMember}) on 0<br>
&gt; from sales;<br>
&gt;<br>
&gt; and the generated readTuples query is doing the cross join on Products<br>
&gt; and Time natively.<br>
&gt;<br>
&gt; 5299 [main] DEBUG mondrian.rolap.RolapUtil  - SqlTupleReader.readTuples<br>
&gt; [[Product].[Product Name], [Time].[Quarter]]: executing sql [select<br>
&gt; &quot;product_class&quot;.&quot;product_family&quot;, &quot;product_class&quot;.&quot;product_department&quot;,<br>
&gt; &quot;product_class&quot;.&quot;product_category&quot;,<br>
&gt; &quot;product_class&quot;.&quot;product_subcategory&quot;, &quot;product&quot;.&quot;brand_name&quot;,<br>
&gt; &quot;product&quot;.&quot;product_name&quot;, &quot;time_by_day&quot;.&quot;the_year&quot;,<br>
&gt; &quot;time_by_day&quot;.&quot;quarter&quot; from &quot;product&quot; as &quot;product&quot;, &quot;product_class&quot; as<br>
&gt; &quot;product_class&quot;, &quot;sales_fact_1997&quot; as &quot;sales_fact_1997&quot;, &quot;time_by_day&quot;<br>
&gt; as &quot;time_by_day&quot; where &quot;product&quot;.&quot;product_class_id&quot; =<br>
&gt; &quot;product_class&quot;.&quot;product_class_id&quot; and &quot;sales_fact_1997&quot;.&quot;product_id&quot; =<br>
&gt; &quot;product&quot;.&quot;product_id&quot; and &quot;sales_fact_1997&quot;.&quot;time_id&quot; =<br>
&gt; &quot;time_by_day&quot;.&quot;time_id&quot; and (&quot;time_by_day&quot;.&quot;quarter&quot; in (&#39;Q4&#39;, &#39;Q3&#39;) and<br>
&gt; &quot;time_by_day&quot;.&quot;the_year&quot; = 1997) group by<br>
&gt; &quot;product_class&quot;.&quot;product_family&quot;, &quot;product_class&quot;.&quot;product_department&quot;,<br>
&gt; &quot;product_class&quot;.&quot;product_category&quot;,<br>
&gt; &quot;product_class&quot;.&quot;product_subcategory&quot;, &quot;product&quot;.&quot;brand_name&quot;,<br>
&gt; &quot;product&quot;.&quot;product_name&quot;, &quot;time_by_day&quot;.&quot;the_year&quot;,<br>
&gt; &quot;time_by_day&quot;.&quot;quarter&quot; order by &quot;product_class&quot;.&quot;product_family&quot; ASC,<br>
&gt; &quot;product_class&quot;.&quot;product_department&quot; ASC,<br>
&gt; &quot;product_class&quot;.&quot;product_category&quot; ASC,<br>
&gt; &quot;product_class&quot;.&quot;product_subcategory&quot; ASC, &quot;product&quot;.&quot;brand_name&quot; ASC,<br>
&gt; &quot;product&quot;.&quot;product_name&quot; ASC, &quot;time_by_day&quot;.&quot;the_year&quot; ASC,<br>
&gt; &quot;time_by_day&quot;.&quot;quarter&quot; ASC], exec 1469 ms<br>
&gt;<br>
&gt; -- Zelaine<br>
&gt;<br>
&gt; Matt Campbell wrote:<br>
&gt;&gt; I’m involved in the development of a reporting application for analyzing<br>
&gt;&gt; medical claims data.  Users of our application often want to run reports<br>
&gt;&gt; that generate very high cardinality queries.  This could mean queries<br>
&gt;&gt; with very large dimensions (e.g. “Patients”, which could have millions<br>
&gt;&gt; of members) or deeply crossjoined axes (e.g. 15 nested dimensions) or a<br>
&gt;&gt; combination of both.  Since they are executed NON EMPTY and usually are<br>
&gt;&gt; tightly constrained, the final results often involve only a few dozen<br>
&gt;&gt; tuples.  While Mondrian does have some facilities to help push NON EMPTY<br>
&gt;&gt; into native evaluation, we have run into a number of limitations that<br>
&gt;&gt; have prevented us from taking advantage of the feature.  In particular<br>
&gt;&gt; it fails if the CrossJoin contains complex expressions or calculated<br>
&gt;&gt; members (which occur in nearly all of our queries).<br>
&gt;&gt;<br>
&gt;&gt; The existing native code will look for certain features within the set<br>
&gt;&gt; it is evaluating.  For example, it will look for &lt;Level&gt;.members, or<br>
&gt;&gt; &lt;Member&gt;.children within a crossjoin arg.  If it finds a construct that<br>
&gt;&gt; it can’t recognize, or if any number of conditions fail to hold, then it<br>
&gt;&gt; will abort native evaluation.  If everything goes correctly, then it<br>
&gt;&gt; will use SqlTupleReader to load the set of tuples with non empty data<br>
&gt;&gt; using the individual members within the set as a constraint.  The key<br>
&gt;&gt; piece here is to come up with that list of individual members for the<br>
&gt;&gt; constraint.  So if I have a CrossJoin of ( Product.[Product<br>
&gt;&gt; Name].members, { Time.1997.Q1 } ), the native query should be<br>
&gt;&gt; constrained to Q1 1997.<br>
&gt;&gt;<br>
&gt;&gt; An alternative to get the set of applicable constraints would be to use<br>
&gt;&gt; a multi-pass approach, first transforming the query to a simpler form<br>
&gt;&gt; and using the results of that query to determine how to natively<br>
&gt;&gt; evaluate it.  So for example:<br>
&gt;&gt;<br>
&gt;&gt; 1)       Given an input set, modify any references to &lt;Level&gt;.members,<br>
&gt;&gt; &lt;Member&gt;.children, etc. to be a set consisting of a single calculated<br>
&gt;&gt; member with a scalar value (note that the scalar value is not<br>
&gt;&gt; important—we just want to replace it with something that needs no<br>
&gt;&gt; further evaluation).<br>
&gt;&gt;<br>
&gt;&gt; 2)       Evaluate the modified set.  This should produce a comparatively<br>
&gt;&gt; small set of tuples that captures the individual values of any other<br>
&gt;&gt; dimensions in the set.  Any dimension that contains only individual<br>
&gt;&gt; members at a single level can be used as constraints, since the<br>
&gt;&gt; &lt;Level&gt;.members intersects with them.<br>
&gt;&gt;<br>
&gt;&gt; 3)       Fire a native query to get the tuples that have non empty data<br>
&gt;&gt; with the constraints identified in (2), expanding back out the<br>
&gt;&gt; expressions that were modified in (1).  (or, take an approach like<br>
&gt;&gt; crossjoin optimizer and actually evaluate the remaining intersections).<br>
&gt;&gt;<br>
&gt;&gt; I implemented a quick and dirty proof-of-concept function which uses the<br>
&gt;&gt; above approach.  So with a query like the following:<br>
&gt;&gt;<br>
&gt;&gt;     SELECT NativizeSet( Crossjoin( Product.[Product Name].members,<br>
&gt;&gt;            {Time.[1997].LastChild, Time.[1997].LastChild.PrevMember}  ))<br>
&gt;&gt;     on 0<br>
&gt;&gt;     from sales<br>
&gt;&gt;<br>
&gt;&gt; (1)  The function will first transform the query to<br>
&gt;&gt;<br>
&gt;&gt;     with member [Product].[substitution-Product] as &#39;101010.0&#39;<br>
&gt;&gt;       set [setProduct] as &#39;{[Product].[substitution-Product]}&#39;<br>
&gt;&gt;     select NativizeSet(Crossjoin([setProduct], {[Time].[1997].LastChild,<br>
&gt;&gt;     [Time].[1997].LastChild.PrevMember})) ON COLUMNS<br>
&gt;&gt;     from [Sales]<br>
&gt;&gt;<br>
&gt;&gt; (2)  It will then evaluate the transformed set, which will return a list<br>
&gt;&gt; of tuples<br>
&gt;&gt;<br>
&gt;&gt;       ( product.[substitution-Product], Time.1997.Q4)<br>
&gt;&gt;       ( product.[substitution-Product], Time.1997.Q3)<br>
&gt;&gt;<br>
&gt;&gt; (3)  The function can then fire a native query to retrieve the actual<br>
&gt;&gt; [Product Name] members that intersect with Q4 and Q3.<br>
&gt;&gt;<br>
&gt;&gt; This works nicely with sets that have arbitrarily complex expressions,<br>
&gt;&gt; but with some caveats:<br>
&gt;&gt;<br>
&gt;&gt; * the set expression must contain an expression that can actually be<br>
&gt;&gt; modified (like &lt;Level&gt;.members).<br>
&gt;&gt;<br>
&gt;&gt; * expressions replaced in (1) can’t be inside of functions like filter,<br>
&gt;&gt; topcount, or head, since the expression actually needs to look at the<br>
&gt;&gt; set of members to determine what to return.  I’m sure there are other<br>
&gt;&gt; cases like this where the “substituted” set is dynamic and the<br>
&gt;&gt; transformation described above would not result in the desired result.<br>
&gt;&gt;<br>
&gt;&gt; Even with the caveats above I believe that an approach like the above<br>
&gt;&gt; will work for most of our use cases.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; Let me know if anyone has feedback.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; ------------------------------------------------------------------------<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; Mondrian mailing list<br>
&gt;&gt; <a href="mailto:Mondrian@pentaho.org">Mondrian@pentaho.org</a><br>
&gt;&gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Mondrian mailing list<br>
&gt; <a href="mailto:Mondrian@pentaho.org">Mondrian@pentaho.org</a><br>
&gt; <a href="http://lists.pentaho.org/mailman/listinfo/mondrian" target="_blank">http://lists.pentaho.org/mailman/listinfo/mondrian</a><br>
&gt;<br>
</div></div></blockquote></div><br>