I wrote a complete book about it! It is also available free of charge on the Internet: http://use-the-index-luke.com/
I will try to answer your questions in the near future - this is not quite what I am capable of. The last time I tried, I finished writing a book ...
Like tables, indexes consist of rows and columns, but store data in a logically sorted way to improve search efficiency. Think of it as a phone book (printed). They are usually sorted by last_name , first_name and potentially other criteria (e.g. zip code). This sorting allows you to quickly find all the records for a specific last name. If you know the first name, you can even quickly find entries for the surname / first name combination.
If you only know the name, the phone book really will not help you. The same is true for multi-column database indexes. So yes, an index can potentially improve search performance. If you have the wrong index for your question (for example, a phone book when searching by name), they may not be useful.
You can have many indexes in the same table, but in different columns. Thus, the index on last_name , first_name differs from the index only on first_name (which you will need to optimize the search by name).
Indexes contain redundant data (for example: clustered indexes = phone book). They have the same information as in the table (for example: functional indexes ), but are sorted. This redundancy is automatically maintained by the database for each write operation you perform ( insert / update / delete ). Consequently, indexed performance is reduced .
In addition, to quickly find data, indexes can also be used to optimize order by operations and physically sort related data together ( clustering ).
To get a better idea, view the full contents of my book: http://use-the-index-luke.com/sql/table-of-contents
Markus Winand Mar 06 '13 at 9:42 on 2013-03-06 09:42
source share