Skip to content

Commit

Permalink
executor: only use the transaction buffer for union scan (pingcap#9428)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackysp authored and zz-jason committed Mar 3, 2019
1 parent 560e8cf commit 0b371ea
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0b371ea

Please sign in to comment.