performance - Speed up this MySQL query -


i have query getting slower , slower because there more , more records in table. i'm trying speed things up.

database size:
records: 1,200,000
data 22,9 mib
index 46,8 mib
total 69,7 mib

the purpose of query counting number of records exist match conditions. conditions date (current date) , status number. see query below:

select   count(id) total   order_process   date(datetime) = curdate() ,   status = '7'; 

at moment, query taking 800ms. , need run query multiple times different dates. these in same script script execution going on 3 seconds @ moment. how can speed up?

what have done:

  • created indexes (index on status , datetime both don't speed query).
  • tested innodb engine (which slower, reading on table)

to make complete, below current table setup.

create table if not exists `order_process` (   `id` int(11) not null auto_increment,   `order_id` int(11) not null,   `status` int(11) not null,   `datetime` timestamp not null default current_timestamp,   `remark` text not null,   primary key (`id`),   key `orderid` (`order_id`),   key `datetime` (`datetime`) ) engine=myisam  default charset=utf8; 

when use date() function on timestamp/datetime column , if column indexed can't use index

so need construct query as

where datetime >= concat(curdate(),' 00:00:00')  , datetime <= concat(curdate(),' 23:59:59') , status = '7' 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -