SELECT * from a where is_delete and
(exists SELECT 1 FROM sub_a limit 1
or
exists SELECT 1 FROM sub_b limit 1)
这个sql
去掉一个exists
就不慢, 但是 or
一下就很慢
有没有大哥有改进办法
UNION 语句 试试?
https://www.runoob.com/sql/sql-union.html
再加个 去重。
是的,后面就是 这样的
AND (exists
(SELECT DISTINCT 1 FROM
( SELECT * FROM ( SELECT a."id" "Id" FROM "bms"."fin_order_profit" a ) a
UNION ALL
SELECT * FROM ( SELECT a."id" "Id" FROM "bms"."fin_order_profit" a WHERE (filter1."Id" = a."id") limit 1)
)