I believe we wrote about this before, but this topic popups again
and again.
Today I've read opinion that if we have clause WHERE
has_something=1 we should have index on column `has_something`
(the column has two values 0 and 1).
In reality the right answer is not so simple.
Let's look next table
PLAIN TEXT SQL:
- CREATE TABLE `testr` (
- `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
- `name` varchar(32) NOT NULL,
- `has_something` tinyint(3) UNSIGNED NOT NULL,
- PRIMARY KEY (`id`),
- KEY `has_something` (`has_something`)
- ) ENGINE=MyISAM
with 20.000.000 records.
And in first case has_something=0 for 90% of rows (with random distribution)
PLAIN TEXT SQL:
- mysql> SELECT cnt0/cnt FROM (SELECT count(*) cnt0 FROM …