tags:

views:

42

answers:

1

I have a table looking like this:

CREATE TABLE `item` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255),
`my_number` int(10) unsigned default NULL
);

There are a hundreds of thousands of items, and I usually order them by 'my_number'.

Will adding an index on 'my_number' increase performance on queries when I order by this field?

I use MySQL, the table is InnoDB.

+5  A: 

I know the answer but it doesn't matter. What you should do in all cases of potential database optimisation is to add the index and test it. And, by that, I mean test all of your affected queries, inserts and updates to ensure you have a performance boost that outdoes any loss of performance elsewhere.

You shouldn't trust my knowledge or anyone else's if the alternative is concrete data that you can gather yourself. Measure, don't guess!

The answer is, by the way: "it should, unless your DBMS is truly brain-dead". Generally, adding indexes will increase the speed of selects but slow down inserts and updates. But I mean "generally" - it's not always the case. A good DBA continuously examines the performance of the DBMS and tunes it where necessary. Databases are not set-and-forget objects, they need to be cared for and nurtured :-)

paxdiablo
Well I tested, and adding an index increased performance dramatically.That makes you right both on testing and indexing :-)
Hobhouse