mdx查询占用的时间比sql多

时间:2014-12-08 14:45:08

标签: mdx geospatial data-warehouse olap mondrian

我已将sql分析转换为mdx分析,发现mdx在执行时间方面比sql贵得多。下面是我想要转换为mdx的sql



select  inc.incident_id,inc.incident_start_time, inc.incident_end_time,inc_type.incident_type,inc.incident_desc,st_x(inc.the_geom) as incident_lon, st_y(inc.the_geom) as incident_lat,inc_type.class_name as incident_class, inc_type.incident_image  ,fir.modus_operandi, fir.fir_status, fir.fir_serial_no as fir_id  from analyst_mdx.incident as inc  join analyst_mdx.incident_types as inc_type on inc.incident_type = inc_type.incident_type_id left outer join analyst_mdx.fir_details as fir on inc.fir_no = fir.fir_no  join analyst_mdx.district on (st_contains(district.the_geom, inc.the_geom) and district.district_id=1)  where inc.incident_type in ('10','8','14','11','5','9','19','21','6','7','16','3','4','12','20','13','1','2','23','17','18')  and ((inc.incident_start_time between '2012-01-29T00:00:00'  and '2014-12-29T23:59:59')) order by incident_start_time, incident_end_time




这就是表格相互连接的事实

enter image description here 现在让我告诉你我制作的mdx



with member [Measures].[incident_type] as '[incident].CurrentMember.Properties("incident_type")'  
  member [Measures].[incident_desc] as '[incident].CurrentMember.Properties("incident_desc")'
  member [Measures].[incident_class] as '[incident].CurrentMember.Properties("incident_class")'
  member [Measures].[incident_image] as '[incident].CurrentMember.Properties("incident_image")'
  member [Measures].[modus_operandi] as '[incident].CurrentMember.Properties("modus_operandi")'
  member [Measures].[fir_status] as '[incident].CurrentMember.Properties("fir_status")'
  member [Measures].[fir_id] as '[incident].CurrentMember.Properties("fir_id")'
  member [Measures].[date_start_time] as '[incident].CurrentMember.Properties("date_start_time")'
  member [Measures].[the_geom] as '[incident].CurrentMember.Properties("the_geom")'
  member [Measures].[date_end_time] as '[incident].CurrentMember.Properties("date_end_time")'
  member [time].[newtime] as 'Aggregate({([time].[all  periods].[2012].[4].[15] : [time].[all  periods].[2012].[4].[30]),([time].[all  periods].[2012].[5]:[time].[all  periods].[2012].[12]) ,([time].[all  periods].[2013]),([time].[all  periods].[2014].[1] : [time].[all  periods].[2014].[6]),([time].[all  periods].[2014].[7].[1] : [time].[all  periods].[2014].[7].[15])})'
select {[Measures].[incident_type], [Measures].[incident_desc], [Measures].[incident_class],[Measures].[incident_image], [Measures].[modus_operandi], [Measures].[fir_status],[Measures].[fir_id], [Measures].[the_geom], [Measures].[date_start_time],[Measures].[date_end_time], [Measures].[incident_count]} ON COLUMNS,
NON EMPTY Filter([incident].[incident_id].Members, ST_Contains([district].[all district].[1].Properties("the_geom"),[incident].CurrentMember.Properties("the_geom"))) ON ROWS
from [pin_mapping]
where ([time].[newtime])




表的最大记录是6.5万,sql执行时间不超过3秒,mdx需要超过10分钟。我的整个olap概念都失败了。有谁能解释我哪里出错了?

这是我正在使用的立方体......



<Schema name="analyst_haryana">
  <Cube name="pin_mapping" cache="true" enabled="true">
    <Table name="pin_mapping_fact_table" schema="analyst_mdx"></Table>
    <Dimension type="StandardDimension" foreignKey="incident_id" name="incident">
      <Hierarchy hasAll="true" allMemberName="all incident" primaryKey="incident_id">
        <Table name="incident" schema="analyst_mdx"> </Table>
        <Level name="incident_id" column="incident_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="Never">
          <Property name="the_geom" column="the_geom" type="Geometry"></Property>
          <Property name="incident_type" column="incident_desc" type="String"></Property>
          <Property name="incident_desc" column="incident_desc" type="String"></Property>
          <Property name="fir_status" column="fir_status" type="String"></Property>
          <Property name="incident_image" column="incident_image" type="String"></Property>
          <Property name="modus_operandi" column="incident_desc" type="String"></Property>
          <Property name="incident_class" column="incident_desc" type="String"></Property>
          <Property name="date_start_time" column="date_start_time" type="String"></Property>
          <Property name="date_end_time" column="date_end_time" type="String"></Property>
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="TimeDimension" foreignKey="time_id" name="time">
      <Hierarchy hasAll="true" allMemberName="all  periods" primaryKey="time_id">
        <Table name="aux_dates" schema="analyst_mdx"></Table>
        <Level name="year" column="the_year" type="Numeric" uniqueMembers="true" levelType="TimeYears" hideMemberIf="Never"></Level>
		<Level name="quarter" column="the_quarter" type="String" uniqueMembers="false" levelType="TimeQuarters" hideMemberIf="IfParentsName"></Level>
        <Level name="month" column="the_month" type="Numeric" uniqueMembers="false" levelType="TimeMonths" hideMemberIf="IfParentsName"></Level>
        <Level name="day" column="the_day" type="Numeric" uniqueMembers="false" levelType="TimeDays" hideMemberIf="IfParentsName"></Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="StandardDimension" foreignKey="district_id" name="district">
      <Hierarchy hasAll="true" allMemberName="all district" primaryKey="district_id">
        <Table name="district" schema="analyst_mdx"></Table>
        <Level name="district_id" column="district_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="IfParentsName">
          <Property name="the_geom" column="the_geom" type="Geometry"></Property>
        </Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="StandardDimension" foreignKey="incident_type_id" name="incident_type">
      <Hierarchy hasAll="true" allMemberName="all incident _types" primaryKey="incident_type_id">
        <Table name="incident_types" schema="analyst_mdx"></Table>
        <Level name="incident_type_id" column="incident_type_id" type="Numeric" uniqueMembers="true" levelType="Regular" hideMemberIf="Never"></Level>
      </Hierarchy>
    </Dimension>
    <Dimension type="StandardDimension" foreignKey="fir_serial_no" name="fir_details">
      <Hierarchy hasAll="true" allMemberName="all status" primaryKey="fir_serial_no">
        <Table name="fir_details" schema="analyst_mdx"></Table>
        <Level name="fir_status" column="fir_status" type="String" uniqueMembers="false" levelType="Regular" hideMemberIf="Never"></Level>
      </Hierarchy>
    </Dimension>
    <Measure name="incident_count" column="incident_count" datatype="Numeric" aggregator="count" visible="true"></Measure>
  </Cube>
</Schema>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

嗯,不完全确定,因为我没有执行计划,但这里什么也没有。

  1. 你有一个调优良好的SQL查询,它正在进行集合计算,这是SQL Server擅长的。由于表的大小相对较小,因此必然会很快。另一方面,在MDX查询中,您实际上正在进行逐个单元计算(由于使用了CURRENTMEMBER函数。分析引擎很糟糕!因此它一定很慢。

  2. 您正在使用NON EMPTY函数,该函数基本上遍历每一行并过滤掉EMPTY函数。这增加了引擎的开销。通过删除NON EMPTY子句来运行查询,看看它是否会缩短执行时间(尽管我观察到sometimes NON EMPTY子句实际上改善了渲染时间)

    < / LI>

    必须在此处重新考虑立方体设计。必要时,必须尝试将所有计算成员作为所涉及维度的属性。

答案 1 :(得分:0)

启用mondrian slow sql查询日志(在log4j.xml中完成)并查看哪个查询是问题。

看看它是一个查询,还是只是蒙德里安正在执行1000个。

如果后者检查架构中的approxRowCount选项以及uniqueMembers选项。可能会发布上述更改的架构和结果,以便我们了解更多信息。还有(已弃用的)高心率选项。