优化where子句,其中x在y中或z在y中

3duebb1j  于 2021-06-28  发布在  Hive
关注(0)|答案(2)|浏览(373)

我只是想知道是否有任何方法可以优化这个查询:

select * from table_x where buyer_id in (select id from table_y) x or 
seller_id in (select id from table_y) y

因为where子句中的两个子查询是相同的,我怀疑程序将分别运行这两个子查询
谢谢!

gwo2fgha

gwo2fgha1#

要解决配置单元中的多个等式问题,请使用半左连接ie

select x.*
from table_x x
LEFT SEMI JOIN  table_y  b on (x.buyer_id= b.id )
LEFT SEMI JOIN  table_y  c on (x.seller_id= c.id )
hfyxw5xn

hfyxw5xn2#

您的查询基本上是:

select x.*
from table_x x
where x.buyer_id in (select y.id from table_y y) or
      x.seller_id in (select y.id from table_y y);

这个构造应该很好。在某些数据库中,可以使用 exists 而不是 in ,但我想Hive可以用这个。

相关问题