Skip to content

Commit fa40bca

Browse files
authored
core: fix missing update on nested generated column (#55829) (#55853)
close #53967
1 parent ac1493d commit fa40bca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/planner/core/integration_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2809,3 +2809,20 @@ func TestIssue48257(t *testing.T) {
28092809
"└─TableFullScan 1.00 cop[tikv] table:t1 keep order:false",
28102810
))
28112811
}
2812+
2813+
func TestNestedVirtualGeneratedColumnUpdate(t *testing.T) {
2814+
store := testkit.CreateMockStore(t)
2815+
tk := testkit.NewTestKit(t, store)
2816+
tk.MustExec("use test")
2817+
2818+
tk.MustExec("CREATE TABLE test1 (\ncol1 bigint(20) NOT NULL ,\ncol2 varchar(36) NOT NULL ,\ncol3 int(11) DEFAULT NULL ,\ncol4 varchar(36) NOT NULL ,\ncol5 varchar(255) DEFAULT NULL ,\nmodify_time bigint(20) DEFAULT NULL,\ncreate_time bigint(20) DEFAULT NULL,\ncol6 json DEFAULT NULL ,\n" +
2819+
"col7 json DEFAULT NULL ," +
2820+
"col8 json GENERATED ALWAYS AS (json_merge_patch(ifnull(col6, _utf8mb4\"{}\"), ifnull(col7, _utf8mb4\"{}\"))) STORED," +
2821+
"col9 varchar(36) GENERATED ALWAYS AS (left(json_unquote(json_extract(col8, _utf8mb4\"$.col9[0]\")), 36)) VIRTUAL," +
2822+
"col10 varchar(30) GENERATED ALWAYS AS (left(json_unquote(json_extract(col8, _utf8mb4\"$.col10\")), 30)) VIRTUAL," +
2823+
"KEY dev_idx1 (col10)) " +
2824+
"ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;")
2825+
tk.MustExec("INSERT INTO test1 VALUES (-100000000, \"123459789332\", 1, \"123459789332\", \"BBBBB\", 1675871896, 1675871896, '{\"col10\": \"CCCCC\",\"col9\": [\"ABCDEFG\"]}', NULL, DEFAULT, DEFAULT, DEFAULT);\n")
2826+
tk.MustExec("UPDATE test1 SET col7 = '{\"col10\":\"DDDDD\",\"col9\":[\"abcdefg\"]}';\n")
2827+
tk.MustExec("DELETE FROM test1 WHERE col1 < 0;\n")
2828+
}

pkg/planner/core/logical_plan_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6430,6 +6430,9 @@ func (b *PlanBuilder) buildUpdateLists(ctx context.Context, tableList []*ast.Tab
64306430
break
64316431
}
64326432
}
6433+
if isModified {
6434+
dependentColumnsModified[col.UniqueID] = true
6435+
}
64336436
// skip unmodified generated columns
64346437
if !isModified {
64356438
continue

0 commit comments

Comments
 (0)