No indexes on small tables?

后端 未结 13 1022
忘掉有多难
忘掉有多难 2020-12-13 06:35

\"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.\" (Donald Knuth). My SQL tables are unlikely to conta

13条回答
  •  感动是毒
    2020-12-13 07:15

    Absolutely incorrect. 100% incorrect. Don't put a million pointless indexes, but you do want a Primary Key (in most cases), and you do want it CLUSTERED correctly.

    Here's why:

    SELECT * FROM MySmallTable <-- No worries... Index won't help
    
    SELECT
        *
    FROM
        MyBigTable INNER JOIN MySmallTable ON... <-- Ahh, now I'm glad I have my index.
    

    Here's a good rule to go by.

    "Since I have a TABLE, I'm likely going to want to query it at some time... If I'm going to query it, I'm likely going to do so in a consistent way..." <-- That's how you should index the table.

    EDIT: I'm adding this line: If you have a concrete example in mind, I'll show you how to index it, and how much of a savings you'll get from doing so. Please supply a table, and an example of how you plan in using that table.

提交回复
热议问题