Should I get rid of clustered indexes on Guid columns

后端 未结 9 566
遇见更好的自我
遇见更好的自我 2020-12-05 17:19

I am working on a database that usually uses GUIDs as primary keys.

By default SQL Server places a clustered index on primary key columns. I understand that this is

9条回答
  •  無奈伤痛
    2020-12-05 18:03

    Yes, there's no point in having a clustered index on a random value.

    You probably do want clustered indexes SOMEWHERE in your database. For example, if you have a "Author" table and a "Book" table with a foreign key to "Author", and if you have a query in your application that says, "select ... from Book where AuthorId = ..", then you would be reading a set of books. It will be faster if those book are physically next to each other on the disk, so that the disk head doesn't have to bounce around from sector to sector gathering all the books of that author.

    So, you need to think about your application, the ways in which it queries the database.

    Make the changes.

    And then test, because you never know...

提交回复
热议问题