查询
SELECT *
FROM user_ip_tmp
WHERE too = 'http://example.com/'
AND contry != 'CN'
AND contry != 'TW'
ORDER BY id DESC
LIMIT 50
MySQL 返回:
Showing rows 0 - 29 ( 50 total, Query took 11.9276 sec) [id: 3452538 - 3448824]
如果我删除 ORDER BY id DESC。
Showing rows 0 - 29 ( 50 total, Query took 0.0033 sec)
解释计划: count:
SELECT count( * )
FROM user_ip_tmp
数据库使用的示例
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 ;
我希望得到正确的查询和优化数据库的方法,以便使用 ORDER BY id DESC 进行排序。
#1248-每个派生表都必须有自己的别名
- 10neen comuser_ip_tmp
(too
,id
) 后停止工作了。我认为这是因为有超过 600 万条记录,数据库达到了 1 GB 的容量限制。 - 10neen com