*: address comment.

This commit is contained in:
qiuyesuifeng
2015-10-30 18:49:39 +08:00
parent 4bf9078438
commit a8d0629139
2 changed files with 14 additions and 7 deletions

View File

@ -245,26 +245,33 @@ func (c *kvIndex) SeekFirst(txn Transaction) (iter IndexIterator, err error) {
return &indexIter{it: it, idx: c, prefix: c.prefix}, nil
}
func (c *kvIndex) Exist(txn Transaction, indexedValues []interface{}, h int64) (int64, bool, error) {
func (c *kvIndex) Exist(txn Transaction, indexedValues []interface{}, h int64) (bool, int64, error) {
key, err := c.genIndexKey(indexedValues, h)
if err != nil {
return 0, false, errors.Trace(err)
return false, 0, errors.Trace(err)
}
value, err := txn.Get(key)
if IsErrNotFound(err) {
return false, 0, nil
}
if err != nil {
return 0, false, errors.Trace(err)
return false, 0, errors.Trace(err)
}
// For uniq index, the value of key is handle.
if c.unique {
handle, err := decodeHandle(value)
if err != nil {
return 0, false, errors.Trace(err)
return false, 0, errors.Trace(err)
}
return handle, handle == h, nil
if handle != h {
return true, handle, errors.Trace(ErrKeyExists)
}
return true, handle, nil
}
return h, true, nil
return true, h, nil
}

View File

@ -193,7 +193,7 @@ type Index interface {
Create(txn Transaction, indexedValues []interface{}, h int64) error // supports insert into statement
Delete(txn Transaction, indexedValues []interface{}, h int64) error // supports delete from statement
Drop(txn Transaction) error // supports drop table, drop index statements
Exist(txn Transaction, indexedValues []interface{}, h int64) (int64, bool, error) // supports check index exist
Exist(txn Transaction, indexedValues []interface{}, h int64) (bool, int64, error) // supports check index exist
Seek(txn Transaction, indexedValues []interface{}) (iter IndexIterator, hit bool, err error) // supports where clause
SeekFirst(txn Transaction) (iter IndexIterator, err error) // supports aggregate min / ascending order by
}