code: func (q *TagQuery) sortByCost() {
  	for i, kv := range q.equal {
  		q.equal[i].cost = uint(len(q.index[kv.key][kv.value]))
  	}
  
  	// for prefix and match clauses we can't determine the actual cost
  	// without actually evaluating them, so we estimate based on
  	// cardinality of the key
  	for i, kv := range q.prefix {
  		q.prefix[i].cost = uint(len(q.index[kv.key]))
  	}
  
  	for i, kvRe := range q.match {
  		q.match[i].cost = uint(len(q.index[kvRe.key]))
  	}
  
  	sort.Sort(KvByCost(q.equal))
  	sort.Sort(KvByCost(q.notEqual))
  	sort.Sort(KvByCost(q.prefix))
  	sort.Sort(KvReByCost(q.match))
  	sort.Sort(KvReByCost(q.notMatch))
  }
docs: // sortByCost tries to estimate the cost of different expressions and sort them
  // in increasing order
  // this is to reduce the result set cheaply and only apply expensive tests to an
  // already reduced set of results