【发布时间】:2016-04-21 09:42:47
【问题描述】:
我正在尝试找出哪些字段用于我的事实表的聚集索引(它们都有类似的结构)。我将以 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) 聚集索引:DateOfSaleKey。 这可能会使 INSERT 更容易,但我不确定 DELETE。
(2) 聚集索引:DateOfSaleKey、ProfitCentreKey。 我必须将 ProfitCentreKey 添加到表中。它可能会使 DELETE 更容易,但它会将表分割为 ProfitCentreKey 不会按顺序加载
DELETE 会更简单:
DELETE FROM FactSales WHERE DateOfSaleKey = 20160105 AND ProfitCentreKey = 385
任何建议都会有帮助。谢谢
【问题讨论】:
标签: database database-design indexing data-warehouse database-performance