开发者

How to create a new index on a massive SQL table

开发者 https://www.devze.com 2023-03-16 12:53 出处:网络
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 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...

  1. Switch out all the daily partitions to tables
  2. Index the now empty fact table
  3. Index the individual partition
  4. Switch all the partitions back in

Initial investigation implies that this will work. I will report back...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号