Hi,
We have a table on mysql to log all visitors of our site. The structure is shown below
CREATE TABLE `tblvisitors` ( `visitorURL` longtext, `visitorDatetime` datetime DEFAULT NULL, `visitorIP` varchar(255) DEFAULT NULL, `visitorID` int(10) NOT NULL AUTO_INCREMENT, `visitorUser` varchar(255) DEFAULT NULL, `visitorShow` varchar(50) DEFAULT NULL, `visitorIPcaption` varchar(255) DEFAULT NULL, `visitorIPRange` varchar(255) DEFAULT NULL, PRIMARY KEY (`visitorID`), KEY `INDEXDT` (`visitorDatetime`), KEY `INDEXIP` (`visitorIP`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
The table has right now more than 5 million records.
We have an INSERT operation every half second and also a SELECT operation every half second which involves a CRITERIA on visitorURL column and Select of COUNT field.
The query is :
SELECT COUNT(visitorURL) FROM tblVisitors WHERE visitorURL='http://mihirdarji.com/something'
This shoots up the CPU usage to 90% in an 8 core server with 8 GB Ram.
The MySQL admin shows lot of connection with above query waiting to be executed.
Any suggestions would be welcome.
Explain plan says
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | 1 | SIMPLE | tblVIsitors | ALL | NULL | NULL | NULL | NULL | 4293277 | Using where |