广播连接超出阈值,返回内存不足错误
报错信息:org.apache.spark.sql.execution.OutOfMemorySparkException: Size of broadcasted table far exceeds estimates and exceeds limit of spark.driver.maxResultSize=4294967296. You can disable broadcasts for this query using set spark.sql.autoBroadcastJoinThreshold=-1
背景
有一个sparksql脚本运行了一个多月没有报错,最近突然报上述错误,重试了几次还是报同样的错误
解决方法
1.脚本有用到了 /*+ BROADCASTJOIN (t1) */ 加了几个内存的参数 还是报错
2.exlpain 查看了执行计划发现不仅有BroadcastHashJoin 还有BroadcastNestedLoopJoin。看了下代码 有用not in 而且not in 的表最近刚补了大量的数据。改成left join后,不再报错,问题解决。改成not exists后,不再报错,问题解决。
select * from t1 where not exists (select 1 from t2 where t1.id = t2.id group by t2.id)
3.从执行效率看 left join 用了20分钟,not exists 用了23分钟。