From 0b371ea4fa95a829aa83376d9882dae10bee15d2 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Sun, 3 Mar 2019 14:54:18 +0800 Subject: [PATCH] executor: only use the transaction buffer for union scan (#9428) --- executor/union_scan.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/executor/union_scan.go b/executor/union_scan.go index 8d09db467f40e..893c0c823e561 100644 --- a/executor/union_scan.go +++ b/executor/union_scan.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/table" + "github.com/pingcap/tidb/table/tables" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" ) @@ -274,13 +275,31 @@ func (us *UnionScanExec) compare(a, b []types.Datum) (int, error) { return cmp, nil } +// rowWithColsInTxn gets the row from the transaction buffer. +func (us *UnionScanExec) rowWithColsInTxn(t table.Table, h int64, cols []*table.Column) ([]types.Datum, error) { + key := t.RecordKey(h) + txn, err := us.ctx.Txn(true) + if err != nil { + return nil, errors.Trace(err) + } + value, err := txn.GetMemBuffer().Get(key) + if err != nil { + return nil, errors.Trace(err) + } + v, _, err := tables.DecodeRawRowData(us.ctx, t.Meta(), h, cols, value) + if err != nil { + return nil, errors.Trace(err) + } + return v, nil +} + func (us *UnionScanExec) buildAndSortAddedRows(t table.Table) error { us.addedRows = make([][]types.Datum, 0, len(us.dirty.addedRows)) mutableRow := chunk.MutRowFromTypes(us.retTypes()) cols := t.WritableCols() for h := range us.dirty.addedRows { newData := make([]types.Datum, 0, us.schema.Len()) - data, err := t.RowWithCols(us.ctx, h, cols) + data, err := us.rowWithColsInTxn(t, h, cols) if err != nil { return err }