<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;">
<div>
<div>
<div>Hi&nbsp;<span style="color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: 13px;">Longxing,</span></div>
<div><br>
</div>
<div>Mondrian will evaluate many functions in-process, so it’s possible that the same SQL will execute for similar MDX (assuming the cells aren’t in cache). &nbsp;Mondrian will retrieve the cell data, and then determine after the fact which tuples to project onto
 the axis. &nbsp;That said, <a href="http://mondrian.pentaho.com/documentation/api/mondrian/olap/MondrianProperties.html#EnableNativeTopCount">
native topcount</a>&nbsp;is enabled by default, and I would expect it to limit the tuples loaded from the database with a query like you have below. &nbsp;IIRC correctly it doesn’t put a LIMIT in the SQL, though, it just cursors through the first N records and stops
 when it reaches the specified topcount. &nbsp;</div>
<div><br>
</div>
<div>If you’re really interested in the nitty gritty details, a good place to start is debugging through RolapResult. &nbsp;There’s even a handy summary of the evaluation algorithm in that class:</div>
<div><a href="https://github.com/pentaho/mondrian/blob/lagunitas/src/main/java/mondrian/rolap/RolapResult.java#L109">https://github.com/pentaho/mondrian/blob/lagunitas/src/main/java/mondrian/rolap/RolapResult.java#L109</a></div>
<div><br>
</div>
<div>
<div id="MAC_OUTLOOK_SIGNATURE"></div>
</div>
</div>
</div>
<div>-matt</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:12pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>&lt;<a href="mailto:mondrian-bounces@pentaho.org">mondrian-bounces@pentaho.org</a>&gt; on behalf of 魏龙星 &lt;<a href="mailto:wlxwolves@gmail.com">wlxwolves@gmail.com</a>&gt;<br>
<span style="font-weight:bold">Reply-To: </span>Mondrian list &lt;<a href="mailto:mondrian@pentaho.org">mondrian@pentaho.org</a>&gt;<br>
<span style="font-weight:bold">Date: </span>Friday, February 26, 2016 at 3:03 AM<br>
<span style="font-weight:bold">To: </span>Mondrian list &lt;<a href="mailto:mondrian@pentaho.org">mondrian@pentaho.org</a>&gt;<br>
<span style="font-weight:bold">Subject: </span>[Mondrian] What happenes during a query using mondrian?<br>
</div>
<div><br>
</div>
<div>
<div>
<div dir="ltr"><br>
<br>
<div class="gmail_quote">
<div dir="ltr">---------- Forwarded message ---------<br>
From: 魏龙星 &lt;<a href="mailto:wlxwolves@gmail.com">wlxwolves@gmail.com</a>&gt;<br>
Date: 2016年2月26日周五 下午4:01<br>
Subject: What happenes during a query using mondrian?<br>
To: &lt;<a href="mailto:mondrian@pentaho.org">mondrian@pentaho.org</a>&gt;<br>
</div>
<br>
<br>
<div dir="ltr"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">I know mondrian converts MDX queries into relational queries and return the result. But is there any details about this process?</span>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
I use the sample cube HR. Here is the MDX:</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
WITH<br>
SET [~ROWS] AS<br>
&nbsp; &nbsp; TopCount({[Time].[Time].[Month].Members},&nbsp;<font color="#ff0000" style="margin:0px;padding:0px;border:0px">3,</font>&nbsp;[Measures].[Org Salary])<br>
SELECT<br>
NON EMPTY {[Measures].[Org Salary]} ON COLUMNS,<br>
NON EMPTY [~ROWS] ON ROWS<br>
FROM [HR]</blockquote>
<div style="margin:0px;padding:0px;border:0px"><br>
</div>
<div style="margin:0px;padding:0px;border:0px">And &nbsp;this is the SQL generated by the MDX. I find it in log:</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
select<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;the_year&quot; as &quot;c0&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;quarter&quot; as &quot;c1&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;the_month&quot; as &quot;c2&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;month_of_year&quot; as &quot;c3&quot;,<br>
&nbsp; &nbsp; sum(&quot;salary&quot;.&quot;salary_paid&quot;) as &quot;c4&quot;<br>
from<br>
&nbsp; &nbsp; &quot;salary&quot; as &quot;salary&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot; as &quot;time_by_day&quot;<br>
where<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;the_year&quot; = 1997<br>
and<br>
&nbsp; &nbsp; &quot;salary&quot;.&quot;pay_date&quot; = &quot;time_by_day&quot;.&quot;the_date&quot;<br>
group by<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;the_year&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;quarter&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;the_month&quot;,<br>
&nbsp; &nbsp; &quot;time_by_day&quot;.&quot;month_of_year&quot;<br>
order by<br>
&nbsp; &nbsp; CASE WHEN sum(&quot;salary&quot;.&quot;salary_paid&quot;) IS NULL THEN 1 ELSE 0 END, sum(&quot;salary&quot;.&quot;salary_paid&quot;) DESC,<br>
&nbsp; &nbsp; CASE WHEN &quot;time_by_day&quot;.&quot;the_year&quot; IS NULL THEN 1 ELSE 0 END, &quot;time_by_day&quot;.&quot;the_year&quot; ASC,<br>
&nbsp; &nbsp; CASE WHEN &quot;time_by_day&quot;.&quot;quarter&quot; IS NULL THEN 1 ELSE 0 END, &quot;time_by_day&quot;.&quot;quarter&quot; ASC,<br>
&nbsp; &nbsp; CASE WHEN &quot;time_by_day&quot;.&quot;the_month&quot; IS NULL THEN 1 ELSE 0 END, &quot;time_by_day&quot;.&quot;the_month&quot; ASC,<br>
&nbsp; &nbsp; CASE WHEN &quot;time_by_day&quot;.&quot;month_of_year&quot; IS NULL THEN 1 ELSE 0 END, &quot;time_by_day&quot;.&quot;month_of_year&quot; ASC</blockquote>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<font color="#ff0000" style="margin:0px;padding:0px;border:0px">I change top 3 to top 10 and I got the same SQL</font>. And the SQL has nothing like &quot;limit&quot;. But it just returned 3 or 10 items. It works, but how?</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<b><font color="#ff0000" style="margin:0px;padding:0px;border:0px">So I am wondering what happened during a query</font></b>? I searched and didn't get any useful information. Can anybody help?&nbsp;</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
Thank you.</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
<br>
</div>
<div style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;font-size:13px;line-height:normal">
Longxing</div>
</div>
</div>
</div>
</div>
</div>
</span>
</body>
</html>