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

Lightning: fix performance regression introduced by behavior change of columnAPI.Cols() #59529

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions br/pkg/lightning/backend/kv/sql2kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

type tableKVEncoder struct {
tbl table.Table
columns []*table.Column
autoRandomColID int64
se *session
recordCache []types.Datum
Expand Down Expand Up @@ -120,6 +121,7 @@

return &tableKVEncoder{
tbl: tbl,
columns: cols,
autoRandomColID: autoRandomColID,
se: se,
genCols: genCols,
Expand Down Expand Up @@ -380,7 +382,6 @@
// when generating error such as mysql.ErrDataOutOfRange, the data will be part of the error, causing the buf
// unable to release. So we truncate the warnings here.
defer kvcodec.se.vars.StmtCtx.TruncateWarnings(0)
cols := kvcodec.tbl.Cols()

var value types.Datum
var err error
Expand All @@ -390,11 +391,11 @@
if kvcodec.recordCache != nil {
record = kvcodec.recordCache
} else {
record = make([]types.Datum, 0, len(cols)+1)
record = make([]types.Datum, 0, len(kvcodec.columns)+1)
}

meta := kvcodec.tbl.Meta()
for i, col := range cols {
for i, col := range kvcodec.columns {
var theDatum *types.Datum = nil
j := columnPermutation[i]
if j >= 0 && j < len(row) {
Expand Down Expand Up @@ -424,7 +425,7 @@

if common.TableHasAutoRowID(meta) {
rowValue := rowID
j := columnPermutation[len(cols)]
j := columnPermutation[len(kvcodec.columns)]
if j >= 0 && j < len(row) {
value, err = table.CastValue(kvcodec.se, row[j], ExtraHandleColumnInfo, false, false)
rowValue = value.GetInt64()
Expand All @@ -443,7 +444,7 @@
}

if len(kvcodec.genCols) > 0 {
if errCol, err := evaluateGeneratedColumns(kvcodec.se, record, cols, kvcodec.genCols); err != nil {
if errCol, err := evaluateGeneratedColumns(kvcodec.se, record, kvcodec.columns, kvcodec.genCols); err != nil {

Check warning on line 447 in br/pkg/lightning/backend/kv/sql2kv.go

View check run for this annotation

Codecov / codecov/patch

br/pkg/lightning/backend/kv/sql2kv.go#L447

Added line #L447 was not covered by tests
return nil, logEvalGenExprFailed(logger, row, errCol, err)
}
}
Expand Down Expand Up @@ -494,11 +495,9 @@
err error
)

cols := kvcodec.tbl.Cols()

// Since this method is only called when iterating the columns in the `Encode()` method,
// we can assume that the `colIndex` always have a valid input
col := cols[colIndex]
col := kvcodec.columns[colIndex]

isBadNullValue := false
if inputDatum != nil {
Expand Down