mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add shortcuts for empty postings
Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
This commit is contained in:
parent
ae02ffd5ae
commit
f3d001df2e
|
@ -113,7 +113,9 @@ func (h *headIndexReader) Postings(name string, values ...string) (index.Posting
|
||||||
default:
|
default:
|
||||||
res := make([]index.Postings, 0, len(values))
|
res := make([]index.Postings, 0, len(values))
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
res = append(res, h.head.postings.Get(name, value))
|
if p := h.head.postings.Get(name, value); !index.IsEmptyPostings(p) {
|
||||||
|
res = append(res, p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return index.Merge(res...), nil
|
return index.Merge(res...), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,6 +428,13 @@ func EmptyPostings() Postings {
|
||||||
return emptyPostings
|
return emptyPostings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEmptyPostings returns true if the postings are an empty postings list.
|
||||||
|
// When this function returns false, it doesn't mean that the postings isn't empty
|
||||||
|
// (it could be an empty intersection of two non-empty postings, for example).
|
||||||
|
func IsEmptyPostings(p Postings) bool {
|
||||||
|
return p == emptyPostings
|
||||||
|
}
|
||||||
|
|
||||||
// ErrPostings returns new postings that immediately error.
|
// ErrPostings returns new postings that immediately error.
|
||||||
func ErrPostings(err error) Postings {
|
func ErrPostings(err error) Postings {
|
||||||
return errPostings{err}
|
return errPostings{err}
|
||||||
|
|
|
@ -215,6 +215,9 @@ func PostingsForMatchers(ix IndexPostingsReader, ms ...*labels.Matcher) (index.P
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if index.IsEmptyPostings(it) {
|
||||||
|
return index.EmptyPostings(), nil
|
||||||
|
}
|
||||||
its = append(its, it)
|
its = append(its, it)
|
||||||
} else { // l="a"
|
} else { // l="a"
|
||||||
// Non-Not matcher, use normal postingsForMatcher.
|
// Non-Not matcher, use normal postingsForMatcher.
|
||||||
|
@ -222,6 +225,9 @@ func PostingsForMatchers(ix IndexPostingsReader, ms ...*labels.Matcher) (index.P
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if index.IsEmptyPostings(it) {
|
||||||
|
return index.EmptyPostings(), nil
|
||||||
|
}
|
||||||
its = append(its, it)
|
its = append(its, it)
|
||||||
}
|
}
|
||||||
} else { // l=""
|
} else { // l=""
|
||||||
|
|
Loading…
Reference in a new issue