[SPARK-3198] [SQL] Generate the expression id when necessary

I would consider generating new TreeNodes in the critical path a bug, and any places where we do that should be removed (as you have done in other PRs).

As far as I know, we only use this `id` in a few places and all of these could be replaced with `eq`.  I just try removing it and see what breaks.