44 changed files with 1825 additions and 23 deletions
			
			
		- 
					1libmysqld/CMakeLists.txt
 - 
					1mysql-test/main/ssl-big.test
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYD
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYI
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_stored.frm
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI
 - 
					BINmysql-test/std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm
 - 
					2mysql-test/suite/binlog/t/flashback-largebinlog.test
 - 
					6mysql-test/suite/gcol/r/innodb_virtual_basic.result
 - 
					2mysql-test/suite/gcol/r/innodb_virtual_index.result
 - 
					6mysql-test/suite/gcol/t/innodb_virtual_basic.test
 - 
					2mysql-test/suite/gcol/t/innodb_virtual_index.test
 - 
					1mysql-test/suite/innodb_fts/t/fulltext_table_evict.test
 - 
					2mysql-test/suite/innodb_gis/t/update_root.test
 - 
					2mysql-test/suite/vcol/inc/vcol_trigger_sp.inc
 - 
					4mysql-test/suite/vcol/r/update.result
 - 
					8mysql-test/suite/vcol/r/update_binlog.result
 - 
					438mysql-test/suite/vcol/r/vcol_sql_mode.result
 - 
					336mysql-test/suite/vcol/r/vcol_sql_mode_upgrade.result
 - 
					2mysql-test/suite/vcol/r/vcol_trigger_sp_innodb.result
 - 
					2mysql-test/suite/vcol/r/vcol_trigger_sp_myisam.result
 - 
					2mysql-test/suite/vcol/t/update.test
 - 
					322mysql-test/suite/vcol/t/vcol_sql_mode.test
 - 
					193mysql-test/suite/vcol/t/vcol_sql_mode_upgrade.test
 - 
					2sql/CMakeLists.txt
 - 
					70sql/field.cc
 - 
					17sql/field.h
 - 
					35sql/item.h
 - 
					40sql/item_cmpfunc.cc
 - 
					2sql/item_cmpfunc.h
 - 
					16sql/item_func.cc
 - 
					5sql/item_func.h
 - 
					67sql/item_strfunc.cc
 - 
					6sql/item_strfunc.h
 - 
					1sql/mysqld.h
 - 
					1sql/set_var.h
 - 
					3sql/sql_insert.cc
 - 
					34sql/sql_mode.cc
 - 
					162sql/sql_mode.h
 - 
					5sql/sql_string.h
 - 
					8sql/sys_vars.cc
 - 
					26sql/table.cc
 - 
					16sql/table.h
 
@ -0,0 +1,438 @@ | 
				
			|||
# | 
				
			|||
# Start of 10.2 tests | 
				
			|||
# | 
				
			|||
# | 
				
			|||
# MDEV-18156 Assertion `0' failed or `btr_validate_index(index, 0, false)' in row_upd_sec_index_entry or error code 126: Index is corrupted upon DELETE with PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# | 
				
			|||
# | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + various virtual column data types | 
				
			|||
# | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v CHAR(5) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` char(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TIME AS (a) VIRTUAL, KEY(v)); | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (c CHAR(8), v BINARY(8) AS (c), KEY(v)); | 
				
			|||
ERROR HY000: Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v BIT(64) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (a) VIRTUAL, KEY(v(100))); | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + TRIM resolving dependency | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RTRIM(a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (RTRIM(a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` text GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`(100)) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (trim(trailing ' ' from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(TRAILING ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` text GENERATED ALWAYS AS (trim(trailing ' ' from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`(100)) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (trim(both ' ' from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(BOTH ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` text GENERATED ALWAYS AS (trim(both ' ' from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`(100)) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING NULL FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (trim(trailing NULL from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH NULL FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (trim(both NULL from `a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + TRIM not resolving dependency | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(LEADING ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(leading ' ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(leading ' ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(LEADING ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
ERROR HY000: Function or expression 'trim(leading ' ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(leading ' ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING '' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(trailing '' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(trailing '' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH '' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(both '' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(both '' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING 'x' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(trailing 'x' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(trailing 'x' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH 'x' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(both 'x' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(both 'x' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a CHAR(5), | 
				
			|||
v VARCHAR(5) AS (TRIM(TRAILING '  ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(trailing '  ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(trailing '  ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a CHAR(5), | 
				
			|||
v VARCHAR(5) AS (TRIM(BOTH '  ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'trim(both '  ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(both '  ' from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + TRIM(... non_constant FROM a) | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a CHAR(5), | 
				
			|||
b CHAR(5), | 
				
			|||
v TEXT AS (TRIM(TRAILING b FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
ERROR HY000: Function or expression 'trim(trailing `b` from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'trim(trailing `b` from `a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + RPAD resolving dependency | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,5,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rpad(`a`,5,' ')) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,6,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rpad(`a`,6,' ')) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,6,NULL)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rpad(`a`,6,NULL)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,NULL,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rpad(`a`,NULL,' ')) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + RPAD not resolving dependency | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,4,' ')) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'rpad(`a`,4,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'rpad(`a`,4,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a CHAR(5), | 
				
			|||
b CHAR(5), | 
				
			|||
v VARCHAR(5) AS (RPAD(a,NULL,b)) VIRTUAL, | 
				
			|||
KEY(v) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression 'rpad(`a`,NULL,`b`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'rpad(`a`,NULL,`b`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + comparison | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a='a') VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` int(11) GENERATED ALWAYS AS (`a` = 'a') VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a CHAR(5) CHARACTER SET latin1 COLLATE latin1_nopad_bin, | 
				
			|||
v INT AS (a='a') VIRTUAL, KEY(v) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression '`a` = 'a'' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a` = 'a'' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + LIKE | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE 'a%') VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` int(11) GENERATED ALWAYS AS (`a` like 'a%') VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE NULL) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` int(11) GENERATED ALWAYS AS (`a` like NULL) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE 'a') VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression '`a` like 'a'' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a` like 'a'' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# PAD_CHAR_TO_FULL_LENGTH + LENGTH(char_column) = hard dependency | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (LENGTH(a)) VIRTUAL, KEY(v)); | 
				
			|||
ERROR HY000: Function or expression 'octet_length(`a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'octet_length(`a`)' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# | 
				
			|||
# Testing NO_UNSIGNED_SUBTRACTION | 
				
			|||
# | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c INT GENERATED ALWAYS AS (a-b) VIRTUAL, | 
				
			|||
KEY (c) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression '`a` - `b`' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a` - `b`' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value NO_UNSIGNED_SUBTRACTION | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c INT GENERATED ALWAYS AS (CAST(a AS SIGNED)-b) VIRTUAL, | 
				
			|||
KEY (c) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression 'cast(`a` as signed) - `b`' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'cast(`a` as signed) - `b`' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value NO_UNSIGNED_SUBTRACTION | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c INT GENERATED ALWAYS AS (a-CAST(b AS SIGNED)) VIRTUAL, | 
				
			|||
KEY (c) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression '`a` - cast(`b` as signed)' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a` - cast(`b` as signed)' cannot be used in the GENERATED ALWAYS AS clause of `c` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value NO_UNSIGNED_SUBTRACTION | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c INT GENERATED ALWAYS AS (CAST(a AS SIGNED)-CAST(b AS SIGNED)) VIRTUAL, | 
				
			|||
KEY (c) | 
				
			|||
); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` int(10) unsigned DEFAULT NULL, | 
				
			|||
  `b` int(10) unsigned DEFAULT NULL, | 
				
			|||
  `c` int(11) GENERATED ALWAYS AS (cast(`a` as signed) - cast(`b` as signed)) VIRTUAL, | 
				
			|||
  KEY `c` (`c`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c INT GENERATED ALWAYS AS (CAST(a AS DECIMAL(20,0))-CAST(b AS DECIMAL(20,0))) VIRTUAL, | 
				
			|||
KEY (c) | 
				
			|||
); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` int(10) unsigned DEFAULT NULL, | 
				
			|||
  `b` int(10) unsigned DEFAULT NULL, | 
				
			|||
  `c` int(11) GENERATED ALWAYS AS (cast(`a` as decimal(20,0)) - cast(`b` as decimal(20,0))) VIRTUAL, | 
				
			|||
  KEY `c` (`c`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Comnination: PAD_CHAR_TO_FULL_LENGTH + NO_UNSIGNED_SUBTRACTION | 
				
			|||
# | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c CHAR(5), | 
				
			|||
v VARCHAR(5) GENERATED ALWAYS AS (RPAD(c,a-b,' ')) VIRTUAL, | 
				
			|||
KEY (v) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression 'rpad(`c`,`a` - `b`,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'rpad(`c`,`a` - `b`,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value NO_UNSIGNED_SUBTRACTION | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c CHAR(5), | 
				
			|||
v VARCHAR(5) GENERATED ALWAYS AS (RPAD(c,CAST(a AS DECIMAL(20,1))-b,' ')) VIRTUAL, | 
				
			|||
KEY (v) | 
				
			|||
); | 
				
			|||
ERROR HY000: Function or expression 'rpad(`c`,cast(`a` as decimal(20,1)) - `b`,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression 'rpad(`c`,cast(`a` as decimal(20,1)) - `b`,' ')' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# ALTER TABLE ADD KEY(vcol_depending_on_sql_mode) --> error | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
a INT UNSIGNED, | 
				
			|||
b INT UNSIGNED, | 
				
			|||
c CHAR(5), | 
				
			|||
v VARCHAR(5) GENERATED ALWAYS AS (c) VIRTUAL | 
				
			|||
); | 
				
			|||
ALTER TABLE t1 ADD KEY(v); | 
				
			|||
ERROR HY000: Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Warning	1901	Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
Error	1901	Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE INDEX v ON t1 (v); | 
				
			|||
ERROR HY000: Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Warning	1901	Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
Error	1901	Function or expression '`c`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
DROP TABLE t1; | 
				
			|||
# A virtual column on the second position in an index - cannot depend on sql_mode | 
				
			|||
CREATE TABLE t1 (id int, a CHAR(5), v TEXT AS (a) VIRTUAL, KEY(id, v(100))); | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
# A persisten virtual column cannot depend on sql_mode | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (a) PERSISTENT); | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW WARNINGS; | 
				
			|||
Level	Code	Message | 
				
			|||
Error	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RTRIM(a)) PERSISTENT); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rtrim(`a`)) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# End of 10.2 tests | 
				
			|||
# | 
				
			|||
@ -0,0 +1,336 @@ | 
				
			|||
call mtr.add_suppression("Table rebuild required"); | 
				
			|||
# | 
				
			|||
# Opening a Maria-10.2.26 table with a stored VARCHAR column | 
				
			|||
# | 
				
			|||
# Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
FLUSH TABLES; | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 ADD b INT DEFAULT a; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
FLUSH TABLES; | 
				
			|||
ALTER TABLE t1 ADD c INT DEFAULT a; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Fixing a Maria-10.2.26 table with a stored VARCHAR column | 
				
			|||
# | 
				
			|||
# Fixing by dropping the generated stored column | 
				
			|||
# Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
ALTER TABLE t1 DROP v; | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a | 
				
			|||
1 | 
				
			|||
2 | 
				
			|||
3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# Fixing by altering the generation expression of the stored column | 
				
			|||
# Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 MODIFY v VARCHAR(5) AS (RTRIM(a)) PERSISTENT; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rtrim(`a`)) STORED | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Opening a Maria-10.2.26 table with a virtual VARCHAR column | 
				
			|||
# | 
				
			|||
# Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
FLUSH TABLES; | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 ADD b INT DEFAULT a; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
FLUSH TABLES; | 
				
			|||
ALTER TABLE t1 ADD c INT DEFAULT a; | 
				
			|||
ERROR HY000: Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Fixing a Maria-10.2.26 table with a virtual VARCHAR column | 
				
			|||
# | 
				
			|||
# Fixing by dropping the virtual column | 
				
			|||
# Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 DROP v; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a | 
				
			|||
1 | 
				
			|||
2 | 
				
			|||
3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# Fixing by dropping a key on a virtual column, using ALTER TABLE | 
				
			|||
# Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 DROP KEY v; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# Fixing by dropping a key on a virtual column, using DROP INDEX | 
				
			|||
# Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
DROP INDEX v ON t1; | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
DROP TABLE t1; | 
				
			|||
# Fixing by altering the generation expression of a virtual column | 
				
			|||
# Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (`a`) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
Warnings: | 
				
			|||
Warning	1901	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
Warning	1105	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
ALTER TABLE t1 MODIFY v VARCHAR(5) AS(RTRIM(a)) VIRTUAL; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
Table	Create Table | 
				
			|||
t1	CREATE TABLE `t1` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
SELECT * FROM t1; | 
				
			|||
a	v | 
				
			|||
1	1 | 
				
			|||
2	2 | 
				
			|||
3	3 | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
SHOW CREATE TABLE t2; | 
				
			|||
Table	Create Table | 
				
			|||
t2	CREATE TABLE `t2` ( | 
				
			|||
  `a` char(5) DEFAULT NULL, | 
				
			|||
  `v` varchar(5) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL, | 
				
			|||
  KEY `v` (`v`) | 
				
			|||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 | 
				
			|||
DROP TABLE t2; | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Upgrading a Maria-10.2.26 table with a stored column | 
				
			|||
# | 
				
			|||
# Copying maria100226_char_to_varchar.* to MYSQLD_DATADIR | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
Table	Op	Msg_type	Msg_text | 
				
			|||
test.t1	check	Warning	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
test.t1	check	Warning	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
test.t1	check	status	OK | 
				
			|||
FLUSH TABLES; | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
Table	Op	Msg_type	Msg_text | 
				
			|||
test.t1	check	Warning	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
test.t1	check	Warning	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
test.t1	check	status	OK | 
				
			|||
DROP TABLE t1; | 
				
			|||
# | 
				
			|||
# Upgrading a Maria-10.2.26 table with a virtual column | 
				
			|||
# | 
				
			|||
# Copying maria100226_char_to_varchar.* to MYSQLD_DATADIR | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
Table	Op	Msg_type	Msg_text | 
				
			|||
test.t1	check	Warning	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
test.t1	check	Warning	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
test.t1	check	status	OK | 
				
			|||
FLUSH TABLES; | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
Table	Op	Msg_type	Msg_text | 
				
			|||
test.t1	check	Warning	Function or expression '`a`' cannot be used in the GENERATED ALWAYS AS clause of `v` | 
				
			|||
test.t1	check	Warning	Expression depends on the @@sql_mode value PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
test.t1	check	status	OK | 
				
			|||
DROP TABLE t1; | 
				
			|||
@ -0,0 +1,322 @@ | 
				
			|||
--echo # | 
				
			|||
--echo # Start of 10.2 tests | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # MDEV-18156 Assertion `0' failed or `btr_validate_index(index, 0, false)' in row_upd_sec_index_entry or error code 126: Index is corrupted upon DELETE with PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + various virtual column data types | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v CHAR(5) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TIME AS (a) VIRTUAL, KEY(v)); | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (c CHAR(8), v BINARY(8) AS (c), KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v BIT(64) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (a) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (a) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + TRIM resolving dependency | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RTRIM(a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (RTRIM(a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(TRAILING ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(BOTH ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING NULL FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH NULL FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + TRIM not resolving dependency | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(LEADING ' ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v TEXT AS (TRIM(LEADING ' ' FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING '' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH '' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(TRAILING 'x' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (TRIM(BOTH 'x' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
# more than one space | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a CHAR(5), | 
				
			|||
  v VARCHAR(5) AS (TRIM(TRAILING '  ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
# more than one space | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a CHAR(5), | 
				
			|||
  v VARCHAR(5) AS (TRIM(BOTH '  ' FROM a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + TRIM(... non_constant FROM a) | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a CHAR(5), | 
				
			|||
  b CHAR(5), | 
				
			|||
  v TEXT AS (TRIM(TRAILING b FROM a)) VIRTUAL, KEY(v(100))); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + RPAD resolving dependency | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,5,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,6,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,6,NULL)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,NULL,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + RPAD not resolving dependency | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RPAD(a,4,' ')) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a CHAR(5), | 
				
			|||
  b CHAR(5), | 
				
			|||
  v VARCHAR(5) AS (RPAD(a,NULL,b)) VIRTUAL, | 
				
			|||
  KEY(v) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + comparison | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a='a') VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
   a CHAR(5) CHARACTER SET latin1 COLLATE latin1_nopad_bin, | 
				
			|||
   v INT AS (a='a') VIRTUAL, KEY(v) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + LIKE | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE 'a%') VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE NULL) VIRTUAL, KEY(v)); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (a LIKE 'a') VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # PAD_CHAR_TO_FULL_LENGTH + LENGTH(char_column) = hard dependency | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v INT AS (LENGTH(a)) VIRTUAL, KEY(v)); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Testing NO_UNSIGNED_SUBTRACTION | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c INT GENERATED ALWAYS AS (a-b) VIRTUAL, | 
				
			|||
  KEY (c) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c INT GENERATED ALWAYS AS (CAST(a AS SIGNED)-b) VIRTUAL, | 
				
			|||
  KEY (c) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c INT GENERATED ALWAYS AS (a-CAST(b AS SIGNED)) VIRTUAL, | 
				
			|||
  KEY (c) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c INT GENERATED ALWAYS AS (CAST(a AS SIGNED)-CAST(b AS SIGNED)) VIRTUAL, | 
				
			|||
  KEY (c) | 
				
			|||
); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
# 'CAST(signed AS DECIMAL)' does not copy 'unsigned_flag' from the argument. | 
				
			|||
# So the below is safe. | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c INT GENERATED ALWAYS AS (CAST(a AS DECIMAL(20,0))-CAST(b AS DECIMAL(20,0))) VIRTUAL, | 
				
			|||
  KEY (c) | 
				
			|||
); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Comnination: PAD_CHAR_TO_FULL_LENGTH + NO_UNSIGNED_SUBTRACTION | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c CHAR(5), | 
				
			|||
  v VARCHAR(5) GENERATED ALWAYS AS (RPAD(c,a-b,' ')) VIRTUAL, | 
				
			|||
  KEY (v) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
# The below solves the dependency on NO_UNSIGNED_SUBTRACTION | 
				
			|||
# but does not solve the dependency on PAD_CHAR_TO_FULL_LENGTH, | 
				
			|||
# because the 'length' argument to RPAD() is not a constant. | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c CHAR(5), | 
				
			|||
  v VARCHAR(5) GENERATED ALWAYS AS (RPAD(c,CAST(a AS DECIMAL(20,1))-b,' ')) VIRTUAL, | 
				
			|||
  KEY (v) | 
				
			|||
); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # ALTER TABLE ADD KEY(vcol_depending_on_sql_mode) --> error | 
				
			|||
 | 
				
			|||
# This makes sure that QT_ITEM_IDENT_SKIP_DB_NAMES and | 
				
			|||
# QT_ITEM_IDENT_SKIP_TABLE_NAMES are passed to print() | 
				
			|||
# to avoid temporary table names like `test`.`#sql-50a6_4`.`c` | 
				
			|||
# in the error message. | 
				
			|||
# | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 ( | 
				
			|||
  a INT UNSIGNED, | 
				
			|||
  b INT UNSIGNED, | 
				
			|||
  c CHAR(5), | 
				
			|||
  v VARCHAR(5) GENERATED ALWAYS AS (c) VIRTUAL | 
				
			|||
); | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
ALTER TABLE t1 ADD KEY(v); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE INDEX v ON t1 (v); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # A virtual column on the second position in an index - cannot depend on sql_mode | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (id int, a CHAR(5), v TEXT AS (a) VIRTUAL, KEY(id, v(100))); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # A persisten virtual column cannot depend on sql_mode | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (a) PERSISTENT); | 
				
			|||
SHOW WARNINGS; | 
				
			|||
 | 
				
			|||
CREATE TABLE t1 (a CHAR(5), v VARCHAR(5) AS (RTRIM(a)) PERSISTENT); | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # End of 10.2 tests | 
				
			|||
--echo # | 
				
			|||
@ -0,0 +1,193 @@ | 
				
			|||
-- source include/mysql_upgrade_preparation.inc | 
				
			|||
call mtr.add_suppression("Table rebuild required"); | 
				
			|||
 | 
				
			|||
let $MYSQLD_DATADIR= `select @@datadir`; | 
				
			|||
 | 
				
			|||
--enable_prepare_warnings | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Opening a Maria-10.2.26 table with a stored VARCHAR column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
ALTER TABLE t1 ADD b INT DEFAULT a; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
ALTER TABLE t1 ADD c INT DEFAULT a; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Fixing a Maria-10.2.26 table with a stored VARCHAR column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Fixing by dropping the generated stored column | 
				
			|||
--echo # Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
ALTER TABLE t1 DROP v; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--echo # Fixing by altering the generation expression of the stored column | 
				
			|||
--echo # Copying maria100226_char_to_vchar_stored.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
ALTER TABLE t1 MODIFY v VARCHAR(5) AS (RTRIM(a)) PERSISTENT; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Opening a Maria-10.2.26 table with a virtual VARCHAR column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
 | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
 | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
FLUSH TABLES; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
ALTER TABLE t1 ADD b INT DEFAULT a; | 
				
			|||
FLUSH TABLES; | 
				
			|||
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED | 
				
			|||
ALTER TABLE t1 ADD c INT DEFAULT a; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Fixing a Maria-10.2.26 table with a virtual VARCHAR column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Fixing by dropping the virtual column | 
				
			|||
--echo # Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
ALTER TABLE t1 DROP v; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
--echo # Fixing by dropping a key on a virtual column, using ALTER TABLE | 
				
			|||
--echo # Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
ALTER TABLE t1 DROP KEY v; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # Fixing by dropping a key on a virtual column, using DROP INDEX | 
				
			|||
--echo # Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
DROP INDEX v ON t1; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # Fixing by altering the generation expression of a virtual column | 
				
			|||
--echo # Copying maria100226_char_to_vchar_virtual.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
ALTER TABLE t1 MODIFY v VARCHAR(5) AS(RTRIM(a)) VIRTUAL; | 
				
			|||
SHOW CREATE TABLE t1; | 
				
			|||
SELECT * FROM t1; | 
				
			|||
CREATE TABLE t2 LIKE t1; | 
				
			|||
SHOW CREATE TABLE t2; | 
				
			|||
DROP TABLE t2; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Upgrading a Maria-10.2.26 table with a stored column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Copying maria100226_char_to_varchar.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_stored.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
FLUSH TABLES; | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
DROP TABLE t1; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
--echo # | 
				
			|||
--echo # Upgrading a Maria-10.2.26 table with a virtual column | 
				
			|||
--echo # | 
				
			|||
 | 
				
			|||
--echo # Copying maria100226_char_to_varchar.* to MYSQLD_DATADIR | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.frm $MYSQLD_DATADIR/test/t1.frm | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYD $MYSQLD_DATADIR/test/t1.MYD | 
				
			|||
--copy_file std_data/vcol_upgrade/maria100226_char_to_vchar_virtual.MYI $MYSQLD_DATADIR/test/t1.MYI | 
				
			|||
 | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
FLUSH TABLES; | 
				
			|||
CHECK TABLE t1 FOR UPGRADE; | 
				
			|||
DROP TABLE t1; | 
				
			|||
@ -0,0 +1,34 @@ | 
				
			|||
/*
 | 
				
			|||
   Copyright (c) 2019, MariaDB. | 
				
			|||
 | 
				
			|||
   This program is free software; you can redistribute it and/or modify | 
				
			|||
   it under the terms of the GNU General Public License as published by | 
				
			|||
   the Free Software Foundation; version 2 of the License. | 
				
			|||
 | 
				
			|||
   This program is distributed in the hope that it will be useful, | 
				
			|||
   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
   GNU General Public License for more details. | 
				
			|||
 | 
				
			|||
   You should have received a copy of the GNU General Public License | 
				
			|||
   along with this program; if not, write to the Free Software | 
				
			|||
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */ | 
				
			|||
 | 
				
			|||
#include "mariadb.h"
 | 
				
			|||
#include "set_var.h"
 | 
				
			|||
 | 
				
			|||
void Sql_mode_dependency::push_dependency_warnings(THD *thd) | 
				
			|||
{ | 
				
			|||
  sql_mode_t all= m_hard | m_soft; | 
				
			|||
  for (uint i= 0; all ; i++, all >>= 1) | 
				
			|||
  { | 
				
			|||
    if (all & 1) | 
				
			|||
    { | 
				
			|||
      // TODO-10.5: add a new error code
 | 
				
			|||
      push_warning_printf(thd, | 
				
			|||
                          Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, | 
				
			|||
                          "Expression depends on the @@%s value %s", | 
				
			|||
                          "sql_mode", sql_mode_string_representation(i)); | 
				
			|||
    } | 
				
			|||
  } | 
				
			|||
} | 
				
			|||
@ -0,0 +1,162 @@ | 
				
			|||
#ifndef SQL_MODE_H_INCLUDED | 
				
			|||
#define SQL_MODE_H_INCLUDED | 
				
			|||
/* | 
				
			|||
   Copyright (c) 2019, MariaDB. | 
				
			|||
 | 
				
			|||
   This program is free software; you can redistribute it and/or modify | 
				
			|||
   it under the terms of the GNU General Public License as published by | 
				
			|||
   the Free Software Foundation; version 2 of the License. | 
				
			|||
 | 
				
			|||
   This program is distributed in the hope that it will be useful, | 
				
			|||
   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
				
			|||
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
				
			|||
   GNU General Public License for more details. | 
				
			|||
 | 
				
			|||
   You should have received a copy of the GNU General Public License | 
				
			|||
   along with this program; if not, write to the Free Software | 
				
			|||
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335  USA */ | 
				
			|||
 | 
				
			|||
#ifdef USE_PRAGMA_INTERFACE | 
				
			|||
#pragma interface			/* gcc class implementation */ | 
				
			|||
#endif | 
				
			|||
 | 
				
			|||
#include "sql_basic_types.h" | 
				
			|||
 | 
				
			|||
/* | 
				
			|||
  class Sql_mode_dependency | 
				
			|||
 | 
				
			|||
  A combination of hard and soft dependency on sql_mode. | 
				
			|||
  Used to watch if a GENERATED ALWAYS AS expression guarantees consitent | 
				
			|||
  data written to its virtual column. | 
				
			|||
 | 
				
			|||
  A virtual column can appear in an index if: | 
				
			|||
  - the generation expression does not depend on any sql_mode flags, or | 
				
			|||
  - the generation expression has a soft dependency on an sql_mode flag, | 
				
			|||
    and the column knows how to handle this dependeny. | 
				
			|||
 | 
				
			|||
  A virtual column cannot appear in an index if: | 
				
			|||
  - its generation expression has a hard dependency | 
				
			|||
  - its generation expression has a soft dependency, but the column | 
				
			|||
    cannot handle it on store. | 
				
			|||
  An error is reported in such cases. | 
				
			|||
 | 
				
			|||
  How dependencies appear: | 
				
			|||
  - When a column return value depends on some sql_mode flag, | 
				
			|||
    its Item_field adds a corresponding bit to m_soft. For example, | 
				
			|||
    Item_field for a CHAR(N) column adds the PAD_CHAR_TO_FULL_LENGTH flag. | 
				
			|||
  - When an SQL function/operator return value depends on some sql_mode flag, | 
				
			|||
    it adds a corresponding bit to m_soft. For example, Item_func_minus | 
				
			|||
    adds the MODE_NO_UNSIGNED_SUBTRACTION in case of unsigned arguments. | 
				
			|||
 | 
				
			|||
  How dependency are processed (see examples below): | 
				
			|||
  - All SQL functions/operators bit-OR all hard dependencies from all arguments. | 
				
			|||
  - Some soft dependencies can be handled by the underlying Field on store, | 
				
			|||
    e.g. CHAR(N) can handle PAD_CHAR_TO_FULL_LENGTH. | 
				
			|||
  - Some soft dependencies can be handled by SQL functions and operators, | 
				
			|||
    e.g. RTRIM(expr) removes expr's soft dependency on PAD_CHAR_TO_FULL_LENGTH. | 
				
			|||
    If a function or operator handles a soft dependency on a certain sql_mode | 
				
			|||
    flag, it removes the corresponding bit from m_soft (see below). | 
				
			|||
    Note, m_hard is not touched in such cases. | 
				
			|||
  - When an expression with a soft dependency on a certain sql_mode flag | 
				
			|||
    goes as an argument to an SQL function/operator which cannot handle | 
				
			|||
    this flag, the dependency escalates from soft to hard | 
				
			|||
    (by moving the corresponding bit from m_soft to m_hard) and cannot be | 
				
			|||
    handled any more on the upper level, neither by a Field on store, | 
				
			|||
    nor by another SQL function/operator. | 
				
			|||
 | 
				
			|||
  There are four kinds of Items: | 
				
			|||
  1. Items that generate a soft or hard dependency, e.g. | 
				
			|||
     - Item_field for CHAR(N) - generates soft/PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
     - Item_func_minus        - generates soft/NO_UNSIGNED_SUBTRACTION | 
				
			|||
  2. Items that convert a soft dependency to a hard dependency. | 
				
			|||
     This happens e.g. when an Item_func instance gets a soft dependency | 
				
			|||
     from its arguments, and it does not know how to handle this dependency. | 
				
			|||
     Most Item_func descendants do this. | 
				
			|||
  3. Items that remove soft dependencies, e.g.: | 
				
			|||
     - Item_func_rtrim - removes soft/PAD_CHAR_TO_FULL_LENGTH | 
				
			|||
                         that came from args[0] (under certain conditions) | 
				
			|||
     - Item_func_rpad  - removes soft/PAD_CJAR_TO_FULL_LENGTH | 
				
			|||
                         that came from args[0] (under certain conditions) | 
				
			|||
  4. Items that repeat soft dependency from its arguments to the caller. | 
				
			|||
     They are not implemented yet. But functions like Item_func_coalesce, | 
				
			|||
     Item_func_case, Item_func_case_abbreviation2 could do this. | 
				
			|||
 | 
				
			|||
  Examples: | 
				
			|||
 | 
				
			|||
  1. CREATE OR REPLACE TABLE t1 (a CHAR(5), v CHAR(20) AS(a), KEY(v)); | 
				
			|||
 | 
				
			|||
     Here `v` has a soft dependency on `a`. | 
				
			|||
     The value of `a` depends on PAD_CHAR_TO_FULL_LENGTH, it can return: | 
				
			|||
     - 'a'                         - if PAD_CHAR_TO_FULL_LENGTH is disabled | 
				
			|||
     - 'a' followed by four spaces - if PAD_CHAR_TO_FULL_LENGTH is enabled | 
				
			|||
     But `v` will pad trailing spaces to the full length on store anyway. | 
				
			|||
     So Field_string handles this soft dependency on store. | 
				
			|||
     This combination of the virtial column data type and its generation | 
				
			|||
     expression is safe and provides consistent data in `v`, which is | 
				
			|||
     'a' followed by four spaces, no matter what PAD_CHAR_TO_FULL_LENGTH is. | 
				
			|||
 | 
				
			|||
  2. CREATE OR REPLACE TABLE t1 (a CHAR(5), v VARCHAR(20) AS(a), KEY(v)); | 
				
			|||
 | 
				
			|||
     Here `v` has a soft dependency on `a`. But Field_varstring does | 
				
			|||
     not pad spaces on store, so it cannot handle this dependency. | 
				
			|||
     This combination of the virtual column data type and its generation | 
				
			|||
     expression is not safe. An error is returned. | 
				
			|||
 | 
				
			|||
  3. CREATE OR REPLACE TABLE t1 (a CHAR(5), v INT AS(LENGTH(a)), KEY(v)); | 
				
			|||
 | 
				
			|||
     Here `v` has a hard dependency on `a`, because the value of `a` | 
				
			|||
     is wrapped to the function LENGTH(). | 
				
			|||
     The value of `LENGTH(a)` depends on PAD_CHAR_TO_FULL_LENGTH, it can return: | 
				
			|||
     - 1  - if PAD_CHAR_TO_FULL_LENGTH is disabled | 
				
			|||
     - 4  - if PAD_CHAR_TO_FULL_LENGTH is enabled | 
				
			|||
     This combination cannot provide consistent data stored to `v`, | 
				
			|||
     therefore it's disallowed. | 
				
			|||
*/ | 
				
			|||
class Sql_mode_dependency | 
				
			|||
{ | 
				
			|||
  sql_mode_t m_hard; | 
				
			|||
  sql_mode_t m_soft; | 
				
			|||
public: | 
				
			|||
  Sql_mode_dependency() | 
				
			|||
   :m_hard(0), m_soft(0) | 
				
			|||
  { } | 
				
			|||
  Sql_mode_dependency(sql_mode_t hard, sql_mode_t soft) | 
				
			|||
   :m_hard(hard), m_soft(soft) | 
				
			|||
  { } | 
				
			|||
  sql_mode_t hard() const { return m_hard; } | 
				
			|||
  sql_mode_t soft() const { return m_soft; } | 
				
			|||
  operator bool () const | 
				
			|||
  { | 
				
			|||
    return m_hard > 0 || m_soft > 0; | 
				
			|||
  } | 
				
			|||
  Sql_mode_dependency operator|(const Sql_mode_dependency &other) const | 
				
			|||
  { | 
				
			|||
    return Sql_mode_dependency(m_hard | other.m_hard, m_soft | other.m_soft); | 
				
			|||
  } | 
				
			|||
  Sql_mode_dependency operator&(const Sql_mode_dependency &other) const | 
				
			|||
  { | 
				
			|||
    return Sql_mode_dependency(m_hard & other.m_hard, m_soft & other.m_soft); | 
				
			|||
  } | 
				
			|||
  Sql_mode_dependency &operator|=(const Sql_mode_dependency &other) | 
				
			|||
  { | 
				
			|||
    m_hard|= other.m_hard; | 
				
			|||
    m_soft|= other.m_soft; | 
				
			|||
    return *this; | 
				
			|||
  } | 
				
			|||
  Sql_mode_dependency &operator&=(const Sql_mode_dependency &other) | 
				
			|||
  { | 
				
			|||
    m_hard&= other.m_hard; | 
				
			|||
    m_soft&= other.m_soft; | 
				
			|||
    return *this; | 
				
			|||
  } | 
				
			|||
  Sql_mode_dependency &soft_to_hard() | 
				
			|||
  { | 
				
			|||
    m_hard|= m_soft; | 
				
			|||
    m_soft= 0; | 
				
			|||
    return *this; | 
				
			|||
  } | 
				
			|||
  void push_dependency_warnings(THD *thd); | 
				
			|||
}; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
#endif // SQL_MODE_H_INCLUDED | 
				
			|||
						Write
						Preview
					
					
					Loading…
					
					Cancel
						Save
					
		Reference in new issue