Skip to content

Commit 7333f16

Browse files
author
Sreeharsha Ramanavarapu
committed
Bug #26838771: GCOL: INCORRECT BEHAVIOR WITH UPDATE ON FLY
Issue: ------ When an UPDATE statement is using update on the fly optimization, generated column related checks are skipped. Solution: --------- On 5.7: Call validate_gc_assignment at an earlier place in Query_result_update::initialize_tables. On 8.0 and trunk: Move the call to validate_gc_assignment Sql_cmd_update::prepare_inner(). This way no separate handling is required for single and multi-table UPDATE.
1 parent 9a0c517 commit 7333f16

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

mysql-test/suite/gcol/r/gcol_update.result

+19
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,22 @@ set global innodb_purge_run_now=1;
3131
set global innodb_fast_shutdown=0;
3232
# restart
3333
drop table t1;
34+
#
35+
# Bug #26838771: GCOL: INCORRECT BEHAVIOR WITH UPDATE ON FLY
36+
#
37+
CREATE TABLE t1(c1 INT);
38+
CREATE TABLE t2(c1 INT, c2 JSON, c3 varchar(15) GENERATED ALWAYS AS
39+
(concat(c2,_utf8mb4'x')) VIRTUAL);
40+
CREATE TABLE t3(c1 JSON, c2 INT GENERATED ALWAYS AS ((c1 + 1)) VIRTUAL);
41+
INSERT INTO t2(c1,c2) VALUES(1, '{"tr": "x"}'), (2, '{"tr": "x"}');
42+
INSERT INTO t3(c1) VALUES(CAST(7 AS JSON));
43+
UPDATE t3 SET c2 = 0;
44+
ERROR HY000: The value specified for generated column 'c2' in table 't3' is not allowed.
45+
UPDATE t3 JOIN t2 ON (t3.c1 = t2.c1) SET t3.c2 = 0;
46+
ERROR HY000: The value specified for generated column 'c2' in table 't3' is not allowed.
47+
UPDATE t1 RIGHT JOIN
48+
t2 ON (t1.c1 = t2.c1),
49+
t3
50+
SET t2.c2 = 'tr', t3.c2 = 0;
51+
ERROR HY000: The value specified for generated column 'c2' in table 't3' is not allowed.
52+
DROP TABLE t1,t2,t3;

mysql-test/suite/gcol/t/gcol_update.test

+27
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,30 @@ set global innodb_purge_run_now=1;
5454
set global innodb_fast_shutdown=0;
5555
--source include/restart_mysqld.inc
5656
drop table t1;
57+
58+
--echo #
59+
--echo # Bug #26838771: GCOL: INCORRECT BEHAVIOR WITH UPDATE ON FLY
60+
--echo #
61+
62+
CREATE TABLE t1(c1 INT);
63+
CREATE TABLE t2(c1 INT, c2 JSON, c3 varchar(15) GENERATED ALWAYS AS
64+
(concat(c2,_utf8mb4'x')) VIRTUAL);
65+
CREATE TABLE t3(c1 JSON, c2 INT GENERATED ALWAYS AS ((c1 + 1)) VIRTUAL);
66+
67+
INSERT INTO t2(c1,c2) VALUES(1, '{"tr": "x"}'), (2, '{"tr": "x"}');
68+
INSERT INTO t3(c1) VALUES(CAST(7 AS JSON));
69+
70+
71+
--error ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
72+
UPDATE t3 SET c2 = 0;
73+
74+
--error ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
75+
UPDATE t3 JOIN t2 ON (t3.c1 = t2.c1) SET t3.c2 = 0;
76+
77+
--error ER_NON_DEFAULT_VALUE_FOR_GENERATED_COLUMN
78+
UPDATE t1 RIGHT JOIN
79+
t2 ON (t1.c1 = t2.c1),
80+
t3
81+
SET t2.c2 = 'tr', t3.c2 = 0;
82+
83+
DROP TABLE t1,t2,t3;

sql/sql_update.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,9 @@ bool Query_result_update::initialize_tables(JOIN *join)
20212021
List<Item> temp_fields;
20222022
ORDER group;
20232023
Temp_table_param *tmp_param;
2024+
if (table->vfield &&
2025+
validate_gc_assignment(thd, fields, values, table))
2026+
DBUG_RETURN(0);
20242027

20252028
if (thd->lex->is_ignore())
20262029
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
@@ -2080,15 +2083,11 @@ bool Query_result_update::initialize_tables(JOIN *join)
20802083
if (safe_update_on_fly(thd, join->best_ref[0], table_ref, all_tables))
20812084
{
20822085
table->mark_columns_needed_for_update(true/*mark_binlog_columns=true*/);
2083-
table_to_update= table; // Update table on the fly
2086+
table_to_update= table; // Update table on the fly
20842087
continue;
20852088
}
20862089
}
20872090
table->mark_columns_needed_for_update(true/*mark_binlog_columns=true*/);
2088-
2089-
if (table->vfield &&
2090-
validate_gc_assignment(thd, fields, values, table))
2091-
DBUG_RETURN(0);
20922091
/*
20932092
enable uncacheable flag if we update a view with check option
20942093
and check option has a subselect, otherwise, the check option

0 commit comments

Comments
 (0)