From 83339f42a306bbec60e545a4ac88b5a380a083c0 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Wed, 17 Dec 2025 19:58:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(exports):=20=E5=A2=9E=E5=BC=BA=E8=A1=8C?= =?UTF-8?q?=E6=95=B0=E4=BC=B0=E7=AE=97=E5=8A=9F=E8=83=BD=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=B2=BE=E7=A1=AE=E7=BB=9F=E8=AE=A1=E5=92=8C=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在create函数中添加行数估算逻辑,优先使用分块统计,失败时回退到精确COUNT - 添加日志记录以跟踪估算过程,确保在估算为0时能够进行精确统计 - 提升代码可读性,确保行数估算和日志记录逻辑清晰明了 --- server/internal/api/exports.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/internal/api/exports.go b/server/internal/api/exports.go index 5494fee..15acdb9 100644 --- a/server/internal/api/exports.go +++ b/server/internal/api/exports.go @@ -305,8 +305,18 @@ func (a *ExportsAPI) create(w http.ResponseWriter, r *http.Request) { fail(w, r, http.StatusBadRequest, fmt.Sprintf("EXPLAIN 未通过:评分=%d,请优化索引或缩小查询范围", score)) return } + // 估算行数(优先使用分块统计,失败或结果为 0 时回退到单次 COUNT) var estimate int64 estimate = rrepo.EstimateFastChunked(dataDB, ds, main, p.Filters) + if estimate <= 0 { + logging.JSON("WARN", map[string]interface{}{ + "event": "estimate_zero_fallback", + "datasource": ds, + "main_table": main, + "filters": p.Filters, + }) + estimate = rrepo.EstimateFast(dataDB, ds, main, p.Filters) + } hdrs := make([]string, len(filtered)) for i, tf := range filtered { if v, ok := labels[tf]; ok {