### Description

As we have more rules doing analysis across plans, a number of methods are useful to add to the `QueryPlan` class itself, mainly around expressions:

```
- expressions() - return the expressions declared by this plan
- references() - return the references from the expressions above
```
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java
@Override
        public LogicalPlan apply(LogicalPlan plan) {
            var used = new AttributeSet();
            
            var seenProjection = new Holder<>(Boolean.FALSE);
            
            
            var pl = plan.transformDown(p -> {
                
                if (p instanceof Limit) {
                    return p;
                }
                
                boolean recheck;
                
                
                do {
                    recheck = false;
                    if (p instanceof Aggregate aggregate) {