Академический Документы
Профессиональный Документы
Культура Документы
aspx
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fsqlp%2Frbafysqltrig.htm
Clustered Index
Only one per table Faster to read than non clustered as data is physically stored in index order
Can be used many times per table Quicker for insert and update operations than a clustered index
Both types of index will improve performance when select data with fields that use the index but will slow down update and insert operations.
Because of the slower insert and update clustered indexes should be set on a field that is normally incremental ie Id or Timestamp. SQL Server will normally only use an index if its selectivity is above 95% (ie 95% of the records are unique values).
Martynnw 1,313614 There are also storage considerations. When inserting rows into a table with no clustered index, the rows are stored back to back on the page and updating a row 1 may result in the row being moved to the end of table, leaving empty space and fragmenting the table and indexes. Jeremiah Peschka Sep 18 '08 at 15:44 What does it mean that an index is "faster to read"? How many more x per second can you do? What is x? Stephanie Page Aug 9 '10 at 22:23 you don't have to care what is x. All you need to know is that for an app with millions of users, x will be significant Pacerier Jul 23 at 13:42
feedback
Clustered indexes are stored physically on the table. This means they are the fastest and you can only have one clustered index per table. Non-clustered indexes are stored separately, and you can have as many as you want. The best option is to set your clustered index on the most used unique column, usually the PK. You should always have a well selected clustered index in your tables, unless a very compelling reason--can't think of a single one, but hey, it may be out there--for not doing so comes up.
91714
santiiiii 1,470411 can you elaborate more on "we should always have a clustered index in our tables" ? without elaboration that statement is simply wrong because of the word always Pacerier Jul 23 at 13:43 You're right Pacerier, one shouldn't use absolute statements lightly. Though I don't know of a single case when you shouldn't have a well selected clustered index, such case might exist so I've changed my answer to a more generic version. santiiiii Jul 27 at 10:24 feedback
Clustered indexes physically order the data on the disk. This means no extra data is needed for the index, but there can be only one clustered index (obviously). Accessing data using a clustered index is fastest.
up All other indexes must be non-clustered. A non-clustered index has a duplicate of the data vote 6 down vote from the indexed columns kept ordered together with pointers to the actual data rows
(pointers to the clustered index if there is one). This means that accessing data through a non-clustered index has to go through an extra layer of indirection. However if you select only the data that's available in the indexed columns you can get the data back directly from the duplicated index data (that's why it's a good idea to SELECT only the columns
91748
4 down vote
91740
up vote
Cons: Clustered indexes are can slow down inserts because the physical layouts of the records have to be modified as records are put in if the new keys are not in sequential order.
3 down vote
up vote 2
down vote
tjrobinson 1,8821935 Why the downvote? Is this incorrect? tjrobinson Nov 18 '09 at 11:28
5 poor attempt at answering the question? flesh Oct 26 '10 at 14:22 feedback
A clustered index alters the way that the rows are stored. When you create a clustered index on a column (or a number of columns), SQL server sorts the tables rows by that column(s). It is like a dictionary, where all words are sorted in alphabetical order in the entire book. A non-clustered index, on the other hand, does not alter the way the rows are stored in the table. It creates a completely different object within the table that contains the column(s) selected for indexing and a pointer back to the tables rows containing the data. It is like an index in the last pages of a book, where keywords are sorted and contain the page number to the material of the book for faster reference.
7766076
Your Answer