أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Advantages
Disadvantages
The advantages of indexes are as follows:
The disadvantages of indexes are as follows:
You should only create indexes when they are actually needed.
Advantages:
The most important use for an index is in finding a record or set of records matching a WHERE clause.
It could fasten Update and Delete command by means of where clause in non-clustered index.
When there are no indexes, the database will scan the table and then sort the rows to process the query. However, the index will provide the database with already sorted list of table’s columns. The database can simply scan the index from the first record to the last record and retrieve the rows in sorted order.
We can use a GROUP BY clause to group records and aggregate values, e.g. for counting the number of customers (table) in a country (column). To process a query with a GROUP BY clause, the database will quite often sort the results on the columns included in the GROUP BY. The following query counts the number of customers from every country with the same UnitPrice value. SELECT Count(*) FROM Products GROUP BY UnitPrice.
Index is the best tool for the database to use to enforce uniqueness in data of a column. Each time an application adds or modifies a row in the table, the database needs to search all existing records to ensure none of values in the new data duplicate existing values. Indexes, as we should know by now, will improve this search time.
Disadvantages:
Indexes are stored on the disk, and the amount of space required will depend on the size of the table, and the number and types of columns used in the index. Disk space is generally cheap enough to trade for application performance, particularly when a database serves a large number of users. (To see the space required for a table, use the sp_spaceused system stored procedure in a query window.)
If the data is modified on regular intervals then database engine requires updating all the indexes, thus too many indexes will slows down the performance.
Also if we update a record and change the value of an indexed column in a clustered index, the database might need to move the entire row into a new position to keep the rows in sorted order. This behavior essentially turns an update query into a DELETE followed by an INSERT, with an obvious decrease in performance. In this sense, it’ll slowdown Update and Delete command.
The disadvantage of a non-clustered index is that it is slightly slower than a clustered index and they can take up quite a bit of space on the disk.
Irrespective of frequently modifying database, too many indexes can actually slow your database down. Thinking of a book again, imagine if every "the", "and" or "at" was included in the index. That would stop the indemx being useful - the index becomes as big as the text!