It looks like spark sql unable to do this kind of optimization. Here’s my sample code:
spark.sql("create temp view v1 as select t1.id as id, t2.id as id2, name, score, age from t1 left join t2 on t1.id = t2.id")
val result = spark.sql("select name from v1");
result.explain("extended")
In this sample code, the join can be eliminated, but query plan show that the join is still here, just wondering whether this join can be eliminated by spark sql optimizer?