My table structure is something like below:
CREATE TABLE test (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
field_1 VARCHAR(60) NOT NULL,
field_2 INT(10) UNSIGNED NULL,
field_3 INT(10) UNSIGNED NULL,
field_4 INT(10) UNSIGNED NULL,
field_5 CHAR(2) NULL,
field_6 INT(10) UNSIGNED NOT NULL,
rank TINYINT(2) NOT NULL DEFAULT '0',
status TINYINT(3) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
INDEX (status)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = MyISAM;
On above table the fields rank
and status
will have integer value between 0-9 and 0-4 respectively.
Currently the table is filled with around 950K data and I am trying to optimize my queries as much as possible.
Basically I need to select fields with some where clause with a descending order on field rank
.
For example, below are few sql queries:
SELECT field_1, field_2, field_3 FROM test WHERE field_1 = 'data1' && status IN ('0', '1', '2') ORDER BY rank DESC LIMIT 0, 20;
SELECT field_1, field_2, field_3 FROM test WHERE field_2 = '5' && status IN ('1', '2') ORDER BY rank DESC LIMIT 0, 20;
SELECT field_1, field_2, field_3 FROM test WHERE field_5 = 'US' && status IN ('0', '2') ORDER BY rank DESC LIMIT 0, 20;
On above query ORDER BY rank DESC
is very important. So I am quite confuse whether I should add index on single column or multi-column.
Could anyone suggest me the best solution.
EXPLAIN
plans. – sgeddes 2 days ago