```
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
});
                return p;
            });
            return plan;
        }
        private static LogicalPlan normalize(Aggregate aggregate, AttributeMap<Expression> aliases) {
            var aggs = aggregate.aggregates();
            List<NamedExpression> newAggs = new ArrayList<>(aggs.size());
            boolean changed = false;
            for (NamedExpression agg : aggs) {
                if (agg instanceof Alias as && as.child() instanceof AggregateFunction af) {
                    
                    if (af.field() instanceof NamedExpression ne) {
                        Attribute attr = ne.toAttribute();
                        var resolved = aliases.resolve(attr, attr);
                        if (resolved != attr) {
                            changed = true;
                            var newChildren = CollectionUtils.combine(Collections.singletonList(resolved), af.parameters());
                            
                            af = (AggregateFunction) af.replaceChildren(newChildren);
                            agg = as.replaceChild(af);
                        }
                    }
                    
                    if (af instanceof Count count) {
                        var field = af.field();
                        if (field.foldable()) {
                            var fold = field.fold();
                            if (fold != null && StringUtils.WILDCARD.equals(fold) == false) {
                                changed = true;