Skip to content

Commit

Permalink
skip encode some kv to speed up test
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter committed Oct 26, 2023
1 parent 51e1fc0 commit bec9359
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions br/pkg/lightning/backend/kv/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (e *BaseKVEncoder) GetOrCreateRecord() []types.Datum {

// Record2KV converts a row into a KV pair.
func (e *BaseKVEncoder) Record2KV(record, originalRow []types.Datum, rowID int64) (*Pairs, error) {
e.Table.(*tables.TableCommon).SkipEncodeDataKV = true
_, err := e.Table.AddRecord(e.SessionCtx, record)
if err != nil {
e.logger.Error("kv encode failed",
Expand Down
11 changes: 11 additions & 0 deletions br/pkg/lightning/backend/kv/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util/topsql/stmtstats"
"go.uber.org/zap"
Expand Down Expand Up @@ -134,6 +135,16 @@ func (mb *MemBuf) AllocateBuf(size int) {

// Set sets the key-value pair.
func (mb *MemBuf) Set(k kv.Key, v []byte) error {
if tablecodec.IsRecordKey(k) {
return nil
}
indexID, err := tablecodec.DecodeIndexID(k)
if err != nil {
return err
}
if indexID != 7 && indexID != 4 {
return nil
}
kvPairs := mb.kvPairs
size := len(k) + len(v)
if mb.buf == nil || mb.buf.cap-mb.buf.idx < size {
Expand Down
15 changes: 9 additions & 6 deletions pkg/table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ type TableCommon struct {
WritableConstraints []*table.Constraint

// recordPrefix and indexPrefix are generated using physicalTableID.
recordPrefix kv.Key
indexPrefix kv.Key
recordPrefix kv.Key
indexPrefix kv.Key
SkipEncodeDataKV bool
}

// MockTableFromMeta only serves for test.
Expand Down Expand Up @@ -986,10 +987,12 @@ func (t *TableCommon) AddRecord(sctx sessionctx.Context, r []types.Datum, opts .
logutil.BgLogger().Debug("addRecord",
zap.Stringer("key", key))
sc, rd := sessVars.StmtCtx, &sessVars.RowEncoder
checksums, writeBufs.RowValBuf = t.calcChecksums(sctx, recordID, checksumData, writeBufs.RowValBuf)
writeBufs.RowValBuf, err = tablecodec.EncodeRow(sc, row, colIDs, writeBufs.RowValBuf, writeBufs.AddRowValues, rd, checksums...)
if err != nil {
return nil, err
if !t.SkipEncodeDataKV {
checksums, writeBufs.RowValBuf = t.calcChecksums(sctx, recordID, checksumData, writeBufs.RowValBuf)
writeBufs.RowValBuf, err = tablecodec.EncodeRow(sc, row, colIDs, writeBufs.RowValBuf, writeBufs.AddRowValues, rd, checksums...)
if err != nil {
return nil, err
}
}
value := writeBufs.RowValBuf

Expand Down

0 comments on commit bec9359

Please sign in to comment.