开发者

MySQL thinks subquery is derived when it is not!

开发者 https://www.devze.com 2023-01-27 03:41 出处:网络
EXPLAIN SELECT node_id FROM node WHERE person_id IN (SELECT person_id FROM user 开发者_开发知识库WHERE is_locked = 0);
EXPLAIN SELECT node_id 
          FROM node 
         WHERE person_id IN (SELECT person_id 
                               FROM user 
    开发者_开发知识库                          WHERE is_locked = 0);

Results in MySql telling me the subquery is derived. But it's not!

(I know this could easily be re-written as a JOIN, but I want to know why MySQL thinks this is a dependent subquery.)


This is a bug in the MySQL Query Optimizer. It would seem that, if the table in the subquery matches the table in the main query, it is considered a dependent subquery even if it obviously should not be, and there's no easy fix. Sorry; go for the join.

0

精彩评论

暂无评论...
验证码 换一张
取 消