diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-06-26 20:11:56 +0300 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2021-07-16 13:31:19 +0300 |
commit | c47e4aab62c65e1a1d431f9888ba1bc6b9841687 (patch) | |
tree | 6f50b28b85c00320651d9589ada644e996c48262 /mysql-test | |
parent | 6a89f346dea852b267994e6f32e1c163e7688b34 (diff) | |
download | mariadb-git-c47e4aab62c65e1a1d431f9888ba1bc6b9841687.tar.gz |
MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT
The columns that are part of DEFAULT expression were not read-marked
in statements like UPDATE...SET b=DEFAULT.
The problem is `F(DEFAULT)` expression depends of the left-hand side of an
assignment. However, setup_fields accepts only right-hand side value.
Neither Item::fix_fields does.
Suchwise, b=DEFAULT(b) works fine, because Item_default_field has
information on what field it is default of:
if (thd->mark_used_columns != MARK_COLUMNS_NONE)
def_field->default_value->expr->update_used_tables();
in Item_default_value::fix_fields().
It is not reasonable to pass a left-hand side to Item:fix_fields, because
the case is rare, so the rewrite
b= F(DEFAULT) -> b= F(DEFAULT(b))
is made instead.
Both UPDATE and multi-UPDATE are affected, however any form of INSERT
is not: it marks all the fields in DEFAULT expressions for read in
TABLE::mark_default_fields_for_write().
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/r/default.result | 4 | ||||
-rw-r--r-- | mysql-test/suite/gcol/inc/gcol_ins_upd.inc | 22 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result | 22 | ||||
-rw-r--r-- | mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result | 22 | ||||
-rw-r--r-- | mysql-test/t/default.test | 2 |
5 files changed, 69 insertions, 3 deletions
diff --git a/mysql-test/r/default.result b/mysql-test/r/default.result index 8335b553a8e..369734ae92a 100644 --- a/mysql-test/r/default.result +++ b/mysql-test/r/default.result @@ -3089,8 +3089,8 @@ DROP TABLE t1; # # Collations # -CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('ö')) CHARACTER SET koi8r COLLATE koi8r_bin; -ERROR 22007: Encountered illegal value 'ö' when converting to koi8r +CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('�')) CHARACTER SET koi8r COLLATE koi8r_bin; +ERROR 22007: Encountered illegal value '�' when converting to koi8r CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); SHOW CREATE TABLE t1; Table Create Table diff --git a/mysql-test/suite/gcol/inc/gcol_ins_upd.inc b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc index 4cfcf371fd7..e02a3828ea2 100644 --- a/mysql-test/suite/gcol/inc/gcol_ins_upd.inc +++ b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc @@ -660,3 +660,25 @@ INSERT IGNORE INTO t1 SELECT * FROM t1; DROP TABLE t1; } + +--echo # +--echo # MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT +--echo # + +CREATE TABLE t1 (a INT UNIQUE, b INT DEFAULT (c+1), c int); +INSERT INTO t1 VALUES (1,1,1); +UPDATE t1 SET b=DEFAULT; +SELECT * from t1; + +REPLACE t1 VALUES(1,1,1); +INSERT INTO t1 VALUES (1,1,1) ON DUPLICATE KEY UPDATE b= DEFAULT; +SELECT * from t1; + +REPLACE t1 VALUES(1,1,1); +CREATE TABLE t2 (a INT, b INT DEFAULT (c+1), c int); +INSERT INTO t2 VALUES (5,5,5); +UPDATE t1 join t2 set t1.b= DEFAULT, t2.b= DEFAULT; +SELECT * from t1, t2; + +DROP TABLE t1, t2; + diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result index 1d85fc837dc..143e1b725c4 100644 --- a/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result @@ -791,6 +791,28 @@ Warnings: Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored DROP TABLE t1; +# +# MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT +# +CREATE TABLE t1 (a INT UNIQUE, b INT DEFAULT (c+1), c int); +INSERT INTO t1 VALUES (1,1,1); +UPDATE t1 SET b=DEFAULT; +SELECT * from t1; +a b c +1 2 1 +REPLACE t1 VALUES(1,1,1); +INSERT INTO t1 VALUES (1,1,1) ON DUPLICATE KEY UPDATE b= DEFAULT; +SELECT * from t1; +a b c +1 2 1 +REPLACE t1 VALUES(1,1,1); +CREATE TABLE t2 (a INT, b INT DEFAULT (c+1), c int); +INSERT INTO t2 VALUES (5,5,5); +UPDATE t1 join t2 set t1.b= DEFAULT, t2.b= DEFAULT; +SELECT * from t1, t2; +a b c a b c +1 2 1 5 6 5 +DROP TABLE t1, t2; DROP VIEW IF EXISTS v1,v2; DROP TABLE IF EXISTS t1,t2,t3; DROP PROCEDURE IF EXISTS p1; diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result index e10b83cabf5..2c883b2de35 100644 --- a/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result +++ b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result @@ -713,6 +713,28 @@ Warnings: Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored Warning 1906 The value specified for generated column 'v' in table 't1' has been ignored DROP TABLE t1; +# +# MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT +# +CREATE TABLE t1 (a INT UNIQUE, b INT DEFAULT (c+1), c int); +INSERT INTO t1 VALUES (1,1,1); +UPDATE t1 SET b=DEFAULT; +SELECT * from t1; +a b c +1 2 1 +REPLACE t1 VALUES(1,1,1); +INSERT INTO t1 VALUES (1,1,1) ON DUPLICATE KEY UPDATE b= DEFAULT; +SELECT * from t1; +a b c +1 2 1 +REPLACE t1 VALUES(1,1,1); +CREATE TABLE t2 (a INT, b INT DEFAULT (c+1), c int); +INSERT INTO t2 VALUES (5,5,5); +UPDATE t1 join t2 set t1.b= DEFAULT, t2.b= DEFAULT; +SELECT * from t1, t2; +a b c a b c +1 2 1 5 6 5 +DROP TABLE t1, t2; DROP VIEW IF EXISTS v1,v2; DROP TABLE IF EXISTS t1,t2,t3; DROP PROCEDURE IF EXISTS p1; diff --git a/mysql-test/t/default.test b/mysql-test/t/default.test index 31cf589c487..aec518d94a6 100644 --- a/mysql-test/t/default.test +++ b/mysql-test/t/default.test @@ -1855,7 +1855,7 @@ DROP TABLE t1; --echo # --error ER_BAD_DATA -CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('ö')) CHARACTER SET koi8r COLLATE koi8r_bin; +CREATE TABLE t1 (a VARCHAR(20) CHARACTER SET latin1 DEFAULT CONCAT('�')) CHARACTER SET koi8r COLLATE koi8r_bin; CREATE OR REPLACE TABLE t1 (a char(2) default concat('A') COLLATE utf8mb4_unicode_ci); SHOW CREATE TABLE t1; DROP TABLE t1; |