上一篇文章介紹了添加filter能夠加快查詢速度。下面繼續分析:sql
下面這個MDX語句:測試
WITH SET [~FILTER] AS {[create_date].[create_date].[2013-01-01]} SET [~ROWS_dimPartner_dimPartner] AS {[dimPartner].[dimPartner].[name].Members} SET [~ROWS_sight_sight] AS Hierarchize({{[sight].[sight].[country].Members}, {[sight].[sight].[area].Members}}) SELECT NON EMPTY {[Measures].[money], [Measures].[quantity], [Measures].[qunar_income], [Measures].[order_num]} ON COLUMNS, NON EMPTY Order(NonEmptyCrossJoin([~ROWS_dimPartner_dimPartner], [~ROWS_sight_sight]), [Measures].[money], BDESC) ON ROWS FROM [com_order_detail_cube] WHERE [~FILTER] 2016-04-15 17:56:05,176 DEBUG [org.saiku.service.olap.ThinQueryService] Query End 2016-04-15 17:56:05,177 INFO [org.saiku.service.olap.ThinQueryService] RUN#:94 Size: 7/8 Execute: 444501ms Format: 1ms Totals: 0ms Total: 444502ms
查看數據查詢語句,本琢磨這應該很快,執行一個sql便可優化
select "com_order_detail_view"."create_date" as "c0", "dim_partner"."name" as "c1", "com_order_detail_view"."area" as "c2", sum("com_order_detail_view"."money") as "m0", sum("com_order_detail_view"."quantity") as "m1", sum("com_order_detail_view"."qunar_income") as "m2", count(distinct "com_order_detail_view"."display_id") as "m3" from "com_order_detail_view" as "com_order_detail_view", "dim_partner" as "dim_partner" where "com_order_detail_view"."create_date" = DATE '2013-01-01' and "com_order_detail_view"."partner" = "dim_partner"."code" group by "com_order_detail_view"."create_date", "dim_partner"."name", "com_order_detail_view"."area";
結果發如今這以前,還須要執行這條語句,且執行時間最長:spa
select count(distinct "area") from "com_order_detail_view"
意淫緣由應該是saiku對執行的結果進行format,因此才執行這條語句,而這個字段應該是維度表,因此猜測使用維度表或者能夠提高效率。通過測試,發現確實如此,因此儘可能使用緯度表優化數據的使用。code