How can I optimize this sql: select count (*) from `order` where` time`> 1307894400000

I need to get the number of orders per day (the β€œtime” field is the java timestamp, and the β€œorder” table has 1,000,000 entries ), I use:

select count(*) from `order` where `time`>1307894400000 && `time`<1307980799999

this sql used 540 ms

I tried to create a time index using field, but still needed 390ms

How can I optimize this sql statement?

+3
source share
2 answers

If this is not enough, then your only choice is to split the table. Many db mechanisms allow you to specify automatic partitions.

0
source

Try below.

count (YourPrimaryKey) order time > 1307894400000 && & && & time < 1307980799999

0

All Articles