表详细信息-->
CREATE TABLE `redeem_vouchers` (
`voucherid` int(11) NOT NULL,
`voucheramount` decimal(18,2) DEFAULT NULL,
`redeemedto` int(11) DEFAULT NULL,
`redeemedon` datetime DEFAULT NULL,
`transid` varchar(100) DEFAULT NULL,
`paymentconfirmed` tinyint(1) NOT NULL DEFAULT '0',
`confirmedby` int(11) DEFAULT NULL,
`confirmedon` datetime DEFAULT NULL,
`redeemedby` int(11) DEFAULT '0',
PRIMARY KEY (`voucherid`),
KEY `NewIndex2` (`redeemedto`),
KEY `NewIndex3` (`voucheramount`),
FULLTEXT KEY `NewIndex1` (`transid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
查询-->
SELECT DISTINCT(transid),
(SELECT (COUNT(voucheramount)*16) FROM redeem_vouchers WHERE transid = r.transid) AS amount,
(SELECT redeemedto FROM redeem_vouchers WHERE transid = r.transid LIMIT 0,1) AS 'Name'
FROM
redeem_vouchers r
WHERE
confirmedon
BETWEEN ('2013-07-23 19:00:00') AND ('2013-07-24 19:00:00')
表仅包含 4909 行,查询需要 35 秒才能返回结果。我添加了 4 个索引,但没有发现速度增益。我知道我在做一些危险的事情,但我是 sql 新手。请帮我。