```
row x = 1, y = 2, z = 3 | stats  a = count(*), b = count(*) | stats  c = count(*)
```

The logical optimizer does not seem to be able to handle this query:

```
{
    "error": {
        "root_cause": [
            {
                "type": "rule_execution_exception",
                "reason": "Rule execution limit [100] reached"
            }
        ],
        "type": "rule_execution_exception",
        "reason": "Rule execution limit [100] reached"
    },
    "status": 500
}
```

The problem seems to be limited to this corner case scenario where you have two aggs with the same expression in one STATS and another STATS after that.

The problem is not limited to `count(*)`, also the following fails with the same error

```
row x = 1, y = 2, z = 3 | stats  a = max(x), b = max(x) | stats  c = max(a)
```

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java
SubPlan,
        LogicalPlan,
        P> {
        public final LogicalPlan apply(LogicalPlan plan, P context) {
            return plan.transformDown(typeToken(), t -> rule(t, context));
        }
        protected abstract LogicalPlan rule(SubPlan plan, P context);
    }
    /**
     * Normalize aggregation functions by:
     * 1. replaces reference to field attributes with their source
     * 2. in case of Count, aligns the various forms (Count(1), Count(0), Count(), Count(*)) to Count(*)
     */
    
    static class NormalizeAggregate extends Rule<LogicalPlan, LogicalPlan> {
        @Override
        public LogicalPlan apply(LogicalPlan plan) {
            AttributeMap<Expression> aliases = new AttributeMap<>();
            
            
            
            plan = plan.transformUp(p -> {
                if (p instanceof Aggregate agg) {
                    p = normalize(agg, aliases);
                }
                p.forEachExpression(Alias.class, a -> {
                    var child = a.child();
                    if (child.foldable() || child instanceof NamedExpression) {
                        aliases.putIfAbsent(a.toAttribute(), child);
                    }