Saturday, June 18, 2016

Improve Database Performance Using Indexes

Tags



Let start with index. What is index?
An index is a database structure that you can use to improve the performance of database activity.

How many indexes can we include in a database table?
 A database table can have one or more indexes associated with it.

Example scenario
Consider the following Where clause:

WHERE id = 'XA3001'

Without an index, the driver must search the entire database table to find those records having an id of XA3001. By using an index on the id field, however, the driver can quickly find those records.

Can indexes improve the performance of SQL statement?
Yes. You may not notice this improvement with small tables but it can be significant for large tables.

What are the disadvantages of having too many indexes?

  1. Slow down the performance of some inserts, updates, and deletes when the driver has to maintain the indexes as well as the database tables. 
  2. Indexes take additional disk space.

How to use index?

Improving Record Selection Performance 

Set an index on image_name.
Below statement uses the index :

SELECT * FROM testing WHERE image_name = 'com3';

But this statement does not use the index:

SELECT * FROM testing WHERE UPPER(image_name) = 'COM3';

WHY?

Because the where clause contains UPPER(image_name) which does not match the index expression image_name. If you plan to use UPPER statement, you should define the index using the expression UPPER(image_name).




EmoticonEmoticon