diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2022-04-18 12:44:27 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2022-04-18 12:44:27 +0300 |
commit | 08c7ab404f69d9c4ca6ca7a9cf7eec74c804f917 (patch) | |
tree | 6e2009151bc6fb68dd4ebb1632f5d7fd09e5a919 /mysql-test/suite/vcol | |
parent | c02ebf3510850ba78a106be9974c94c3b97d8585 (diff) | |
download | mariadb-git-08c7ab404f69d9c4ca6ca7a9cf7eec74c804f917.tar.gz |
MDEV-24176 Server crashes after insert in the table with virtual
column generated using date_format() and if()
vcol_info->expr is allocated on expr_arena at parsing stage. Since
expr item is allocated on expr_arena all its containee items must be
allocated on expr_arena too. Otherwise fix_session_expr() will
encounter prematurely freed item.
When table is reopened from cache vcol_info contains stale
expression. We refresh expression via TABLE::vcol_fix_exprs() but
first we must prepare a proper context (Vcol_expr_context) which meets
some requirements:
1. As noted above expr update must be done on expr_arena as there may
be new items created. It was a bug in fix_session_expr_for_read() and
was just not reproduced because of no second refix. Now refix is done
for more cases so it does reproduce. Tests affected: vcol.binlog
2. Also name resolution context must be narrowed to the single table.
Tested by: vcol.update main.default vcol.vcol_syntax gcol.gcol_bugfixes
3. sql_mode must be clean and not fail expr update.
sql_mode such as MODE_NO_BACKSLASH_ESCAPES, MODE_NO_ZERO_IN_DATE, etc
must not affect vcol expression update. If the table was created
successfully any further evaluation must not fail. Tests affected:
main.func_like
Reviewed by: Sergei Golubchik <serg@mariadb.org>
Diffstat (limited to 'mysql-test/suite/vcol')
-rw-r--r-- | mysql-test/suite/vcol/r/vcol_syntax.result | 93 | ||||
-rw-r--r-- | mysql-test/suite/vcol/t/vcol_syntax.test | 83 |
2 files changed, 174 insertions, 2 deletions
diff --git a/mysql-test/suite/vcol/r/vcol_syntax.result b/mysql-test/suite/vcol/r/vcol_syntax.result index 0063f38ea36..5e7ebcda287 100644 --- a/mysql-test/suite/vcol/r/vcol_syntax.result +++ b/mysql-test/suite/vcol/r/vcol_syntax.result @@ -94,6 +94,97 @@ create table t1 (a int, v_a int generated always as (a)); update t1 as x set a = 1; alter table t1 force; drop table t1; +create table t1 ( +id int not null auto_increment primary key, +order_date_time datetime not null, +order_date date generated always as (convert(order_date_time, date)), +language_id binary(16) null +); +update t1 as tx set order_date= null; +alter table t1 modify column language_id binary(16) not null; +drop table t1; # -# End of 10.2 tests +# MDEV-24176 Server crashes after insert in the table with virtual column generated using date_format() and if() # +create table t1 (d1 date not null, d2 date not null, +gd text as (concat(d1,if(d1 <> d2, date_format(d2, 'to %y-%m-%d '), ''))) ); +insert into t1(d1,d2) values +('2020-09-01','2020-09-01'),('2020-05-01','2020-09-01'); +select * from t1; +d1 d2 gd +2020-09-01 2020-09-01 2020-09-01 +2020-05-01 2020-09-01 2020-05-01to 20-09-01 +drop table t1; +# MDEV-25772 (duplicate) and LOCK TABLES case +create table t1 (d1 datetime , v_d1 tinyint(1) as (d1 < curdate())); +insert into t1 (d1) values ('2021-09-11 08:38:23'), ('2021-09-01 08:38:23'); +lock tables t1 write; +select * from t1 where v_d1=1; +d1 v_d1 +2021-09-11 08:38:23 1 +2021-09-01 08:38:23 1 +select * from t1; +d1 v_d1 +2021-09-11 08:38:23 1 +2021-09-01 08:38:23 1 +unlock tables; +drop table t1; +# MDEV-26432 (duplicate) +create table t1 (v2 int, v1 int as ((user() like 'x'))) ; +select 1 from t1 where v1=1 ; +1 +select * from t1; +v2 v1 +drop table t1; +create table t1 (v2 int as ( user () like 'x')); +select 1 from t1 order by v2 ; +1 +alter table t1 add i int; +drop table t1; +# MDEV-26437 (duplicate) +create table v0 (v2 int not null, +v1 bigint as (case 'x' when current_user() then v2 end)); +select v2 as v3 from v0 where v1 like 'x' escape 'x'; +v3 +insert into v0 (v2) values (-128); +drop table v0; +create table t1 (vi int as (case 'x' when current_user() then 1 end)); +select 1 from t1 where vi=1; +1 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `vi` int(11) GENERATED ALWAYS AS (case 'x' when current_user() then 1 end) VIRTUAL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (vi int as (case 'x' when current_user() then 1 end)); +select 1 from t1 where vi=1; +1 +select 1 from t1 where vi=1; +1 +drop table t1; +# MDEV-28092 (duplicate) +create table t1 (b timestamp, a int as (1 in (dayofmonth (b between 'x' and current_user) = b))); +insert into t1(b) values ('2022-03-17 14:55:37'); +select 1 from t1 x natural join t1; +1 +1 +Warnings: +Warning 1292 Incorrect datetime value: 'x' +Warning 1292 Incorrect datetime value: 'root@localhost' +Warning 1292 Incorrect datetime value: 'x' +Warning 1292 Incorrect datetime value: 'root@localhost' +drop table t1; +# MDEV-28089 (duplicate) +create table t1 (a int , b date as (1 in ('x' ,(database () = 'x' is null) ))) ; +select b from t1; +b +select a from t1 order by 'x' = b; +a +drop table t1; +create table t1 (a int , b date as (1 in ('x' ,(database ()) ))) ; +select b from t1; +b +select a from t1 order by 'x' = b; +a +drop table t1; diff --git a/mysql-test/suite/vcol/t/vcol_syntax.test b/mysql-test/suite/vcol/t/vcol_syntax.test index 3c8a50a7f36..198d61a13aa 100644 --- a/mysql-test/suite/vcol/t/vcol_syntax.test +++ b/mysql-test/suite/vcol/t/vcol_syntax.test @@ -77,7 +77,88 @@ update t1 as x set a = 1; alter table t1 force; drop table t1; +create table t1 ( + id int not null auto_increment primary key, + order_date_time datetime not null, + order_date date generated always as (convert(order_date_time, date)), + language_id binary(16) null +); + +update t1 as tx set order_date= null; +alter table t1 modify column language_id binary(16) not null; +# Cleanup +drop table t1; --echo # ---echo # End of 10.2 tests +--echo # MDEV-24176 Server crashes after insert in the table with virtual column generated using date_format() and if() --echo # +create table t1 (d1 date not null, d2 date not null, + gd text as (concat(d1,if(d1 <> d2, date_format(d2, 'to %y-%m-%d '), ''))) ); + +insert into t1(d1,d2) values + ('2020-09-01','2020-09-01'),('2020-05-01','2020-09-01'); +select * from t1; + +drop table t1; + +--echo # MDEV-25772 (duplicate) and LOCK TABLES case +create table t1 (d1 datetime , v_d1 tinyint(1) as (d1 < curdate())); +insert into t1 (d1) values ('2021-09-11 08:38:23'), ('2021-09-01 08:38:23'); + +lock tables t1 write; +select * from t1 where v_d1=1; +select * from t1; +unlock tables; + +drop table t1; + +--echo # MDEV-26432 (duplicate) +create table t1 (v2 int, v1 int as ((user() like 'x'))) ; +select 1 from t1 where v1=1 ; +select * from t1; + +drop table t1; + +create table t1 (v2 int as ( user () like 'x')); +select 1 from t1 order by v2 ; +alter table t1 add i int; +drop table t1; + +--echo # MDEV-26437 (duplicate) +create table v0 (v2 int not null, + v1 bigint as (case 'x' when current_user() then v2 end)); + +select v2 as v3 from v0 where v1 like 'x' escape 'x'; +insert into v0 (v2) values (-128); + +drop table v0; + +create table t1 (vi int as (case 'x' when current_user() then 1 end)); +select 1 from t1 where vi=1; +show create table t1; + +drop table t1; + +create table t1 (vi int as (case 'x' when current_user() then 1 end)); +select 1 from t1 where vi=1; +select 1 from t1 where vi=1; + +drop table t1; + +--echo # MDEV-28092 (duplicate) +create table t1 (b timestamp, a int as (1 in (dayofmonth (b between 'x' and current_user) = b))); +insert into t1(b) values ('2022-03-17 14:55:37'); + +select 1 from t1 x natural join t1; +drop table t1; + +--echo # MDEV-28089 (duplicate) +create table t1 (a int , b date as (1 in ('x' ,(database () = 'x' is null) ))) ; +select b from t1; +select a from t1 order by 'x' = b; +drop table t1; + +create table t1 (a int , b date as (1 in ('x' ,(database ()) ))) ; +select b from t1; +select a from t1 order by 'x' = b; +drop table t1; |