SCD 2 table 上的索引或分区通常从每日快照汇总到每月快照
Index or partition on SCD 2 table commonly rolled up from daily to monthly snapshots
我有一个非常大的 table,每天都会加载。业务用户大多只对月度快照感兴趣(每个月关键字段的最新记录)。
例如:
Loan_Number Balance Load_Date
1 4/25/2016
1 $.75 2/15/2015
1 .50 4/13/2016
2 1/1/2016
2 .75 4/30/2016
2 .50 5/05/2016
2 4/15/2016
3 5/05/2016
3 .50 5/15/2016
4 月快照为:
SELECT *
FROM Loan_Table
WHERE Load_Date <= DATE '4/30/2016'
QUALIFY
row_number() OVER(
PARTITION BY Loan_Number
ORDER BY Load_Date DESC)
= 1
是否可以向此 table 添加任何索引或分区结构以提高性能?如果有帮助,我们是 运行 TD 14。
Load_Number
上的 PI 可能是您可以获得的最好的,分区无济于事。 Explain 希望显示“STAT FUNCTION ... built locally”。
但根据行数和记录大小,一个好的旧 NUSI 加 MAX 可能会有所帮助:
CREATE INDEX (Loan_Number, Load_Date) ORDER BY HASH(Loan_Number) ON Loan_Table;
SELECT *
FROM Loan_Table AS t1
WHERE Load_Date =
( SELECT MAX(Load_Date )
FROM Loan_Table AS t2
WHERE t1.Loan_Number = t2.Loan_Number
AND Load_Date <= DATE '2016-04-30'
)
我有一个非常大的 table,每天都会加载。业务用户大多只对月度快照感兴趣(每个月关键字段的最新记录)。
例如:
Loan_Number Balance Load_Date
1 4/25/2016
1 $.75 2/15/2015
1 .50 4/13/2016
2 1/1/2016
2 .75 4/30/2016
2 .50 5/05/2016
2 4/15/2016
3 5/05/2016
3 .50 5/15/2016
4 月快照为:
SELECT *
FROM Loan_Table
WHERE Load_Date <= DATE '4/30/2016'
QUALIFY
row_number() OVER(
PARTITION BY Loan_Number
ORDER BY Load_Date DESC)
= 1
是否可以向此 table 添加任何索引或分区结构以提高性能?如果有帮助,我们是 运行 TD 14。
Load_Number
上的 PI 可能是您可以获得的最好的,分区无济于事。 Explain 希望显示“STAT FUNCTION ... built locally”。
但根据行数和记录大小,一个好的旧 NUSI 加 MAX 可能会有所帮助:
CREATE INDEX (Loan_Number, Load_Date) ORDER BY HASH(Loan_Number) ON Loan_Table;
SELECT *
FROM Loan_Table AS t1
WHERE Load_Date =
( SELECT MAX(Load_Date )
FROM Loan_Table AS t2
WHERE t1.Loan_Number = t2.Loan_Number
AND Load_Date <= DATE '2016-04-30'
)