We have a large table, 13mm+ records. Specifically its a phplist table, structure is below.
Running this query:
select sum(clicked) from phplist_linktrack where messageid = 113;
causes a full table scan to happen as is evident by running the query through explain.
What's odd is that the same query using a different messageid does use the messageid index correctly.
My only "guess" is that the optimizer is seeing many records for messageid 113 and is opting to do a full scan rather than use the index.
Even using "use index" doesn't force the issue.
mysql> show create table phplist_linktrack \G
*************************** 1. row ***************************
Table: phplist_linktrack
Create Table: CREATE TABLE `phplist_linktrack` (
`linkid` int(11) NOT NULL AUTO_INCREMENT,
`messageid` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`url` varchar(255) DEFAULT NULL,
`forward` text,
`firstclick` datetime DEFAULT NULL,
`latestclick` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`clicked` int(11) DEFAULT '0',
PRIMARY KEY (`linkid`),
UNIQUE KEY `messageid` (`messageid`,`userid`,`url`),
KEY `midindex` (`messageid`),
KEY `uidindex` (`userid`),
KEY `urlindex` (`url`),
KEY `miduidindex` (`messageid`,`userid`),
KEY `miduidurlindex` (`messageid`,`userid`,`url`)
) ENGINE=MyISAM AUTO_INCREMENT=13206016 DEFAULT CHARSET=latin1
Running this query:
select sum(clicked) from phplist_linktrack where messageid = 113;
causes a full table scan to happen as is evident by running the query through explain.
What's odd is that the same query using a different messageid does use the messageid index correctly.
My only "guess" is that the optimizer is seeing many records for messageid 113 and is opting to do a full scan rather than use the index.
Even using "use index" doesn't force the issue.
mysql> show create table phplist_linktrack \G
*************************** 1. row ***************************
Table: phplist_linktrack
Create Table: CREATE TABLE `phplist_linktrack` (
`linkid` int(11) NOT NULL AUTO_INCREMENT,
`messageid` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`url` varchar(255) DEFAULT NULL,
`forward` text,
`firstclick` datetime DEFAULT NULL,
`latestclick` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`clicked` int(11) DEFAULT '0',
PRIMARY KEY (`linkid`),
UNIQUE KEY `messageid` (`messageid`,`userid`,`url`),
KEY `midindex` (`messageid`),
KEY `uidindex` (`userid`),
KEY `urlindex` (`url`),
KEY `miduidindex` (`messageid`,`userid`),
KEY `miduidurlindex` (`messageid`,`userid`,`url`)
) ENGINE=MyISAM AUTO_INCREMENT=13206016 DEFAULT CHARSET=latin1
Comment