### Description

Tracking total hits sometimes has a non-negligible impact on performance. We should disable it when not strictly required.
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/execution/search/SourceGenerator.java
if (container.query() != null) {
                            container.query().enrichNestedSort(nestedSort);
                        }
                        sortBuilder = fieldSort;
                    }
                }
            } else if (sortable instanceof ScriptSort ss) {
                sortBuilder = scriptSort(ss.script().toPainless(), ss.script().outputType().scriptSortType());
            } else if (sortable instanceof ScoreSort) {
                sortBuilder = scoreSort();
            }
            if (sortBuilder != null) {
                sortBuilder.order(sortable.direction().asOrder());
                source.sort(sortBuilder);
            }
        }
    }
    private static void optimize(QueryContainer query, SearchSourceBuilder builder) {
        
        if (query.isAggsOnly()) {
            builder.size(0);
            builder.trackScores(false);
        }
        if (query.shouldTrackHits()) {
            builder.trackTotalHits(true);
        }
        builder.fetchSource(FetchSourceContext.DO_NOT_FETCH_SOURCE);
    }
}