From d1881fa582d117c2a071438230f90fcd57a69e11 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 24 Feb 2022 12:47:24 +0200 Subject: [PATCH] lib/storage: add a comment to indexSearch.containsTimeRange() on why it allows false positives Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2239 --- lib/storage/index_db.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/storage/index_db.go b/lib/storage/index_db.go index 2ebc63c26..7da690b9d 100644 --- a/lib/storage/index_db.go +++ b/lib/storage/index_db.go @@ -1893,7 +1893,12 @@ func (is *indexSearch) containsTimeRange(tr TimeRange) (bool, error) { ts := &is.ts kb := &is.kb - // Verify whether the maximum date in `ts` covers tr.MinTimestamp. + // Verify whether the tr.MinTimestamp is included into `ts` or is smaller than the minimum date stored in `ts`. + // Do not check whether tr.MaxTimestamp is included into `ts` or is bigger than the max date stored in `ts` for performance reasons. + // This means that containsTimeRange() can return true if `tr` is located below the min date stored in `ts`. + // This is OK, since this case isn't encountered too much in practice. + // The main practical case allows skipping searching in prev indexdb (`ts`) when `tr` + // is located above the max date stored there. minDate := uint64(tr.MinTimestamp) / msecPerDay kb.B = is.marshalCommonPrefix(kb.B[:0], nsPrefixDateToMetricID) prefix := kb.B