Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: improve UnionScanRead performance #32668

Merged
merged 11 commits into from
Apr 1, 2022
Prev Previous commit
Next Next commit
fix getMemRows()
  • Loading branch information
Defined2014 committed Mar 1, 2022
commit 258d16d93684864608f818fd861d1002a3ff7c2c
14 changes: 7 additions & 7 deletions executor/mem_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ func buildMemTableReader(us *UnionScanExec, tblReader *TableReaderExecutor) *mem
// TODO: Try to make memXXXReader lazy, There is no need to decode many rows when parent operator only need 1 row.
func (m *memTableReader) getMemRows() ([][]types.Datum, error) {
mutableRow := chunk.MutRowFromTypes(m.retFieldTypes)
resultRows := make([]types.Datum, 0, len(m.columns))
resultRows := make([]types.Datum, len(m.columns))
err := iterTxnMemBuffer(m.ctx, m.cacheTable, m.kvRanges, func(key, value []byte) error {
err := m.decodeRecordKeyValue(key, value, resultRows)
err := m.decodeRecordKeyValue(key, value, &resultRows)
if err != nil {
return err
}
Expand All @@ -230,6 +230,7 @@ func (m *memTableReader) getMemRows() ([][]types.Datum, error) {
return err
}
m.addedRows = append(m.addedRows, resultRows)
resultRows = make([]types.Datum, len(m.columns))
return nil
})
if err != nil {
Expand All @@ -243,7 +244,7 @@ func (m *memTableReader) getMemRows() ([][]types.Datum, error) {
return m.addedRows, nil
}

func (m *memTableReader) decodeRecordKeyValue(key, value []byte, resultRows []types.Datum) error {
func (m *memTableReader) decodeRecordKeyValue(key, value []byte, resultRows *[]types.Datum) error {
handle, err := tablecodec.DecodeRowKey(key)
if err != nil {
return errors.Trace(err)
Expand All @@ -252,19 +253,18 @@ func (m *memTableReader) decodeRecordKeyValue(key, value []byte, resultRows []ty
}

// decodeRowData uses to decode row data value.
func (m *memTableReader) decodeRowData(handle kv.Handle, value []byte, resultRows []types.Datum) error {
func (m *memTableReader) decodeRowData(handle kv.Handle, value []byte, resultRows *[]types.Datum) error {
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
values, err := m.getRowData(handle, value)
if err != nil {
return err
}
resultRows = resultRows[0:0]
for _, col := range m.columns {
for i, col := range m.columns {
offset := m.colIDs[col.ID]
d, err := tablecodec.DecodeColumnValue(values[offset], &col.FieldType, m.ctx.GetSessionVars().Location())
if err != nil {
return err
}
resultRows = append(resultRows, d)
(*resultRows)[i] = d
}
return nil
}
Expand Down