We’ve got a table we use as a queue. Entries are constantly being added, and constantly being updated, and then deleted. Though we might be adding 3 entries/sec the table never grows to be more than a few hundred rows.
To get entries out of table we are doing a simple select.
SELECT * FROM queue_table WHERE some_id = ?
We are debating adding an index on some_id. I think the small size and speed at which we are adding and removing rows would say no, but conventionally, it seems we should have an index.
Any thoughts?
If you are using
InnoDB(which you should do having a table of this kind) and the table is accessed concurrently, then you should definitely create the index.When performing
DMLoperations,InnoDBlocks all rows it scans, not only those that match theWHEREclause conditions.This means that without an index, a query like this:
will have to do a full table scan and lock all rows.
This kills all concurrency (even if the threads access different
some_id‘s they’ll still have to wait for each other), and may even result in deadlocks.With
3transactions per second, no index should be a problem, so just create it.