@@ -234,7 +234,8 @@ func deriveIndexPathStats(ds *logicalop.DataSource, path *util.AccessPath, _ []e
234
234
path .IndexFilters = append (path .IndexFilters , indexFilters ... )
235
235
// If the `CountAfterAccess` is less than `stats.RowCount`, there must be some inconsistent stats info.
236
236
// We prefer the `stats.RowCount` because it could use more stats info to calculate the selectivity.
237
- if path .CountAfterAccess < ds .StatsInfo ().RowCount && ! isIm {
237
+ // Add an arbitrary tolerance factor to account for comparison with floating point
238
+ if (path .CountAfterAccess + cost .ToleranceFactor ) < ds .StatsInfo ().RowCount && ! isIm {
238
239
path .CountAfterAccess = math .Min (ds .StatsInfo ().RowCount / cost .SelectionFactor , float64 (ds .StatisticTable .RealtimeCount ))
239
240
}
240
241
if path .IndexFilters != nil {
@@ -333,7 +334,8 @@ func deriveTablePathStats(ds *logicalop.DataSource, path *util.AccessPath, conds
333
334
path .CountAfterAccess , err = cardinality .GetRowCountByIntColumnRanges (ds .SCtx (), & ds .StatisticTable .HistColl , pkCol .ID , path .Ranges )
334
335
// If the `CountAfterAccess` is less than `stats.RowCount`, there must be some inconsistent stats info.
335
336
// We prefer the `stats.RowCount` because it could use more stats info to calculate the selectivity.
336
- if path .CountAfterAccess < ds .StatsInfo ().RowCount && ! isIm {
337
+ // Add an arbitrary tolerance factor to account for comparison with floating point
338
+ if (path .CountAfterAccess + cost .ToleranceFactor ) < ds .StatsInfo ().RowCount && ! isIm {
337
339
path .CountAfterAccess = math .Min (ds .StatsInfo ().RowCount / cost .SelectionFactor , float64 (ds .StatisticTable .RealtimeCount ))
338
340
}
339
341
return err
@@ -371,7 +373,8 @@ func deriveCommonHandleTablePathStats(ds *logicalop.DataSource, path *util.Acces
371
373
}
372
374
// If the `CountAfterAccess` is less than `stats.RowCount`, there must be some inconsistent stats info.
373
375
// We prefer the `stats.RowCount` because it could use more stats info to calculate the selectivity.
374
- if path .CountAfterAccess < ds .StatsInfo ().RowCount && ! isIm {
376
+ // Add an arbitrary tolerance factor to account for comparison with floating point
377
+ if (path .CountAfterAccess + cost .ToleranceFactor ) < ds .StatsInfo ().RowCount && ! isIm {
375
378
path .CountAfterAccess = math .Min (ds .StatsInfo ().RowCount / cost .SelectionFactor , float64 (ds .StatisticTable .RealtimeCount ))
376
379
}
377
380
return nil
0 commit comments