本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/internal/client.Batch.Del方法的典型用法代码示例。如果您正苦于以下问题:Golang Batch.Del方法的具体用法?Golang Batch.Del怎么用?Golang Batch.Del使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/internal/client.Batch
的用法示例。
在下文中一共展示了Batch.Del方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteRow
// deleteRow adds to the batch the kv operations necessary to delete a table row
// with the given values.
func (rd *rowDeleter) deleteRow(ctx context.Context, b *client.Batch, values []parser.Datum) error {
if err := rd.fks.checkAll(values); err != nil {
return err
}
primaryIndexKey, secondaryIndexEntries, err := rd.helper.encodeIndexes(rd.fetchColIDtoRowIndex, values)
if err != nil {
return err
}
for _, secondaryIndexEntry := range secondaryIndexEntries {
if log.V(2) {
log.Infof(ctx, "Del %s", secondaryIndexEntry.Key)
}
b.Del(secondaryIndexEntry.Key)
}
// Delete the row.
rd.startKey = roachpb.Key(primaryIndexKey)
rd.endKey = roachpb.Key(encoding.EncodeNotNullDescending(primaryIndexKey))
if log.V(2) {
log.Infof(ctx, "DelRange %s - %s", rd.startKey, rd.endKey)
}
b.DelRange(&rd.startKey, &rd.endKey, false)
rd.startKey, rd.endKey = nil, nil
return nil
}
示例2: deleteIndexRow
// deleteIndexRow adds to the batch the kv operations necessary to delete a
// table row from the given index.
func (rd *rowDeleter) deleteIndexRow(
ctx context.Context, b *client.Batch, idx *sqlbase.IndexDescriptor, values []parser.Datum,
) error {
if err := rd.fks.checkAll(values); err != nil {
return err
}
secondaryIndexEntry, err := sqlbase.EncodeSecondaryIndex(
rd.helper.tableDesc, idx, rd.fetchColIDtoRowIndex, values)
if err != nil {
return err
}
if log.V(2) {
log.Infof(ctx, "Del %s", secondaryIndexEntry.Key)
}
b.Del(secondaryIndexEntry.Key)
return nil
}
示例3: delMeta
func delMeta(b *client.Batch, key roachpb.Key, desc *roachpb.RangeDescriptor) {
b.Del(key)
}
示例4: updateRow
//.........这里部分代码省略.........
// backwards compatible with the original BaseFormatVersion.
idx, ok := ru.updateColIDtoRowIndex[family.DefaultColumnID]
if !ok {
continue
}
ru.key = keys.MakeFamilyKey(primaryIndexKey, uint32(family.ID))
if log.V(2) {
log.Infof(ctx, "Put %s -> %v", ru.key, ru.marshalled[idx].PrettyPrint())
}
b.Put(&ru.key, &ru.marshalled[idx])
ru.key = nil
continue
}
ru.key = keys.MakeFamilyKey(primaryIndexKey, uint32(family.ID))
ru.valueBuf = ru.valueBuf[:0]
var lastColID sqlbase.ColumnID
familySortedColumnIDs, ok := ru.helper.sortedColumnFamily(family.ID)
if !ok {
panic("invalid family sorted column id map")
}
for _, colID := range familySortedColumnIDs {
if ru.helper.columnInPK(colID) {
if family.ID != 0 {
return nil, errors.Errorf("primary index column %d must be in family 0, was %d", colID, family.ID)
}
// Skip primary key columns as their values are encoded in the key of
// each family. Family 0 is guaranteed to exist and acts as a sentinel.
continue
}
idx, ok := ru.fetchColIDtoRowIndex[colID]
if !ok {
return nil, errors.Errorf("column %d was expected to be fetched, but wasn't", colID)
}
col := ru.fetchCols[idx]
if ru.newValues[idx].Compare(parser.DNull) == 0 {
continue
}
if lastColID > col.ID {
panic(fmt.Errorf("cannot write column id %d after %d", col.ID, lastColID))
}
colIDDiff := col.ID - lastColID
lastColID = col.ID
ru.valueBuf, err = sqlbase.EncodeTableValue(ru.valueBuf, colIDDiff, ru.newValues[idx])
if err != nil {
return nil, err
}
}
if family.ID != 0 && len(ru.valueBuf) == 0 {
// The family might have already existed but every column in it is being
// set to NULL, so delete it.
if log.V(2) {
log.Infof(ctx, "Del %s", ru.key)
}
b.Del(&ru.key)
} else {
ru.value.SetTuple(ru.valueBuf)
if log.V(2) {
log.Infof(ctx, "Put %s -> %v", ru.key, ru.value.PrettyPrint())
}
b.Put(&ru.key, &ru.value)
}
ru.key = nil
}
// Update secondary indexes.
for i, newSecondaryIndexEntry := range newSecondaryIndexEntries {
secondaryIndexEntry := secondaryIndexEntries[i]
secondaryKeyChanged := !bytes.Equal(newSecondaryIndexEntry.Key, secondaryIndexEntry.Key)
if secondaryKeyChanged {
if err := ru.fks.checkIdx(ru.helper.indexes[i].ID, oldValues, ru.newValues); err != nil {
return nil, err
}
if log.V(2) {
log.Infof(ctx, "Del %s", secondaryIndexEntry.Key)
}
b.Del(secondaryIndexEntry.Key)
// Do not update Indexes in the DELETE_ONLY state.
if _, ok := ru.deleteOnlyIndex[i]; !ok {
if log.V(2) {
log.Infof(ctx, "CPut %s -> %v", newSecondaryIndexEntry.Key, newSecondaryIndexEntry.Value.PrettyPrint())
}
b.CPut(newSecondaryIndexEntry.Key, &newSecondaryIndexEntry.Value, nil)
}
}
}
return ru.newValues, nil
}