当我运行带有解释的查询时,表中有一个独特的复合键,如fr(fromid,toid),得到以下结果:
Impossible WHERE noticed after reading const tables`
我运行的查询:
explain SELECT rid FROM relationship WHERE fromid=78 AND toid=60
有什么帮助吗?
EDIT1:
当我使用以下查询时:
explain SELECT rid FROM relationship WHERE fromid=60 and toid=78 AND is_approved='s' OR is_approved='f' OR is_approved='t'
我看到的USING WHERE
不是上一条消息,而是当我使用以下查询时:
explain SELECT rid FROM relationship WHERE fromid=60 and toid=78 AND (is_approved='s' OR is_approved='f' OR is_approved='t')
我再次收到第一条impossible ...
消息!这些括号在这里做什么?
编辑2:
CREATE TABLE `relationship` (
`rid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`fromid` mediumint(8) unsigned NOT NULL,
`toid` mediumint(8) unsigned NOT NULL,
`type` tinyint(3) unsigned NOT NULL,
`is_approved` char(1) NOT NULL,
PRIMARY KEY (`rid`),
UNIQUE KEY `fromid` (`fromid`,`toid`),
KEY `toid` (`toid`),
CONSTRAINT `relationship_ibfk_1` FOREIGN KEY (`fromid`) REFERENCES `user` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `relationship_ibfk_2` FOREIGN KEY (`toid`) REFERENCES `user` (`uid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB
EDIT3:
作为mysql网站说:
读取const表后,不可能在哪里注意到
MySQL已读取所有const(和系统)表,并注意到WHERE子句始终为false。
但是在查询中我得到了想要的结果,但WHERE
部分却没有false
。有没有人可以解释这一点并阐明这个问题?
using index
更多内容代替impossible...
SELECT COUNT(1) FROM relationship WHERE fromid=78 AND toid=60;
返回什么?