```
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
* PushDownAndCombineLimits rule will copy the "limit 15" after "sort emp_no" if there is no filter on the expanded values
     * OR if there is no sort between "limit" and "mv_expand".
     * But, since this type of query has such a filter, the "sort emp_no" will have no limit when it reaches the current rule.
     */
    static class AddDefaultTopN extends ParameterizedOptimizerRule<LogicalPlan, LogicalOptimizerContext> {
        @Override
        protected LogicalPlan rule(LogicalPlan plan, LogicalOptimizerContext context) {
            if (plan instanceof UnaryPlan unary && unary.child() instanceof OrderBy order && order.child() instanceof EsRelation relation) {
                var limit = new Literal(Source.EMPTY, context.configuration().resultTruncationMaxSize(), DataTypes.INTEGER);
                return unary.replaceChild(new TopN(plan.source(), relation, order.order(), limit));
            }
            return plan;
        }
    }
    public static class ReplaceRegexMatch extends OptimizerRules.ReplaceRegexMatch {
        protected Expression regexToEquals(RegexMatch<?> regexMatch, Literal literal) {
            return new Equals(regexMatch.source(), regexMatch.field(), literal);
        }
    }
    /**
     * Replace aliasing evals (eval x=a) with a projection which can be further combined / simplified.
     * The rule gets applied only if there's another project (Project/Stats) above it.
     *
     * Needs to take into account shadowing of potentially intermediate fields:
     * eval x = a + 1, y = x, z = y + 1, y = z, w = y + 1
     * The output should be
     * eval x = a + 1, z = a + 1 + 1, w = a + 1 + 1
     * project x, z, z as y, w
     */
    static class ReplaceAliasingEvalWithProject extends Rule<LogicalPlan, LogicalPlan> {