Add where-clause optimization in join queries