I have a query that takes over 2 seconds.
Here is my table schema:
CREATE TABLE `vouchers` (
`id` int(11) NOT NULL,
`voucher_dealer` int(11) NOT NULL,
`voucher_number` varchar(20) NOT NULL,
`voucher_customer_id` int(11) NOT NULL,
`voucher_date` date NOT NULL,
`voucher_added_date` datetime NOT NULL,
`voucher_type` int(11) NOT NULL,
`voucher_amount` double NOT NULL,
`voucher_last_debt` double NOT NULL,
`voucher_total_debt` double NOT NULL,
`voucher_pay_method` int(11) NOT NULL,
`voucher_note` text NOT NULL,
`voucher_inserter` int(11) NOT NULL
)
The primary key is id
and is auto incremented.
The table has more than 1 million rows.
The query looks like this:
select *
from vouchers
where voucher_customer_id = **
and voucher_date between date and date
and sometimes it looks like this:
select sum(voucher_amount)
from vouchers
where voucher_customer_id=**
and voucher_date> date limit 1
Is there a way to speed up my queries?