I need to check whether the surfer has alrady voted this can be done using
Method 1
Select record_num FROM table where etc etc.
i.e.
SELECT record_num
FROM content_votes_tmp
WHERE up = 1
AND ip = INET_ATON('$_SERVER[REMOTE_ADDR]')
AND content = $_POST[id]
AND UNIX_TIMESTAMP(datetime) > '$old_time'
Method 2
Select Sum(votes) FROM table where etc etc.
i.e.
SELECT SUM(up) as up_count
FROM content_votes_tmp
WHERE ip = INET_ATON('$_SERVER[REMOTE_ADDR]')
AND content = $_POST[id]
AND UNIX_TIMESTAMP(datetime) > '$old_time'
Using storage engine as MyISAM , Table has around 1 million rows, ROW Format is static.
I am looking for query which is faster in terms of performance.
So which query will be faster ? this query will be fired every time someone clicks the vote up or vote down button.,
here is a table structure
CREATE TABLE IF NOT EXISTS `content_votes_tmp` (
`up` int(11) NOT NULL DEFAULT '0',
`down` int(11) NOT NULL DEFAULT '0',
`ip` int(10) unsigned NOT NULL,
`content` int(11) NOT NULL,
`datetime` datetime NOT NULL,
`is_updated` tinyint(2) NOT NULL DEFAULT '0',
`record_num` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`record_num`)
KEY `content` (`content`),
KEY `datetime` (`datetime`),
KEY `is_updated` (`is_updated`),
KEY `ip` (`ip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=25 ;
SHOW CREATE TABLEand a more complete query (even if you rename columns to col1, col2, etc. for privacy)? We need more details to see if indexes are going to be helpful.