MCPcopy
hub / github.com/pingcap/tidb / compareData

Method compareData

pkg/executor/distsql.go:1730–1845  ·  view source on GitHub ↗
(ctx context.Context, task *lookupTableTask, tableReader exec.Executor)

Source from the content-addressed store, hash-verified

1728}
1729
1730func (w *tableWorker) compareData(ctx context.Context, task *lookupTableTask, tableReader exec.Executor) error {
1731 chk := exec.TryNewCacheChunk(tableReader)
1732 tblInfo := w.idxLookup.table.Meta()
1733 vals := make([]types.Datum, 0, len(w.idxTblCols))
1734
1735 // Prepare collator for compare.
1736 collators := make([]collate.Collator, 0, len(w.idxColTps))
1737 for _, tp := range w.idxColTps {
1738 collators = append(collators, collate.GetCollator(tp.GetCollate()))
1739 }
1740
1741 ir := func() *consistency.Reporter {
1742 return &consistency.Reporter{
1743 HandleEncode: func(handle kv.Handle) kv.Key {
1744 return tablecodec.EncodeRecordKey(w.idxLookup.table.RecordPrefix(), handle)
1745 },
1746 IndexEncode: func(idxRow *consistency.RecordData) kv.Key {
1747 var idx table.Index
1748 for _, v := range w.idxLookup.table.Indices() {
1749 if strings.EqualFold(v.Meta().Name.String(), w.idxLookup.index.Name.O) {
1750 idx = v
1751 break
1752 }
1753 }
1754 if idx == nil {
1755 return nil
1756 }
1757 ectx := w.idxLookup.ectx.GetEvalCtx()
1758 k, _, err := idx.GenIndexKey(ectx.ErrCtx(), ectx.Location(), idxRow.Values[:len(idx.Meta().Columns)], idxRow.Handle, nil)
1759 if err != nil {
1760 return nil
1761 }
1762 return k
1763 },
1764 Tbl: tblInfo,
1765 Idx: w.idxLookup.index,
1766 EnableRedactLog: w.idxLookup.enableRedactLog,
1767 Storage: w.idxLookup.storage,
1768 }
1769 }
1770
1771 for {
1772 err := exec.Next(ctx, tableReader, chk)
1773 if err != nil {
1774 return errors.Trace(err)
1775 }
1776
1777 // If ctx is cancelled, `Next` may return empty result when the actual data is not empty. To avoid producing
1778 // false-positive error logs that cause confusion, exit in this case.
1779 select {
1780 case <-ctx.Done():
1781 return nil
1782 default:
1783 }
1784
1785 if chk.NumRows() == 0 {
1786 task.indexOrder.Range(func(h kv.Handle, val any) bool {
1787 idxRow := task.idxRows.GetRow(val.(int))

Callers 1

executeTaskMethod · 0.95

Calls 15

MetaMethod · 0.95
GenIndexKeyMethod · 0.95
BeginMethod · 0.95
EndMethod · 0.95
NextMethod · 0.95
TryNewCacheChunkFunction · 0.92
GetCollatorFunction · 0.92
EncodeRecordKeyFunction · 0.92
NextFunction · 0.92
NewIterator4ChunkFunction · 0.92
TruncateIndexValuesFunction · 0.92
TruncateIndexValueFunction · 0.92

Tested by

no test coverage detected