Query
SELECT * FROM user_ip_tmp WHERE too = 'http://example.com/' AND contry != 'CN' AND contry != 'TW' ORDER BY id DESC LIMIT 50
MySQL returns:
Showing rows 0 - 29 ( 50 total, Query took 11.9276 sec) [id: 3452538 - 3448824]
if I remove ORDER BY id id DES
Showing rows 0 - 29 ( 50 total, Query took 0.0033 sec)
Explain the plan: 
counter
SELECT count( * ) FROM user_ip_tmp

Example used database
CREATE TABLE IF NOT EXISTS `user_ip_tmp` ( `id` int(9) NOT NULL AUTO_INCREMENT, `ip` varchar(20) NOT NULL, `dataip` bigint(20) NOT NULL, `ref` text NOT NULL, `click` int(20) NOT NULL, `code` varchar(17) NOT NULL, `too` text NOT NULL, `checkopen` varchar(17) NOT NULL, `contry` text NOT NULL, `vOperation` text NOT NULL, `vBrowser` text NOT NULL, `iconOperation` text NOT NULL, `iconBrowser` text NOT NULL, PRIMARY KEY (`id`), KEY `ip` (`dataip`), KEY `ip` (`checkopen`), KEY `ip` (`code`), KEY `ip` (`too`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5426268 ;
I need the right way to execute a query and optimize the database for ORDER BY id id
source share