包含许多站点的事实数据表上的聚集索引



我正在尝试找出用于事实数据表(它们都具有相似结构)的聚集索引的字段。我将以FactSales为例

CREATE TABLE dbo.FactSales
(
DateOfSaleKey int NOT NULL, -- PK,
--ProfitCentreKey int NOT NULL, -- (maybe add this?)
RevenueCentreKey int NOT NULL, -- PK
TransactionHeaderNumber int NOT NULL, -- PK
TransactionDetailNumber int NOT NULL, -- PK
TableNumber int NOT NULL,
TransactionOrCheckNumber int NOT NULL,
TerminalKey int NOT NULL,
CashierKey int NOT NULL,
TimeSlotKey int NOT NULL,
TransactionTypeKey int NOT NULL,
TransactionDetailTypeKey int NOT NULL,
MediaKey int NOT NULL,
SaleItemKey int NOT NULL,
SaleTypeKey int NOT NULL,
SalesQuantity int NOT NULL,
SalesGross smallmoney NOT NULL,
SalesNet decimal (16, 8) NOT NULL,
VAT decimal (16, 8) NOT NULL,
...
) 

加载中:事实数据表由ProfitCentre(ProfitCentreKey)和按天(DateOfSaleKey)加载。我们的表中没有ProfitCentreKey,因为我们有更精细的RevenueCentreKey,它是餐厅中的一个部分。

因此,每个负载如下所示:

DELETE s
FROM FactSales s
INNER JOIN DimOrganisation o ON s.RevenueCentreKey = o.RevenueCentreKey
WHERE s.DateOfSaleKey = 20160105 AND o.ProfitCentreKey = 385
INSERT INTO FactSales (DateOfSaleKey, RevenueCentreKey, ...)
SELECT DateOfSaleKey, RevenueCentreKey, ... FROM #SalesForProfitCentreAndDateOfSale

我正在考虑什么...

(1) 簇状索引:销售日期密钥。这可能会使插入更容易,但我不确定删除。

(2)簇簇指数:销售日期、利润中心键。我将不得不将ProfitCentreKey添加到表中。它可能会使删除更容易,但它会分割表,因为 ProfitCentreKey 不会按顺序加载

删除会更简单:

DELETE FROM FactSales WHERE DateOfSaleKey = 20160105 AND ProfitCentreKey = 385

任何建议都会有所帮助。谢谢

嗨,

如果只关心删除。

应使用分区表。 在利润中心键上创建分区函数。 然后切换部分。

最新更新