-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: Fix add index after add column with default value #3510
Changes from 1 commit
01b4f8d
5dee15a
c4a3e38
88ffe84
508f5c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -459,34 +459,30 @@ func (t *Table) RowWithCols(ctx context.Context, h int64, cols []*table.Column) | |
} | ||
colTps[col.ID] = &col.FieldType | ||
} | ||
row, err := tablecodec.DecodeRow(value, colTps, ctx.GetSessionVars().GetTimeZone()) | ||
rowMap, err := tablecodec.DecodeRow(value, colTps, ctx.GetSessionVars().GetTimeZone()) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
defaultVals := make([]types.Datum, len(cols)) | ||
for i, col := range cols { | ||
if col == nil { | ||
continue | ||
} | ||
if col.IsPKHandleColumn(t.meta) { | ||
continue | ||
} | ||
ri, ok := row[col.ID] | ||
ri, ok := rowMap[col.ID] | ||
if ok { | ||
v[i] = ri | ||
continue | ||
} | ||
|
||
if col.OriginDefaultValue != nil && col.State == model.StatePublic { | ||
ri, err = table.GetColOriginDefaultValue(ctx, col.ToInfo()) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
v[i] = ri | ||
continue | ||
} | ||
if mysql.HasNotNullFlag(col.Flag) { | ||
return nil, errors.New("Miss column") | ||
} | ||
v[i], err = GetColDefaultValue(ctx, col, defaultVals) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move this before line 479? |
||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
} | ||
return v, nil | ||
} | ||
|
@@ -633,29 +629,21 @@ func (t *Table) IterRecords(ctx context.Context, startKey kv.Key, cols []*table. | |
} | ||
data := make([]types.Datum, len(cols)) | ||
for _, col := range cols { | ||
if col.IsPKHandleColumn(t.Meta()) { | ||
data[col.Offset] = types.NewIntDatum(handle) | ||
if col.IsPKHandleColumn(t.meta) { | ||
if mysql.HasUnsignedFlag(col.Flag) { | ||
data[col.Offset].SetUint64(uint64(handle)) | ||
} else { | ||
data[col.Offset].SetInt64(handle) | ||
} | ||
continue | ||
} | ||
if _, ok := rowMap[col.ID]; ok { | ||
data[col.Offset] = rowMap[col.ID] | ||
continue | ||
} | ||
if col.OriginDefaultValue == nil && mysql.HasNotNullFlag(col.Flag) { | ||
return errors.New("Miss column") | ||
} | ||
if col.State != model.StatePublic { | ||
continue | ||
} | ||
if defaultVals[col.Offset].IsNull() { | ||
d, err := table.GetColOriginDefaultValue(ctx, col.ToInfo()) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
data[col.Offset] = d | ||
defaultVals[col.Offset] = d | ||
} else { | ||
data[col.Offset] = defaultVals[col.Offset] | ||
data[col.Offset], err = GetColDefaultValue(ctx, col, defaultVals) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
} | ||
more, err := fn(handle, data, cols) | ||
|
@@ -673,6 +661,27 @@ func (t *Table) IterRecords(ctx context.Context, startKey kv.Key, cols []*table. | |
return nil | ||
} | ||
|
||
func GetColDefaultValue(ctx context.Context, col *table.Column, defaultVals []types.Datum) ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can implement a GetAllColDefaultValues to return default values for every column at one time. Passing a slice every time is a little strange. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If implement a |
||
colVal types.Datum, err error) { | ||
if col.OriginDefaultValue == nil && mysql.HasNotNullFlag(col.Flag) { | ||
return colVal, errors.New("Miss column") | ||
} | ||
if col.State != model.StatePublic { | ||
return colVal, nil | ||
} | ||
if defaultVals[col.Offset].IsNull() { | ||
colVal, err = table.GetColOriginDefaultValue(ctx, col.ToInfo()) | ||
if err != nil { | ||
return colVal, errors.Trace(err) | ||
} | ||
defaultVals[col.Offset] = colVal | ||
} else { | ||
colVal = defaultVals[col.Offset] | ||
} | ||
|
||
return colVal, nil | ||
} | ||
|
||
// AllocAutoID implements table.Table AllocAutoID interface. | ||
func (t *Table) AllocAutoID() (int64, error) { | ||
return t.alloc.Alloc(t.ID) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.