本文整理匯總了Golang中github.com/pingcap/tidb/table.Table.KeyPrefix方法的典型用法代碼示例。如果您正苦於以下問題:Golang Table.KeyPrefix方法的具體用法?Golang Table.KeyPrefix怎麽用?Golang Table.KeyPrefix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Table
的用法示例。
在下文中一共展示了Table.KeyPrefix方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: buildIndex
func (d *ddl) buildIndex(ctx context.Context, t table.Table, idxInfo *model.IndexInfo, unique bool) error {
firstKey := t.FirstKey()
prefix := t.KeyPrefix()
txn, err := ctx.GetTxn(false)
if err != nil {
return errors.Trace(err)
}
it, err := txn.Seek([]byte(firstKey))
if err != nil {
return errors.Trace(err)
}
defer it.Close()
for it.Valid() && strings.HasPrefix(it.Key(), prefix) {
var err error
handle, err := util.DecodeHandleFromRowKey(it.Key())
log.Info("building index...", handle)
if err != nil {
return errors.Trace(err)
}
// TODO: v is timestamp ?
// fetch datas
cols := t.Cols()
var vals []interface{}
for _, v := range idxInfo.Columns {
var (
data []byte
val interface{}
)
col := cols[v.Offset]
k := t.RecordKey(handle, col)
data, err = txn.Get([]byte(k))
if err != nil {
return errors.Trace(err)
}
val, err = t.DecodeValue(data, col)
if err != nil {
return errors.Trace(err)
}
vals = append(vals, val)
}
// build index
kvX := kv.NewKVIndex(t.IndexPrefix(), idxInfo.Name.L, unique)
err = kvX.Create(txn, vals, handle)
if err != nil {
return errors.Trace(err)
}
rk := []byte(t.RecordKey(handle, nil))
it, err = kv.NextUntil(it, util.RowKeyPrefixFilter(rk))
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例2: dropTableData
func (d *ddl) dropTableData(t table.Table) error {
// delete table data
err := d.delKeysWithPrefix(t.KeyPrefix())
if err != nil {
return errors.Trace(err)
}
// delete table index
err = d.delKeysWithPrefix(t.IndexPrefix())
return errors.Trace(err)
}
示例3: getSnapshotRows
func (d *ddl) getSnapshotRows(t table.Table, version uint64, seekHandle int64) ([]int64, error) {
ver := kv.Version{Ver: version}
snap, err := d.store.GetSnapshot(ver)
if err != nil {
return nil, errors.Trace(err)
}
defer snap.MvccRelease()
firstKey := t.RecordKey(seekHandle, nil)
prefix := []byte(t.KeyPrefix())
it := snap.NewMvccIterator([]byte(firstKey), ver)
defer it.Close()
handles := make([]int64, 0, maxBatchSize)
for it.Valid() {
key := []byte(it.Key())
if !bytes.HasPrefix(key, prefix) {
break
}
var handle int64
handle, err = util.DecodeHandleFromRowKey(string(key))
if err != nil {
return nil, errors.Trace(err)
}
rk := t.RecordKey(handle, nil)
handles = append(handles, handle)
if len(handles) == maxBatchSize {
seekHandle = handle + 1
break
}
err = kv.NextUntil(it, util.RowKeyPrefixFilter(rk))
if terror.ErrorEqual(err, kv.ErrNotExist) {
break
} else if err != nil {
return nil, errors.Trace(err)
}
}
return handles, nil
}