0
我只是想知道是否有任何的方式来优化这个查询子句:优化哪里其中x在Y或Z y中
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子句的两个子查询是相同的,我怀疑该程序将分别运行两个子查询
谢谢!
我只是想知道是否有任何的方式来优化这个查询子句:优化哪里其中x在Y或Z y中
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子句的两个子查询是相同的,我怀疑该程序将分别运行两个子查询
谢谢!
您的查询基本上是:
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会很好。
要在蜂巢使用解决多个问题侍从即semi left join
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)
您好,感谢您的答复。这是否意味着内部配置单元已经优化(从table_y y选择y.id),从某种意义上说它不会重复子查询? – chrishendra93
@ chrishendra93。 。 。它可能会“重复”查询,但这不会影响性能。 –