Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does index on Varchar make performance difference?

Does index on a varchar column make the query run slower? I can make that be int. and I don't need to do the LIKE % comparison.

like image 364
Murvinlai Avatar asked Dec 14 '09 01:12

Murvinlai


People also ask

Do indexes affect performance?

Indexes will degrade insert/delete performance since indexes have to be updated. In case of update it depends on whether you update indexed columns. If not, performance should not be affected. Indexes can also speed up a DELETE and UPDATE statements if the WHERE condition can make use of the index.

Can we apply index on varchar data type?

1) You can also create indexes on multiple fields combining int and varchar types, taking special care for filtering always on first field defined in the index. If you just filter using the second field index will not be used. 2) Try to avoid use of "*" operator.

Does index improve query performance?

Indexes in Oracle and other databases are objects that store references to data in other tables. They are used to improve the query performance, most often the SELECT statement. They aren't a “silver bullet” – they don't always solve performance problems with SELECT statements. However, they can certainly help.

What are the benefits of index in MySQL?

Advantages of MySQL Indexes 1- Indexes make search queries much faster. 2- Indexes like primary key index and unique index help to avoid duplicate row data. 3- Full-text indexes in MySQL, users have the opportunity to optimize searching against even large amounts of text located in any field indexed as such.


1 Answers

Does index on a varchar column make the query run slower?

No, it does not.
If the optimizer decides to use of the index, the query will run faster. INSERTs/UPDATEs/DELETEs on that table will be slower, but not likely enough to notice.

I don't need to do the LIKE % comparison

Be aware that using:

LIKE '%whatever%' 

...will not use an index, but the following will:

LIKE 'whatever%' 

The key is wildcarding the lefthand side of the string means that an index on the column can't be used.

Also know that MySQL limits the amount of space set aside for indexes - they can be up to 1000 bytes long for MyISAM (767 bytes for InnoDB) tables.

like image 118
OMG Ponies Avatar answered Oct 11 '22 08:10

OMG Ponies