```
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
@Override
        protected LogicalPlan rule(Limit limit) {
            if (limit.child() instanceof Limit childLimit) {
                var limitSource = limit.limit();
                var l1 = (int) limitSource.fold();
                var l2 = (int) childLimit.limit().fold();
                return new Limit(limit.source(), Literal.of(limitSource, Math.min(l1, l2)), childLimit.child());
            } else if (limit.child() instanceof UnaryPlan unary) {
                if (unary instanceof Eval || unary instanceof Project || unary instanceof RegexExtract || unary instanceof Enrich) {
                    return unary.replaceChild(limit.replaceChild(unary.child()));
                }
                
                
                
                else {
                    Limit descendantLimit = descendantLimit(unary);
                    if (descendantLimit != null) {
                        var l1 = (int) limit.limit().fold();
                        var l2 = (int) descendantLimit.limit().fold();
                        if (l2 <= l1) {
                            return new Limit(limit.source(), Literal.of(limit.limit(), l2), limit.child());
                        }