Skip to content

Commit

Permalink
kv: use EncodeBytes instead
Browse files Browse the repository at this point in the history
  • Loading branch information
siddontang committed Sep 12, 2015
1 parent 6e4e4b2 commit c3ae56c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions kv/index_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"

"github.com/juju/errors"
"github.com/pingcap/tidb/util/codec"
)

var (
Expand Down Expand Up @@ -104,13 +105,13 @@ type kvIndex struct {
}

func genIndexPrefix(indexPrefix, indexName string) string {
// Adding \xFF\xFF seperator to guarantee not iterating same prefix index
// e.g, two indices c1 and c with index prefix p, if no \xFF\xFF,
// Use EncodeBytes to guarantee generating different index prefix.
// e.g, two indices c1 and c with index prefix p, if no EncodeBytes,
// the index format looks p_c and p_c1, if c has a index value which the first encoded byte is '1',
// we will meet a error, because p_c1 is for index c1.
// Why \xFF\xFF? We guarantee that all the encoded value with util/codec EncodeKey is less than \xFF\xFF.
// TODO: check indexName whether has \xFF\xFF suffix?
return fmt.Sprintf("%s_%s\xFF\xFF", indexPrefix, indexName)
// If EncodeBytes, c1 -> c1\x00\x01 and c -> c\x00\x01, the prefixs are different.
key := fmt.Sprintf("%s_%s", indexPrefix, indexName)
return string(codec.EncodeBytes(nil, []byte(key)))
}

// NewKVIndex builds a new kvIndex object.
Expand Down

0 comments on commit c3ae56c

Please sign in to comment.