Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I add indices to small table?

Is there any reason to add indices to table with few (less than 10) elements? It is frequently used in joins, but I'm not sure if index on such small table increase its performance or decrease.

Edit: rows in table are quite small: 7 columns, with total size smaller than 500 bytes, so I think that it could be stored in server memory (it is answer to Paul Sanwald note)

like image 999
Marek Kwiendacz Avatar asked Oct 11 '22 09:10

Marek Kwiendacz


2 Answers

It is unlikely that a table that size will ever use the index. If the table will be stable in size and always be small, I would not add indexes.

From Books Online:

Indexing small tables may not be optimal because it can take the query optimizer longer to traverse the index searching for data than to perform a simple table scan. Therefore, indexes on small tables might never be used, but must still be maintained as data in the table changes.

So it likely to be a poor idea to index small tables.

like image 124
HLGEM Avatar answered Oct 27 '22 09:10

HLGEM


As with all performance questions, the answer is: Create a performance test and measure the results.

Otherwise, there is a 90% chance the answer is wrong.

like image 36
Aaron Digulla Avatar answered Oct 27 '22 11:10

Aaron Digulla