As with most database issues, it depends :-)
In fact, it cannot be removed under any circumstances. If you have a query that uses only code in the where clause, it is possible that using subject_x1 will still be superior to subject_x2 just by the fact that less index data needs to be read.
As an extreme example, suppose code is char(2) and status is char (4094) `. If you have a request:
select code from tbl where code > 'dd' and code < 'gg';
This is likely to lead to checking only the index, since there is absolutely no reason to go to the table. If you use subject_x1 and you read in 4K blocks from your index, you can enter several thousand codes with each reading.
Using subject_x2 , each read only gives you one code (and perhaps the state is wasted). This is a huge performance difference.
However, and I canβt stress this enough, I donβt know!
Profile your queries (and updates) using both indexes to see what works best and do it with representative data. If you find that subject_x1 gives better performance for some queries, leave it. This will affect the update and insert speed and storage requirements, but you will find that it usually does not matter:
- the vast majority of databases are read much more often than written; and
- most database complaints are related to speed, not storage.
source share