dqwd71332 2011-10-21 09:42
浏览 31
已采纳

mysql查询性能指标

my following query needs more then two minutes and i don't which index is the best to improve the performance:

SELECT COUNT(sid), COUNT(DISTINCT(cid)), shop 
FROM forwarding 
WHERE fDate BETWEEN '2011-06-01' AND '2011-06-30' 
GROUP BY shop;

The EXPLAIN result:

id   select_type   table            type    possible_keys                                                        key       key_len    ref       rows     Extra
1    SIMPLE        sal_forwarding   index   forwardDate,forwardDate_2,forwardDate_3,forwardDate_4,forwardDate_5  f_shop    40         (NULL)    2448997  Using where; Using index

The key f_shop has the following structure: (f_shop, forwardDate, cid)

What is the best Index to improve the performance for my query?

Thank you very much.

UPDATE: Here is the table Create Statement:

CREATE TABLE `forwarding` (
  `sid` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `f_shop` INT(11) NOT NULL,
  `f_offer` INT(11) DEFAULT NULL,
  `cid` CHAR(32) DEFAULT NULL,
  `f_partner` VARCHAR(20) NOT NULL,
   .
   . 
   .
   +8-10
   .
   .
   .
  `fDate` DATE NOT NULL,
  PRIMARY KEY (`sid`),
  KEY `f_shop` (`f_shop`,`fDate`,`cid`),
  KEY `f_partner` (`f_partner`,`fDate`),
  KEY `fDate` (`fDate`,`cid`),
  KEY `fDate_2` (`fDate`,`f_shop`),
  KEY `fDate_3` (`fDate`,`f_shop`,`f_partner`),
  KEY `fDate_4` (`fDate`,`f_partner`,`cid`),
  KEY `fDate_5` (`fDate`,`f_affiliateId`)
) ENGINE=INNODB AUTO_INCREMENT=10747233 DEFAULT CHARSET=latin1

Actually there are more then 5million rows.

  • 写回答

4条回答 默认 最新

查看更多回答(3条)

报告相同问题?