@ -370,6 +370,9 @@ func compareLabels(a, b Labels) int {
if d := strings.Compare(a[i].Name, b[i].Name); d != 0 {
return d
}
if d := strings.Compare(a[i].Value, b[i].Value); d != 0 {
// If all labels so far were in common, the set with fewer labels comes first.
return len(a) - len(b)
@ -211,6 +211,19 @@ func TestCompareLabels(t *testing.T) {
b: []Label{{"aa", ""}, {"ab", ""}},
res: 1,
},
{
a: []Label{
{"__name__", "go_gc_duration_seconds"},
{"job", "prometheus"},
{"quantile", "0.75"},
b: []Label{
{"quantile", "1"},
res: -1,
for _, c := range cases {
// Use constructor to ensure sortedness.
@ -271,7 +271,7 @@ func (r *indexReader) Series(ref uint32, mint, maxt int64) (Series, error) {
// the underlying strings.
labels := make(Labels, 0, k)
for i := 0; i < int(k); i += 2 {
for i := 0; i < len(offsets); i += 2 {
n, err := r.lookupSymbol(offsets[i])
if err != nil {
return nil, errors.Wrap(err, "symbol lookup")