MySQL 对待 EXISTS 子句时,仍然采用嵌套子查询的执行方式。如下面的 SQL 语句:
- SELECT *
- FROM my_neighbor n
- LEFT JOIN my_neighbor_apply sra
- ON n.id = sra.neighbor_id
- AND sra.user_id = 'xxx'
- WHERE n.topic_status < 4
- AND EXISTS(SELECT 1
- FROM message_info m
- WHERE n.id = m.neighbor_id
- AND m.inuser = 'xxx')
- AND n.topic_type <> 5
执行计划为:
- +----+--------------------+-------+------+-----+------------------------------------------+---------+-------+---------+ -----+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+--------------------+-------+------+ -----+------------------------------------------+---------+-------+---------+ -----+
- | 1 | PRIMARY | n | ALL | | NULL | NULL | NULL | 1086041 | Using where |
- | 1 | PRIMARY | sra | ref | | idx_user_id | 123 | const | 1 | Using where |
- | 2 | DEPENDENT SUBQUERY | m | ref | | idx_message_info | 122 | const | 1 | Using index condition; Using where |
- +----+--------------------+-------+------+ -----+------------------------------------------+---------+-------+---------+ -----+
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|