Hive SQL on where 优化(先做join,left join时on中条件无过滤记录作用,后做where条件过滤记录。on 优先级高于 where)

1. select t.* from A f join B t 
on (f.id = t.id and f.分区=20181111 and t.分区=20181111)
 
2. select t.* from (select id from A where 分区=20181111) f
join
(select * from B where 分区=20181111) t
on (f.id = t.id)
 
 
总结一:
1. 对于a join b,无论过滤条件放到on中还是where中,结果相同。
2. 对于a left join b,过滤条件在on中:忽略a表的过滤条件,b表的过滤条件只会导致不满足条件的记录在b表的所有字段上都为空;过滤条件在where中:过滤掉所有不满足条件的记录。
3. 核心:先做join,left join时on中条件无过滤记录作用,后做where条件过滤记录。on 优先级高于 where
 
 
总结二:
1. sql1先单表过滤,在join。原因:查询在map端,进行了数据过滤,shuffle阶段数据更少,join在reduce端。
2. sql2shuffle阶段数据更多。查询和过滤都在reduce端。
 

猜你喜欢

转载自blog.csdn.net/u011500419/article/details/88639698