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

planner, expression: fix a bug causes schema change after DML (#21027) #21050

Merged
merged 3 commits into from Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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