本文整理匯總了Golang中github.com/pingcap/tidb/table.Index.Delete方法的典型用法代碼示例。如果您正苦於以下問題:Golang Index.Delete方法的具體用法?Golang Index.Delete怎麽用?Golang Index.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Index
的用法示例。
在下文中一共展示了Index.Delete方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: removeRowIndex
// RemoveRowIndex implements table.Table RemoveRowIndex interface.
func (t *Table) removeRowIndex(rm kv.RetrieverMutator, h int64, vals []types.Datum, idx table.Index) error {
if err := idx.Delete(rm, vals, h); err != nil {
return errors.Trace(err)
}
return nil
}
示例2: testIndex
func (s *testSuite) testIndex(c *C, tb table.Table, idx table.Index) {
txn, err := s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, IsNil)
cnt, err := GetIndexRecordsCount(txn, idx, nil)
c.Assert(err, IsNil)
c.Assert(cnt, Equals, int64(2))
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// index col data (handle, data): (1, 10), (2, 20), (4, 40)
err = idx.Create(txn, types.MakeDatums(int64(30)), 3)
c.Assert(err, IsNil)
col := tb.Cols()[idx.Meta().Columns[0].Offset]
key := tb.RecordKey(4, col)
err = tables.SetColValue(txn, key, types.NewDatum(int64(40)))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 := &RecordData{Handle: int64(3), Values: types.MakeDatums(int64(30))}
diffMsg := newDiffRetError("index", record1, &RecordData{Handle: int64(3), Values: types.MakeDatums(nil)})
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (4, 40), (3, 31)
err = idx.Create(txn, types.MakeDatums(int64(40)), 4)
c.Assert(err, IsNil)
key = tb.RecordKey(3, col)
err = tables.SetColValue(txn, key, types.NewDatum(int64(31)))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record2 := &RecordData{Handle: int64(3), Values: types.MakeDatums(int64(31))}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (4, 40), (5, 30)
key = tb.RecordKey(3, col)
txn.Delete(key)
key = tb.RecordKey(5, col)
err = tables.SetColValue(txn, key, types.NewDatum(int64(30)))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = checkRecordAndIndex(txn, tb, idx)
c.Assert(err, NotNil)
record2 = &RecordData{Handle: int64(5), Values: types.MakeDatums(int64(30))}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (3, 30)
key = tb.RecordKey(4, col)
txn.Delete(key)
key = tb.RecordKey(3, col)
err = tables.SetColValue(txn, key, types.NewDatum(int64(30)))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 = &RecordData{Handle: int64(4), Values: types.MakeDatums(int64(40))}
diffMsg = newDiffRetError("index", record1, &RecordData{Handle: int64(4), Values: types.MakeDatums(nil)})
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// index col data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
err = idx.Delete(txn, types.MakeDatums(int64(40)), 4)
c.Assert(err, IsNil)
key = tb.RecordKey(4, col)
err = tables.SetColValue(txn, key, types.NewDatum(int64(40)))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
//.........這裏部分代碼省略.........
示例3: testIndex
func (s *testSuite) testIndex(c *C, tb table.Table, idx table.Index) {
txn, err := s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, IsNil)
cnt, err := GetIndexRecordsCount(txn, idx, nil)
c.Assert(err, IsNil)
c.Assert(cnt, Equals, int64(2))
// set data to:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// table data (handle, data): (1, 10), (2, 20), (4, 40)
err = idx.Create(txn, types.MakeDatums(int64(30)), 3)
c.Assert(err, IsNil)
key := tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 4))
setColValue(c, txn, key, types.NewDatum(int64(40)))
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 := &RecordData{Handle: int64(3), Values: types.MakeDatums(int64(30))}
diffMsg := newDiffRetError("index", record1, nil)
c.Assert(err.Error(), DeepEquals, diffMsg)
// set data to:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// table data (handle, data): (1, 10), (2, 20), (4, 40), (3, 31)
err = idx.Create(txn, types.MakeDatums(int64(40)), 4)
c.Assert(err, IsNil)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 3))
setColValue(c, txn, key, types.NewDatum(int64(31)))
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record2 := &RecordData{Handle: int64(3), Values: types.MakeDatums(int64(31))}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// set data to:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// table data (handle, data): (1, 10), (2, 20), (4, 40), (5, 30)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 3))
txn.Delete(key)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 5))
setColValue(c, txn, key, types.NewDatum(int64(30)))
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = checkRecordAndIndex(txn, tb, idx)
c.Assert(err, NotNil)
record2 = &RecordData{Handle: int64(5), Values: types.MakeDatums(int64(30))}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// set data to:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// table data (handle, data): (1, 10), (2, 20), (3, 30)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 4))
txn.Delete(key)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 3))
setColValue(c, txn, key, types.NewDatum(int64(30)))
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 = &RecordData{Handle: int64(4), Values: types.MakeDatums(int64(40))}
diffMsg = newDiffRetError("index", record1, nil)
c.Assert(err.Error(), DeepEquals, diffMsg)
// set data to:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// table data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
err = idx.Delete(txn, types.MakeDatums(int64(40)), 4)
c.Assert(err, IsNil)
key = tablecodec.EncodeRowKey(tb.Meta().ID, codec.EncodeInt(nil, 4))
setColValue(c, txn, key, types.NewDatum(int64(40)))
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
diffMsg = newDiffRetError("index", nil, record1)
c.Assert(err.Error(), DeepEquals, diffMsg)
}