ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Why it is not good to use Indexes on every column?

user-image
تم إضافة السؤال من قبل Syed Alamdar Hussain , Software Engineer , Matts Consulting
تاريخ النشر: 2017/01/25
Jacintha A
من قبل Jacintha A , Associate Content Analyst , BOSCH Ltd

No good deed goes unpunished. At least that’s how it works with indexes. Sure, they’re great as long as all you run are SELECTstatements against the database, but throw in a lot of INSERT, UPDATE, and DELETE statements, and the landscape quickly changes.

When you issue a SELECT statement, the query engine finds the index, navigates the B-tree structure, and locates the desired data. What could be simpler? But that all changes if you issue a data modification statement, such an UPDATE. True, for the first part of the UPDATE operation, the query engine can again use the index to locate the row to be modified. That’s the good news. And if it’s a simple update and no key values are involved, chances are the process will be fairly painless. But if the update forces a page split or key values change and get moved to different nodes, the index might need to be reorganized, impacting other indexes and operations and resulting in slower performance all around.

Same with a DELETE statement. An index can help locate the data to be deleted, but the deletion itself might result in page reshuffling. And as for the INSERT statement, its the sworn enemy of all indexes. You start adding a lot of data and your indexes have to be modified and reorganized and everybody suffers.

So the way in which your database is queried must be uppermost in your thinking when determining what sort of indexes to add and how many. More is not necessarily better. Before you throw another index at a table, consider the costs, not only on query performance, but also on disk space, index maintenance, and the domino effects on other operations. Your index strategy is one of the most important aspects of a successful database implementation and should take into account a number of considerations, from index size to the number of unique values to the type of queries being supported.

Nauman Rashid
من قبل Nauman Rashid , PSE - Microsoft Dynamics AX and D365 FO , A.F Ferguson (PwC Pakistan)

Indexes take up space in memory (RAM); Too many or too large of indexes and the DB is going to have to be swapping them to and from the disk. They also increase insert and delete time (each index must be updated for every piece of data inserted/deleted/updated).

You don't have infinite memory. Making it so all indexes fit in RAM = good.

You don't have infinite time. Indexing only the columns you need indexed minimizes the insert/delete/update performance hit

Umair Khan
من قبل Umair Khan , Web Developer , Innovative Designers

Indexes takes memory and extra time during its creation. It is just good for only fewer fields. 

المزيد من الأسئلة المماثلة