使用相同中间维度的多个引用维度

时间:2014-10-08 16:15:54

标签: sql sql-server-2008-r2 ssas olap dimension

SQL Server 2008 R2

我有一个链接到维度的事实表。该维度具有针对不同日期,开始,结束等的多个date_id。因此,在维度使用屏幕中,将与度量值组链接的日期维度的各种化身作为引用维度。

为填充度量值组而生成的SQL似乎多次链接到维度表,这会大大减慢速度。实际上有6个连接,根据执行计划,每个都是总成本的14%,所以如果我能阻止这样做,我认为这个东西将以当前成本的30%执行。

事实表实际上是一个视图,因此我可以将date_id添加到视图中,并将尺寸设置为常规关系。

是否有更简洁的方法来强制更高效的SQL?

以下三个表可用于说明问题:

CREATE TABLE dbo.FactTable
(
Fact1 numeric(16, 2) NOT NULL,
ForeignKey1 int NOT NULL
)  ON [PRIMARY]
GO

CREATE TABLE dbo.IntermediateDimension
(
[Key]    int NOT NULL,
DateId1 int not null,
DateId2 int not null,
DateId3 int not null,
DateId4 int not null,
DateId5 int not null,
DateId6 int not null,
Attr1 nvarchar(30),
Attr2 nvarchar(30)
) on [PRIMARY]  
GO

CREATE TABLE dbo.DateDimension
(
[Key]    int NOT NULL,
[Date] datetime not null
) on [PRIMARY]   
GO

Fact Table链接到中间维度以检索日期ID 从表DateDimension在多维数据集中创建6个维度。它们通过中间维度作为参考尺寸链接。

当我处理多维数据集时,运行以下SQL: -

SELECT 
[dbo_FactTable].[Fact1] AS [dbo_FactTableFact10_0],
[dbo_FactTable].[ForeignKey1] AS [dbo_FactTableForeignKey10_1],
[dbo_IntermediateDimension_2].[DateId1] AS [dbo_IntermediateDimensionDateId17_0],
[dbo_IntermediateDimension_3].[DateId2] AS [dbo_IntermediateDimensionDateId29_0],
[dbo_IntermediateDimension_4].[DateId3] AS [dbo_IntermediateDimensionDateId311_0],
[dbo_IntermediateDimension_5].[DateId4] AS [dbo_IntermediateDimensionDateId413_0],
[dbo_IntermediateDimension_6].[DateId5] AS [dbo_IntermediateDimensionDateId515_0],
[dbo_IntermediateDimension_7].[DateId6] AS [dbo_IntermediateDimensionDateId617_0]
FROM 
[dbo].[FactTable] AS [dbo_FactTable],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_2],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_3],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_4],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_5],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_6],
[dbo].[IntermediateDimension] AS [dbo_IntermediateDimension_7]
WHERE    (       (    
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_2].[Key]   )  AND     (    
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_3].[Key]   )      AND     (   
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_4].[Key]   )      AND     (    
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_5].[Key]   )      AND     (    
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_6].[Key]   )      AND     (    
[dbo_FactTable].[ForeignKey1]   =  [dbo_IntermediateDimension_7].[Key]   )     )

您可以看到它连接到同一行6次以获取每个日期ID。它不需要这样做。

0 个答案:

没有答案