From 171fc4ab5da16793145d0e1df4403a073b1d2f78 Mon Sep 17 00:00:00 2001 From: Alin Sinpalean Date: Fri, 9 Nov 2018 14:54:56 +0100 Subject: [PATCH] Limit the returned db.Querier to the requested time range (#351) Limit the returned `db.Querier` to the requested time range. Preallocate the `baseChunkSeries.lset` and `baseChunkSeries.chks` slices to the previous series' slice sizes to avoid unnecessary grow slice reallocations. --- db.go | 6 +++++- querier.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index bfb7d4c2c..8f452137e 100644 --- a/db.go +++ b/db.go @@ -793,7 +793,11 @@ func (db *DB) Querier(mint, maxt int64) (Querier, error) { } } if maxt >= db.head.MinTime() { - blocks = append(blocks, db.head) + blocks = append(blocks, &rangeHead{ + head: db.head, + mint: mint, + maxt: maxt, + }) } sq := &querier{ diff --git a/querier.go b/querier.go index bddb81f86..a4da8e689 100644 --- a/querier.go +++ b/querier.go @@ -499,8 +499,8 @@ func (s *baseChunkSeries) Err() error { return s.err } func (s *baseChunkSeries) Next() bool { var ( - lset labels.Labels - chkMetas []chunks.Meta + lset = make(labels.Labels, len(s.lset)) + chkMetas = make([]chunks.Meta, len(s.chks)) err error )