Skip to content

Commit

Permalink
planner, expression: fix a bug causes schema change after DML (#21027) (
Browse files Browse the repository at this point in the history
#21050)

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
ti-srebot committed Nov 17, 2020
1 parent a1bdbef commit 1e4def5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion expression/expression.go
Expand Up @@ -779,7 +779,7 @@ func ColumnInfos2ColumnsAndNames(ctx sessionctx.Context, dbName, tblName model.C
ColName: col.Name,
})
newCol := &Column{
RetType: &col.FieldType,
RetType: col.FieldType.Clone(),
ID: col.ID,
UniqueID: ctx.GetSessionVars().AllocPlanColumnID(),
Index: col.Offset,
Expand Down
14 changes: 14 additions & 0 deletions expression/integration_test.go
Expand Up @@ -6777,6 +6777,20 @@ func (s *testIntegrationSerialSuite) TestIssue17989(c *C) {
tk.MustExec("admin check table t")
}

func (s *testIntegrationSuite2) TestSchemaDMLNotChange(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk2 := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk2.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int primary key, c_json json);")
tk.MustExec("insert into t values (1, '{\"k\": 1}');")
tk.MustExec("begin")
tk.MustExec("update t set c_json = '{\"k\": 2}' where id = 1;")
tk2.MustExec("alter table t rename column c_json to cc_json;")
tk.MustExec("commit")
}

func (s *testIntegrationSerialSuite) TestIssue18702(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Expand Up @@ -2948,7 +2948,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
newCol := &expression.Column{
UniqueID: sessionVars.AllocPlanColumnID(),
ID: col.ID,
RetType: &col.FieldType,
RetType: col.FieldType.Clone(),
OrigName: names[i].String(),
IsHidden: col.Hidden,
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/point_get_plan.go
Expand Up @@ -1172,7 +1172,7 @@ func findCol(tbl *model.TableInfo, colName *ast.ColumnName) *model.ColumnInfo {

func colInfoToColumn(col *model.ColumnInfo, idx int) *expression.Column {
return &expression.Column{
RetType: &col.FieldType,
RetType: col.FieldType.Clone(),
ID: col.ID,
UniqueID: int64(col.Offset),
Index: idx,
Expand Down

0 comments on commit 1e4def5

Please sign in to comment.