I'm new to database query optimization. Here is the create table query:
CREATE TABLE mo (
id int UNSIGNED NOT NULL auto_increment,
msisdn varchar(20) NOT NULL,
operatorid int UNSIGNED NOT NULL,
shortcodeid int UNSIGNED NOT NULL,
text varchar(100) NOT NULL,
auth_token varchar(60) NOT NULL,
created_at DATETIME,
PRIMARY KEY(id)
);
My query is this:
SELECT count(id) as mo_count from mo where created_at > DATE_SUB(NOW(), INTERVAL 15 MINUTE)
When I tested it the result was
Time taken for tests: 3.50 seconds
[0] => Array
(
[id] => 1
[select_type] => SIMPLE
[table] => mo
[type] => ALL
[possible_keys] =>
[key] =>
[key_len] =>
[ref] =>
[rows] => 10000255
[Extra] => Using where
)
Please teach me how to optimize this query. Thank you so much.