mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Add fast-path for equality matching
This commit is contained in:
parent
1579e12011
commit
7de2217011
|
@ -7,20 +7,20 @@ import (
|
|||
)
|
||||
|
||||
func mmap(f *os.File, sz int) ([]byte, error) {
|
||||
low, high := uint32(size), uint32(size>>32)
|
||||
low, high := uint32(sz), uint32(sz>>32)
|
||||
|
||||
h, errno := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, low, high, nil)
|
||||
if h == 0 {
|
||||
return os.NewSyscallError("CreateFileMapping", errno)
|
||||
return nil, os.NewSyscallError("CreateFileMapping", errno)
|
||||
}
|
||||
|
||||
addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, uintptr(sz))
|
||||
if addr == 0 {
|
||||
return os.NewSyscallError("MapViewOfFile", errno)
|
||||
return nil, os.NewSyscallError("MapViewOfFile", errno)
|
||||
}
|
||||
|
||||
if err := syscall.CloseHandle(syscall.Handle(h)); err != nil {
|
||||
return os.NewSyscallError("CloseHandle", err)
|
||||
return nil, os.NewSyscallError("CloseHandle", err)
|
||||
}
|
||||
|
||||
return (*[1 << 30]byte)(unsafe.Pointer(addr))[:sz], nil
|
||||
|
|
2
index.go
2
index.go
|
@ -688,7 +688,7 @@ func (r *indexReader) Postings(name, value string) (Postings, error) {
|
|||
|
||||
off, ok := r.postings[key]
|
||||
if !ok {
|
||||
return nil, ErrNotFound
|
||||
return emptyPostings, nil
|
||||
}
|
||||
|
||||
flag, b, err := r.section(off)
|
||||
|
|
|
@ -34,6 +34,9 @@ func (m *EqualMatcher) Name() string { return m.name }
|
|||
// Matches implements Matcher interface.
|
||||
func (m *EqualMatcher) Matches(v string) bool { return v == m.value }
|
||||
|
||||
// Value returns the matched value.
|
||||
func (m *EqualMatcher) Value() string { return m.value }
|
||||
|
||||
// NewEqualMatcher returns a new matcher matching an exact label value.
|
||||
func NewEqualMatcher(name, value string) Matcher {
|
||||
return &EqualMatcher{name: name, value: value}
|
||||
|
|
10
querier.go
10
querier.go
|
@ -157,6 +157,15 @@ func (q *blockQuerier) Select(ms ...labels.Matcher) SeriesSet {
|
|||
}
|
||||
|
||||
func (q *blockQuerier) selectSingle(m labels.Matcher) Postings {
|
||||
// Fast-path for equal matching.
|
||||
if em, ok := m.(*labels.EqualMatcher); ok {
|
||||
it, err := q.index.Postings(em.Name(), em.Value())
|
||||
if err != nil {
|
||||
return errPostings{err: err}
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
||||
tpls, err := q.index.LabelValues(m.Name())
|
||||
if err != nil {
|
||||
return errPostings{err: err}
|
||||
|
@ -174,7 +183,6 @@ func (q *blockQuerier) selectSingle(m labels.Matcher) Postings {
|
|||
res = append(res, vals[0])
|
||||
}
|
||||
}
|
||||
|
||||
if len(res) == 0 {
|
||||
return emptyPostings
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue