Postgresql join sub或where sub

时间:2018-04-29 12:31:01

标签: sql postgresql conditional-statements where

我的测试给出了相同的运行速度。我想弄清楚最好使用加入子查询。我理解这很大程度上取决于数据,索引和 DB 本身,但我想区分它,以便 t1 中的记录小于 t2 然后子查询应该有效,但如果相反则加入

EXPLAIN ANALYSE SELECT *
FROM safety_policies
WHERE safety_policies.area_id IN (SELECT areas.id
                                  FROM areas
                                    INNER JOIN departments ON areas.department_id = departments.id);


EXPLAIN ANALYSE SELECT safety_policies.*
                FROM safety_policies
                  INNER JOIN areas ON safety_policies.area_id = areas.id
                  INNER JOIN departments ON areas.department_id = departments.id;

0 个答案:

没有答案