From 5d82985900d69743697807d3e57d3372c3f11fbf Mon Sep 17 00:00:00 2001 From: nitao Date: Wed, 11 Dec 2024 17:55:59 +0800 Subject: [PATCH] optimize stats for runtime filters when table not flushed (#20717) optimize stats for runtime filters when table not flushed Approved by: @ouyuanning --- pkg/sql/plan/runtime_filter.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/sql/plan/runtime_filter.go b/pkg/sql/plan/runtime_filter.go index fdfddfc0e5266..7c46884d336ae 100644 --- a/pkg/sql/plan/runtime_filter.go +++ b/pkg/sql/plan/runtime_filter.go @@ -163,7 +163,11 @@ func (builder *QueryBuilder) generateRuntimeFilters(nodeID int32) { sortOrder := GetSortOrder(tableDef, probeCol.ColPos) if node.JoinType != plan.Node_INDEX { probeNdv := getExprNdv(probeExprs[0], builder) - if probeNdv == -1 || node.Stats.HashmapStats.HashmapSize/probeNdv >= 0.1 { + if probeNdv <= 1 { + //maybe not flushed yet, set at least 100 to continue calculation + probeNdv = 100 + } + if node.Stats.HashmapStats.HashmapSize/probeNdv >= 0.1 { return } if sortOrder != 0 {