One 400GB table, One query - Need Tuning Ideas (SQL2005)

后端 未结 24 2315
予麋鹿
予麋鹿 2021-01-30 15:03

I have a single large table which I would like to optimize. I\'m using MS-SQL 2005 server. I\'ll try to describe how it is used and if anyone has any suggestions I would appreci

24条回答
  •  花落未央
    2021-01-30 15:59

    OK,

    Let's try to solve this problem with statistics. Before you try and create any index, you should ask what combination of keys gives me better selectiveness:

    1. K1 : 10 different values
    2. K3 : 100 different values
    3. k4 : 10 different values
    4. k5 : 2 differente values
    5. k6 : 2 differente values

    If we make a compund key of k1,k3,k4,k5,and k6 that means that key will only have 40,000 different combinations(10 * 100 * 10 * 2 * 2). That means that if we have 100,000,000 record divides by 40,000, statistically we will have a subset of 2,500 different records, on wich a sequential search will be aplied to complete the other restrictions of the WHERE clause.

    If we extrapolate this result and compare them with the current execution time(30 minutes), with a key(k1) that generates statistically a subset of 10 million different records we get:

    10,000,000 rec * X sec = 30 * 60 sec * 2,500 rec

    => X sec = 0.45 sec

    Not bad huh? Better yet. How about if we eliminate k5 and k6 from the compund index? Statistically we will have a subset of 10,000 different records where the sequential search will be performed. In theory, How much time will that take? lets see:

    10,000,000 rec * X sec = 30 * 60 * 10,000 rec

    => X sec = 1.8 sec

    Since we want the smallest index footprint traded off with the best possible performance, I would say an index on k1 + K3 + K4 is as good as it gets.

    Hope this helps,

提交回复
热议问题