How to create a new index on a massive SQL table
I have a massive (3,000,000,000 rows) fact table in a datawarehouse star schema. The table is partitioned on the date key.
I would like to add an index on one of the foreign keys. This is to allow me to identify and remove childless rows开发者_Go百科 in a large dimension table.
If I just issue a CREATE INDEX statement then it would take forever.
Do any SQL gurus have any fancy techniques for this problem?
(SQL 2008)
--Simplified example...
CREATE TABLE FactRisk
(
DateId int not null,
TradeId int not null,
Amount decimal not null
)
--I want to create this index, but the straightforward way will take forever...
CREATE NONCLUSTERED INDEX IX_FactRisk_TradeId on FactRisk (TradeId)
I have a plan...
- Switch out all the daily partitions to tables
- Index the now empty fact table
- Index the individual partition
- Switch all the partitions back in
Initial investigation implies that this will work. I will report back...
精彩评论