summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/gcol
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test/suite/gcol')
-rw-r--r--mysql-test/suite/gcol/disabled.def12
-rw-r--r--mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc268
-rw-r--r--mysql-test/suite/gcol/inc/gcol_cleanup.inc24
-rw-r--r--mysql-test/suite/gcol/inc/gcol_column_def_options.inc609
-rw-r--r--mysql-test/suite/gcol/inc/gcol_dependancies_on_vcol.inc43
-rw-r--r--mysql-test/suite/gcol/inc/gcol_handler.inc77
-rw-r--r--mysql-test/suite/gcol/inc/gcol_ins_upd.inc692
-rw-r--r--mysql-test/suite/gcol/inc/gcol_keys.inc822
-rw-r--r--mysql-test/suite/gcol/inc/gcol_non_stored_columns.inc155
-rw-r--r--mysql-test/suite/gcol/inc/gcol_partition.inc183
-rw-r--r--mysql-test/suite/gcol/inc/gcol_select.inc1172
-rw-r--r--mysql-test/suite/gcol/inc/gcol_supported_sql_funcs.inc47
-rw-r--r--mysql-test/suite/gcol/inc/gcol_supported_sql_funcs_main.inc1236
-rw-r--r--mysql-test/suite/gcol/inc/gcol_trigger_sp.inc114
-rw-r--r--mysql-test/suite/gcol/inc/gcol_unsupported_storage_engines.inc21
-rw-r--r--mysql-test/suite/gcol/inc/gcol_view.inc278
-rw-r--r--mysql-test/suite/gcol/inc/innodb_v_large_col.inc53
-rw-r--r--mysql-test/suite/gcol/r/federated_gcol.result49
-rw-r--r--mysql-test/suite/gcol/r/gcol_archive.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_blackhole.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_innodb.result194
-rw-r--r--mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result196
-rw-r--r--mysql-test/suite/gcol/r/gcol_bug20746926.result32
-rw-r--r--mysql-test/suite/gcol/r/gcol_bugfixes.result746
-rw-r--r--mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result736
-rw-r--r--mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result736
-rw-r--r--mysql-test/suite/gcol/r/gcol_csv.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_falcon.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_handler_innodb.result83
-rw-r--r--mysql-test/suite/gcol/r/gcol_handler_myisam.result83
-rw-r--r--mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result823
-rw-r--r--mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result745
-rw-r--r--mysql-test/suite/gcol/r/gcol_keys_innodb.result956
-rw-r--r--mysql-test/suite/gcol/r/gcol_keys_myisam.result897
-rw-r--r--mysql-test/suite/gcol/r/gcol_memory.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_merge.result15
-rw-r--r--mysql-test/suite/gcol/r/gcol_ndb.result14
-rw-r--r--mysql-test/suite/gcol/r/gcol_non_stored_columns_innodb.result237
-rw-r--r--mysql-test/suite/gcol/r/gcol_non_stored_columns_myisam.result237
-rw-r--r--mysql-test/suite/gcol/r/gcol_partition_innodb.result135
-rw-r--r--mysql-test/suite/gcol/r/gcol_partition_myisam.result121
-rw-r--r--mysql-test/suite/gcol/r/gcol_purge.result24
-rw-r--r--mysql-test/suite/gcol/r/gcol_rejected_innodb.result8
-rw-r--r--mysql-test/suite/gcol/r/gcol_rollback.result107
-rw-r--r--mysql-test/suite/gcol/r/gcol_select_innodb.result981
-rw-r--r--mysql-test/suite/gcol/r/gcol_select_myisam.result1613
-rw-r--r--mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result3003
-rw-r--r--mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result3003
-rw-r--r--mysql-test/suite/gcol/r/gcol_trigger_sp_innodb.result94
-rw-r--r--mysql-test/suite/gcol/r/gcol_trigger_sp_myisam.result94
-rw-r--r--mysql-test/suite/gcol/r/gcol_update.result39
-rw-r--r--mysql-test/suite/gcol/r/gcol_view_innodb.result322
-rw-r--r--mysql-test/suite/gcol/r/gcol_view_myisam.result322
-rw-r--r--mysql-test/suite/gcol/r/innodb_partition.result26
-rw-r--r--mysql-test/suite/gcol/r/innodb_prefix_index_check.result15
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_basic.result1495
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_blob.result12
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_debug.result147
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_debug_purge.result205
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_fk.result1028
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_fk_restart.result55
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_index.result372
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_purge.result173
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_rebuild.result98
-rw-r--r--mysql-test/suite/gcol/r/innodb_virtual_stats.result87
-rw-r--r--mysql-test/suite/gcol/r/innodb_wl8114.result52
-rw-r--r--mysql-test/suite/gcol/r/main_alter_table.result52
-rw-r--r--mysql-test/suite/gcol/r/main_mysqldump.result49
-rw-r--r--mysql-test/suite/gcol/r/rpl_gcol.result33
-rw-r--r--mysql-test/suite/gcol/r/virtual_index_drop.result72
-rw-r--r--mysql-test/suite/gcol/t/gcol_archive.test44
-rw-r--r--mysql-test/suite/gcol/t/gcol_blackhole.test44
-rw-r--r--mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_innodb.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_myisam.test44
-rw-r--r--mysql-test/suite/gcol/t/gcol_bug20746926.test28
-rw-r--r--mysql-test/suite/gcol/t/gcol_bugfixes.test726
-rw-r--r--mysql-test/suite/gcol/t/gcol_column_def_options_innodb.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_column_def_options_myisam.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_handler_innodb.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_handler_myisam.test45
-rw-r--r--mysql-test/suite/gcol/t/gcol_ins_upd_innodb.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_ins_upd_myisam.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_keys_innodb.test89
-rw-r--r--mysql-test/suite/gcol/t/gcol_keys_myisam.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_memory.test43
-rw-r--r--mysql-test/suite/gcol/t/gcol_merge.test52
-rw-r--r--mysql-test/suite/gcol/t/gcol_non_stored_columns_innodb.test48
-rw-r--r--mysql-test/suite/gcol/t/gcol_non_stored_columns_myisam.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_partition_innodb.test63
-rw-r--r--mysql-test/suite/gcol/t/gcol_partition_myisam.test45
-rw-r--r--mysql-test/suite/gcol/t/gcol_purge.test33
-rw-r--r--mysql-test/suite/gcol/t/gcol_rejected_innodb.test41
-rw-r--r--mysql-test/suite/gcol/t/gcol_rollback.test136
-rw-r--r--mysql-test/suite/gcol/t/gcol_select_innodb.test53
-rw-r--r--mysql-test/suite/gcol/t/gcol_select_myisam.test52
-rw-r--r--mysql-test/suite/gcol/t/gcol_supported_sql_funcs_innodb.test45
-rw-r--r--mysql-test/suite/gcol/t/gcol_supported_sql_funcs_myisam.test44
-rw-r--r--mysql-test/suite/gcol/t/gcol_trigger_sp_innodb.test47
-rw-r--r--mysql-test/suite/gcol/t/gcol_trigger_sp_myisam.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_update.test62
-rw-r--r--mysql-test/suite/gcol/t/gcol_view_innodb.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_view_myisam.test45
-rw-r--r--mysql-test/suite/gcol/t/innodb_partition.test30
-rw-r--r--mysql-test/suite/gcol/t/innodb_prefix_index_check.test22
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_basic.test1446
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_blob.test25
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_debug.test341
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt1
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_debug_purge.test268
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_fk.test879
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_fk_restart.test51
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_index.opt1
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_index.test386
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_purge.test185
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_rebuild.test51
-rw-r--r--mysql-test/suite/gcol/t/innodb_virtual_stats.test56
-rw-r--r--mysql-test/suite/gcol/t/innodb_wl8114.test42
-rw-r--r--mysql-test/suite/gcol/t/main_alter_table.test50
-rw-r--r--mysql-test/suite/gcol/t/main_mysqldump.test44
-rw-r--r--mysql-test/suite/gcol/t/rpl_gcol.test65
-rw-r--r--mysql-test/suite/gcol/t/virtual_index_drop.test74
121 files changed, 32803 insertions, 0 deletions
diff --git a/mysql-test/suite/gcol/disabled.def b/mysql-test/suite/gcol/disabled.def
new file mode 100644
index 00000000..77359887
--- /dev/null
+++ b/mysql-test/suite/gcol/disabled.def
@@ -0,0 +1,12 @@
+##############################################################################
+#
+# List the test cases that are to be disabled temporarily.
+#
+# Separate the test case name and the comment with ':'.
+#
+# <testcasename> : BUG#<xxxx> <date disabled> <disabler> <comment>
+#
+# Do not use any TAB characters for whitespace.
+#
+##############################################################################
+gcol.innodb_virtual_fk: MDEV-29181 Constant failures "InnoDB: tried to purge non-delete-marked record in index"
diff --git a/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc b/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc
new file mode 100644
index 00000000..4cc10730
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc
@@ -0,0 +1,268 @@
+################################################################################
+# inc/gcol_blocked_sql_funcs_main.inc #
+# #
+# Purpose: #
+# Tests around sql functions #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# MySQL doesn't support them, but MariaDB does:
+#
+create or replace table t1 (b double generated always as (rand()) virtual);
+create or replace table t1 (a datetime generated always as (curdate()) virtual);
+create or replace table t1 (a datetime generated always as (current_date) virtual);
+create or replace table t1 (a datetime generated always as (current_date()) virtual);
+create or replace table t1 (a datetime generated always as (current_time) virtual);
+create or replace table t1 (a datetime generated always as (current_time()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp) virtual);
+create or replace table t1 (a datetime generated always as (curtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (now()) virtual);
+create or replace table t1 (a int, b varchar(10) generated always as (sysdate()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (unix_timestamp()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_date()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_time()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_timestamp()) virtual);
+create or replace table t1 (a int generated always as (connection_id()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (database()) virtual);
+create or replace table t1 (a varchar(32) generated always as (schema()) virtual);
+create or replace table t1 (a varchar(32) generated always as (session_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (system_user()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (user()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid_short()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (version()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (encrypt(a)) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (UpdateXML(a,'/a','<e>fff</e>')) virtual);
+drop table t1;
+
+#
+# NOTE: All SQL functions below should be rejected, otherwise BUG.
+#
+
+--echo # LOAD_FILE()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual);
+
+--echo # MATCH()
+if (!$skip_full_text_check)
+{
+ -- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+ create table t1 (a varchar(32), b bool generated always as (match a against ('sample text')) virtual);
+}
+
+--echo # BENCHMARK()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (benchmark(a,3)) virtual);
+
+--echo # FOUND_ROWS()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (found_rows()) virtual);
+
+--echo # GET_LOCK()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (get_lock(a,10)) virtual);
+
+--echo # IS_FREE_LOCK()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual);
+
+--echo # IS_USED_LOCK()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_used_lock(a)) virtual);
+
+--echo # LAST_INSERT_ID()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (last_insert_id()) virtual);
+
+--echo # MASTER_POS_WAIT()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32), b int generated always as (master_pos_wait(a,0,2)) virtual);
+
+--echo # NAME_CONST()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32) generated always as (name_const('test',1)) virtual);
+
+--echo # RELEASE_LOCK()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32), b int generated always as (release_lock(a)) virtual);
+
+--echo # ROW_COUNT()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (row_count()) virtual);
+
+--echo # SLEEP()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (sleep(a)) virtual);
+
+--echo # VALUES()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (value(a)) virtual);
+
+--echo # Stored procedures
+
+delimiter //;
+create procedure p1()
+begin
+ select current_user();
+end //
+
+create function f1()
+returns int
+begin
+ return 1;
+end //
+
+delimiter ;//
+
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (p1()) virtual);
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (f1()) virtual);
+
+drop procedure p1;
+drop function f1;
+
+--echo # Unknown functions
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (f1()) virtual);
+
+--echo #
+--echo # GROUP BY FUNCTIONS
+--echo #
+
+--echo # AVG()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (avg(a)) virtual);
+
+--echo # BIT_AND()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_and(a)) virtual);
+
+--echo # BIT_OR()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_or(a)) virtual);
+
+--echo # BIT_XOR()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_xor(a)) virtual);
+
+--echo # COUNT(DISTINCT)
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (count(distinct a)) virtual);
+
+--echo # COUNT()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (count(a)) virtual);
+
+--echo # GROUP_CONCAT()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32), b int generated always as (group_concat(a,'')) virtual);
+
+--echo # MAX()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (max(a)) virtual);
+
+--echo # MIN()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (min(a)) virtual);
+
+--echo # STD()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (std(a)) virtual);
+
+--echo # STDDEV_POP()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
+
+--echo # STDDEV_SAMP()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
+
+--echo # STDDEV()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev(a)) virtual);
+
+--echo # SUM()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (sum(a)) virtual);
+
+--echo # VAR_POP()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (var_pop(a)) virtual);
+
+--echo # VAR_SAMP()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (var_samp(a)) virtual);
+
+--echo # VARIANCE()
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (variance(a)) virtual);
+
+--echo #
+--echo # Sub-selects
+--echo #
+
+create table t1 (a int);
+-- error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t2 (a int, b int generated always as (select count(*) virtual from t1));
+drop table t1;
+
+--echo #
+--echo # Long expression
+
+let $tmp_long_string = `SELECT repeat('a',240)`;
+eval create table t1 (a int, b varchar(300) generated always as (concat(a,'$tmp_long_string')) virtual);
+drop table t1;
+let $tmp_long_string = `SELECT repeat('a',243)`;
+# Limit is lifted to 64K. TODO write a test for it.
+# --error 1470
+eval create table t1 (a int, b varchar(300) generated always as (concat(a,'$tmp_long_string')) virtual);
+drop table t1;
+
+--echo #
+--echo # Constant expression
+create table t1 (a int generated always as (PI()) virtual);
+drop table t1;
+
+--echo # bug#21098119: GCOL WITH MATCH/AGAINST -->
+--echo # ASSERTION FAILED: TR && TR->TABLE->FILE
+--echo #
+create table t1 (a int);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t1 add column r blob generated always
+as (match(a) against ('' in boolean mode)) virtual;
+drop table t1;
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
+
+--echo #
+--echo # MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column
+--echo #
+
+create table t1 (a int);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+alter table t1 add column b binary(32) generated always as (random_bytes(a));
+alter table t1 add column b binary(32) default (random_bytes(a));
+drop table t1;
+
+--echo #
+--echo #
+--echo # End of 10.10 tests
+--echo #
diff --git a/mysql-test/suite/gcol/inc/gcol_cleanup.inc b/mysql-test/suite/gcol/inc/gcol_cleanup.inc
new file mode 100644
index 00000000..39f7ff7f
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_cleanup.inc
@@ -0,0 +1,24 @@
+################################################################################
+# inc/gcol_cleanup.inc #
+# #
+# Purpose: #
+# Removal of the objects created by the t/<test_name>.test #
+# scripts. #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--disable_warnings
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
+--enable_warnings
diff --git a/mysql-test/suite/gcol/inc/gcol_column_def_options.inc b/mysql-test/suite/gcol/inc/gcol_column_def_options.inc
new file mode 100644
index 00000000..d4db5b5d
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_column_def_options.inc
@@ -0,0 +1,609 @@
+################################################################################
+# inc/gcol_column_def_options.inc #
+# #
+# Purpose: #
+# Testing different optional parameters specified when defining #
+# a generated column. #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+--source include/have_partition.inc
+
+--echo #
+--echo # Section 1. Wrong column definition options
+--echo # - DEFAULT <value>
+--echo # - AUTO_INCREMENT
+
+--echo # NOT NULL
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual not null);
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) stored not null);
+create table t1 (a int);
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) virtual not null;
+drop table t1;
+
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual null);
+create table t1 (a int);
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) virtual null;
+drop table t1;
+
+--echo # Added columns mixed with virtual GC and other columns
+create table t1 (a int);
+insert into t1 values(1);
+--enable_info
+alter table t1 add column (b int generated always as (a+1) virtual, c int);
+alter table t1 add column (d int, e int generated always as (a+1) virtual);
+alter table t1 add column (f int generated always as (a+1) virtual, g int as(5) stored);
+alter table t1 add column (h int generated always as (a+1) virtual, i int as(5) virtual);
+--disable_info
+drop table t1;
+
+--echo # DEFAULT
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual default 0);
+create table t1 (a int);
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) virtual default 0;
+drop table t1;
+
+--echo # AUTO_INCREMENT
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual AUTO_INCREMENT);
+create table t1 (a int);
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) virtual AUTO_INCREMENT;
+drop table t1;
+
+--echo # [PRIMARY] KEY
+if ($support_virtual_index)
+{
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual key);
+}
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) stored key);
+if ($support_virtual_index)
+{
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) virtual primary key);
+}
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a+1) stored primary key);
+create table t1 (a int);
+if ($support_virtual_index)
+{
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) virtual key;
+}
+--error ER_PARSE_ERROR
+alter table t1 add column b int generated always as (a+1) stored key;
+if ($support_virtual_index)
+{
+--error ER_PARSE_ERROR
+alter table t1 add column c int generated always as (a+2) virtual primary key;
+}
+show create table t1;
+--error ER_PARSE_ERROR
+alter table t1 add column c int generated always as (a+2) stored primary key;
+drop table t1;
+
+--echo # Section 2. Other column definition options
+--echo # - COMMENT
+--echo # - REFERENCES (only syntax testing here)
+--echo # - STORED (only systax testing here)
+create table t1 (a int, b int generated always as (a % 2) virtual comment 'my comment');
+show create table t1;
+describe t1;
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) virtual comment 'my comment';
+show create table t1;
+describe t1;
+insert into t1 (a) values (1);
+select * from t1;
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+create table t2 like t1;
+show create table t2;
+describe t2;
+insert into t2 (a) values (1);
+select * from t2;
+insert into t2 values (2,default);
+select a,b from t2 order by a;
+drop table t2;
+drop table t1;
+
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+describe t1;
+insert into t1 (a) values (1);
+select * from t1;
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+drop table t1;
+
+
+create table t2 (a int);
+--error ER_PARSE_ERROR
+create table t1 (a int, b int generated always as (a % 2) stored references t2(a));
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+--error ER_PARSE_ERROR
+alter table t1 modify b int generated always as (a % 2) stored references t2(a);
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+alter table t1 modify b int generated always as (a % 2) stored;
+show create table t1;
+drop table t1;
+drop table t2;
+--echo FK options
+create table t1(a int, b int as (a % 2), c int as (a) stored);
+create table t2 (a int);
+--error ER_KEY_COLUMN_DOES_NOT_EXIST
+alter table t1 add constraint foreign key fk(d) references t2(a);
+if ($support_virtual_foreign)
+{
+--error ER_CANT_CREATE_TABLE
+alter table t1 add constraint foreign key fk(b) references t2(a);
+}
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add constraint foreign key fk(c) references t2(a) on delete set null;
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add constraint foreign key fk(c) references t2(a) on update set null;
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add constraint foreign key fk(c) references t2(a) on update cascade;
+drop table t1;
+drop table t2;
+--echo Generated always is optional
+create table t1 (a int, b int as (a % 2) virtual);
+show create table t1;
+describe t1;
+drop table t1;
+create table t1 (a int, b int as (a % 2) stored);
+show create table t1;
+describe t1;
+drop table t1;
+--echo Default should be non-stored column
+create table t1 (a int, b int as (a % 2));
+show create table t1;
+describe t1;
+drop table t1;
+--echo Expression can be constant
+create table t1 (a int, b int as (5 * 2));
+show create table t1;
+describe t1;
+drop table t1;
+--echo Test generated columns referencing other generated columns
+create table t1 (a int unique, b int generated always as(-a) virtual, c int generated always as (b + 1) virtual);
+insert into t1 (a) values (1), (2);
+--sorted_result
+select * from t1;
+insert into t1(a) values (1) on duplicate key update a=3;
+--sorted_result
+select * from t1;
+update t1 set a=4 where a=2;
+--sorted_result
+select * from t1;
+drop table t1;
+
+--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+create table t1 (a int, b int generated always as(-b) virtual, c int generated always as (b + 1) virtual);
+--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+create table t1 (a int, b int generated always as(-c) virtual, c int generated always as (b + 1) virtual);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
+show create table t1;
+insert t1 (col_int_key) values (10),(20),(30);
+select * from t1;
+drop table t1;
+
+--echo # Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
+create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
+insert into t1(a) values(1),(2);
+create table tt as select * from t1;
+select * from t1 order by a;
+select * from tt order by a;
+drop table t1,tt;
+
+if (!$support_virtual_index)
+{
+--echo # Bug#20769299: INCORRECT KEY ERROR WHEN TRYING TO CREATE INDEX ON
+--echo # VIRTUAL GC FOR MYISAM
+--error ER_KEY_BASED_ON_GENERATED_GENERATED_COLUMN
+CREATE TABLE A (
+pk INTEGER,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (pk + col_int_nokey) VIRTUAL, KEY
+(col_int_key));
+}
+
+--echo # Bug#20745142: GENERATED COLUMNS: ASSERTION FAILED:
+--echo # THD->CHANGE_LIST.IS_EMPTY()
+--echo #
+--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+CREATE TABLE t1(a bigint AS (a between 1 and 1));
+
+--echo # Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+--echo # IN FIND_FIELD_IN_TABLE
+--echo #
+CREATE TABLE t1(a int);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+DROP TABLE t1;
+
+--echo # Bug#20566243: ERROR WHILE DOING CREATE TABLE T1 SELECT (QUERY ON GC COLUMNS)
+CREATE TABLE t1(a int, b int as (a + 1),
+ c varchar(12) as ("aaaabb") stored, d blob as (c));
+INSERT INTO t1(a) VALUES(1),(3);
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 order by a;
+CREATE TABLE t2 LIKE t1;
+SHOW CREATE TABLE t2;
+CREATE TABLE t3 AS SELECT * FROM t1;
+SHOW CREATE TABLE t3;
+SELECT * FROM t3 order by a;
+CREATE TABLE t4 AS SELECT b,c,d FROM t1;
+SHOW CREATE TABLE t4;
+SELECT * FROM t4 order by b;
+DROP TABLE t1,t2,t3,t4;
+
+--echo # Bug#21025003:WL8149:ASSERTION `CTX->NUM_TO_DROP_FK
+--echo # == HA_ALTER_INFO->ALTER_INFO-> FAILED
+--echo #
+CREATE TABLE t1 (
+ col1 int(11) DEFAULT NULL,
+ col2 int(11) DEFAULT NULL,
+ col3 int(11) DEFAULT NULL,
+ col4 int(11) DEFAULT NULL,
+ col5 int(11) GENERATED ALWAYS AS (col4 / col2) VIRTUAL,
+ col6 text
+);
+INSERT INTO t1(col1,col2,col3,col4,col6) VALUES(NULL,1,4,0,REPEAT(2,1000));
+--error ER_CANT_DROP_FIELD_OR_KEY
+ALTER TABLE t1 DROP PRIMARY KEY , ADD KEY idx ( col5, col2 );
+DROP TABLE t1;
+--echo # Bug#20949226:i CAN ASSIGN NON-DEFAULT() VALUE TO GENERATED COLUMN
+--echo #
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5 AS c2;
+CREATE TABLE t2 (a int);
+INSERT INTO t2 values(1);
+DROP TABLE t1;
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, a AS c2 from t2;
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5;
+SELECT * FROM t1;
+DROP TABLE t1, t2;
+
+if ($support_virtual_index)
+{
+--echo # Bug#21074624:i WL8149:SIG 11 INNOBASE_GET_COMPUTED_VALUE |
+--echo # INNOBASE/HANDLER/HA_INNODB.CC:19082
+CREATE TABLE t1 (
+ col1 int(11) NOT NULL,
+ col2 int(11) DEFAULT NULL,
+ col3 int(11) NOT NULL,
+ col4 int(11) DEFAULT NULL,
+ col5 int(11) GENERATED ALWAYS AS (col2 % col4) VIRTUAL,
+ col6 int(11) GENERATED ALWAYS AS (col3 + col3) VIRTUAL,
+ col7 int(11) GENERATED ALWAYS AS (col5 / col5) VIRTUAL,
+ col8 int(11) GENERATED ALWAYS AS (col6 / col5) VIRTUAL,
+ col9 text,
+ extra int(11) DEFAULT NULL,
+ KEY idx (col5)
+);
+INSERT INTO t1(col1,col2,col3,col4,col9,extra)
+VALUES(0,6,3,4,REPEAT(4,1000),0);
+ALTER TABLE t1 DROP COLUMN col1;
+DROP TABLE t1;
+
+--echo # Bug#21390605:VALGRIND ERROR ON DELETE FROM TABLE CONTAINING
+--echo # AN INDEXED VIRTUAL COLUMN
+CREATE TABLE t1 (
+ a INTEGER,
+ b INTEGER GENERATED ALWAYS AS (a) VIRTUAL,
+ c INTEGER GENERATED ALWAYS AS (b) VIRTUAL,
+ INDEX idx (b,c)
+);
+INSERT INTO t1 (a) VALUES (42);
+DELETE FROM t1 WHERE c = 42;
+DROP TABLE t1;
+}
+
+--echo # Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+--echo # IN FIND_FIELD_IN_TABLE
+--echo #
+CREATE TABLE t1(a int);
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM t1 WHERE not_exist_col)));
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM dual)));
+DROP TABLE t1;
+
+if(! $testing_ndb) {
+--echo # Bug#21142905: PARTITIONED GENERATED COLS -
+--echo # !TABLE || (!TABLE->WRITE_SET || BITMAP_IS_SET
+--echo #
+CREATE TABLE t1 (
+a int,
+b int generated always as (a) virtual,
+c int generated always as (b+a) virtual,
+d int generated always as (b+a) virtual
+) PARTITION BY LINEAR HASH (b);
+INSERT INTO t1(a) VALUES(0);
+DELETE FROM t1 WHERE c=1;
+DROP TABLE t1;
+}
+
+CREATE TABLE t1 (c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar"));
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+CREATE TABLE t1 (i INT);
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+--error ER_PARSE_ERROR
+CREATE TABLE t1 (i INT COLLATE utf8_bin, c INT COLLATE utf8_bin GENERATED ALWAYS AS (10));
+
+--echo # Check for a charset mismatch processing:
+
+--echo # Bug #21469535: VALGRIND ERROR (CONDITIONAL JUMP) WHEN INSERT
+--echo # ROWS INTO A PARTITIONED TABLE
+--echo #
+CREATE TABLE t1 (
+ id INT NOT NULL,
+ store_id INT NOT NULL,
+ x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+ PARTITION p0 VALUES LESS THAN (6),
+ PARTITION p1 VALUES LESS THAN (11),
+ PARTITION p2 VALUES LESS THAN (16),
+ PARTITION p3 VALUES LESS THAN (21)
+);
+
+INSERT INTO t1 VALUES(1, 2, default);
+DROP TABLE t1;
+
+--echo # Bug#21465626:ASSERT/CRASH ON DROPPING/ADDING VIRTUAL COLUMN
+CREATE TABLE t (a int(11), b int(11),
+ c int(11) GENERATED ALWAYS AS (a+b) VIRTUAL,
+ d int(11) GENERATED ALWAYS AS (a+b) VIRTUAL);
+INSERT INTO t(a,b) VALUES(1,2);
+--enable_info
+--echo # Mixed drop/add/rename virtual with non-virtual columns,
+--echo # ALGORITHM=INPLACE is not supported for InnoDB
+ALTER TABLE t DROP d, ADD e varchar(10);
+ALTER TABLE t ADD d int, ADD f char(10) AS ('aaa');
+ALTER TABLE t CHANGE d dd int, CHANGE f ff varchar(10) AS ('bbb');
+--echo # Only drop/add/change virtual, inplace is supported for Innodb
+ALTER TABLE t DROP c, DROP ff;
+ALTER TABLE t ADD c int(11) as (a+b), ADD f varchar(10) as ('aaa');
+ALTER TABLE t CHANGE c c int(11) as (a), CHANGE f f varchar(10) as('bbb');
+--echo # Change order should be ALGORITHM=INPLACE on Innodb
+ALTER TABLE t CHANGE c c int(11) as (a) after f;
+ALTER TABLE t CHANGE b b int(11) after c;
+--echo # TODO: Changing virtual column type should be ALGORITHM=INPLACE on InnoDB, current it goes only with COPY method
+ALTER TABLE t CHANGE c c varchar(10) as ('a');
+--echo # Changing stored column type is ALGORITHM=COPY
+ALTER TABLE t CHANGE dd d varchar(10);
+if ($support_virtual_index)
+{
+# no RENAME INDEX yet
+#ALTER TABLE t ADD INDEX idx(a), ADD INDEX idx1(c);
+#ALTER TABLE t RENAME INDEX idx TO idx2, RENAME INDEX idx1 TO idx3;
+#ALTER TABLE t DROP INDEX idx2, DROP INDEX idx3;
+ALTER TABLE t ADD INDEX idx(c), ADD INDEX idx1(d);
+ALTER TABLE t DROP INDEX idx, DROP INDEX idx1;
+}
+--disable_info
+DROP TABLE t;
+
+--echo # Bug#21854004: GCOLS:INNODB: FAILING ASSERTION: I < TABLE->N_DEF
+CREATE TABLE t1(
+ col1 INTEGER PRIMARY KEY,
+ col2 INTEGER,
+ col3 INTEGER,
+ col4 INTEGER,
+ vgc1 INTEGER AS (col2 + col3) VIRTUAL,
+ sgc1 INTEGER AS (col2 - col3) STORED
+);
+
+INSERT INTO t1(col1, col2, col3) VALUES
+ (1, 10, 100), (2, 20, 200);
+
+SELECT * FROM t1 order by col1;
+
+# Change expression of a virtual generated column
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+
+# Change expression of a stored generated column
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+
+if ($support_virtual_index)
+{
+ALTER TABLE t1 ADD INDEX vgc1 (vgc1);
+}
+ALTER TABLE t1 ADD INDEX sgc1 (sgc1);
+
+if ($support_virtual_index)
+{
+# Change expression of a virtual generated column, with index
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+SELECT vgc1 FROM t1 order by vgc1;
+}
+
+# Change expression of a stored generated column, with index
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+SELECT sgc1 FROM t1 order by sgc1;
+
+if ($support_virtual_index)
+{
+ALTER TABLE t1 DROP INDEX vgc1;
+}
+ALTER TABLE t1 DROP INDEX sgc1;
+
+if ($support_virtual_index)
+{
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 ADD UNIQUE INDEX vgc1 (vgc1);
+}
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD UNIQUE INDEX sgc1 (sgc1);
+
+# Change expression of a virtual generated column, with unique index
+if ($support_virtual_index)
+{
+--error ER_DUP_ENTRY
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 / col3) VIRTUAL;
+}
+--error ER_DUP_ENTRY
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+SELECT vgc1 FROM t1 order by col1;
+
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 * col3) STORED;
+SELECT * FROM t1 order by col1;
+SELECT sgc1 FROM t1 order by sgc1;
+
+# Change virtual generated column to become stored
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) STORED;
+
+# Change stored generated column to become virtual
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) VIRTUAL;
+
+# Change base column to become stored generated column:
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER AS (col1 + col2 + col3) STORED;
+SELECT * FROM t1 order by col1;
+
+# Change stored generated column to become base column:
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER;
+SELECT * FROM t1 order by col1;
+
+DROP TABLE t1;
+
+if ($support_virtual_index)
+{
+--echo #
+--echo # bug#22018979: RECORD NOT FOUND ON UPDATE,
+--echo # VIRTUAL COLUMN, ASSERTION 0
+--disable_warnings
+SET @sql_mode_save= @@sql_mode;
+SET sql_mode= 'ANSI';
+CREATE TABLE t1 (
+ a INT,
+ b VARCHAR(10),
+ c CHAR(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+ PRIMARY KEY (a),
+ KEY c(c)
+);
+INSERT INTO t1(a, b) values(1, 'bbbb'), (2, 'cc');
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 order by a;
+
+SET sql_mode= '';
+FLUSH TABLE t1;
+SHOW CREATE TABLE t1;
+SELECT * FROM t1 order by a;
+DELETE FROM t1 where a= 2;
+
+SET sql_mode= @sql_mode_save;
+DROP TABLE t1;
+--enable_warnings
+}
+
+
+--echo #
+--echo # Bug#22680839: DEFAULT IS NOT DETERMINISTIC AND SHOULD NOT BE
+--echo # ALLOWED IN GENERATED COLUMNS
+--echo #
+if ($support_virtual_index)
+{
+CREATE TABLE tzz(a INT DEFAULT 5,
+ gc1 INT AS (a+DEFAULT(a)) VIRTUAL,
+ gc2 INT AS (a+DEFAULT(a)) STORED,
+ KEY k1(gc1));
+INSERT INTO tzz(A) VALUES (1);
+SELECT * FROM tzz;
+SELECT gc1 FROM tzz;
+
+ALTER TABLE tzz MODIFY COLUMN a INT DEFAULT 6;
+SELECT * FROM tzz;
+SELECT gc1 FROM tzz;
+DROP TABLE tzz;
+}
+
+--echo # Test 1: ALTER DEFAULT
+--echo #
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5,
+ b INT AS (1 + DEFAULT(a)) STORED,
+ c INT AS (1 + DEFAULT(a)) VIRTUAL);
+INSERT INTO t1 VALUES ();
+--disable_warnings
+# Check how many rows are accessed: >0 = COPY
+--enable_info
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7;
+ALTER TABLE t1 MODIFY COLUMN a INT DEFAULT 8;
+ALTER TABLE t1 CHANGE COLUMN a a DOUBLE DEFAULT 5;
+--disable_info
+DROP TABLE t1;
+
+--echo # Test 2: ALTER DEFAULT + ADD GCOL
+--echo #
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5);
+INSERT INTO t1 VALUES();
+--enable_info
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ ADD COLUMN b1 INT AS (1 + DEFAULT(a)) STORED;
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ ADD COLUMN c1 INT AS (1 + DEFAULT(a)) VIRTUAL;
+--disable_info
+# Check how many rows are accessed: >0 = COPY
+--enable_info
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ ADD COLUMN b INT AS (1 + DEFAULT(a)) STORED,
+ ADD COLUMN c INT AS (1 + DEFAULT(a)) VIRTUAL;
+--disable_info
+DROP TABLE t1;
+--enable_warnings
+
+--echo #
+--echo # MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+--echo #
+
+--error ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);
+
+--let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err
+--let SEARCH_PATTERN=Incorrect information in file: './test/MDEV_26262.frm'
+--source include/search_pattern_in_file.inc
diff --git a/mysql-test/suite/gcol/inc/gcol_dependancies_on_vcol.inc b/mysql-test/suite/gcol/inc/gcol_dependancies_on_vcol.inc
new file mode 100644
index 00000000..5ef43309
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_dependancies_on_vcol.inc
@@ -0,0 +1,43 @@
+################################################################################
+# inc/gcol_dependencies_on_gcol.inc #
+# #
+# Purpose: #
+# Testing scenarios when columns depend on generated columns, i.e. such as #
+# - a generated column is based on a generated column #
+# - a "real" column on which a generated one is renamed/dropped #
+# - a generated column involved in partitioning is renamed/dropped #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--echo # Can't define a generated column on another generated column
+--error ER_VCOL_BASED_ON_VCOL
+create table t1 (a int, b int generated always as (a+1) virtual, c int generated always as (b+1) virtual);
+create table t1 (a int, b int generated always as (a+1) virtual);
+--error ER_VCOL_BASED_ON_VCOL
+alter table t1 add column c int generated always as (b+1) virtual;
+drop table t1;
+
+--echo # Can't rename or drop a column used in the function of a generated column
+create table t1 (a int, b int generated always as (a+1) virtual);
+--echo # On renaming/dropping a column on which a virtual field is
+--echo # defined the following error is displayed:
+--echo # "Unknown column 'a' in 'generated column function'"
+--error 1054
+alter table t1 drop column a;
+--error 1054
+alter table t1 change a c int;
+drop table t1;
+
+--echo # Can't rename or drop a generated column used by the paritition function
+create table t1 (a int, b int generated always as (a+1) virtual) partition by hash(b);
+--error 1054
+alter table t1 drop b;
+--error 1054
+alter table t1 change b c int generated always as (a+1) virtual;
+
diff --git a/mysql-test/suite/gcol/inc/gcol_handler.inc b/mysql-test/suite/gcol/inc/gcol_handler.inc
new file mode 100644
index 00000000..9ac6d591
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_handler.inc
@@ -0,0 +1,77 @@
+################################################################################
+# inc/gcol_handler.inc #
+# #
+# Purpose: #
+# Testing HANDLER. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored,
+ d char(1),
+ index (a),
+ index (c));
+insert into t1 (a,d) values (4,'a'), (2,'b'), (1,'c'), (3,'d');
+select * from t1;
+
+--echo # HANDLER tbl_name OPEN
+handler t1 open;
+
+--echo # HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...)
+handler t1 read a > (2);
+
+--echo # HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read a > (2) where d='c';
+
+--echo # HANDLER tbl_name READ gcol_index_name = (value1,value2,...)
+handler t1 read c = (-2);
+
+--echo # HANDLER tbl_name READ gcol_index_name = (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read c = (-2) where d='c';
+
+--echo # HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read a > (2) where b=-3 && c=-3;
+
+--echo # HANDLER tbl_name READ gcol_index_name <= (value1,value2,...)
+handler t1 read c <= (-2);
+
+--echo # HANDLER tbl_name READ gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read c <= (-2) where b=-3;
+
+--echo # HANDLER tbl_name READ gcol_index_name FIRST
+handler t1 read c first;
+
+--echo # HANDLER tbl_name READ gcol_index_name NEXT
+handler t1 read c next;
+
+--echo # HANDLER tbl_name READ gcol_index_name PREV
+handler t1 read c prev;
+
+--echo # HANDLER tbl_name READ gcol_index_name LAST
+handler t1 read c last;
+
+--echo # HANDLER tbl_name READ FIRST where non-gcol=expr
+handler t1 read FIRST where a >= 2;
+
+--echo # HANDLER tbl_name READ FIRST where gcol=expr
+handler t1 read FIRST where b >= -2;
+
+--echo # HANDLER tbl_name READ NEXT where non-gcol=expr
+handler t1 read NEXT where d='c';
+
+--echo # HANDLER tbl_name READ NEXT where gcol=expr
+handler t1 read NEXT where b<=-4;
+
+--echo # HANDLER tbl_name CLOSE
+handler t1 close;
+
+drop table t1;
diff --git a/mysql-test/suite/gcol/inc/gcol_ins_upd.inc b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc
new file mode 100644
index 00000000..f025752b
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc
@@ -0,0 +1,692 @@
+################################################################################
+# inc/gcol_ins_upd.inc #
+# #
+# Purpose: #
+# Testing DDL operations such as INSERT, UPDATE, REPLACE and DELETE. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+let $create1 = create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+let $create2 = create table t1 (a int unique,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+let $create3 = create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored unique);
+let $create4 = create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored unique,
+ d varchar(16));
+eval $create1;
+set sql_warnings = 1;
+
+--echo #
+--echo # *** INSERT ***
+--echo #
+
+--echo # INSERT INTO tbl_name VALUES... DEFAULT is specified against gcols
+insert into t1 values (1,default,default);
+select * from t1;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name VALUES... NULL is specified against gcols
+insert into t1 values (1,null,null);
+select * from t1;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name VALUES... a non-NULL value is specified against gcols
+insert ignore into t1 values (1,2,3);
+select * from t1;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name (<non_gcol_list>) VALUES...
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name (<normal+gcols>) VALUES... DEFAULT is specified
+--echo # against gcols
+insert into t1 (a,b) values (1,default), (2,default);
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name (<normal+gcols>) VALUES... NULL is specified against gcols
+insert into t1 (a,b) values (1,null), (2,null);
+select * from t1;
+delete from t1;
+select * from t1;
+
+--echo # INSERT INTO tbl_name (<normal+gcols>) VALUES... a non-NULL value is specified
+--echo # against gcols
+insert ignore into t1 (a,b) values (1,3), (2,4);
+select * from t1;
+delete from t1;
+select * from t1;
+drop table t1;
+
+--echo # Table with UNIQUE non-gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+--echo # KEY UPDATE <non_gcol>=expr, <gcol>=expr
+eval $create2;
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+ on duplicate key update a=2, b=default;
+select a,b,c from t1;
+delete from t1 where b in (1,2);
+select * from t1;
+drop table t1;
+
+--echo # Table with UNIQUE gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+--echo # KEY UPDATE <non_gcol>=expr, <gcol>=expr
+eval $create3;
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+ on duplicate key update a=2, b=default;
+select a,b,c from t1;
+
+--echo # CREATE new_table ... LIKE old_table
+--echo # INSERT INTO new_table SELECT * from old_table
+create table t2 like t1;
+insert into t2(a) select a from t1;
+select * from t2;
+drop table t2;
+
+--echo # CREATE new_table ... LIKE old_table INSERT INTO new_table (<non-gcols>, <gcols>)
+--echo # SELECT <non-gcols>, <gcols> from old_table
+insert into t1 values (1,default,default);
+select * from t1;
+create table t2 like t1;
+insert into t2 (a) select a from t1;
+select * from t2 order by a;
+drop table t2;
+drop table t1;
+
+--echo #
+--echo # *** UPDATE ***
+--echo #
+
+--echo # UPDATE tbl_name SET non-gcol=expr WHERE non-gcol=expr
+eval $create1;
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update t1 set a=3 where a=2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # UPDATE tbl_name SET gcol=expr WHERE non-gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update ignore t1 set c=3 where a=2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # UPDATE tbl_name SET non-gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update t1 set a=3 where b=-2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # UPDATE tbl_name SET gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update ignore t1 set c=3 where b=-2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+drop table t1;
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr WHERE gcol=const
+eval $create3;
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update t1 set a=3 where c=-2;
+select * from t1;
+delete from t1;
+select * from t1;
+
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update t1 set a=3 where c between -3 and -2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # No INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+update t1 set a=3 where b between -3 and -2;
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr
+--echo # WHERE gcol=between const1 and const2 ORDER BY gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+update t1 set a=6 where c between -1 and 0
+ order by c;
+select * from t1 order by a;
+delete from t1 where c between -6 and 0;
+select * from t1;
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr
+--echo # WHERE gcol=between const1 and const2 ORDER BY gcol LIMIT 2
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+update t1 set a=6 where c between -1 and 0
+ order by c limit 2;
+select * from t1 order by a;
+delete from t1 where c between -2 and 0 order by c;
+select * from t1 order by a;
+delete from t1;
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr
+--echo # WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+update t1 set a=6 where (c between -2 and 0) and (b=-1);
+select * from t1 order by a;
+delete from t1;
+
+--echo # INDEX created on gcol
+--echo # UPDATE tbl_name SET non-gcol=expr
+--echo # WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+--echo # ORDER BY indexed gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+update t1 set a=6 where (c between -2 and 0) and (b=-1) order by c;
+select * from t1 order by a;
+delete from t1;
+drop table t1;
+
+let $innodb_engine = `SELECT @@session.default_storage_engine='innodb'`;
+if ($innodb_engine)
+{
+ --echo #
+ --echo # Verify ON UPDATE/DELETE actions of FOREIGN KEYs
+ create table t2 (a int primary key, name varchar(10));
+ create table t1 (a int primary key, b int generated always as (a % 10) stored);
+ insert into t2 values (1, 'value1'), (2,'value2'), (3,'value3');
+ insert into t1 (a) values (1),(2),(3);
+ select * from t1 order by a;
+ select * from t2 order by a;
+ select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a order by t1.a;
+
+ --echo # - ON UPDATE RESTRICT
+ alter table t1 add foreign key (b) references t2(a) on update restrict;
+ --error 1452
+ insert into t1 (a) values (4);
+ --error 1451
+ update t2 set a=4 where a=3;
+ select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+ alter table t1 drop foreign key t1_ibfk_1;
+
+ --echo # - ON DELETE RESTRICT
+ alter table t1 add foreign key (b) references t2(a) on delete restrict;
+ --error 1451
+ delete from t2 where a=3;
+ select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+ select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a);
+ alter table t1 drop foreign key t1_ibfk_1;
+
+ --echo # - ON DELETE CASCADE
+ alter table t1 add foreign key (b) references t2(a) on delete cascade;
+ delete from t2 where a=3;
+ select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+ select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a);
+ alter table t1 drop foreign key t1_ibfk_1;
+
+ drop table t1;
+ drop table t2;
+}
+
+--echo #
+--echo # *** REPLACE ***
+--echo #
+
+--echo # UNIQUE INDEX on gcol
+--echo # REPLACE tbl_name (non-gcols) VALUES (non-gcols);
+eval $create4;
+insert into t1 (a,d) values (1,'a'), (2,'b');
+select * from t1 order by a;
+replace t1 (a,d) values (1,'c');
+select * from t1 order by a;
+delete from t1;
+select * from t1;
+
+
+# *** DELETE
+# All required tests for DELETE are performed as part of the above testing
+# for INSERT, UPDATE and REPLACE.
+
+set sql_warnings = 0;
+drop table t1;
+
+if ($innodb_engine) {
+--echo Bug#20170778: WL411:FAILING ASSERTION `!TABLE || (!TABLE->WRITE_SET ||
+--echo BITMAP_IS_SET(TABLE->WR
+--echo #
+CREATE TABLE t1 (col1 INT, col2 INT, col3 INT, col4 INT, col5
+INT GENERATED ALWAYS AS (col3 * col2) VIRTUAL, col6 INT GENERATED ALWAYS AS
+(col4 * col1) STORED, col7 INT GENERATED ALWAYS AS (col6 + col6) VIRTUAL,
+col8 INT GENERATED ALWAYS AS (col6 / col5) STORED, col9 TEXT);
+
+SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
+
+INSERT INTO t1 (col1,col2,col3,col4,col5,col6,col7,col8,col9) VALUES /* 3 */
+(3, 3 / 3, 3 + 3, 3 / 3, DEFAULT, DEFAULT, DEFAULT, DEFAULT ,REPEAT(CAST(3 AS
+CHAR(1)),@fill_amount)) , (3, 3 * 3, 3 + 3, 3 / 3, DEFAULT, DEFAULT, DEFAULT,
+DEFAULT ,REPEAT(CAST(3 AS CHAR(1)),@fill_amount));
+
+UPDATE t1 SET col1 = 2;
+UPDATE t1 SET col7 = DEFAULT;
+UPDATE t1 SET col8 = DEFAULT;
+DROP TABLE t1;
+}
+
+if ($support_virtual_index)
+{
+--echo Bug#20797344: WL#8149: ALLOCATED SPACE FOR INDEXED BLOB VGC CAN BE
+--echo OVERWRITTEN FOR UPDATE
+--echo #
+CREATE TABLE t (a varchar(100), b blob,
+c blob GENERATED ALWAYS AS (concat(a,b)) VIRTUAL,
+d blob GENERATED ALWAYS AS (b) VIRTUAL,
+e int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+h int(11) NOT NULL, PRIMARY KEY (h), key(c(20)));
+INSERT INTO t(a,b,h) VALUES('aaaaaaa','1111111', 11);
+INSERT INTO t(a,b,h) VALUES('bbbbbbb','2222222', 22);
+SELECT c FROM t;
+UPDATE t SET a='ccccccc';
+SELECT c FROM t;
+DROP TABLE t;
+}
+
+--echo # Bug#21081742: ASSERTION !TABLE || (!TABLE->WRITE_SET ||
+--echo # BITMAP_IS_SET(TABLE->WRITE_SET
+--echo #
+
+CREATE TABLE b (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+
+INSERT INTO b (col_varchar_nokey) VALUES ('v'),('v');
+
+CREATE TABLE d (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+) ;
+
+INSERT INTO d (col_varchar_nokey) VALUES ('q'),('g'),('e'),('l'),(NULL),('v'),('c'),('u'),('x');
+
+CREATE TABLE bb (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+
+INSERT INTO bb (col_varchar_nokey) VALUES ('j'),('h');
+
+EXPLAIN UPDATE
+d AS OUTR1, b AS OUTR2
+SET OUTR1.col_varchar_nokey = NULL
+WHERE
+( 't', 'b' ) IN
+(
+SELECT
+INNR1.col_varchar_nokey AS x,
+INNR1.col_varchar_key AS y
+FROM bb AS INNR1
+WHERE OUTR1.pk = 1
+);
+
+DROP TABLE IF EXISTS b,bb,d;
+
+
+--echo #
+--echo # Bug#21216067 ASSERTION FAILED ROW_UPD_SEC_INDEX_ENTRY (INNOBASE/ROW/ROW0UPD.CC:2103)
+--echo #
+
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1) STORED
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t2.y = 1, t1.x = 2;
+SELECT * FROM t;
+DROP TABLE t;
+
+if ($support_virtual_index)
+{
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1), KEY (x,gc)
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t1.x = 1, t2.y = 2;
+SELECT * FROM t;
+SELECT gc FROM t;
+CHECK TABLE t;
+DROP TABLE t;
+}
+
+let $query=
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+
+--echo # stored
+
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED
+);
+
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+eval EXPLAIN $query;
+eval $query;
+SELECT * from C;
+DROP TABLE C;
+
+--echo # stored, indexed
+
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+eval EXPLAIN $query;
+eval $query;
+SELECT * from C;
+DROP TABLE C;
+
+--echo # virtual
+
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL
+);
+
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+eval EXPLAIN $query;
+eval $query;
+SELECT * from C;
+DROP TABLE C;
+
+if ($support_virtual_index)
+{
+--echo # virtual, indexed
+
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+eval EXPLAIN $query;
+eval $query;
+SELECT * from C;
+DROP TABLE C;
+
+--echo #
+--echo # Bug #21530366 CRASH/ASSERTION, CORRUPTION WITH INDEXES +
+--echo # VIRTUAL COLUMNS, BLOB
+--echo #
+
+CREATE TABLE t (
+ a INTEGER,
+ b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+ INDEX (b(57))
+);
+
+INSERT INTO t (a) VALUES (9);
+UPDATE t SET a = 10;
+DELETE FROM t WHERE a = 10;
+
+DROP TABLE t;
+
+--echo # Bug#21807818: Generated columns not updated with empty insert list
+
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL,
+KEY (a(183),b)
+);
+
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL
+);
+
+INSERT IGNORE INTO t VALUES(), (), ();
+
+DELETE IGNORE FROM t;
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug#22195458:GCOLS: ASSERTION 0 AND CORRUPTION...
+--echo #
+--disable_warnings
+CREATE TABLE t (
+ a INT,
+ b YEAR GENERATED ALWAYS AS ('a') VIRTUAL,
+ c YEAR GENERATED ALWAYS AS ('aaaa') VIRTUAL,
+ b1 YEAR GENERATED ALWAYS AS ('a') STORED,
+ c1 YEAR GENERATED ALWAYS AS ('aaaa') STORED,
+ UNIQUE(b),
+ UNIQUE(b1)
+);
+INSERT IGNORE INTO t VALUES();
+SELECT b from t;
+SELECT b1 from t;
+SELECT * from t;
+DELETE FROM t;
+CHECK TABLE t EXTENDED;
+DROP TABLE t;
+--enable_warnings
+
+--echo # Bug#22195364:GCOLS: FAILING ASSERTION:
+--echo # DFIELD_IS_NULL(DFIELD2) || DFIELD2->DATA
+CREATE TABLE t (
+ a INT,
+ c BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+ UNIQUE KEY(c(1),a)
+);
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+# Test Field_blob::store_to_mem
+SELECT GROUP_CONCAT(c ORDER BY c) FROM t;
+DROP TABLE t;
+}
+
+--echo #Bug#21929967:GCOLS:GCOL VALUE CHANGES WHEN SESSION CHANGES SQL_MODE
+CREATE TABLE t(c1 INT GENERATED ALWAYS AS (1) VIRTUAL,
+ c2 INT GENERATED ALWAYS AS(2) STORED);
+INSERT INTO t VALUES(DEFAULT, DEFAULT);
+SELECT * FROM t;
+CREATE TABLE t1(c1 INT, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t1(c2) VALUES(DEFAULT);
+SELECT * FROM t1;
+CREATE TABLE t2(c1 INT DEFAULT 1, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t2(c2) VALUES(DEFAULT);
+SELECT * FROM t2;
+DROP TABLE t, t1, t2;
+
+--echo # Bug#22179637: INSERT INTO TABLE FROM SELECT ACCEPTS TO INSERT INTO
+--echo # GENERATED COLUMNS
+CREATE TABLE t1 (
+ i1 INTEGER,
+ i2 INTEGER GENERATED ALWAYS AS (i1 + i1)
+);
+INSERT INTO t1 (i1) SELECT 5;
+INSERT INTO t1 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t1;
+
+CREATE TABLE t2 (
+ i1 INTEGER,
+ i2 INTEGER GENERATED ALWAYS AS (i1 + i1) STORED
+);
+INSERT INTO t2 (i1) SELECT 5;
+INSERT INTO t2 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t2;
+
+DROP TABLE t1,t2;
+
+if ($support_virtual_index)
+{
+
+--echo #
+--echo # Bug#22070021 GCOL:ASSERTION `!TABLE || (!TABLE->WRITE_SET ||
+--echo # BITMAP_IS_SET(TABLE->WRITE_SET,
+--echo #
+
+CREATE TABLE t1(
+c1 INT,
+c2 INT GENERATED ALWAYS AS (c1 + c1) VIRTUAL,
+KEY(c2)
+);
+
+INSERT INTO t1(c1) VALUES(0);
+DELETE O1.* FROM t1 AS O1, t1 AS O2;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21944199 SIMPLE DELETE QUERY CAUSES INNODB: FAILING ASSERTION: 0
+--echo # & DATA CORRUPTION
+--echo #
+
+CREATE TEMPORARY TABLE t1 (
+ a INTEGER NOT NULL,
+ b INTEGER GENERATED ALWAYS AS (a+1) VIRTUAL
+);
+
+INSERT INTO t1 (a) VALUES (0), (0), (0);
+
+ALTER TABLE t1 ADD INDEX idx (b);
+
+DELETE FROM t1;
+
+DROP TEMPORARY TABLE t1;
+
+--echo #
+--echo # Original test case from MDEV-17890
+--echo #
+
+CREATE TABLE t1 (
+ pk BIGINT AUTO_INCREMENT,
+ b BIT(15),
+ v BIT(10) AS (b) VIRTUAL,
+ PRIMARY KEY(pk),
+ UNIQUE(v)
+);
+
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+--disable_ps2_protocol
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+--enable_ps2_protocol
+--error ER_DATA_TOO_LONG
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+
+# Cleanup
+DROP TABLE t1;
+--let $datadir= `SELECT @@datadir`
+--remove_file $datadir/test/load.data
+
+
+--echo #
+--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+--echo #
+
+CREATE TABLE t1 (
+ id INT NOT NULL AUTO_INCREMENT,
+ f ENUM('a','b','c'),
+ v ENUM('a','b','c') AS (f),
+ KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+
+# Cleanup
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (
+ id INT NOT NULL AUTO_INCREMENT,
+ f ENUM('a','b','c'),
+ v ENUM('a','b','c') AS (f),
+ KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+
+# Cleanup
+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/inc/gcol_keys.inc b/mysql-test/suite/gcol/inc/gcol_keys.inc
new file mode 100644
index 00000000..4ae47afc
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_keys.inc
@@ -0,0 +1,822 @@
+################################################################################
+# inc/gcol_keys.inc #
+# #
+# Purpose: #
+# Testing keys, indexes defined upon generated columns. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+if (!$support_virtual_index) {
+ let $skip_spatial_index_check=1;
+ let $skip_foreign_key_check=1;
+}
+
+--echo # - UNIQUE KEY
+--echo # - INDEX
+--echo # - FULLTEXT INDEX
+--echo # - SPATIAL INDEX (not supported)
+--echo # - FOREIGN INDEX (partially supported)
+--echo # - CHECK (allowed but not used)
+
+--echo # UNIQUE
+if($support_virtual_index)
+{
+create table t1 (a int, b int generated always as (a*2) virtual unique);
+show create table t1;
+describe t1;
+drop table t1;
+}
+create table t1 (a int, b int generated always as (a*2) stored unique);
+show create table t1;
+describe t1;
+drop table t1;
+
+if($support_virtual_index)
+{
+create table t1 (a int, b int generated always as (a*2) virtual, unique key (b));
+show create table t1;
+describe t1;
+drop table t1;
+}
+create table t1 (a int, b int generated always as (a*2) stored, unique (b));
+show create table t1;
+describe t1;
+drop table t1;
+
+if($support_virtual_index)
+{
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add unique key (b);
+drop table t1;
+}
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add unique key (b);
+drop table t1;
+
+--echo # Testing data manipulation operations involving UNIQUE keys
+--echo # on generated columns can be found in:
+--echo # - gcol_ins_upd.inc
+--echo # - gcol_select.inc
+
+--echo #
+--echo # INDEX
+if($support_virtual_index)
+{
+create table t1 (a int, b int generated always as (a*2) virtual, index (b));
+show create table t1;
+describe t1;
+drop table t1;
+
+create table t1 (a int, b int generated always as (a*2) virtual, index (a,b));
+drop table t1;
+}
+
+create table t1 (a int, b int generated always as (a*2) stored, index (b));
+show create table t1;
+describe t1;
+drop table t1;
+
+create table t1 (a int, b int generated always as (a*2) stored, index (a,b));
+show create table t1;
+describe t1;
+drop table t1;
+
+if($support_virtual_index)
+{
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add index (b);
+
+alter table t1 add index (a,b);
+drop table t1;
+}
+
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (b);
+drop table t1;
+
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (a,b);
+create table t2 like t1;
+drop table t2;
+drop table t1;
+
+--echo # Testing data manipulation operations involving INDEX
+--echo # on generated columns can be found in:
+--echo # - gcol_select.inc
+
+--echo #
+--echo # TODO: FULLTEXT INDEX
+
+--echo # SPATIAL INDEX
+if (!$skip_spatial_index_check)
+{
+ --echo # Error "All parts of a SPATIAL index must be geometrical"
+ --error ER_WRONG_ARGUMENTS
+ create table t1 (a int, b int generated always as (a+1) stored, spatial index (b));
+ create table t1 (a int, b int generated always as (a+1) stored);
+ --error ER_WRONG_ARGUMENTS
+ alter table t1 add spatial index (b);
+ drop table t1;
+}
+
+--echo # FOREIGN KEY
+
+--echo # Rejected FK options.
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+create table t1 (a int, b int generated always as (a+1) stored,
+ foreign key (b) references t2(a) on update set null);
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+create table t1 (a int, b int generated always as (a+1) stored,
+ foreign key (b) references t2(a) on update cascade);
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+create table t1 (a int, b int generated always as (a+1) stored,
+ foreign key (b) references t2(a) on delete set null);
+
+create table t1 (a int, b int generated always as (a+1) stored);
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add foreign key (b) references t2(a) on update set null;
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add foreign key (b) references t2(a) on update cascade;
+--error ER_WRONG_FK_OPTION_FOR_GENERATED_COLUMN
+alter table t1 add foreign key (b) references t2(a) on delete set null;
+drop table t1;
+
+if(!$skip_foreign_key_check)
+{
+--error ER_CANT_CREATE_TABLE
+create table t1 (a int, b int generated always as (a+1) virtual,
+ foreign key (b) references t2(a));
+
+create table t1 (a int, b int generated always as (a+1) virtual);
+--error ER_CANT_CREATE_TABLE
+alter table t1 add foreign key (b) references t2(a);
+drop table t1;
+}
+
+--echo # Allowed FK options.
+create table t2 (a int primary key, b char(5));
+create table t1 (a int, b int generated always as (a % 10) stored,
+ foreign key (b) references t2(a) on update restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+ foreign key (b) references t2(a) on update no action);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+ foreign key (b) references t2(a) on delete restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+ foreign key (b) references t2(a) on delete cascade);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+ foreign key (b) references t2(a) on delete no action);
+drop table t1,t2;
+
+if($support_virtual_index)
+{
+--echo #
+--echo # Bug#20553262: WL8149: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED
+--echo #
+CREATE TABLE c (
+pk integer AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_datetime_key));
+
+INSERT INTO c ( col_time_nokey,col_datetime_nokey,col_varchar_nokey) values
+('14:03:03.042673','2001-11-28 00:50:27.051028', 'c'),
+('01:46:09.016386','2007-10-09 19:53:04.008332', NULL),
+('16:21:18.052408','2001-11-08 21:02:12.009395', 'x'),
+('18:56:33.027423','2003-04-01 00:00:00', 'i');
+
+--replace_column 9 x 10 x
+EXPLAIN SELECT
+outr.col_time_key AS x
+FROM c as outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+ outr.col_datetime_key = '2009-09-27');
+
+SELECT
+outr.col_time_key AS x
+FROM c AS outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+ outr.col_datetime_key = '2009-09-27');
+
+DROP TABLE c;
+
+--echo #
+--echo # Bug#20913803: WL8149: SIG 11 IN DFIELD_DUP |
+--echo # INNOBASE/INCLUDE/DATA0DATA.IC:253
+--echo #
+CREATE TABLE A (
+col_varchar_nokey TEXT ,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+KEY (col_varchar_key(50))
+);
+
+INSERT INTO A (col_varchar_nokey) VALUES ('');
+
+CREATE TABLE D (
+pk INTEGER AUTO_INCREMENT,
+col_date_nokey BLOB,
+col_date_key BLOB GENERATED ALWAYS AS (REPEAT(col_date_nokey,1000)) VIRTUAL,
+col_datetime_nokey LONGBLOB,
+col_time_nokey LONGTEXT,
+
+col_datetime_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+col_time_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+
+col_varchar_nokey TEXT,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+
+PRIMARY KEY (pk),
+KEY (col_varchar_key(50)),
+KEY (col_date_key(20)),
+KEY (col_time_key(20)),
+KEY (col_datetime_key(20)),
+KEY (col_varchar_key(10), col_date_key(10), col_time_key(5), col_datetime_key(5))
+);
+
+INSERT INTO D (
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES ('', '', '', ''),('', '', '', '');
+
+DELETE FROM OUTR1.* USING D AS OUTR1 RIGHT JOIN A AS OUTR2 ON
+( OUTR1 . `col_varchar_nokey` = OUTR2 . `col_varchar_nokey` );
+
+DROP TABLE IF EXISTS A,D;
+--echo #
+--echo # Bug#21024896: SIG 11 INNOBASE_ADD_ONE_VIRTUAL |
+--echo # INNOBASE/HANDLER/HANDLER0ALTER.CC
+--echo #
+CREATE TABLE t1 (
+ col1 int(11) DEFAULT NULL,
+ col2 int(11) DEFAULT NULL,
+ col3 int(11) NOT NULL,
+ col4 int(11) DEFAULT NULL,
+ col5 int(11) GENERATED ALWAYS AS (col2 / col2) VIRTUAL,
+ col7 int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
+ col8 int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
+ col9 text,
+ col6 int(11) DEFAULT NULL,
+ PRIMARY KEY (`col3`),
+ UNIQUE KEY uidx (`col2`),
+ KEY idx (`col5`)
+);
+
+INSERT INTO t1(col1,col2,col3,col4,col9,col6)
+VALUES(1,1,0,1,REPEAT(col1,1000),0), (3,2,1,1,REPEAT(col1,1000),NULL);
+
+ALTER TABLE t1 ADD COLUMN extra INT;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Bug#21316860: WL8149:INNODB: FAILING ASSERTION:
+--echo # TEMPL->CLUST_REC_FIELD_NO != ULINT_UNDEFINED
+--echo #
+CREATE TABLE t1 (
+ pk int(11) NOT NULL,
+ col_int_nokey int(11),
+ col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+ col_date_nokey date,
+ col_date_key date GENERATED ALWAYS AS (col_date_nokey) VIRTUAL,
+ PRIMARY KEY (pk),
+ UNIQUE KEY col_int_key (col_int_key)
+);
+
+ALTER TABLE t1 DROP COLUMN pk;
+DROP TABLE t1;
+
+--echo # Remove the impact on PK choose by index on virtual generated column
+CREATE TABLE t1 (
+ pk int(11) NOT NULL,
+ col_int_nokey int(11) DEFAULT NULL,
+ col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+ UNIQUE KEY col_int_key (col_int_key)
+);
+
+ALTER TABLE t1 add unique index idx(pk);
+DESC t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21320151 WL8149: WRONG RESULT WITH INDEX SCAN
+--echo #
+
+CREATE TABLE t1 (
+ id INTEGER NOT NULL,
+ b INTEGER GENERATED ALWAYS AS (id+1) VIRTUAL,
+ UNIQUE KEY (b)
+);
+
+INSERT INTO t1 (id) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);
+
+--disable_query_log
+--disable_result_log
+ANALYZE TABLE t1;
+--enable_result_log
+--enable_query_log
+
+# covering index scan
+let query= SELECT b FROM t1 FORCE INDEX(b);
+eval EXPLAIN $query;
+eval $query;
+
+# range scan
+let $query= SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+eval EXPLAIN $query;
+eval $query;
+
+DROP TABLE t1;
+
+}
+--echo
+--echo # Testing data manipulation operations involving FOREIGN KEY
+--echo # on generated columns can be found in:
+--echo # - gcol_ins_upd.inc
+--echo # - gcol_select.inc
+
+--echo #
+--echo # TODO: CHECK
+
+--echo #
+--echo # Test how optimizer picks indexes defined on a GC
+--echo #
+CREATE TABLE t1 (f1 int, gc int AS (f1 + 1) STORED, UNIQUE(gc));
+INSERT INTO t1(f1) VALUES (1),(2),(0),(9),(3),(4),(8),(7),(5),(6);
+ANALYZE TABLE t1;
+--echo # Should use index
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 > 7;
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7;
+
+SELECT * FROM t1 WHERE f1 + 1 = 7;
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 = 7;
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 IN (7,5);
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 IN(7,5);
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+
+--echo # Check that expression isn't transformed for a disabled key
+--sorted_result
+SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+
+--echo # Check that ORDER BY could be optimized
+SELECT * FROM t1 ORDER BY f1 + 1;
+EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) ORDER BY f1 + 1;
+
+--echo # Check that GROUP BY could be optimized
+SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+EXPLAIN SELECT f1 + 1, MAX(GC)
+ FROM t1 IGNORE KEY (gc) GROUP BY f1 + 1;
+
+--echo # Shouldn't use index
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+
+DROP TABLE t1;
+--echo # Pick index with proper type
+CREATE TABLE t1 (f1 int,
+ gc_int int AS (f1 + 1) STORED,
+ gc_date DATE AS (f1 + 1) STORED,
+ KEY gc_int_idx(gc_int),
+ KEY gc_date_idx(gc_date));
+INSERT INTO t1(f1) VALUES
+ (030303),(040404),
+ (050505),(060606),
+ (010101),(020202),
+ (030303),(040404),
+ (050505),(060606),
+ (010101),(020202),
+ (090909),(101010),
+ (010101),(020202),
+ (070707),(080808);
+ANALYZE TABLE t1;
+
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 > 070707;
+--echo # INT column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 070707;
+--sorted_result
+SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+--echo # DATE column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+
+DROP TABLE t1;
+
+--echo #
+--echo # BUG#21229846: WL8170: SIGNAL 11 IN JOIN::MAKE_SUM_FUNC_LIST
+--echo #
+CREATE TABLE t1 (
+ pk int primary key auto_increment,
+ col_int_key INTEGER ,
+ col_int_gc_key INT GENERATED ALWAYS AS (col_int_key + 1) STORED,
+ KEY col_int_gc_key(col_int_gc_key)
+);
+
+INSERT INTO t1 ( col_int_key) VALUES (7);
+
+ANALYZE TABLE t1;
+
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+ FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ ORDER BY field1, field2;
+
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+ FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ ORDER BY field1, field2;
+
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+ FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ GROUP BY field1, field2;
+
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+ FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ GROUP BY field1, field2;
+
+DROP TABLE t1;
+
+if($support_virtual_index)
+{
+--echo #
+--echo # Bug#21391781 ASSERT WHEN RUNNING ALTER TABLE ON A TABLE WITH INDEX
+--echo # ON VIRTUAL COLUMN
+--echo #
+
+#
+# Test 1: column number 2 and 66 are virtual and there is an index
+# on column number 2.
+#
+CREATE TABLE t1 (
+ col1 INTEGER NOT NULL,
+ col2 INTEGER NOT NULL,
+ gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+ col3 INTEGER NOT NULL,
+ col4 INTEGER NOT NULL,
+ col5 INTEGER DEFAULT NULL,
+ col6 INTEGER DEFAULT NULL,
+ col7 INTEGER DEFAULT NULL,
+ col8 INTEGER DEFAULT NULL,
+ col9 INTEGER DEFAULT NULL,
+ col10 INTEGER DEFAULT NULL,
+ col11 INTEGER DEFAULT NULL,
+ col12 INTEGER DEFAULT NULL,
+ col13 INTEGER DEFAULT NULL,
+ col14 INTEGER DEFAULT NULL,
+ col15 INTEGER DEFAULT NULL,
+ col16 INTEGER DEFAULT NULL,
+ col17 INTEGER DEFAULT NULL,
+ col18 INTEGER DEFAULT NULL,
+ col19 INTEGER DEFAULT NULL,
+ col20 INTEGER DEFAULT NULL,
+ col21 INTEGER DEFAULT NULL,
+ col22 INTEGER DEFAULT NULL,
+ col23 INTEGER DEFAULT NULL,
+ col24 INTEGER DEFAULT NULL,
+ col25 INTEGER DEFAULT NULL,
+ col26 INTEGER DEFAULT NULL,
+ col27 INTEGER DEFAULT NULL,
+ col28 INTEGER DEFAULT NULL,
+ col29 INTEGER DEFAULT NULL,
+ col30 INTEGER DEFAULT NULL,
+ col31 INTEGER DEFAULT NULL,
+ col32 INTEGER DEFAULT NULL,
+ col33 INTEGER DEFAULT NULL,
+ col34 INTEGER DEFAULT NULL,
+ col35 INTEGER DEFAULT NULL,
+ col36 INTEGER DEFAULT NULL,
+ col37 INTEGER DEFAULT NULL,
+ col38 INTEGER DEFAULT NULL,
+ col39 INTEGER DEFAULT NULL,
+ col40 INTEGER DEFAULT NULL,
+ col41 INTEGER DEFAULT NULL,
+ col42 INTEGER DEFAULT NULL,
+ col43 INTEGER DEFAULT NULL,
+ col44 INTEGER DEFAULT NULL,
+ col45 INTEGER DEFAULT NULL,
+ col46 INTEGER DEFAULT NULL,
+ col47 INTEGER DEFAULT NULL,
+ col48 INTEGER DEFAULT NULL,
+ col49 INTEGER DEFAULT NULL,
+ col50 INTEGER DEFAULT NULL,
+ col51 INTEGER DEFAULT NULL,
+ col52 INTEGER DEFAULT NULL,
+ col53 INTEGER DEFAULT NULL,
+ col54 INTEGER DEFAULT NULL,
+ col55 INTEGER DEFAULT NULL,
+ col56 INTEGER DEFAULT NULL,
+ col57 INTEGER DEFAULT NULL,
+ col58 INTEGER DEFAULT NULL,
+ col59 INTEGER DEFAULT NULL,
+ col60 INTEGER DEFAULT NULL,
+ col61 INTEGER DEFAULT NULL,
+ col62 INTEGER DEFAULT NULL,
+ col63 INTEGER DEFAULT NULL,
+ col64 INTEGER DEFAULT NULL,
+ col65 INTEGER DEFAULT NULL,
+ gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+ KEY idx1 (gcol1)
+);
+
+INSERT INTO t1 (col1, col2, col3, col4)
+ VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+
+# This will call my_eval_gcolumn_expr to compute the indexed column value
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+
+DROP TABLE t1;
+
+#
+# Test 2: column number 2 and 66 are virtual and there is an index
+# on column number 66.
+#
+CREATE TABLE t1 (
+ col1 INTEGER NOT NULL,
+ col2 INTEGER NOT NULL,
+ gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+ col3 INTEGER NOT NULL,
+ col4 INTEGER NOT NULL,
+ col5 INTEGER DEFAULT NULL,
+ col6 INTEGER DEFAULT NULL,
+ col7 INTEGER DEFAULT NULL,
+ col8 INTEGER DEFAULT NULL,
+ col9 INTEGER DEFAULT NULL,
+ col10 INTEGER DEFAULT NULL,
+ col11 INTEGER DEFAULT NULL,
+ col12 INTEGER DEFAULT NULL,
+ col13 INTEGER DEFAULT NULL,
+ col14 INTEGER DEFAULT NULL,
+ col15 INTEGER DEFAULT NULL,
+ col16 INTEGER DEFAULT NULL,
+ col17 INTEGER DEFAULT NULL,
+ col18 INTEGER DEFAULT NULL,
+ col19 INTEGER DEFAULT NULL,
+ col20 INTEGER DEFAULT NULL,
+ col21 INTEGER DEFAULT NULL,
+ col22 INTEGER DEFAULT NULL,
+ col23 INTEGER DEFAULT NULL,
+ col24 INTEGER DEFAULT NULL,
+ col25 INTEGER DEFAULT NULL,
+ col26 INTEGER DEFAULT NULL,
+ col27 INTEGER DEFAULT NULL,
+ col28 INTEGER DEFAULT NULL,
+ col29 INTEGER DEFAULT NULL,
+ col30 INTEGER DEFAULT NULL,
+ col31 INTEGER DEFAULT NULL,
+ col32 INTEGER DEFAULT NULL,
+ col33 INTEGER DEFAULT NULL,
+ col34 INTEGER DEFAULT NULL,
+ col35 INTEGER DEFAULT NULL,
+ col36 INTEGER DEFAULT NULL,
+ col37 INTEGER DEFAULT NULL,
+ col38 INTEGER DEFAULT NULL,
+ col39 INTEGER DEFAULT NULL,
+ col40 INTEGER DEFAULT NULL,
+ col41 INTEGER DEFAULT NULL,
+ col42 INTEGER DEFAULT NULL,
+ col43 INTEGER DEFAULT NULL,
+ col44 INTEGER DEFAULT NULL,
+ col45 INTEGER DEFAULT NULL,
+ col46 INTEGER DEFAULT NULL,
+ col47 INTEGER DEFAULT NULL,
+ col48 INTEGER DEFAULT NULL,
+ col49 INTEGER DEFAULT NULL,
+ col50 INTEGER DEFAULT NULL,
+ col51 INTEGER DEFAULT NULL,
+ col52 INTEGER DEFAULT NULL,
+ col53 INTEGER DEFAULT NULL,
+ col54 INTEGER DEFAULT NULL,
+ col55 INTEGER DEFAULT NULL,
+ col56 INTEGER DEFAULT NULL,
+ col57 INTEGER DEFAULT NULL,
+ col58 INTEGER DEFAULT NULL,
+ col59 INTEGER DEFAULT NULL,
+ col60 INTEGER DEFAULT NULL,
+ col61 INTEGER DEFAULT NULL,
+ col62 INTEGER DEFAULT NULL,
+ col63 INTEGER DEFAULT NULL,
+ col64 INTEGER DEFAULT NULL,
+ col65 INTEGER DEFAULT NULL,
+ gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+ KEY idx1 (gcol2)
+);
+
+INSERT INTO t1 (col1, col2, col3, col4)
+ VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+
+# This will call my_eval_gcolumn_expr to compute the indexed column value
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+
+SELECT gcol2 FROM t1 FORCE INDEX(idx1);
+
+DROP TABLE t1;
+}
+
+if($support_virtual_index)
+{
+--echo #
+--echo # Bug#21628161 CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
+--echo #
+# When generating the value of column b, an out-of-range warning is
+# raised. A warning is required in order to reproduce the bug, but it
+# is promoted to an error on insertion unless we turn off strict mode.
+CREATE TABLE t (a INT,
+ b BOOLEAN GENERATED ALWAYS AS (a+10000) VIRTUAL,
+ c BLOB GENERATED ALWAYS AS (b=2) VIRTUAL);
+INSERT INTO t(a) VALUES (1);
+# Before index was created, this query returned the expected one match.
+SELECT * FROM t WHERE c = '0';
+# Adding an index sometimes crashed, other times populated it with garbage ...
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD UNIQUE INDEX (c(1));
+# ... so that this query found no match in the index.
+SELECT * FROM t WHERE c = '0';
+DROP TABLE t;
+
+--echo #
+--echo # Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD()
+--echo # DID NOT RETURN TRUE WITH DIVIDE 0
+--echo #
+CREATE TABLE t (a INT, b INT, h VARCHAR(10));
+INSERT INTO t VALUES (12, 3, "ss");
+INSERT INTO t VALUES (13, 4, "ss");
+INSERT INTO t VALUES (14, 0, "ss");
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD c INT GENERATED ALWAYS AS (a/b) VIRTUAL;
+--error ER_DIVISION_BY_ZERO
+CREATE INDEX idx ON t(c);
+CALL mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual column values failed");
+DROP TABLE t;
+}
+
+--echo #
+--echo # Bug#21770798 OPTIMIZER DOES NOT USE INDEX FOR GENERATED EXPRESSIONS
+--echo # WITH LOGICAL OPERATORS
+--echo #
+CREATE TABLE t (a INT, b INT,
+ gc_and INT GENERATED ALWAYS AS (a AND b) STORED,
+ gc_or INT GENERATED ALWAYS AS (a OR b) STORED,
+ gc_xor INT GENERATED ALWAYS AS (a XOR b) STORED,
+ gc_not INT GENERATED ALWAYS AS (NOT a) STORED,
+ gc_case INT GENERATED ALWAYS AS
+ (CASE WHEN (a AND b) THEN a ELSE b END) STORED,
+ INDEX(gc_and), INDEX(gc_or), INDEX(gc_xor), INDEX(gc_not),
+ INDEX(gc_case));
+INSERT INTO t (a, b) VALUES (0, 0), (0, 1), (1, 0), (1, 1);
+ANALYZE TABLE t;
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) = 1;
+SELECT a, b FROM t WHERE (a AND b) = 1;
+EXPLAIN SELECT a, b FROM t WHERE 1 = (a AND b);
+SELECT a, b FROM t WHERE 1 = (a AND b);
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) = 1;
+--sorted_result
+SELECT a, b FROM t WHERE (a OR b) = 1;
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+--sorted_result
+SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+# XOR and NOT worked even before the bug fix, but we test all logical
+# operators here for completeness.
+EXPLAIN SELECT a, b FROM t WHERE (a XOR b) = 1;
+--sorted_result
+SELECT a, b FROM t WHERE (a XOR b) = 1;
+EXPLAIN SELECT a FROM t WHERE (NOT a) = 1;
+SELECT a FROM t WHERE (NOT a) = 1;
+# Also verify that a logical expression nested inside another
+# expression doesn't prevent substitution.
+EXPLAIN SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+--sorted_result
+SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+# The expression must be exactly the same as the generated expression.
+# (b AND a) is not recognized as equivalent to (a AND b).
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b AND a);
+SELECT a, b FROM t WHERE 1 = (b AND a);
+--sorted_result
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b OR a);
+SELECT a, b FROM t WHERE 1 = (b OR a);
+DROP TABLE t;
+
+--echo #
+--echo # Bug#22810883: ASSERTION FAILED:
+--echo # !(USED_TABS & (~READ_TABLES & ~FILTER_FOR_TABLE))
+--echo #
+CREATE TABLE t1 (a1 INTEGER GENERATED ALWAYS AS (1 AND 0) STORED,
+ a2 INTEGER, KEY (a1));
+INSERT INTO t1 VALUES ();
+CREATE TABLE t2 (b INTEGER);
+INSERT INTO t2 VALUES (1);
+ANALYZE TABLE t1, t2;
+--echo # Used to choose the index on a1 and get wrong results.
+--let $query= SELECT * FROM t1 WHERE (a2 AND a2) = 0
+--eval EXPLAIN $query
+--eval $query
+--echo # Used to get assertion or wrong results.
+--let $query= SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1
+--eval EXPLAIN $query
+--eval $query
+DROP TABLE t1, t2;
+
+if($support_virtual_index)
+{
+--echo #
+--echo # MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed
+--echo # in row_upd_sec_index_entry
+--echo #
+CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT,
+ PRIMARY KEY (PK), UNIQUE KEY (VA));
+
+INSERT IGNORE INTO t1 VALUES ( '\r1','a',1);
+--error ER_DATA_TOO_LONG
+REPLACE INTO t1 (PK) VALUES (1);
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17890 Record in index was not found on update, server crash in
+--echo # row_upd_build_difference_binary or
+--echo # Assertion `0' failed in row_upd_sec_index_entry
+--echo #
+CREATE TABLE t1 (
+ pk BIGINT AUTO_INCREMENT,
+ b BIT(15),
+ v BIT(10) AS (b) VIRTUAL,
+ PRIMARY KEY(pk),
+ UNIQUE(v)
+);
+
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+--disable_ps2_protocol
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+--enable_ps2_protocol
+--error ER_DATA_TOO_LONG
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+
+--let $datadir= `SELECT @@datadir`
+--remove_file $datadir/test/load.data
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17834 Server crashes in row_upd_build_difference_binary
+--echo # on LOAD DATA into table with indexed virtual column
+--echo #
+CREATE TABLE t1 (
+ pk INT,
+ i TINYINT,
+ ts TIMESTAMP NULL,
+ vi TINYINT AS (i+1) PERSISTENT,
+ vts TIMESTAMP(5) AS (ts) VIRTUAL,
+ PRIMARY KEY(pk),
+ UNIQUE(vts)
+);
+
+INSERT IGNORE INTO t1 (pk,i) VALUES (1,127);
+
+--write_file $MYSQLTEST_VARDIR/tmp/load.data
+1 4 2019-01-01 00:00:00
+EOF
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--error ER_WARN_DATA_OUT_OF_RANGE
+eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts);
+
+--remove_file $MYSQLTEST_VARDIR/tmp/load.data
+DROP TABLE t1;
+
+--echo # MDEV-19011 Assertion `file->s->base.reclength < file->s->vreclength'
+--echo # failed in ha_myisam::setup_vcols_for_repair
+CREATE TABLE t1 (a INT GENERATED ALWAYS AS (1) VIRTUAL);
+ALTER TABLE t1 ADD KEY (a);
+
+DROP TABLE t1;
+
+}
diff --git a/mysql-test/suite/gcol/inc/gcol_non_stored_columns.inc b/mysql-test/suite/gcol/inc/gcol_non_stored_columns.inc
new file mode 100644
index 00000000..f32487d2
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_non_stored_columns.inc
@@ -0,0 +1,155 @@
+################################################################################
+# inc/gcol_non_stored_columns.inc #
+# #
+# Purpose: #
+# Ensure that MySQL behaviour is consistent irrelevant of #
+# - the place of a non-stored column among other columns, #
+# - the total number of non-stored fields. #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--echo # Case 1. All non-stored columns.
+eval create $opt_tmp table t1 (a int generated always as (2+3) virtual);
+insert into t1 values (default);
+select * from t1;
+insert into t1 values (default);
+select * from t1;
+drop table t1;
+--echo # Case 2. CREATE
+--echo # - Column1: "real"
+--echo # - Column 2: virtual non-stored
+eval create $opt_tmp table t1 (a int, b int generated always as (-a) virtual);
+insert into t1 values (1,default);
+select * from t1;
+insert into t1 values (2,default);
+select * from t1 order by a;
+drop table t1;
+
+--echo # Case 3. CREATE
+--echo # - Column1: "real"
+--echo # - Column 2: virtual stored
+eval create $opt_tmp table t1 (a int, b int generated always as (-a) stored);
+insert into t1 values (1,default);
+select * from t1;
+insert into t1 values (2,default);
+select * from t1 order by a;
+drop table t1;
+
+--echo # Case 4. CREATE
+--echo # - Column1: virtual non-stored
+--echo # - Column2: "real"
+eval create $opt_tmp table t1 (a int generated always as (-b) virtual, b int);
+insert into t1 values (default,1);
+select * from t1;
+insert into t1 values (default,2);
+select * from t1 order by a;
+drop table t1;
+
+--echo # Case 5. CREATE
+--echo # - Column1: virtual stored
+--echo # - Column2: "real"
+eval create $opt_tmp table t1 (a int generated always as (-b) stored, b int);
+insert into t1 values (default,1);
+select * from t1;
+insert into t1 values (default,2);
+select * from t1 order by a;
+drop table t1;
+
+--echo # Case 6. CREATE
+--echo # - Column1: "real"
+--echo # - Column2: virtual non-stored
+--echo # - Column3: virtual stored
+eval create $opt_tmp table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+insert into t1 values (1,default,default);
+select * from t1;
+insert into t1 values (2,default,default);
+select * from t1 order by a;
+drop table t1;
+
+--echo # Case 7. ALTER. Modify virtual stored -> virtual non-stored
+eval create $opt_tmp table t1 (a int, b int generated always as (a % 2) stored);
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+alter table t1 modify b int generated always as (a % 2) virtual;
+show create table t1;
+drop table t1;
+
+--echo # Case 8. ALTER. Modify virtual non-stored -> virtual stored
+eval create $opt_tmp table t1 (a int, b int generated always as (a % 2) virtual);
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+alter table t1 modify b int generated always as (a % 2) stored;
+show create table t1;
+drop table t1;
+
+--echo # Case 9. CREATE LIKE
+--echo # - Column1: "real"
+--echo # - Column2: virtual non-stored
+--echo # - Column3: virtual stored
+eval create $opt_tmp table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+eval create $opt_tmp table t2 like t1;
+insert into t2 values (1,default,default);
+select * from t2;
+insert into t2 values (2,default,default);
+select * from t2 order by a;
+drop table t2;
+drop table t1;
+
+--echo # Case 10. ALTER. Dropping a virtual non-stored column.
+--echo # - Column1: virtual non-stored
+--echo # - Column2: "real"
+eval create $opt_tmp table t1 (a int generated always as (-b) virtual, b int, c varchar(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+alter table t1 drop column a;
+select * from t1 order by b;
+show create table t1;
+drop table t1;
+
+--echo # Case 11. ALTER. Dropping a virtual stored column.
+--echo # - Column1: virtual stored
+--echo # - Column2: "real"
+eval create $opt_tmp table t1 (a int generated always as (-b) stored, b int, c char(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+alter table t1 drop column a;
+select * from t1 order by b;
+show create table t1;
+drop table t1;
+
+--echo # Case 12. ALTER. Adding a new virtual non-stored column.
+eval create $opt_tmp table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+alter table t1 add column c int generated always as (dayofyear(b)) virtual after a;
+select * from t1 order by a;
+show create table t1;
+drop table t1;
+
+--echo # Case 13. ALTER. Adding a new virtual stored column.
+eval create $opt_tmp table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+alter table t1 add column c int generated always as (dayofyear(b)) stored after a;
+select * from t1 order by a;
+show create table t1;
+drop table t1;
+
+--echo # Case 15. ALTER. Changing the expression of a virtual non-stored column.
+eval create $opt_tmp table t1 (a int, b datetime, c int generated always as (week(b)) virtual);
+insert into t1 values (1,'2008-09-04',default);
+insert into t1 values (2,'2008-09-05',default);
+select * from t1 order by a;
+alter table t1 change column c c int generated always as (week(b,1)) virtual;
+select * from t1 order by a;
+show create table t1;
+drop table t1;
+
diff --git a/mysql-test/suite/gcol/inc/gcol_partition.inc b/mysql-test/suite/gcol/inc/gcol_partition.inc
new file mode 100644
index 00000000..50a743c0
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_partition.inc
@@ -0,0 +1,183 @@
+################################################################################
+# inc/gcol_partition.inc #
+# #
+# Purpose: #
+# Testing partitioning tables with generated columns. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--source include/have_partition.inc
+
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+--echo # Case 1. Partitioning by RANGE based on a non-stored generated column.
+
+CREATE TABLE t1 (
+ a DATE NOT NULL,
+ b int generated always as (year(a)) virtual
+)
+PARTITION BY RANGE( b ) (
+ PARTITION p0 VALUES LESS THAN (2006),
+ PARTITION p2 VALUES LESS THAN (2008)
+);
+
+insert into t1 values ('2006-01-01',default);
+insert into t1 values ('2007-01-01',default);
+insert into t1 values ('2005-01-01',default);
+select * from t1;
+
+# Specifically for MyISAM, check that data is written into correct
+# $MYSQLTEST_VARDIR/master-data/test/t1*p?.MYD files
+
+--echo # Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+
+select * from t1;
+
+drop table t1;
+
+--echo # Case 2. Partitioning by LIST based on a stored generated column.
+
+CREATE TABLE t1 (a int, b int generated always as (a % 3 ) stored)
+PARTITION BY LIST (a+1)
+(PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
+
+insert into t1 values (1,default);
+select * from t1;
+
+#
+# NOTE: The following tests are currently failing due to a
+# [suspected] bug in the existing partition functionality.
+# Here is what was observed when using mysqld compiled prior
+# to adding the generated column functionality.
+# mysql> create table t1 (a int) partition by list (a)
+# (partition p1 values in (1), partition p2 values in (2));
+# Query OK, 0 rows affected (0.00 sec)
+#
+# mysql> insert into t1 values (1), (1), (2);
+# Query OK, 3 rows affected (0.00 sec)
+# Records: 3 Duplicates: 0 Warnings: 0
+#
+# mysql> select * from t1;
+# +------+
+# | a |
+# +------+
+# | 1 |
+# | 1 |
+# | 2 |
+# +------+
+# 3 rows in set (0.00 sec)
+#
+# mysql> alter table t1 reorganize partition p1 into
+# (partition p1 values in (3));
+# Query OK, 2 rows affected (3.90 sec)
+# Records: 2 Duplicates: 2 Warnings: 0
+#
+# mysql> select * from t1;
+# +------+
+# | a |
+# +------+
+# | 2 | <- Two row have been lost!!!
+# +------+
+# 1 row in set (0.00 sec)
+
+#
+#alter table t1 change b b virtual int as ((a % 3)+1) stored;
+#--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+#alter table t1 change b b virtual int as (a % 2) stored;
+#if ($myisam_engine)
+#{
+# --echo # Check how data is physically partitioned.
+# --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+# --exec du -b $MYSQLTEST_VARDIR/master-data/test/t1*p?.MYD
+#}
+
+select * from t1;
+
+drop table t1;
+
+--echo # Case 3. Partitioning by HASH based on a non-stored generated column.
+
+CREATE TABLE t1 (
+ a DATE NOT NULL,
+ b int generated always as (year(a)) virtual
+)
+PARTITION BY HASH( b % 3 ) PARTITIONS 3;
+
+insert into t1 values ('2005-01-01',default);
+insert into t1 values ('2006-01-01',default);
+select * from t1;
+
+--echo # Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+
+select * from t1;
+
+drop table t1;
+
+--echo #
+--echo # Bug#21779011 INVALID READS AND SENDING RANDOM SERVER MEMORY BACK
+--echo # TO CLIENT
+--echo #
+
+CREATE TABLE t (
+ c INTEGER GENERATED ALWAYS AS (2) VIRTUAL,
+ d INTEGER,
+ KEY (d)
+) PARTITION BY KEY (d) PARTITIONS 2;
+
+INSERT INTO t (d) VALUES (1),(1),(2),(2);
+
+SELECT c FROM t WHERE d >= 1 GROUP BY d LIMIT 2;
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug#21779554: CHECK_MISPLACED_ROWS BOGUS "FOUND A MISPLACED ROW"
+--echo # AND CRASHES
+--echo #
+CREATE TABLE t(a INT,b INT GENERATED ALWAYS AS (1) VIRTUAL,c INT)
+PARTITION BY KEY (b)PARTITIONS 6;
+INSERT INTO t VALUES();
+CHECK TABLE t EXTENDED;
+FLUSH TABLES;
+CHECK TABLE t EXTENDED;
+DROP TABLE t;
+
+--echo #
+--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+--echo #
+CREATE TABLE t1 (
+ a INT,
+ b INT,
+ c BIT(4) NOT NULL DEFAULT b'0',
+ pk INTEGER AUTO_INCREMENT,
+ d BIT(4) AS (c) VIRTUAL,
+ PRIMARY KEY(pk),
+ KEY (b,d)
+) PARTITION BY HASH(pk);
+INSERT INTO t1 () VALUES (),();
+UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-26220 Server crashes with indexed by prefix virtual column
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
+ KEY (c(10),a)) PARTITION BY HASH(pk);
+INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
+SELECT a FROM t1;
+
+# Cleanup
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/inc/gcol_select.inc b/mysql-test/suite/gcol/inc/gcol_select.inc
new file mode 100644
index 00000000..2386c55f
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_select.inc
@@ -0,0 +1,1172 @@
+##############################################################################
+# inc/gcol_select.inc #
+# #
+# Purpose: #
+# Testing different SELECTs. #
+# #
+# #
+#----------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-18 #
+# Change Author: #
+# Change Date: #
+# Change: #
+##############################################################################
+
+--disable_query_log
+set @local_optimizer_switch=@@optimizer_switch;
+set optimizer_switch='derived_merge=off,join_cache_hashed=off';
+--enable_query_log
+
+# Table t1 is used below to test:
+# - Join type of ALL (sequential scan of the entire table)
+# - Join type of Index
+# - Join type of Range
+# - Join type of Ref_or_null
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored,
+ index (c));
+insert into t1 (a) values (2), (1), (1), (3), (NULL);
+
+# Table t2 is used below to test:
+# - Join type of system and const
+create table t2 like t1;
+insert into t2 (a) values (1);
+
+# Table t3 is used below to test
+# - Join type of Eq_ref with a unique generated column
+# - Join type of Const
+create table t3 (a int primary key,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored unique);
+insert into t3 (a) values (2),(1),(3),(5),(4),(7);
+analyze table t1,t2,t3;
+
+--echo # select_type=SIMPLE, type=system
+let $s = select * from t2;
+eval $s;
+eval explain $s;
+
+let $s = select * from t2 where c=-1;
+eval $s;
+eval explain $s;
+
+--echo # select_type=SIMPLE, type=ALL
+let $s = select * from t1 where b=-1;
+eval $s;
+eval explain $s;
+
+--echo # select_type=SIMPLE, type=const
+let $s = select * from t3 where a=1;
+eval $s;
+eval explain $s;
+
+--echo # select_type=SIMPLE, type=range
+let $s = select * from t3 where c>=-1;
+eval $s;
+eval explain $s;
+
+--echo # select_type=SIMPLE, type=ref
+let $s = select * from t1,t3 where t1.c=t3.c and t3.c=-1;
+eval $s;
+eval explain $s;
+
+--echo # select_type=PRIMARY, type=index,ALL
+let $s = select * from t1 where b in (select c from t3);
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo # select_type=PRIMARY, type=range,ref
+--sorted_result
+let $s = select * from t1 where c in (select c from t3 where c between -2 and -1);
+eval $s;
+eval explain $s;
+
+--echo # select_type=UNION, type=system
+--echo # select_type=UNION RESULT, type=<union1,2>
+let $s = select * from t1 union select * from t2;
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo # select_type=DERIVED, type=system
+let $s = select * from (select a,b,c from t1) as t11;
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo ###
+--echo ### Using aggregate functions with/without DISTINCT
+--echo ###
+--echo # SELECT COUNT(*) FROM tbl_name
+let $s = select count(*) from t1;
+eval $s;
+eval explain $s;
+
+--echo # SELECT COUNT(DISTINCT <non-gcol>) FROM tbl_name
+let $s = select count(distinct a) from t1;
+eval $s;
+eval explain $s;
+
+--echo # SELECT COUNT(DISTINCT <non-stored gcol>) FROM tbl_name
+let $s = select count(distinct b) from t1;
+eval $s;
+eval explain $s;
+
+--echo # SELECT COUNT(DISTINCT <stored gcol>) FROM tbl_name
+let $s = select count(distinct c) from t1;
+eval $s;
+eval explain $s;
+
+--echo ###
+--echo ### filesort & range-based utils
+--echo ###
+--echo # SELECT * FROM tbl_name WHERE <gcol expr>
+let $s = select * from t3 where c >= -2;
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <non-gcol expr>
+let $s = select * from t3 where a between 1 and 2;
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <non-indexed gcol expr>
+let $s = select * from t3 where b between -2 and -1;
+--sorted_result
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <indexed gcol expr>
+let $s = select * from t3 where c between -2 and -1;
+--sorted_result
+eval $s;
+eval explain $s;
+
+#### Remove for MyISAM due to a bug
+#### when all the three records are returned (a=1,2,3)
+#### instead of just two (a=1,2).
+#### This bug is presumably in base SQL routines as the same happens
+#### with this table:
+#### create table t4 (a int primary key, b int, c int unique);
+let $myisam_engine = `SELECT @@session.default_storage_engine='myisam'`;
+if (!$myisam_engine)
+{
+ --echo # SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed gcol>
+ let $s = select * from t3 where a between 1 and 2 order by b;
+ eval $s;
+ eval explain $s;
+ --echo # bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC
+ --echo # SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed stored gcol>
+ let $s = select * from t3 where a between 1 and 2 order by c;
+ eval $s;
+ eval explain $s;
+}
+--echo # bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC
+CREATE TABLE t4 (
+ `pk` int(11) NOT NULL ,
+ `col_int_nokey` int(11) GENERATED ALWAYS AS (pk + col_int_key) STORED,
+ `col_int_key` int(11) DEFAULT NULL,
+ `col_date_nokey` date DEFAULT NULL,
+ `col_datetime_key` datetime DEFAULT NULL,
+ PRIMARY KEY (`pk`),
+ KEY `col_int_key` (`col_int_key`),
+ KEY `col_datetime_key` (`col_datetime_key`)
+);
+
+INSERT INTO t4 VALUES
+(1,default,4,'2008-12-05','1900-01-01 00:00:00');
+
+SELECT
+SQL_BIG_RESULT
+GRANDPARENT1 . `col_int_nokey` AS g1
+FROM t4 AS GRANDPARENT1 LEFT JOIN t4 AS GRANDPARENT2 ON ( GRANDPARENT2 .
+`col_datetime_key` <= GRANDPARENT1 . `col_date_nokey` )
+GROUP BY GRANDPARENT1 . `pk`;
+DROP TABLE t4;
+
+--echo # SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <indexed gcol>
+let $s = select * from t3 where a between 1 and 2 order by c;
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-gcol>
+let $s = select * from t3 where b between -2 and -1 order by a;
+eval $s;
+eval explain $s;
+
+#### Remove for MyISAM due to a bug
+#### when all the three records are returned (a=1,2,3)
+#### instead of just two (a=1,2).
+#### This bug is presumably in base SQL routines as the same happens
+#### with this table:
+#### create table t4 (a int primary key, b int, c int unique);
+let $innodb_engine = `SELECT @@session.default_storage_engine='innodb'`;
+if (!$innodb_engine)
+{
+ --echo # SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-gcol>
+ let $s = select * from t3 where c between -2 and -1 order by a;
+ eval $s;
+ eval explain $s;
+}
+
+--echo # SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-indexed gcol>
+let $s = select * from t3 where b between -2 and -1 order by b;
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-indexed gcol>
+let $s = select * from t3 where c between -2 and -1 order by b;
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <indexed gcol>
+let $s = select * from t3 where b between -2 and -1 order by c;
+eval $s;
+eval explain $s;
+
+--echo # SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <indexed gcol>
+let $s = select * from t3 where c between -2 and -1 order by c;
+eval $s;
+eval explain $s;
+
+--echo # SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+let $s = select sum(b) from t1 group by b;
+eval $s;
+eval explain $s;
+
+--echo # SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+let $s = select sum(c) from t1 group by c;
+eval $s;
+eval explain $s;
+
+--echo # SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+let $s = select sum(b) from t1 group by c;
+eval $s;
+eval explain $s;
+
+--echo # SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+let $s = select sum(c) from t1 group by b;
+eval $s;
+eval explain $s;
+
+drop table t1;
+
+--echo #
+--echo # Bug#20241655: WL411:FAILING ASSERTION ASSERTION
+--echo #
+CREATE TABLE BB (
+ col_time_key time NOT NULL,
+ col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+ col_datetime_key datetime NOT NULL);
+INSERT INTO BB VALUES('23:28:02', default, '2005-03-15 22:48:25');
+
+CREATE TABLE CC (
+ col_time_key time NOT NULL,
+ col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+ col_datetime_key datetime NOT NULL
+);
+INSERT INTO CC VALUES('16:22:51', default, '1900-01-01 00:00:00');
+
+SELECT 1 AS g1 FROM BB AS gp1 LEFT JOIN BB AS gp2 USING ( col_time_nokey);
+DROP TABLE BB, CC;
+
+--echo #
+--echo # Bug#20328786: WL411:VALGRIND WARNINGS OF CONDITIONAL
+--echo # JUMP WHILE SELECTING FROM VIEW
+--echo #
+CREATE TABLE A (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+ PRIMARY KEY (pk)
+);
+
+CREATE TABLE C (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+ col_varchar_nokey VARCHAR(1),
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_varchar_key, col_int_key)
+);
+
+INSERT INTO C (
+ col_int_nokey,
+ col_varchar_nokey
+) VALUES (4, 'v'),(62, 'v'),(7, 'c'),(1, NULL),(0, 'x'),(7, 'i'),(7, 'e'),(1, 'p'),(7, 's'),(1, 'j'),(5, 'z'),(2, 'c'),(0, 'a'),(1, 'q'),(8, 'y'),(1, NULL),(1, 'r'),(9, 'v'),(1, NULL),(5, 'r');
+
+CREATE OR REPLACE ALGORITHM=MERGE VIEW V1 AS SELECT alias1.
+col_varchar_key AS field1 , alias1.pk AS field2, alias2.
+col_int_nokey AS field3 FROM C AS alias1 LEFT JOIN A AS alias2 ON
+alias1.pk = alias2.col_int_key WHERE alias1.pk > 8 AND alias1
+.pk < ( 9 + 2 ) AND alias1.col_int_key <> 1 OR alias1.col_int_key
+> 0 AND alias1.col_int_key <= ( 3 + 2 ) ORDER BY field1, field2, field3
+LIMIT 100 OFFSET 6;
+
+SELECT * FROM V1;
+
+DROP VIEW V1;
+DROP TABLE A,C;
+
+--echo #
+--echo # Bug#20406510: WL411:VALGRIND WARNINGS WITH
+--echo # COUNT DISTINCT QUERY ON VIRTUAL GC VARCHAR COLUMN
+--echo #
+CREATE TABLE A (
+ pk INTEGER AUTO_INCREMENT,
+ col_time_key TIME NOT NULL,
+ col_datetime_key DATETIME NOT NULL,
+ PRIMARY KEY (pk),
+ KEY (col_time_key),
+ KEY (col_datetime_key)
+);
+
+CREATE TABLE C (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_key INTEGER NOT NULL,
+ col_varchar_key VARCHAR(1) NOT NULL,
+ col_varchar_nokey VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_key, col_varchar_key)),
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_varchar_key, col_int_key)
+);
+
+INSERT INTO C (col_int_key,col_varchar_key) VALUES (0, 'j'),(8, 'v'),(1, 'c'),(8, 'm'),(9, 'd');
+SELECT MIN( alias2 . col_int_key ) AS field1,
+COUNT( DISTINCT alias2 . col_varchar_nokey ) AS field2
+FROM ( A AS alias1 , C AS alias2 )
+ORDER BY alias1.col_time_key, alias1.col_datetime_key, alias1.pk ASC;
+DROP TABLE A,C;
+
+--echo #
+--echo # Bug#20566325: WL8149: INNODB: FAILING ASSERTION:
+--echo # COL_NR < TABLE->N_DEF
+--echo #
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+
+INSERT /*! IGNORE */ INTO A (col_varchar_nokey) VALUES ('k');
+
+CREATE TABLE CC (
+pk INTEGER AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk));
+
+INSERT INTO CC (col_time_nokey,col_datetime_nokey,col_varchar_nokey) VALUES
+('13:06:13.033877','1900-01-01 00:00:00', 'p'),
+(NULL, '2007-05-25 11:58:54.015689', 'g');
+
+SELECT
+table1.col_time_key AS field1,
+'z' AS field2
+FROM
+(CC AS table1 LEFT OUTER JOIN (A AS table2 STRAIGHT_JOIN CC AS table3 ON
+(table3.col_varchar_key = table2.col_varchar_nokey)) ON
+(table3.col_varchar_key = table2.col_varchar_nokey))
+WHERE
+table2.pk != 6
+AND table1.col_varchar_key IN ('l', 's' , 'b' )
+AND table3.col_varchar_key != table1.col_varchar_key
+ORDER BY table1.col_varchar_key , field1 , field2;
+
+DROP TABLE A,CC;
+
+if ($support_virtual_index)
+{
+--echo #
+--echo # Bug#20573302: WL8149: SEGV IN HA_INNOBASE::
+--echo # BUILD_TEMPLATE AT INNOBASE/HANDLER/HA_INNODB.CC:665
+--echo #
+CREATE TABLE c (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+
+ col_date_nokey DATE NOT NULL,
+ col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+
+ col_datetime_nokey DATETIME NOT NULL,
+ col_time_nokey TIME NOT NULL,
+
+ col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+ col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_varchar_key),
+ KEY (col_date_key),
+ KEY (col_time_key),
+ KEY (col_datetime_key),
+ KEY (col_int_key, col_varchar_key),
+ KEY (col_int_key, col_varchar_key, col_date_key,
+ col_time_key, col_datetime_key));
+
+INSERT /*! IGNORE */ INTO c (
+ col_int_nokey,
+ col_date_nokey,
+ col_time_nokey,
+ col_datetime_nokey,
+ col_varchar_nokey
+ ) VALUES
+(1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't'),
+(6, '2007-06-18', NULL, '2002-08-20 22:48:00.035785', 'd'),
+(2, '2002-10-13', '00:00:00', '1900-01-01 00:00:00', 's'),
+(4, '1900-01-01', '15:57:25.019666', '2005-08-15 00:00:00', 'r'),
+(8, NULL, '07:05:51.006712', '1900-01-01 00:00:00', 'm'),
+(4, '2006-03-09', '19:22:21.057406', '2008-05-16 08:09:06.002924', 'b'),
+(4, '2001-06-05', '03:53:16.001370', '2001-01-20 12:47:23.022022', 'x'),
+(7, '2006-05-28', '09:16:38.034570', '2008-07-02 00:00:00', 'g'),
+(4, '2001-04-19', '15:37:26.028315', '1900-01-01 00:00:00', 'p'),
+(1, '1900-01-01', '00:00:00', '2002-12-08 11:34:58.001571', 'q'),
+(9, '2004-08-20', '05:03:03.047452', '1900-01-01 00:00:00', 'w'),
+(4, '2004-10-10', '02:59:24.063764', '1900-01-01 00:00:00', 'd'),
+(8, '2000-04-02', '00:01:58.064243', '2002-08-25 20:35:06.064634', 'e'),
+(4, '2006-11-02', '00:00:00', '2001-10-22 11:13:24.048128', 'b'),
+(8, '2009-01-28', '02:20:16.024931', '2003-03-12 02:00:34.029335', 'y');
+
+CREATE TABLE cc (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+
+ col_date_nokey DATE NOT NULL,
+ col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+
+ col_datetime_nokey DATETIME NOT NULL,
+ col_time_nokey TIME NOT NULL,
+
+ col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+ col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_varchar_key),
+ KEY (col_date_key),
+ KEY (col_time_key),
+ KEY (col_datetime_key),
+ KEY (col_int_key, col_varchar_key),
+ KEY (col_int_key, col_varchar_key, col_date_key,
+ col_time_key, col_datetime_key));
+
+INSERT /*! IGNORE */ INTO cc (
+ col_int_nokey,
+ col_date_nokey,
+ col_time_nokey,
+ col_datetime_nokey,
+ col_varchar_nokey
+ ) VALUES
+(0, '2003-02-06', '22:02:09.059926', '2003-08-07 14:43:09.011144', 'x'),
+(0, '2005-04-16', '19:33:15.014160', '2005-12-11 00:00:00', 'n'),
+(1, '2005-07-23', '22:03:16.058787', '2005-12-26 20:48:07.043628', 'w'),
+(7, '2001-11-15', '06:31:23.027263', '2008-06-12 06:41:21.012493', 's'),
+(0, '2006-03-24', '02:19:08.013275', '2007-10-11 18:46:28.030000', 'a'),
+(4, '2008-07-10', NULL, '2006-04-04 22:22:40.057947', 'd'),
+(1, '2009-12-07', NULL, '2002-08-10 20:52:58.035137', 'w'),
+(1, '2008-05-01', '10:28:01.038587', '2008-10-03 11:17:23.005299', 'j'),
+(1, '2008-06-22', '00:00:00', '2009-01-06 20:11:01.034339', 'm'),
+(4, '2001-11-11', '15:02:50.048785', '2009-09-19 00:00:00', 'k'),
+(7, '2000-12-21', '05:29:13.012729', '2007-09-02 12:14:27.029187', 't'),
+(4, '2007-09-03', '23:45:33.048507', '2003-09-26 00:00:00', 'k'),
+(2, '2003-02-18', '19:10:53.057455', '2001-11-18 18:10:16.063189', 'e'),
+(0, '2008-12-01', '01:45:27.037313', '2005-02-15 04:08:17.015554', 'i'),
+(1, '2008-10-18', '03:56:03.060218', '2009-06-13 23:04:40.013006', 't'),
+(91, '2004-08-28', '12:43:17.023797', '1900-01-01 00:00:00', 'm'),
+(6, '2006-10-05', '13:33:46.053634', '2005-03-20 02:48:24.045653', 'z'),
+(3, '2003-05-16', NULL, '2002-03-16 11:47:27.045297', 'c'),
+(6, '2008-10-10', NULL, '2000-05-22 00:00:00', 'i'),
+(8, '2002-01-19', '05:18:40.006865', '2009-02-12 00:00:00', 'v');
+
+--replace_column 9 # 10 #
+EXPLAIN
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+ (c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+ (subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+ (subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+ (c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+ (subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+ (subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+ (c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+ (subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+ (subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+
+DROP TABLE c,cc;
+
+--echo #
+--echo # Bug#2081065: WL8149:RESULT DIFF SEEN FOR SIMPLE
+--echo # RANGE QUERIES WITH ORDER BY
+--echo #
+CREATE TABLE cc (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_int_key INTEGER GENERATED ALWAYS AS
+ (col_int_nokey + col_int_nokey) VIRTUAL,
+ PRIMARY KEY (pk),
+ KEY (col_int_key)
+);
+INSERT INTO cc (col_int_nokey) VALUES (0),(1),(7),(0),(4),(5);
+--replace_column 9 # 10 #
+EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3;
+SELECT pk FROM cc WHERE col_int_key > 3;
+--replace_column 9 # 10 #
+EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1;
+SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1;
+DROP TABLE cc;
+
+--echo #
+--echo # Bug#20849676 :WL8149:ASSERTION `!TABLE || (!TABLE->READ_SET
+--echo # || BITMAP_IS_SET(TABLE->READ_SET
+--echo #
+CREATE TABLE c (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_int_key INTEGER GENERATED ALWAYS AS
+ (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_varchar_key),
+ KEY (col_int_key, col_varchar_key)
+) ;
+
+INSERT INTO c (col_int_nokey, col_varchar_nokey) VALUES
+(1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'),(6, 'd'),
+(2, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'),(1, 'q'),
+(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y');
+
+CREATE TABLE a (
+ pk INTEGER AUTO_INCREMENT,
+ col_datetime_nokey DATETIME NOT NULL,
+ col_time_nokey TIME NOT NULL,
+ col_datetime_key DATETIME GENERATED ALWAYS AS
+ (ADDTIME(col_datetime_nokey, col_time_nokey)),
+ col_time_key TIME GENERATED ALWAYS AS
+ (ADDTIME(col_datetime_nokey, col_time_nokey)),
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+ PRIMARY KEY (pk),
+ KEY (col_varchar_key),
+ KEY (col_time_key),
+ KEY (col_datetime_key),
+ KEY (col_varchar_key, col_time_key, col_datetime_key)
+);
+
+INSERT INTO a (
+ col_time_nokey,
+ col_datetime_nokey,
+ col_varchar_nokey) VALUES
+('04:08:02.046897', '2001-11-04 19:07:55.051133', 'k');
+
+ANALYZE TABLE a, c;
+
+--replace_column 9 #
+--disable_warnings
+EXPLAIN
+SELECT
+table1.pk AS field1 ,
+table1.col_datetime_key AS field2
+FROM
+( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT
+SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2
+STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key =
+SUBQUERY1_t2.col_varchar_key ) )
+ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key
+OR SUBQUERY1_t1.col_int_key <> 1 ) )
+WHERE SUBQUERY1_t2.pk >= 9 ) AS table3
+ON (table3.col_int_key = table2.col_int_key ) ) )
+ON (table3.col_int_nokey = table2.pk ) )
+GROUP BY field1, field2;
+SELECT
+table1.pk AS field1 ,
+table1.col_datetime_key AS field2
+FROM
+( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT
+SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2
+STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key =
+SUBQUERY1_t2.col_varchar_key ) )
+ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key
+OR SUBQUERY1_t1.col_int_key <> 1 ) )
+WHERE SUBQUERY1_t2.pk >= 9 ) AS table3
+ON (table3.col_int_key = table2.col_int_key ) ) )
+ON (table3.col_int_nokey = table2.pk ) )
+GROUP BY field1, field2;
+
+--enable_warnings
+DROP TABLE IF EXISTS c,a;
+CREATE TABLE c (
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS
+ (col_int_nokey + col_int_nokey) VIRTUAL,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+
+KEY (col_int_key),
+KEY (col_int_key, col_varchar_key)
+) ;
+
+INSERT INTO c (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'),
+(6, 'd'),(2, 's'),(4, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'),
+(1, 'q'),(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y');
+
+CREATE TABLE cc (
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+KEY (col_int_key),
+KEY (col_varchar_key),
+KEY (col_int_key, col_varchar_key),
+KEY (col_int_key, col_int_nokey),
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO cc (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (8, 'p'),(9, 'g'),(9, 'i'),(4, 'p'),(7, 'h'),(1, 'e'),(8, 'e'),(6, 'u'),
+(6, 'j'),(6, 'e'),(1, 'z'),(227, 'w'),(NULL, 't'),(9, 'i'),(1, 'i'),(8, 'i'),
+(5, 'b'),(8,'m'),(7, 'j'),(2, 'v');
+ANALYZE TABLE c, cc;
+
+--replace_column 9 #
+--disable_warnings
+
+let query=SELECT
+alias2 . col_varchar_key AS field1
+FROM ( cc AS alias1 , cc AS alias2 )
+WHERE
+( alias2 . col_int_key , alias1 . col_int_nokey )
+NOT IN
+(
+SELECT
+DISTINCT SQ1_alias2 . col_int_nokey AS SQ1_field1 ,
+SQ1_alias1 . col_int_key AS SQ1_field2
+FROM ( cc AS SQ1_alias1 , c AS SQ1_alias2 )
+GROUP BY SQ1_field1 , SQ1_field2
+)
+GROUP BY field1;
+
+eval EXPLAIN $query;
+eval $query;
+
+DROP TABLE IF EXISTS c,cc;
+
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+CREATE TABLE d (
+ col_int int(11) DEFAULT NULL,
+ col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL,
+ pk int(11) NOT NULL AUTO_INCREMENT,
+ col_int_key int(11) GENERATED ALWAYS AS (col_int+col_int) VIRTUAL,
+ col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT(SUBSTRING(col_varchar_10_utf8, -1), 5)) VIRTUAL,
+ PRIMARY KEY (pk),
+ KEY col_int_key (col_int_key),
+ KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key),
+ KEY cover_key1 (col_int_key, col_varchar_10_utf8_key)
+);
+
+INSERT INTO d (col_int, col_varchar_10_utf8) VALUES ('qhlhtrovam',1),('how',2),('htrovamzqr',3),('rovamzqrdc',4),('well',5),('g',6),('rdcenchyhu',7),('want',8);
+
+SELECT table1.pk AS field1 FROM d AS table1 LEFT JOIN d AS table2 ON table1.col_varchar_10_utf8_key = table2.col_varchar_10_utf8_key WHERE table1.col_int_key IS NULL GROUP BY table1.pk ;
+
+DROP TABLE d;
+
+--echo #
+--echo # Bug#21153237: WL8149: QUERIES USING FILESORT
+--echo # ON VIRTUAL GC HAVING INDEX GIVES WRONG RESULTS
+--echo #
+CREATE TABLE j (
+col_int int(11),
+pk int(11) NOT NULL,
+col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL,
+col_varchar_255_utf8_key varchar(255) CHARACTER SET utf8 GENERATED ALWAYS AS
+(col_varchar_10_utf8) VIRTUAL,
+PRIMARY KEY (pk),
+KEY cover_key1 (col_int, col_varchar_255_utf8_key));
+
+INSERT INTO j(col_int, pk, col_varchar_10_utf8) VALUES(9, 1, '951910400'),
+(-1934295040, 2, '1235025920'),(-584581120, 3, '-1176633344'),(3, 4, '1074462720');
+
+--replace_column 9 #
+EXPLAIN SELECT col_varchar_255_utf8_key FROM j ORDER BY 1;
+SELECT col_varchar_255_utf8_key FROM j ORDER BY col_varchar_255_utf8_key;
+
+DROP TABLE j;
+
+set sql_mode= @save_old_sql_mode;
+--enable_warnings
+}
+
+CREATE TABLE cc (
+ pk int(11) NOT NULL AUTO_INCREMENT,
+ col_int_nokey int(11) NOT NULL,
+ col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) STORED,
+ col_date_nokey date NOT NULL,
+ col_date_key date GENERATED ALWAYS AS (col_date_nokey) STORED,
+ col_datetime_nokey datetime NOT NULL,
+ col_time_nokey time NOT NULL,
+ col_datetime_key datetime GENERATED ALWAYS AS (col_datetime_nokey)STORED,
+ col_time_key time GENERATED ALWAYS AS (col_time_nokey) STORED,
+ col_varchar_nokey varchar(1) NOT NULL,
+ col_varchar_key varchar(1) GENERATED ALWAYS AS (col_varchar_nokey)STORED,
+ PRIMARY KEY (pk),
+ KEY gc_idx1 (col_int_key),
+ KEY gc_idx2 (col_varchar_key),
+ KEY gc_idx3 (col_date_key),
+ KEY gc_idx4 (col_time_key),
+ KEY gc_idx5 (col_datetime_key),
+ KEY gc_idx6 (col_varchar_key,col_int_key),
+ KEY gc_idx7 (col_date_key,col_datetime_key,col_time_key),
+ KEY gc_idx8(col_int_key,col_varchar_key,col_date_key,col_time_key,
+ col_datetime_key)
+);
+
+INSERT INTO cc (
+ col_int_nokey,
+ col_date_nokey,
+ col_time_nokey,
+ col_datetime_nokey,
+ col_varchar_nokey
+) VALUES (1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't');
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+
+# Warnings arrive in unpredictable order with NDB and cannot be sorted
+if ($testing_ndb)
+{
+--disable_warnings
+}
+SELECT DISTINCT alias1.col_varchar_key AS field1
+FROM ( cc AS alias1 STRAIGHT_JOIN
+ (( cc AS alias2 STRAIGHT_JOIN cc AS alias3 ON
+ (alias3.col_varchar_key > alias2.col_varchar_key ) ) ) ON
+ (( alias3 .pk >= alias2.col_int_nokey ) AND
+ (alias3 .pk >= alias2.col_int_nokey ) ))
+WHERE alias1.col_varchar_key <= 'v'
+GROUP BY field1 HAVING field1 = 91
+ORDER BY field1, alias1.col_date_key, field1 ASC, field1 DESC,
+ alias1.col_time_key ASC, field1;
+DROP TABLE cc;
+SET sql_mode=@save_old_sql_mode;
+if ($testing_ndb)
+{
+--enable_warnings
+}
+
+--echo #
+--echo # Bug#20797941: WL8149:ASSERTION !TABLE ||
+--echo # (!TABLE->READ_SET || BITMAP_IS_SET(TABLE->READ_SET
+--echo #
+CREATE TABLE t(a int, b int as(a+1));
+INSERT INTO t(a) values(1),(2);
+SELECT * FROM t ORDER BY b;
+DROP TABLE t;
+
+if ($support_virtual_index)
+{
+--echo #
+--echo # Testing a few index-based accesses on the virtual column
+--echo #
+
+CREATE TABLE t1 (
+id int(11) NOT NULL,
+b int(11) GENERATED ALWAYS AS (id+1) VIRTUAL,
+UNIQUE KEY (b) );
+
+--error ER_BAD_NULL_ERROR
+INSERT INTO t1 (id) VALUES(NULL);
+
+INSERT INTO t1 (id) VALUES(2),(3);
+
+# constant table read with one index lookup
+EXPLAIN SELECT * FROM t1 FORCE INDEX(b) WHERE b=3;
+
+# eq_ref
+EXPLAIN SELECT * FROM t1 AS t2 STRAIGHT_JOIN t1 FORCE INDEX(b) WHERE t1.b=t2.b;
+
+# covering index scan
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b);
+
+# range scan
+INSERT INTO t1 (id) VALUES(4),(5),(6),(7),(8),(9),(10);
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+
+# index-subquery
+EXPLAIN SELECT * FROM t2 AS t1 WHERE b NOT IN (SELECT b FROM t1 FORCE INDEX(b));
+
+DROP TABLE t1;
+}
+
+DROP TABLE t2, t3;
+
+--echo #
+--echo # Bug#21317507:GC: STORED COLUMN REJECTED, BUT VIRTUAL IS ACCEPTED
+--echo #
+--disable_abort_on_error
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN b;
+ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN c;
+ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN d;
+ALTER TABLE t1 ADD COLUMN c INT AS(a) VIRTUAL;
+ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL;
+ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL;
+SELECT * FROM t1;
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN h INT AS (a) VIRTUAL;
+ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, ALGORITHM=COPY;
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ALTER TABLE t1 ADD COLUMN e SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ALTER TABLE t1 ADD COLUMN f SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED;
+ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=EXCLUSIVE;
+--enable_abort_on_error
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21980430 GCOLS: CRASHING
+--echo #
+CREATE TABLE t (
+ a INT,
+ b BLOB,
+ c BLOB GENERATED ALWAYS AS (a+b) VIRTUAL,
+ UNIQUE KEY i0008 (a)
+);
+
+INSERT INTO t(a,b) VALUES(1,'cccc');
+let $query=
+SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
+WHERE b.b>c.a;
+eval EXPLAIN $query;
+eval $query;
+DROP TABLE t;
+
+# Force DS-MRR to be used
+set @optimizer_switch_save = @@optimizer_switch;
+set optimizer_switch='mrr_cost_based=off';
+
+# Reduce the size of the DS-MRR sort buffer to force multiple rounds
+set @read_rnd_buffer_size_save= @@read_rnd_buffer_size;
+set read_rnd_buffer_size=32;
+
+CREATE TABLE t0 (
+ i1 INTEGER NOT NULL
+);
+
+INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+CREATE TABLE t1 (
+ pk INTEGER NOT NULL,
+ i1 INTEGER NOT NULL,
+ i2 INTEGER NOT NULL,
+ v1 INTEGER GENERATED ALWAYS AS (i2 + 1) VIRTUAL,
+ v2 INTEGER GENERATED ALWAYS AS (i1 / (i1 - i2 + 57)) VIRTUAL,
+ PRIMARY KEY (pk),
+ INDEX idx(i1)
+);
+
+INSERT INTO t1 (pk, i1, i2)
+SELECT a0.i1 + a1.i1*10 + a2.i1*100,
+ a0.i1 + a1.i1*10,
+ a0.i1 + a1.i1*10
+FROM t0 AS a0, t0 AS a1, t0 AS a2;
+
+# Do a DS-MRR scan on an index on a non-generated column
+# (this caused Division by 0 errors to be reported).
+let query1=
+SELECT * FROM t1
+WHERE i1 > 41 AND i1 <= 43;
+
+eval EXPLAIN $query1;
+--sorted_result
+eval $query1;
+
+if ($support_virtual_index)
+{
+ALTER TABLE t1 ADD INDEX idx2(v1);
+}
+
+# Do a DS-MRR scan on an index on a virtual column
+# (this query returned too few records).
+let query2=
+SELECT * FROM t1
+WHERE v1 > 41 AND v1 <= 43;
+
+--replace_column 9 #
+eval EXPLAIN $query2;
+--sorted_result
+eval $query2;
+
+DROP TABLE t0, t1;
+
+# Restore defaults
+set optimizer_switch= @optimizer_switch_save;
+set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
+
+--echo #
+--echo # Bug#21872184 CONDITIONAL JUMP AT JOIN_CACHE::WRITE_RECORD_DATA IN
+--echo # SQL_JOIN_BUFFER.CC
+--echo #
+
+--echo #
+--echo # Test 1: Dynamic range scan with one covering index
+--echo #
+
+# This is the original test case which produces the valgrind error when
+# inserting data into the join buffer. The test failure only occurs with
+# InnoDB since it is only InnoDB that currently supports indexes on
+# virtual columns and is the only storage engine that includes the
+# primary key in each secondary key.
+
+CREATE TABLE t1 (
+ i1 INTEGER NOT NULL,
+ c1 VARCHAR(1) NOT NULL
+);
+
+INSERT INTO t1
+VALUES (10, 'c'), (10, 'i'), (2, 't'), (4, 'g');
+
+CREATE TABLE t2 (
+ i1 INTEGER NOT NULL,
+ c1 VARCHAR(1) NOT NULL
+);
+
+INSERT INTO t2
+VALUES (2, 'k'), (9, 'k'), (7, 'o'), (5, 'n'), (7, 'e');
+
+CREATE TABLE t3 (
+ pk INTEGER NOT NULL,
+ i1 INTEGER,
+ i2_key INTEGER GENERATED ALWAYS AS (i1 + i1) VIRTUAL,
+ PRIMARY KEY (pk)
+);
+
+if ($support_virtual_index)
+{
+--echo # Add a covering index. The reason for this index being covering is that
+--echo # secondary indexes in InnoDB include the primary key.
+ALTER TABLE t3 ADD INDEX v_idx (i2_key);
+}
+
+INSERT INTO t3 (pk, i1)
+VALUES (1, 1), (2, 48), (3, 228), (4, 3), (5, 5),
+ (6, 39), (7, 6), (8, 8), (9, 3);
+
+CREATE TABLE t4 (
+ i1 INTEGER NOT NULL,
+ c1 VARCHAR(1) NOT NULL
+);
+
+INSERT INTO t4
+VALUES (1, 'j'), (2, 'c'), (0, 'a');
+
+ANALYZE TABLE t1, t2, t3, t4;
+
+# Hint is added to avoid materialization of the subquery
+let query=
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+ (
+ SELECT /*+ QB_NAME(subq1) */ t4.i1
+ FROM t4
+ WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+
+eval EXPLAIN $query;
+--sorted_result
+eval $query;
+
+--echo #
+--echo # Test 2: Two alternative covering indexes for the range scan
+--echo #
+
+# Adding second covering index
+if ($support_virtual_index)
+{
+ALTER TABLE t3 ADD INDEX v_idx2 (i2_key, i1);
+}
+
+# Hint is added to avoid materialization of the subquery
+let query=
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+ (
+ SELECT /*+ QB_NAME(subq1) */ t4.i1
+ FROM t4
+ WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+
+eval EXPLAIN $query;
+--sorted_result
+eval $query;
+
+--echo #
+--echo # Test 3: One covering index including the base column for the virtual
+--echo # column
+--echo #
+
+if ($support_virtual_index)
+{
+--echo # Drop the index with only the virtual column
+ALTER TABLE t3 DROP INDEX v_idx;
+}
+
+# Hint is added to avoid materialization of the subquery
+let query=
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+ (
+ SELECT /*+ QB_NAME(subq1) */ t4.i1
+ FROM t4
+ WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+
+eval EXPLAIN $query;
+--sorted_result
+eval $query;
+
+--echo #
+--echo # Test 4: One non-covering index
+--echo #
+
+if ($support_virtual_index)
+{
+--echo # Drop the index on two columns, add index on just one virtual column
+ALTER TABLE t3 DROP INDEX v_idx2;
+ALTER TABLE t3 ADD INDEX v_idx (i2_key);
+}
+
+--echo # Add more data to the table so that it will run the dynamic range scan
+--echo # as both table scan and range scan (the purpose of this is to make the
+--echo # table scan more expensive).
+INSERT INTO t3 (pk, i1)
+VALUES (10,1), (11,1), (12,1), (13,1), (14,1),(15,1), (16,1),(17,1), (18,1),
+ (19,1), (20,1), (21,1), (22,1), (23,1), (24,1),(25,1),(26,1),(27,1),
+ (28,1), (29,1);
+
+--echo # Change the query to read an extra column (t3.i1) making the index
+--echo # non-covering.
+# Hint is added to avoid materialization of the subquery
+let query=
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+ (
+ SELECT /*+ QB_NAME(subq1) */ t4.i1
+ FROM t4
+ WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+
+eval EXPLAIN $query;
+--sorted_result
+eval $query;
+
+--echo #
+--echo # Test 5: Test where the added primary key to secondary indexes is
+--echo # used after it has been included in the join buffer
+--echo #
+
+# This test is only relevant for storage engines that add the primary key
+# to all secondary keys (e.g. InnoDB). For these engines, the fields in the
+# primary key might be included when deciding that a secondary index is
+# covering for the query. This is the case for most of the secondary indexes
+# on t3 in this test. But in the above queries, the subquery is non-dependent
+# and the "t3.pk IN .." will be evaluated after rows for t3 are read. At this
+# time t3.pk is in the record buffer. t3.pk is not used after it has been
+# inserted into the join buffer. To test that t3.pk is actually correctly
+# included in the join buffer we change the subquery to be dependent and
+# only evaluated after the join has been done.
+# The purpose of this test is to ensure that we correctly handle and
+# include primary key fields that are added to a covering secondary index.
+
+# The difference between this query and the query in test 1 is that
+# an extra query condition is added to the subquery.
+# Hint is added to avoid materialization of the subquery
+let query=
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+ (
+ SELECT /*+ QB_NAME(subq1) */ t4.i1
+ FROM t4
+ WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1)
+ )
+)
+AND t1.i1 <= t3.i2_key;
+
+eval EXPLAIN $query;
+--sorted_result
+eval $query;
+
+DROP TABLE t1, t2, t3, t4;
+
+--disable_query_log
+set @@optimizer_switch=@local_optimizer_switch;
+--enable_query_log
diff --git a/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs.inc b/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs.inc
new file mode 100644
index 00000000..88f2f7c4
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs.inc
@@ -0,0 +1,47 @@
+################################################################################
+# inc/gcol_supported_sql_funcs.inc #
+# #
+# Purpose: #
+# Tests frame for allowed sql functions #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--enable_warnings
+set sql_warnings = 1;
+eval create table t1 ($cols);
+show create table t1;
+if ($rows)
+{
+# Allow out-of-range errors
+--error 0,1264,1690,3020
+ eval insert into t1 values ($values1);
+ dec $rows;
+}
+if ($rows)
+{
+--error 0,1292,1690,3020
+ eval insert into t1 values ($values2);
+ dec $rows;
+}
+if ($rows)
+{
+--error 0,1690,3020
+ eval insert into t1 values ($values3);
+ dec $rows;
+}
+if ($rows)
+{
+ eval insert into t1 values ($values4);
+ dec $rows;
+}
+--sorted_result
+select * from t1;
+drop table t1;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs_main.inc b/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs_main.inc
new file mode 100644
index 00000000..3bb44523
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs_main.inc
@@ -0,0 +1,1236 @@
+################################################################################
+# inc/gcol_supported_sql_funcs_main.inc #
+# #
+# Purpose: #
+# Tests frame for allowed sql functions #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--source include/have_des.inc
+
+set time_zone="+03:00";
+--echo #
+--echo # NUMERIC FUNCTIONS
+--echo #
+
+--echo # ABS()
+let $cols = a int, b int generated always as (abs(a)) virtual;
+let $values1 = -1, default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ACOS()
+let $cols = a double, b double generated always as (format(acos(a),6)) virtual;
+let $values1 = 1, default;
+let $values2 = 1.0001,default;
+let $values3 = 0,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ASIN()
+let $cols = a double, b double generated always as (format(asin(a),6)) virtual;
+let $values1 = 0.2, default;
+let $values2 = 1.0001,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #ATAN
+let $cols = a double, b double, c double generated always as (format(atan(a,b),6)) virtual;
+let $values1 = -2,2,default;
+let $values2 = format(PI(),6),0,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+let $cols = a double, c double generated always as (format(atan(a),6)) virtual;
+let $values1 = -2,default;
+let $values2 = format(PI(),6),default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ATAN2
+let $cols = a double, b double, c double generated always as (format(atan2(a,b),6)) virtual;
+let $values1 = -2,2,default;
+let $values2 = format(PI(),6),0,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CEIL()
+let $cols = a double, b int generated always as (ceil(a)) virtual;
+let $values1 = 1.23,default;
+let $values2 = -1.23,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CONV()
+let $cols = a varchar(10), b int, c int, d varchar(10) generated always as (conv(a,b,c)) virtual;
+let $values1 = 'a',16,2,default;
+let $values2 = '6e',18,8,default;
+let $values3 = -17,10,-18,default;
+let $values4 = 10+'10'+'10'+0xa,10,10,default;
+let $rows = 4;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # COS()
+let $cols = a double, b double generated always as (format(cos(a),6)) virtual;
+let $values1 = format(PI(),6),default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # COT()
+let $cols = a double, b double generated always as (format(cot(a),6)) virtual;
+let $values1 = 0,default;
+let $values2 = 12,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CRC32()
+let $cols = a varchar(10), b bigint generated always as (crc32(a)) virtual;
+let $values1 = 'MySQL',default;
+let $values2 = 'mysql',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DEGREES()
+let $cols = a double, b double generated always as (format(degrees(a),6)) virtual;
+let $values1 = format(PI(),6),default;
+let $values2 = format(PI()/2,6),default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # /
+let $cols = a double, b double generated always as (a/2) virtual;
+let $values1 = 2,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # EXP()
+let $cols = a double, b double generated always as (format(exp(a),6)) virtual;
+let $values1 = 2,default;
+let $values2 = -2,default;
+let $values3 = 0,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FLOOR()
+let $cols = a double, b bigint generated always as (floor(a)) virtual;
+let $values1 = 1.23,default;
+let $values2 = -1.23,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LN()
+let $cols = a double, b double generated always as (format(ln(a),6)) virtual;
+let $values1 = 2,default;
+let $values2 = -2,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LOG()
+let $cols = a double, b double, c double generated always as (format(log(a,b),6)) virtual;
+let $values1 = 2,65536,default;
+let $values2 = 10,100,default;
+let $values3 = 1,100,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+let $cols = a double, b double generated always as (format(log(a),6)) virtual;
+let $values1 = 2,default;
+let $values2 = -2,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LOG2()
+let $cols = a double, b double generated always as (format(log2(a),6)) virtual;
+let $values1 = 65536,default;
+let $values2 = -100,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LOG10()
+let $cols = a double, b double generated always as (format(log10(a),6)) virtual;
+let $values1 = 2,default;
+let $values2 = 100,default;
+let $values3 = -100,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # -
+let $cols = a double, b double generated always as (a-1) virtual;
+let $values1 = 2,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MOD()
+let $cols = a int, b int generated always as (mod(a,10)) virtual;
+let $values1 = 1,default;
+let $values2 = 11,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # %
+let $cols = a int, b int generated always as (a % 10) virtual;
+let $values1 = 1,default;
+let $values2 = 11,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # OCT()
+let $cols = a double, b varchar(10) generated always as (oct(a)) virtual;
+let $values1 = 12,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # PI()
+let $cols = a double, b double generated always as (format(PI()*a*a,6)) virtual;
+let $values1 = 1,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # +
+let $cols = a int, b int generated always as (a+1) virtual;
+let $values1 = 1,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # POW, POWER
+let $cols = a int, b int generated always as (pow(a,2)) virtual, c int generated always as (power(a,2)) virtual;
+let $values1 = 1,default,default;
+let $values2 = 2,default,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # RADIANS()
+let $cols = a double, b double generated always as (format(radians(a),6)) virtual;
+let $values1 = 90,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ROUND()
+let $cols = a double, b int generated always as (round(a)) virtual;
+let $values1 = -1.23,default;
+let $values2 = -1.58,default;
+let $values3 = 1.58,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+let $cols = a double, b double, c int generated always as (round(a,b)) virtual;
+let $values1 = 1.298,1,default;
+let $values2 = 1.298,0,default;
+let $values3 = 23.298,-1,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SIGN()
+let $cols = a double, b int generated always as (sign(a)) virtual;
+let $values1 = -32,default;
+let $values2 = 0,default;
+let $values3 = 234,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SIN()
+let $cols = a double, b double generated always as (format(sin(a),6)) virtual;
+let $values1 = format(PI()/2,6),default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SQRT()
+let $cols = a double, b double generated always as (format(sqrt(a),6)) virtual;
+let $values1 = 4,default;
+let $values2 = 20,default;
+let $values3 = -16,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TAN()
+let $cols = a double, b double generated always as (format(tan(a),6)) virtual;
+let $values1 = format(PI(),6),default;
+let $values2 = format(PI()+1,6),default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # *
+let $cols = a double, b double generated always as (a*3) virtual;
+let $values1 = 0,default;
+let $values2 = 1,default;
+let $values3 = 2,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TRUNCATE()
+let $cols = a double, b double generated always as (truncate(a,4)) virtual;
+let $values1 = 1.223,default;
+let $values2 = 1.999,default;
+let $values3 = 1.999,default;
+let $values4 = 122,default;
+let $rows = 4;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # Unary -
+let $cols = a double, b double generated always as (-a) virtual;
+let $values1 = 1,default;
+let $values2 = -1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # STRING FUNCTIONS
+--echo #
+
+--echo # ASCII()
+let $cols = a char(2), b int generated always as (ascii(a)) virtual;
+let $values1 = '2',default;
+let $values2 = 2,default;
+let $values3 = 'dx',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # BIN()
+let $cols = a int, b varchar(10) generated always as (bin(a)) virtual;
+let $values1 = 12,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # BIT_LENGTH()
+let $cols = a varchar(10), b bigint generated always as (bit_length(a)) virtual;
+let $values1 = 'text',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CHAR_LENGTH()
+let $cols = a varchar(10), b bigint generated always as (char_length(a)) virtual;
+let $values1 = 'text',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CHAR()
+let $cols = a int, b int, c varbinary(10) generated always as (char(a,b)) virtual;
+let $values1 = 77,121,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CHARACTER_LENGTH()
+let $cols = a varchar(10), b bigint generated always as (character_length(a)) virtual;
+let $values1 = 'text',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CONCAT_WS()
+let $cols = a varchar(10), b varchar(10), c varchar(20) generated always as (concat_ws(',',a,b)) virtual;
+let $values1 = 'value1','value2',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CONCAT()
+let $cols = a varchar(10), b varchar(10), c varchar(20) generated always as (concat(a,',',b)) virtual;
+let $values1 = 'value1','value2',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ELT()
+let $cols = a varchar(10), b varchar(10), c int, d varchar(10) generated always as (elt(c,a,b)) virtual;
+let $values1 = 'value1','value2',1,default;
+let $values2 = 'value1','value2',2,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # EXPORT_SET()
+let $cols = a int, b varchar(10) generated always as (export_set(a,'1','0','',10)) virtual;
+let $values1 = 6,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FIELD()
+let $cols = a varchar(10), b varchar(10), c int generated always as (field('aa',a,b)) virtual;
+let $values1 = 'aa','bb',default;
+let $values2 = 'bb','aa',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FIND_IN_SET()
+let $cols = a varchar(10), b varchar(10), c int generated always as (find_in_set(a,b)) virtual;
+let $values1 = 'aa','aa,bb,cc',default;
+let $values2 = 'aa','bb,aa,cc',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FORMAT()
+let $cols = a double, b varchar(20) generated always as (format(a,2)) virtual;
+let $values1 = 12332.123456,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # HEX()
+let $cols = a int, b varchar(10) generated always as (hex(a)) virtual;
+let $values1 = 17,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+let $cols = a varchar(10), b varchar(10) generated always as (hex(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # INSERT()
+let $cols = a varchar(10), b varchar(10), c varchar(20) generated always as (insert(a,length(a),length(b),b)) virtual;
+let $values1 = 'start,','end',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # INSTR()
+let $cols = a varchar(10), b varchar(10), c int generated always as (instr(a,b)) virtual;
+let $values1 = 'foobarbar,','bar',default;
+let $values2 = 'xbar,','foobar',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LCASE()
+let $cols = a varchar(10), b varchar(10) generated always as (lcase(a)) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LEFT()
+let $cols = a varchar(10), b varchar(5) generated always as (left(a,5)) virtual;
+let $values1 = 'foobarbar',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LENGTH()
+let $cols = a varchar(10), b int generated always as (length(a)) virtual;
+let $values1 = 'text',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LIKE
+let $cols = a varchar(10), b bool generated always as (a like 'H%o') virtual;
+let $values1 = 'Hello',default;
+let $values2 = 'MySQL',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LOCATE()
+let $cols = a varchar(10), b varchar(10) generated always as (locate('bar',a)) virtual;
+let $values1 = 'foobarbar',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LOWER()
+let $cols = a varchar(10), b varchar(10) generated always as (lower(a)) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LPAD()
+let $cols = a varchar(10), b varchar(10) generated always as (lpad(a,4,' ')) virtual;
+let $values1 = 'MySQL',default;
+let $values2 = 'M',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LTRIM()
+let $cols = a varchar(10), b varchar(10) generated always as (ltrim(a)) virtual;
+let $values1 = ' MySQL',default;
+let $values2 = 'MySQL',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MAKE_SET()
+let $cols = a varchar(10), b varchar(10), c int, d varchar(30) generated always as (make_set(c,a,b)) virtual;
+let $values1 = 'a','b',1,default;
+let $values2 = 'a','b',3,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MID()
+let $cols = a varchar(10), b varchar(10) generated always as (mid(a,1,2)) virtual;
+let $values1 = 'foobarbar',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # NOT LIKE
+let $cols = a varchar(10), b bool generated always as (a not like 'H%o') virtual;
+let $values1 = 'Hello',default;
+let $values2 = 'MySQL',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # NOT REGEXP
+let $cols = a varchar(10), b bool generated always as (a not regexp 'H.+o') virtual;
+let $values1 = 'Hello',default;
+let $values2 = 'hello',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # OCTET_LENGTH()
+let $cols = a varchar(10), b int generated always as (octet_length(a)) virtual;
+let $values1 = 'text',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ORD()
+let $cols = a varchar(10), b bigint generated always as (ord(a)) virtual;
+let $values1 = '2',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # POSITION()
+let $cols = a varchar(10), b varchar(10) generated always as (position('bar' in a)) virtual;
+let $values1 = 'foobarbar',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # QUOTE()
+let $cols = a varchar(10), b varchar(10) generated always as (quote(a)) virtual;
+let $values1 = 'Don\'t',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # REGEXP()
+let $cols = a varchar(10), b bool generated always as (a regexp 'H.+o') virtual;
+let $values1 = 'Hello',default;
+let $values2 = 'hello',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # REPEAT()
+let $cols = a varchar(10), b varchar(30) generated always as (repeat(a,3)) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # REPLACE()
+let $cols = a varchar(10), b varchar(30) generated always as (replace(a,'aa','bb')) virtual;
+let $values1 = 'maa',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # REVERSE()
+let $cols = a varchar(10), b varchar(30) generated always as (reverse(a)) virtual;
+let $values1 = 'maa',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # RIGHT()
+let $cols = a varchar(10), b varchar(10) generated always as (right(a,4)) virtual;
+let $values1 = 'foobarbar',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # RLIKE()
+let $cols = a varchar(10), b bool generated always as (a rlike 'H.+o') virtual;
+let $values1 = 'Hello',default;
+let $values2 = 'MySQL',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # RPAD()
+let $cols = a varchar(10), b varchar(10) generated always as (rpad(a,4,'??')) virtual;
+let $values1 = 'He',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # RTRIM();
+let $cols = a varchar(10), b varchar(10) generated always as (rtrim(a)) virtual;
+let $values1 = 'Hello ',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SOUNDEX()
+let $cols = a varchar(10), b varchar(20) generated always as (soundex(a)) virtual;
+let $values1 = 'Hello',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SOUNDS LIKE
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a sounds like b) virtual;
+let $values1 = 'Hello','Hello',default;
+let $values2 = 'Hello','MySQL',default;
+let $values3 = 'Hello','hello',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SPACE()
+let $cols = a varchar(5), b varchar(10) generated always as (concat(a,space(5))) virtual;
+let $values1 = 'Hello', default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # STRCMP()
+let $cols = a varchar(9), b varchar(9), c tinyint(1) generated always as (strcmp(a,b)) virtual;
+let $values1 = 'Hello','Hello', default;
+let $values2 = 'Hello','Hello1', default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SUBSTR()
+let $cols = a varchar(5), b varchar(10) generated always as (substr(a,2)) virtual;
+let $values1 = 'Hello',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SUBSTRING_INDEX()
+let $cols = a varchar(15), b varchar(10) generated always as (substring_index(a,'.',2)) virtual;
+let $values1 = 'www.mysql.com',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SUBSTRING()
+let $cols = a varchar(5), b varchar(10) generated always as (substring(a from 2 for 2)) virtual;
+let $values1 = 'Hello',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TRIM()
+let $cols = a varchar(15), b varchar(10) generated always as (trim(a)) virtual;
+let $values1 = ' aa ',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # UCASE()
+let $cols = a varchar(5), b varchar(10) generated always as (ucase(a)) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # UNHEX()
+let $cols = a varchar(15), b varchar(10) generated always as (unhex(a)) virtual;
+let $values1 = '4D7953514C',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # UPPER()
+let $cols = a varchar(5), b varchar(10) generated always as (upper(a)) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # WEIGHT_STRING()
+let $cols = a varchar(5), b varchar(10) generated always as (weight_string(a as char(4))) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # CONTROL FLOW FUNCTIONS
+--echo #
+
+--echo # CASE
+let $cols = a varchar(10), b varchar(16) generated always as (case a when NULL then 'asd' when 'b' then 'B' else a end) virtual;
+let $values1 = NULL,default;
+let $values2 = 'b',default;
+let $values3 = 'c',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # IF
+let $cols = a int, b int, c int generated always as (if(a=1,a,b)) virtual;
+let $values1 = 1,2,default;
+let $values2 = 3,4,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # IFNULL
+let $cols = a varchar(10), b varchar(10), c varchar(10) generated always as (ifnull(a,'DEFAULT')) virtual;
+let $values1 = NULL,'adf',default;
+let $values2 = 'a','adf',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # NULLIF
+let $cols = a varchar(10), b varchar(10) generated always as (nullif(a,'DEFAULT')) virtual;
+let $values1 = 'DEFAULT',default;
+let $values2 = 'a',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # OPERATORS
+--echo #
+
+--echo # AND, &&
+let $cols = a int, b bool generated always as (a>0 && a<2) virtual;
+let $values1 = -1,default;
+let $values2 = 1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # BETWEEN ... AND ...
+let $cols = a int, b bool generated always as (a between 0 and 2) virtual;
+let $values1 = -1,default;
+let $values2 = 1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # BINARY
+let $cols = a varchar(10), b varbinary(10) generated always as (binary a) virtual;
+let $values1 = '11',default;
+let $values2 = 1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # &
+let $cols = a int, b int generated always as (a & 5) virtual;
+let $values1 = 1,default;
+let $values2 = 0,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ~
+let $cols = a int, b int generated always as (~a) virtual;
+let $values1 = 1,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # |
+let $cols = a int, b int generated always as (a | 5) virtual;
+let $values1 = 1,default;
+let $values2 = 0,default;
+let $values3 = 2,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ^
+let $cols = a int, b int generated always as (a ^ 5) virtual;
+let $values1 = 1,default;
+let $values2 = 0,default;
+let $values3 = 2,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DIV
+let $cols = a int, b int generated always as (a div 5) virtual;
+let $values1 = 1,default;
+let $values2 = 7,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # <=>
+let $cols = a int, b int, c bool generated always as (a <=> b) virtual;
+let $values1 = 1,1,default;
+let $values2 = NULL,NULL,default;
+let $values3 = 1,NULL,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # =
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a=b) virtual;
+let $values1 = 'a','b',default;
+let $values2 = 'a','a',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # >=
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a >= b) virtual;
+let $values1 = 'a','b',default;
+let $values2 = 'a','a',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # >
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a > b) virtual;
+let $values1 = 'a','b',default;
+let $values2 = 'a','a',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # IS NOT NULL
+let $cols = a int, b bool generated always as (a is not null) virtual;
+let $values1 = 1,default;
+let $values2 = NULL,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # IS NULL
+let $cols = a int, b bool generated always as (a is null) virtual;
+let $values1 = 1,default;
+let $values2 = NULL,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # <<
+let $cols = a int, b int generated always as (a << 2) virtual;
+let $values1 = 1,default;
+let $values2 = 3,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # <=
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a <= b) virtual;
+let $values1 = 'b','a',default;
+let $values2 = 'b','b',default;
+let $values3 = 'b','c',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # <
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a < b) virtual;
+let $values1 = 'b','a',default;
+let $values2 = 'b','b',default;
+let $values3 = 'b','c',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # NOT BETWEEN ... AND ...
+let $cols = a int, b bool generated always as (a not between 0 and 2) virtual;
+let $values1 = -1,default;
+let $values2 = 1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # <>
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a <> b) virtual;
+let $values1 = 'b','a',default;
+let $values2 = 'b','b',default;
+let $values3 = 'b','c',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # !=
+let $cols = a varchar(10), b varchar(10), c bool generated always as (a != b) virtual;
+let $values1 = 'b','a',default;
+let $values2 = 'b','b',default;
+let $values3 = 'b','c',default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ||, OR
+let $cols = a int, b int generated always as (a>5 || a<3) virtual;
+let $values1 = 1,default;
+let $values2 = 4,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # >>
+let $cols = a int, b int generated always as (a >> 2) virtual;
+let $values1 = 8,default;
+let $values2 = 3,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # XOR
+let $cols = a int, b int generated always as (a xor 5) virtual;
+let $values1 = 0,default;
+let $values2 = 1,default;
+let $values3 = 2,default;
+let $rows = 3;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # DATE AND TIME FUNCTIONS
+--echo #
+
+--echo # ADDDATE()
+let $cols = a datetime, b datetime generated always as (adddate(a,interval 1 month)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ADDTIME()
+let $cols = a datetime, b datetime generated always as (addtime(a,'02:00:00')) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CONVERT_TZ()
+let $cols = a datetime, b datetime generated always as (convert_tz(a,'MET','UTC')) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DATE_ADD()
+let $cols = a datetime, b datetime generated always as (date_add(a,interval 1 month)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DATE_FORMAT()
+let $cols = a datetime, b varchar(64) generated always as (date_format(a,'%W %M %D')) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DATE_SUB()
+let $cols = a datetime, b datetime generated always as (date_sub(a,interval 1 month)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DATE()
+let $cols = a datetime, b datetime generated always as (date(a)) virtual;
+let $values1 = '2008-08-31 02:00:00',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DATEDIFF()
+let $cols = a datetime, b bigint generated always as (datediff(a,'2000-01-01')) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DAY()
+let $cols = a datetime, b int generated always as (day(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DAYNAME()
+let $cols = a datetime, b varchar(10) generated always as (dayname(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DAYOFMONTH()
+let $cols = a datetime, b int generated always as (dayofmonth(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DAYOFWEEK()
+let $cols = a datetime, b int generated always as (dayofweek(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DAYOFYEAR()
+let $cols = a datetime, b int generated always as (dayofyear(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # EXTRACT
+let $cols = a datetime, b int generated always as (extract(year from a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FROM_DAYS()
+let $cols = a bigint, b datetime generated always as (from_days(a)) virtual;
+let $values1 = 730669,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # FROM_UNIXTIME()
+let $cols = a bigint, b datetime generated always as (from_unixtime(a)) virtual;
+let $values1 = 1196440219,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # GET_FORMAT()
+let $cols = a datetime, b varchar(32) generated always as (date_format(a,get_format(DATE,'EUR'))) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # HOUR()
+let $cols = a time, b bigint generated always as (hour(a)) virtual;
+let $values1 = '10:05:03',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # LAST_DAY()
+let $cols = a datetime, b datetime generated always as (last_day(a)) virtual;
+let $values1 = '2003-02-05',default;
+let $values2 = '2003-02-32',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MAKEDATE()
+let $cols = a int, b datetime generated always as (makedate(a,1)) virtual;
+let $values1 = 2001,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MAKETIME()
+let $cols = a int, b time generated always as (maketime(a,1,3)) virtual;
+let $values1 = 12,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MICROSECOND()
+let $cols = a datetime, b bigint generated always as (microsecond(a)) virtual;
+let $values1 = '2009-12-31 12:00:00.123456',default;
+let $values2 = '2009-12-31 23:59:59.000010',default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MINUTE()
+let $cols = a datetime, b int generated always as (minute(a)) virtual;
+let $values1 = '2009-12-31 23:59:59.000010',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MONTH()
+let $cols = a datetime, b int generated always as (month(a)) virtual;
+let $values1 = '2009-12-31 23:59:59.000010',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MONTHNAME()
+let $cols = a datetime, b varchar(16) generated always as (monthname(a)) virtual;
+let $values1 = '2009-12-31 23:59:59.000010',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # PERIOD_ADD()
+let $cols = a int, b int generated always as (period_add(a,2)) virtual;
+let $values1 = 200801,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # PERIOD_DIFF()
+let $cols = a int, b int, c int generated always as (period_diff(a,b)) virtual;
+let $values1 = 200802,200703,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # QUARTER()
+let $cols = a datetime, b int generated always as (quarter(a)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SEC_TO_TIME()
+let $cols = a bigint, b time generated always as (sec_to_time(a)) virtual;
+let $values1 = 2378,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SECOND()
+let $cols = a datetime, b int generated always as (second(a)) virtual;
+let $values1 = '10:05:03',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # STR_TO_DATE()
+let $cols = a varchar(64), b datetime generated always as (str_to_date(a,'%m/%d/%Y')) virtual;
+let $values1 = '04/30/2004',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SUBDATE()
+let $cols = a datetime, b datetime generated always as (subdate(a,interval 1 month)) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SUBTIME()
+let $cols = a datetime, b datetime generated always as (subtime(a,'02:00:00')) virtual;
+let $values1 = '2008-08-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIME_FORMAT()
+let $cols = a datetime, b varchar(32) generated always as (time_format(a,'%r')) virtual;
+let $values1 = '2008-08-31 02:03:04',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIME_TO_SEC()
+let $cols = a time, b bigint generated always as (time_to_sec(a)) virtual;
+let $values1 = '22:23:00',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIME()
+let $cols = a datetime, b time generated always as (time(a)) virtual;
+let $values1 = '2008-08-31 02:03:04',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIMEDIFF()
+let $cols = a datetime, b datetime, c time generated always as (timediff(a,b)) virtual;
+let $values1 = '2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIMESTAMP()
+let $cols = a datetime, b timestamp generated always as (timestamp(a)) virtual;
+let $values1 = '2008-12-31',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIMESTAMPADD()
+let $cols = a datetime, b timestamp generated always as (timestampadd(minute,1,a)) virtual;
+let $values1 = '2003-01-02',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TIMESTAMPDIFF()
+let $cols = a timestamp, c bigint generated always as (timestampdiff(MONTH, a, a)) virtual;
+let $values1 = '2003-02-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # TO_DAYS()
+let $cols = a datetime, b bigint generated always as (to_days(a)) virtual;
+let $values1 = '2007-10-07',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # WEEK()
+let $cols = a datetime, b int generated always as (week(a)) virtual;
+let $values1 = '2008-09-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # WEEKDAY()
+let $cols = a datetime, b int generated always as (weekday(a)) virtual;
+let $values1 = '2008-09-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # WEEKOFYEAR()
+let $cols = a datetime, b int generated always as (weekofyear(a)) virtual;
+let $values1 = '2008-09-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # YEAR()
+let $cols = a datetime, b int generated always as (year(a)) virtual;
+let $values1 = '2008-09-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # YEARWEEK()
+let $cols = a datetime, b int generated always as (yearweek(a)) virtual;
+let $values1 = '2008-09-01',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # FULL TEXT SEARCH FUNCTIONS
+--echo #
+--echo # None.
+
+--echo #
+--echo # CAST FUNCTIONS AND OPERATORS
+--echo #
+
+--echo # CAST()
+let $cols = a int, b bigint unsigned generated always as (cast(a as unsigned)) virtual;
+let $values1 = 1,default;
+let $values2 = -1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # Convert()
+let $cols = a int, b bigint unsigned generated always as (convert(a,unsigned)) virtual;
+let $values1 = 1,default;
+let $values2 = -1,default;
+let $rows = 2;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo #
+--echo # XML FUNCTIONS
+--echo #
+--echo # ExtractValue()
+let $cols = a varchar(1024), b varchar(1024) generated always as (ExtractValue(a,'/b')) virtual;
+let $values1 = '<b>text</b>',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # None.
+
+
+--echo #
+--echo # OTHER FUNCTIONS
+--echo #
+
+--echo # AES_DECRYPT(), AES_ENCRYPT()
+let $cols = a varchar(1024), b varchar(1024) generated always as (aes_encrypt(aes_decrypt(a,'adf'),'adf')) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # BIT_COUNT()
+let $cols = a int, b int generated always as (bit_count(a)) virtual;
+let $values1 = 5,default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # CHARSET()
+let $cols = a varchar(1024), b varchar(1024) generated always as (charset(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # COERCIBILITY()
+let $cols = a varchar(1024), b int generated always as (coercibility(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # COLLATION()
+let $cols = a varchar(1024), b varchar(1024) generated always as (collation(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # COMPRESS(), UNCOMPRESS()
+let $cols = a varchar(1024), b varchar(1024) generated always as (uncompress(compress(a))) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # ENCODE(), DECODE()
+let $cols = a varchar(1024), b varchar(1024) generated always as (decode(encode(a,'abc'),'abc')) virtual;
+let $values1 = 'MySQL',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # DEFAULT()
+let $cols = a varchar(1024) default 'aaa', b varchar(1024) generated always as (ifnull(a,default(a))) virtual;
+let $values1 = 'any value',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # INET_ATON(), INET_NTOA()
+let $cols = a varchar(1024), b varchar(1024) generated always as (inet_ntoa(inet_aton(a))) virtual;
+let $values1 = '127.0.0.1',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # MD5()
+let $cols = a varchar(1024), b varbinary(32) generated always as (md5(a)) virtual;
+let $values1 = 'testing',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # PASSWORD()
+let $cols = a varchar(1024), b varchar(1024) generated always as (password(a)) virtual;
+let $values1 = 'badpwd',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SHA1()
+let $cols = a varchar(1024), b varchar(1024) generated always as (sha1(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SHA()
+let $cols = a varchar(1024), b varchar(1024) generated always as (sha(a)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # SHA2()
+let $cols = a varchar(1024), b varchar(1024) generated always as (sha2(a,224)) virtual;
+let $values1 = 'abc',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
+--echo # UNCOMPRESSED_LENGTH()
+let $cols = a char, b varchar(1024) generated always as (uncompressed_length(compress(repeat(a,30)))) virtual;
+let $values1 = 'a',default;
+let $rows = 1;
+--source suite/gcol/inc/gcol_supported_sql_funcs.inc
+
diff --git a/mysql-test/suite/gcol/inc/gcol_trigger_sp.inc b/mysql-test/suite/gcol/inc/gcol_trigger_sp.inc
new file mode 100644
index 00000000..b6ba5280
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_trigger_sp.inc
@@ -0,0 +1,114 @@
+################################################################################
+# inc/gcol_trigger_sp.inc #
+# #
+# Purpose: #
+# Testing triggers, stored procedures and functions #
+# defined on tables with generated columns. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+create table t1 (a int,
+ b int generated always as (a/10) virtual,
+ c int generated always as (a/10) stored);
+
+create table t2 (a timestamp);
+
+delimiter |;
+
+create trigger trg1 before insert on t1 for each row
+begin
+ if (new.b < 10) then
+ set new.a:= 100;
+ set new.b:= 9;
+ set new.c:= 9;
+ end if;
+
+ if (new.c > 50) then
+ set new.a:= 500;
+ end if;
+end|
+
+create trigger trg2 after insert on t1 for each row
+begin
+ if (new.b >= 60) then
+ insert into t2 values (now());
+ end if;
+end|
+
+create function f1()
+returns int
+begin
+ declare sum1 int default '0';
+ declare cur1 cursor for select sum(b) from t1;
+ open cur1;
+ fetch cur1 into sum1;
+ close cur1;
+ return sum1;
+end|
+
+delimiter ;|
+
+set sql_warnings = 1;
+
+insert into t1 (a) values (200);
+select * from t1;
+select * from t2;
+
+insert into t1 (a) values (10);
+--sorted_result
+select * from t1;
+select * from t2;
+
+insert into t1 (a) values (600);
+--sorted_result
+select * from t1;
+--replace_column 1 <timestamp>
+select * from t2;
+
+select f1();
+
+set sql_warnings = 0;
+
+drop trigger trg1;
+drop trigger trg2;
+drop table t2;
+
+delimiter |;
+
+create procedure p1()
+begin
+ declare i int default '0';
+ create table t2 like t1;
+ insert into t2 (a) values (100), (200);
+ begin
+ declare cur1 cursor for select sum(c) from t2;
+ open cur1;
+ fetch cur1 into i;
+ close cur1;
+ if (i=30) then
+ insert into t1 values (300,default,default);
+ end if;
+ end;
+end|
+
+delimiter ;|
+
+delete from t1;
+
+call p1();
+
+--sorted_result
+select * from t2;
+--sorted_result
+select * from t1;
+
+drop table t1,t2;
+drop procedure p1;
diff --git a/mysql-test/suite/gcol/inc/gcol_unsupported_storage_engines.inc b/mysql-test/suite/gcol/inc/gcol_unsupported_storage_engines.inc
new file mode 100644
index 00000000..2b85a2c2
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_unsupported_storage_engines.inc
@@ -0,0 +1,21 @@
+################################################################################
+# inc/gcol_unsupported_storage_engines.inc #
+# #
+# Purpose: #
+# Ensure that defining a generated column for an unsupported table type #
+# results in a graceful error. #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+--error ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS
+create table t1 (a int, b int generated always as (a+1) virtual);
+create table t1 (a int);
+--error ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS
+alter table t1 add column b int generated always as (a+1) virtual;
+drop table t1;
diff --git a/mysql-test/suite/gcol/inc/gcol_view.inc b/mysql-test/suite/gcol/inc/gcol_view.inc
new file mode 100644
index 00000000..85caa58c
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_view.inc
@@ -0,0 +1,278 @@
+################################################################################
+# inc/gcol_view.inc #
+# #
+# Purpose: #
+# Testing views defined on tables with generated columns. #
+# #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+
+
+create table t1 (a int not null,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+insert into t1 (a) values (1), (1), (2), (2), (3);
+analyze table t1;
+
+# simple view
+create view v1 (d,e) as select abs(b), abs(c) from t1;
+--sorted_result
+select d,e from v1;
+select is_updatable from information_schema.views where table_name='v1';
+
+# view with different algorithms (explain output differs)
+--replace_column 9 X
+explain select d,e from v1;
+create algorithm=temptable view v2 (d,e) as select abs(b), abs(c) from t1;
+show create view v2;
+--sorted_result
+select d,e from v2;
+--replace_column 9 X
+explain select d,e from v2;
+
+# VIEW on VIEW test
+create view v3 (d,e) as select d*2, e*2 from v1;
+--sorted_result
+select * from v3;
+--replace_column 9 X
+explain select * from v3;
+
+drop view v1,v2,v3;
+drop table t1;
+
+#
+# DISTINCT option for VIEW
+#
+create table t1 (a int not null,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (1), (2), (3);
+create view v1 as select distinct b from t1;
+--sorted_result
+select * from v1;
+--replace_column 9 X
+explain select * from v1;
+--sorted_result
+select * from t1;
+drop view v1;
+create view v1 as select distinct c from t1;
+--sorted_result
+select * from v1;
+--replace_column 9 X
+explain select * from v1;
+--sorted_result
+select * from t1;
+drop view v1;
+drop table t1;
+
+#
+# LIMIT clause test
+#
+create table t1 (a int not null,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (4);
+create view v1 as select b+1 from t1 order by 1 desc limit 2;
+select * from v1;
+--replace_column 9 X
+explain select * from v1;
+drop view v1;
+create view v1 as select c+1 from t1 order by 1 desc limit 2;
+--sorted_result
+select * from v1;
+--replace_column 9 X
+explain select * from v1;
+drop view v1;
+drop table t1;
+
+#
+# simple view + simple update, insert and delete
+#
+create table t1 (a int,
+ b int,
+ c int generated always as (-a) virtual,
+ d int generated always as (-a) stored,
+ primary key(a));
+insert into t1 (a,b) values (10,2), (20,3), (30,4), (40,5), (50,10);
+create view v1 (a,e,f,g) as select a, b+1,c+1,d+1 from t1;
+# updatable field of updateable view
+update v1 set a=a+e;
+select * from v1 order by a;
+select * from t1 order by a;
+delete from v1;
+select * from v1;
+select * from t1;
+--error ER_NON_INSERTABLE_TABLE
+insert into v1 (a,e) values (60,15);
+drop table t1;
+drop view v1;
+
+#
+# outer join based on VIEW with WHERE clause
+#
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored,
+ primary key(a));
+insert into t1 (a) values (1), (2), (3);
+create view v1 (x,y,z) as select a,b,c from t1 where b < -1;
+--sorted_result
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.b= v1.y);
+drop view v1;
+create view v1 (x,y,z) as select a,b,c from t1 where c < -1;
+--sorted_result
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.c= v1.z);
+drop view v1;
+drop table t1;
+
+#
+# VIEW built over UNION
+#
+create table t1 (a1 int,
+ b1 int generated always as (-a1) virtual,
+ c1 int generated always as (-a1) stored);
+create table t2 (a2 int,
+ b2 int generated always as (-a2) virtual,
+ c2 int generated always as (-a2) stored);
+insert into t1 (a1) values (1), (2);
+insert into t2 (a2) values (2), (3);
+create view v1 as select * from t1,t2 union all select * from t1,t2;
+--sorted_result
+select * from v1;
+drop view v1;
+drop table t1, t2;
+
+#
+# Showing VIEW with VIEWs in subquery
+#
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+create table t2 like t1;
+create view v1 as select a,b,c from t1;
+create view v2 as select a,b,c from t2 where b in (select b from v1);
+show create view v2;
+drop view v2, v1;
+drop table t1, t2;
+
+#
+# TODO: VIEW with full text
+#
+#CREATE TABLE t1 (c1 int not null auto_increment primary key, c2 varchar(20), fulltext(c2));
+#insert into t1 (c2) VALUES ('real Beer'),('Water'),('Kossu'),('Coca-Cola'),('Vodka'),('Wine'),('almost real Beer');
+#select * from t1 WHERE match (c2) against ('Beer');
+#CREATE VIEW v1 AS SELECT * from t1 WHERE match (c2) against ('Beer');
+#select * from v1;
+#drop view v1;
+#drop table t1;
+
+#
+# distinct in temporary table with a VIEW
+#
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+insert into t1 (a) values (1),(1),(2),(2),(3),(3);
+create view v1 as select b from t1;
+--sorted_result
+select distinct b from v1;
+select distinct b from v1 order by b limit 2;
+select distinct b from t1 order by b limit 2;
+prepare stmt1 from "select distinct b from v1 order by b limit 2";
+execute stmt1;
+execute stmt1;
+deallocate prepare stmt1;
+drop view v1;
+create view v1 as select c from t1;
+--sorted_result
+select distinct c from v1;
+select distinct c from v1 order by c limit 2;
+select distinct c from t1 order by c limit 2;
+prepare stmt1 from "select distinct c from v1 order by c limit 2";
+execute stmt1;
+execute stmt1;
+deallocate prepare stmt1;
+drop view v1;
+drop table t1;
+
+#
+# WITH CHECK OPTION insert/update test
+#
+create table t1 (a int,
+ b int generated always as (-a) virtual,
+ c int generated always as (-a) stored);
+create view v1 as select * from t1 where b > -2 && c >-2 with check option;
+# simple insert
+insert into v1 (a) values (1);
+-- error 1369
+insert into v1 (a) values (3);
+# simple insert with ignore
+insert ignore into v1 (a) values (2),(3),(0);
+--sorted_result
+select * from t1;
+drop view v1;
+drop table t1;
+
+
+--echo #
+--echo # MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+--echo #
+
+CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
+ ('1985-12-24 10:15:08.456');
+DELETE FROM v1 ORDER BY v LIMIT 4;
+
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo #
+--echo # [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
+--echo # Field_blob::val_str with virtual columns and views
+--echo #
+
+CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (a) VALUES ('foo'),('bar');
+DELETE FROM v1 ORDER BY b LIMIT 2;
+
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (d INT, v TINYINT AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004'),('1985') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+
+DROP VIEW v1;
+DROP TABLE t1;
+
+
+CREATE TABLE t1 (d VARCHAR(64), v VARCHAR(63) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),('1985-12-24 10:15:08.456') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+
+DROP TABLE t1;
+DROP VIEW v1;
+
+
+--echo #
+--echo # MDEV-18249 ASSERT_COLUMN_MARKED_FOR_READ failed in ANALYZE TABLE
+--echo #
+
+create table t1 (c varchar(3) not null, v varchar(4) as (c) virtual);
+insert into t1 (c) values ('a'),('b');
+analyze table t1 persistent for columns (v) indexes ();
+
diff --git a/mysql-test/suite/gcol/inc/innodb_v_large_col.inc b/mysql-test/suite/gcol/inc/innodb_v_large_col.inc
new file mode 100644
index 00000000..70e18863
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/innodb_v_large_col.inc
@@ -0,0 +1,53 @@
+--source include/have_innodb.inc
+
+eval CREATE TABLE `t` (
+`a` VARCHAR(10000), `b` VARCHAR(3000),
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`) ) ROW_FORMAT=$row_format ENGINE=InnoDB;
+
+SHOW CREATE TABLE t;
+
+INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+
+INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+
+delimiter |;
+CREATE PROCEDURE UPDATE_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 100) DO
+ UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+ SET i = i + 1;
+ END WHILE;
+END|
+
+CREATE PROCEDURE DELETE_insert_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 100) DO
+ DELETE FROM t WHERE h = 1;
+ INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+ SET i = i + 1;
+ END WHILE;
+END|
+delimiter ;|
+
+CALL UPDATE_t();
+
+CALL DELETE_insert_t();
+
+UPDATE t SET a = NULL WHERE h=1;
+
+START TRANSACTION;
+CALL UPDATE_t();
+ROLLBACK;
+
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
diff --git a/mysql-test/suite/gcol/r/federated_gcol.result b/mysql-test/suite/gcol/r/federated_gcol.result
new file mode 100644
index 00000000..9c8de398
--- /dev/null
+++ b/mysql-test/suite/gcol/r/federated_gcol.result
@@ -0,0 +1,49 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;
+stop slave;
+DROP DATABASE IF EXISTS federated;
+CREATE DATABASE federated;
+DROP DATABASE IF EXISTS federated;
+CREATE DATABASE federated;
+SET @OLD_CONCURRENT_INSERT= @@GLOBAL.CONCURRENT_INSERT;
+SET @@GLOBAL.CONCURRENT_INSERT= 0;
+DROP TABLE IF EXISTS federated.t1;
+Warnings:
+Note 1051 Unknown table 't1'
+DROP TABLE IF EXISTS federated.t1;
+Warnings:
+Note 1051 Unknown table 't1'
+CREATE TABLE federated.t1 (
+`id` int(20) NOT NULL,
+`group` int NOT NULL default 0,
+`tmp` virtual int as (`id` + 1)
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t1';
+ERROR HY000: 'Specified storage engine' is not yet supported for generated columns.
+CREATE TABLE federated.t1 (
+`id` int(20) NOT NULL,
+`group` int NOT NULL default 0
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@127.0.0.1:SLAVE_PORT/federated/t1';
+alter table federated.t1 add column `tmp` virtual int as (`id` + 1);
+ERROR HY000: Table storage engine for 't1' doesn't have this option
+DROP TABLE IF EXISTS federated.t1;
+End of 5.1 tests
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE IF EXISTS federated;
+DROP TABLE IF EXISTS federated.t1;
+DROP DATABASE IF EXISTS federated;
+SET @@GLOBAL.CONCURRENT_INSERT= @OLD_CONCURRENT_INSERT;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_archive.result b/mysql-test/suite/gcol/r/gcol_archive.result
new file mode 100644
index 00000000..fb6fd544
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_archive.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'archive';
+create table t1 (a int, b int generated always as (a+1) virtual);
+ERROR HY000: ARCHIVE storage engine does not support generated columns
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual;
+ERROR HY000: ARCHIVE storage engine does not support generated columns
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_blackhole.result b/mysql-test/suite/gcol/r/gcol_blackhole.result
new file mode 100644
index 00000000..3ee4f4e9
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_blackhole.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'blackhole';
+create table t1 (a int, b int generated always as (a+1) virtual);
+ERROR HY000: BLACKHOLE storage engine does not support generated columns
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual;
+ERROR HY000: BLACKHOLE storage engine does not support generated columns
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_innodb.result b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_innodb.result
new file mode 100644
index 00000000..a79ed43c
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_innodb.result
@@ -0,0 +1,194 @@
+SET @@session.default_storage_engine = 'InnoDB';
+create or replace table t1 (b double generated always as (rand()) virtual);
+create or replace table t1 (a datetime generated always as (curdate()) virtual);
+create or replace table t1 (a datetime generated always as (current_date) virtual);
+create or replace table t1 (a datetime generated always as (current_date()) virtual);
+create or replace table t1 (a datetime generated always as (current_time) virtual);
+create or replace table t1 (a datetime generated always as (current_time()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp) virtual);
+create or replace table t1 (a datetime generated always as (curtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (now()) virtual);
+create or replace table t1 (a int, b varchar(10) generated always as (sysdate()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (unix_timestamp()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_date()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_time()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_timestamp()) virtual);
+create or replace table t1 (a int generated always as (connection_id()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (database()) virtual);
+create or replace table t1 (a varchar(32) generated always as (schema()) virtual);
+create or replace table t1 (a varchar(32) generated always as (session_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (system_user()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (user()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid_short()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (version()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (encrypt(a)) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (UpdateXML(a,'/a','<e>fff</e>')) virtual);
+drop table t1;
+# LOAD_FILE()
+create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual);
+ERROR HY000: Function or expression 'load_file()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MATCH()
+# BENCHMARK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (benchmark(a,3)) virtual);
+ERROR HY000: Function or expression 'benchmark()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# FOUND_ROWS()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (found_rows()) virtual);
+ERROR HY000: Function or expression 'found_rows()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# GET_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (get_lock(a,10)) virtual);
+ERROR HY000: Function or expression 'get_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# IS_FREE_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual);
+ERROR HY000: Function or expression 'is_free_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# IS_USED_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_used_lock(a)) virtual);
+ERROR HY000: Function or expression 'is_used_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# LAST_INSERT_ID()
+create table t1 (a int generated always as (last_insert_id()) virtual);
+ERROR HY000: Function or expression 'last_insert_id()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# MASTER_POS_WAIT()
+create table t1 (a varchar(32), b int generated always as (master_pos_wait(a,0,2)) virtual);
+ERROR HY000: Function or expression 'master_pos_wait()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# NAME_CONST()
+create table t1 (a varchar(32) generated always as (name_const('test',1)) virtual);
+ERROR HY000: Function or expression 'name_const()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# RELEASE_LOCK()
+create table t1 (a varchar(32), b int generated always as (release_lock(a)) virtual);
+ERROR HY000: Function or expression 'release_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# ROW_COUNT()
+create table t1 (a int generated always as (row_count()) virtual);
+ERROR HY000: Function or expression 'row_count()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# SLEEP()
+create table t1 (a int, b int generated always as (sleep(a)) virtual);
+ERROR HY000: Function or expression 'sleep()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VALUES()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (value(a)) virtual);
+ERROR HY000: Function or expression 'value()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# Stored procedures
+create procedure p1()
+begin
+select current_user();
+end //
+create function f1()
+returns int
+begin
+return 1;
+end //
+create table t1 (a int generated always as (p1()) virtual);
+ERROR HY000: Function or expression '`p1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+create table t1 (a int generated always as (f1()) virtual);
+ERROR HY000: Function or expression '`f1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+drop procedure p1;
+drop function f1;
+# Unknown functions
+create table t1 (a int generated always as (f1()) virtual);
+ERROR HY000: Function or expression '`f1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+#
+# GROUP BY FUNCTIONS
+#
+# AVG()
+create table t1 (a int, b int generated always as (avg(a)) virtual);
+ERROR HY000: Function or expression 'avg()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_AND()
+create table t1 (a int, b int generated always as (bit_and(a)) virtual);
+ERROR HY000: Function or expression 'bit_and()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_OR()
+create table t1 (a int, b int generated always as (bit_or(a)) virtual);
+ERROR HY000: Function or expression 'bit_or()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_XOR()
+create table t1 (a int, b int generated always as (bit_xor(a)) virtual);
+ERROR HY000: Function or expression 'bit_xor()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# COUNT(DISTINCT)
+create table t1 (a int, b int generated always as (count(distinct a)) virtual);
+ERROR HY000: Function or expression 'count(distinct )' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# COUNT()
+create table t1 (a int, b int generated always as (count(a)) virtual);
+ERROR HY000: Function or expression 'count()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# GROUP_CONCAT()
+create table t1 (a varchar(32), b int generated always as (group_concat(a,'')) virtual);
+ERROR HY000: Function or expression 'group_concat()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MAX()
+create table t1 (a int, b int generated always as (max(a)) virtual);
+ERROR HY000: Function or expression 'max()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MIN()
+create table t1 (a int, b int generated always as (min(a)) virtual);
+ERROR HY000: Function or expression 'min()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STD()
+create table t1 (a int, b int generated always as (std(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV_POP()
+create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV_SAMP()
+create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
+ERROR HY000: Function or expression 'stddev_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV()
+create table t1 (a int, b int generated always as (stddev(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# SUM()
+create table t1 (a int, b int generated always as (sum(a)) virtual);
+ERROR HY000: Function or expression 'sum()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VAR_POP()
+create table t1 (a int, b int generated always as (var_pop(a)) virtual);
+ERROR HY000: Function or expression 'variance()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VAR_SAMP()
+create table t1 (a int, b int generated always as (var_samp(a)) virtual);
+ERROR HY000: Function or expression 'var_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VARIANCE()
+create table t1 (a int, b int generated always as (variance(a)) virtual);
+ERROR HY000: Function or expression 'variance()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+#
+# Sub-selects
+#
+create table t1 (a int);
+create table t2 (a int, b int generated always as (select count(*) virtual from t1));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+drop table t1;
+#
+# Long expression
+create table t1 (a int, b varchar(300) generated always as (concat(a,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) virtual);
+drop table t1;
+create table t1 (a int, b varchar(300) generated always as (concat(a,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) virtual);
+drop table t1;
+#
+# Constant expression
+create table t1 (a int generated always as (PI()) virtual);
+drop table t1;
+# bug#21098119: GCOL WITH MATCH/AGAINST -->
+# ASSERTION FAILED: TR && TR->TABLE->FILE
+#
+create table t1 (a int);
+alter table t1 add column r blob generated always
+as (match(a) against ('' in boolean mode)) virtual;
+ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `r`
+drop table t1;
+#
+# End of 10.3 tests
+#
+#
+# MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column
+#
+create table t1 (a int);
+alter table t1 add column b binary(32) generated always as (random_bytes(a));
+ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+alter table t1 add column b binary(32) default (random_bytes(a));
+drop table t1;
+#
+#
+# End of 10.10 tests
+#
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result
new file mode 100644
index 00000000..ac8bd0a3
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result
@@ -0,0 +1,196 @@
+SET @@session.default_storage_engine = 'MyISAM';
+create or replace table t1 (b double generated always as (rand()) virtual);
+create or replace table t1 (a datetime generated always as (curdate()) virtual);
+create or replace table t1 (a datetime generated always as (current_date) virtual);
+create or replace table t1 (a datetime generated always as (current_date()) virtual);
+create or replace table t1 (a datetime generated always as (current_time) virtual);
+create or replace table t1 (a datetime generated always as (current_time()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp()) virtual);
+create or replace table t1 (a datetime generated always as (current_timestamp) virtual);
+create or replace table t1 (a datetime generated always as (curtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtime) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp()) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (localtimestamp) virtual);
+create or replace table t1 (a datetime, b varchar(10) generated always as (now()) virtual);
+create or replace table t1 (a int, b varchar(10) generated always as (sysdate()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (unix_timestamp()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_date()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_time()) virtual);
+create or replace table t1 (a datetime, b datetime generated always as (utc_timestamp()) virtual);
+create or replace table t1 (a int generated always as (connection_id()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (current_user) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (database()) virtual);
+create or replace table t1 (a varchar(32) generated always as (schema()) virtual);
+create or replace table t1 (a varchar(32) generated always as (session_user()) virtual);
+create or replace table t1 (a varchar(32) generated always as (system_user()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (user()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid_short()) virtual);
+create or replace table t1 (a varchar(1024) generated always as (uuid()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (version()) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (encrypt(a)) virtual);
+create or replace table t1 (a varchar(1024), b varchar(1024) generated always as (UpdateXML(a,'/a','<e>fff</e>')) virtual);
+drop table t1;
+# LOAD_FILE()
+create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual);
+ERROR HY000: Function or expression 'load_file()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MATCH()
+create table t1 (a varchar(32), b bool generated always as (match a against ('sample text')) virtual);
+ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BENCHMARK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (benchmark(a,3)) virtual);
+ERROR HY000: Function or expression 'benchmark()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# FOUND_ROWS()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (found_rows()) virtual);
+ERROR HY000: Function or expression 'found_rows()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# GET_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (get_lock(a,10)) virtual);
+ERROR HY000: Function or expression 'get_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# IS_FREE_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual);
+ERROR HY000: Function or expression 'is_free_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# IS_USED_LOCK()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (is_used_lock(a)) virtual);
+ERROR HY000: Function or expression 'is_used_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# LAST_INSERT_ID()
+create table t1 (a int generated always as (last_insert_id()) virtual);
+ERROR HY000: Function or expression 'last_insert_id()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# MASTER_POS_WAIT()
+create table t1 (a varchar(32), b int generated always as (master_pos_wait(a,0,2)) virtual);
+ERROR HY000: Function or expression 'master_pos_wait()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# NAME_CONST()
+create table t1 (a varchar(32) generated always as (name_const('test',1)) virtual);
+ERROR HY000: Function or expression 'name_const()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# RELEASE_LOCK()
+create table t1 (a varchar(32), b int generated always as (release_lock(a)) virtual);
+ERROR HY000: Function or expression 'release_lock()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# ROW_COUNT()
+create table t1 (a int generated always as (row_count()) virtual);
+ERROR HY000: Function or expression 'row_count()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+# SLEEP()
+create table t1 (a int, b int generated always as (sleep(a)) virtual);
+ERROR HY000: Function or expression 'sleep()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VALUES()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (value(a)) virtual);
+ERROR HY000: Function or expression 'value()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# Stored procedures
+create procedure p1()
+begin
+select current_user();
+end //
+create function f1()
+returns int
+begin
+return 1;
+end //
+create table t1 (a int generated always as (p1()) virtual);
+ERROR HY000: Function or expression '`p1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+create table t1 (a int generated always as (f1()) virtual);
+ERROR HY000: Function or expression '`f1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+drop procedure p1;
+drop function f1;
+# Unknown functions
+create table t1 (a int generated always as (f1()) virtual);
+ERROR HY000: Function or expression '`f1`()' cannot be used in the GENERATED ALWAYS AS clause of `a`
+#
+# GROUP BY FUNCTIONS
+#
+# AVG()
+create table t1 (a int, b int generated always as (avg(a)) virtual);
+ERROR HY000: Function or expression 'avg()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_AND()
+create table t1 (a int, b int generated always as (bit_and(a)) virtual);
+ERROR HY000: Function or expression 'bit_and()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_OR()
+create table t1 (a int, b int generated always as (bit_or(a)) virtual);
+ERROR HY000: Function or expression 'bit_or()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# BIT_XOR()
+create table t1 (a int, b int generated always as (bit_xor(a)) virtual);
+ERROR HY000: Function or expression 'bit_xor()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# COUNT(DISTINCT)
+create table t1 (a int, b int generated always as (count(distinct a)) virtual);
+ERROR HY000: Function or expression 'count(distinct )' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# COUNT()
+create table t1 (a int, b int generated always as (count(a)) virtual);
+ERROR HY000: Function or expression 'count()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# GROUP_CONCAT()
+create table t1 (a varchar(32), b int generated always as (group_concat(a,'')) virtual);
+ERROR HY000: Function or expression 'group_concat()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MAX()
+create table t1 (a int, b int generated always as (max(a)) virtual);
+ERROR HY000: Function or expression 'max()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# MIN()
+create table t1 (a int, b int generated always as (min(a)) virtual);
+ERROR HY000: Function or expression 'min()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STD()
+create table t1 (a int, b int generated always as (std(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV_POP()
+create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV_SAMP()
+create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
+ERROR HY000: Function or expression 'stddev_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# STDDEV()
+create table t1 (a int, b int generated always as (stddev(a)) virtual);
+ERROR HY000: Function or expression 'std()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# SUM()
+create table t1 (a int, b int generated always as (sum(a)) virtual);
+ERROR HY000: Function or expression 'sum()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VAR_POP()
+create table t1 (a int, b int generated always as (var_pop(a)) virtual);
+ERROR HY000: Function or expression 'variance()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VAR_SAMP()
+create table t1 (a int, b int generated always as (var_samp(a)) virtual);
+ERROR HY000: Function or expression 'var_samp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+# VARIANCE()
+create table t1 (a int, b int generated always as (variance(a)) virtual);
+ERROR HY000: Function or expression 'variance()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+#
+# Sub-selects
+#
+create table t1 (a int);
+create table t2 (a int, b int generated always as (select count(*) virtual from t1));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+drop table t1;
+#
+# Long expression
+create table t1 (a int, b varchar(300) generated always as (concat(a,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) virtual);
+drop table t1;
+create table t1 (a int, b varchar(300) generated always as (concat(a,'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')) virtual);
+drop table t1;
+#
+# Constant expression
+create table t1 (a int generated always as (PI()) virtual);
+drop table t1;
+# bug#21098119: GCOL WITH MATCH/AGAINST -->
+# ASSERTION FAILED: TR && TR->TABLE->FILE
+#
+create table t1 (a int);
+alter table t1 add column r blob generated always
+as (match(a) against ('' in boolean mode)) virtual;
+ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `r`
+drop table t1;
+#
+# End of 10.3 tests
+#
+#
+# MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column
+#
+create table t1 (a int);
+alter table t1 add column b binary(32) generated always as (random_bytes(a));
+ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b`
+alter table t1 add column b binary(32) default (random_bytes(a));
+drop table t1;
+#
+#
+# End of 10.10 tests
+#
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_bug20746926.result b/mysql-test/suite/gcol/r/gcol_bug20746926.result
new file mode 100644
index 00000000..590caf02
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_bug20746926.result
@@ -0,0 +1,32 @@
+#Bug #20746926: GENERATED COLUMNS: INVALID READ OF THD WHEN WARNINGS
+#
+# Testing cmp_item_datetime
+connect con1,localhost,root,,;
+set sql_mode='';
+create table t1 (
+a date not null,
+b mediumtext generated always as ((a not in (a,a))) virtual,
+c timestamp generated always as ((a not in (b,b))) stored
+);
+insert t1(a) values(7777777777);
+Warnings:
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 Truncated incorrect datetime value: '0'
+show warnings;
+Level Code Message
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 Truncated incorrect datetime value: '0'
+disconnect con1;
+connect con2,localhost,root,,;
+set sql_mode='';
+insert t1(a) values(6666666666);
+Warnings:
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 Truncated incorrect datetime value: '0'
+show warnings;
+Level Code Message
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 Truncated incorrect datetime value: '0'
+drop table t1;
+disconnect con2;
+connection default;
diff --git a/mysql-test/suite/gcol/r/gcol_bugfixes.result b/mysql-test/suite/gcol/r/gcol_bugfixes.result
new file mode 100644
index 00000000..f124ebe6
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_bugfixes.result
@@ -0,0 +1,746 @@
+# Bug#21230709: Alter table statement fails with division by zero
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+col3 INTEGER NOT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col3 + col3) VIRTUAL,
+col4 INTEGER DEFAULT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+gcol2 INTEGER GENERATED ALWAYS AS (col2 + col2) VIRTUAL,
+gcol3 INTEGER GENERATED ALWAYS AS (gcol2 / gcol2) VIRTUAL,
+PRIMARY KEY (col1),
+KEY idx1 (gcol1)
+) engine=innodb;
+INSERT INTO t1 (col1, col2, col3)
+VALUES (0,1,2), (1,2,3), (2,3,4), (3,4,5), (4,5,6);
+FLUSH TABLE t1;
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+DROP TABLE t1;
+#
+# Bug 21340801 WL8149:ASSERTION `IS_VIRTUAL_GCOL()' FAILED
+#
+CREATE TABLE t1 (
+c_blob BLOB,
+c_blob_key BLOB GENERATED ALWAYS AS (REPEAT(c_blob,15)) STORED,
+KEY (c_blob_key(200))
+);
+INSERT INTO t1 (c_blob) VALUES ('xceks');
+DROP TABLE t1;
+#
+# Bug#21345972 WL8149:JOIN_CACHE::FILTER_VIRTUAL_GCOL_BASE_COLS(): ASSERTION `FALSE' FAILED.
+#
+CREATE TABLE c (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_date_nokey DATE,
+gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME,
+col_time_nokey TIME,
+gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+col_varchar_nokey VARCHAR(1),
+gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY (gcol_int_key),
+UNIQUE KEY (gcol_varchar_key),
+UNIQUE KEY (gcol_date_key),
+KEY (gcol_time_key),
+KEY (gcol_datetime_key),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+KEY (gcol_int_key, col_int_nokey),
+KEY(gcol_int_key,gcol_date_key),
+KEY(gcol_int_key, gcol_time_key),
+KEY(gcol_int_key, gcol_datetime_key),
+UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) ENGINE=INNODB;
+INSERT IGNORE INTO c ( col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+VALUES (7, '2004-04-09', '14:03:03.042673', '2001-11-28 00:50:27.051028', 'c'),
+(1, '2006-05-13', '01:46:09.016386', '2007-10-09 19:53:04.008332', NULL);
+Warnings:
+Note 1265 Data truncated for column 'gcol_time_key' at row 1
+Note 1265 Data truncated for column 'gcol_time_key' at row 2
+CREATE TABLE bb (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_date_nokey DATE,
+gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME,
+col_time_nokey TIME,
+gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+col_varchar_nokey VARCHAR(1),
+gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY (gcol_int_key),
+UNIQUE KEY (gcol_varchar_key),
+UNIQUE KEY (gcol_date_key),
+KEY (gcol_time_key),
+KEY (gcol_datetime_key),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+KEY (gcol_int_key, col_int_nokey),
+KEY(gcol_int_key,gcol_date_key),
+KEY(gcol_int_key, gcol_time_key),
+KEY(gcol_int_key, gcol_datetime_key),
+UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) AUTO_INCREMENT=10 ENGINE=INNODB;
+INSERT IGNORE INTO bb ( col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+VALUES (0, '2003-08-04', '01:48:05.048577', '2006-11-03 00:00:00', 'p'),
+(2, '2007-11-06', '00:00:00', '2009-11-26 19:28:11.005115', 'n');
+Warnings:
+Note 1265 Data truncated for column 'gcol_time_key' at row 1
+Note 1265 Data truncated for column 'gcol_time_key' at row 2
+CREATE TABLE cc (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_date_nokey DATE,
+gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME,
+col_time_nokey TIME,
+gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+col_varchar_nokey VARCHAR(1),
+gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY (gcol_int_key),
+UNIQUE KEY (gcol_varchar_key),
+UNIQUE KEY (gcol_date_key),
+KEY (gcol_time_key),
+KEY (gcol_datetime_key),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+KEY (gcol_int_key, col_int_nokey),
+KEY(gcol_int_key,gcol_date_key),
+KEY(gcol_int_key, gcol_time_key),
+KEY(gcol_int_key, gcol_datetime_key),
+UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) AUTO_INCREMENT=10 ENGINE=INNODB;
+INSERT IGNORE INTO cc (col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+VALUES (172, '2009-04-23', '00:00:00', '2000-12-07 10:17:40.013275', 'h'),
+(NULL, '2002-10-06', '00:50:49.017545', NULL, 'm');
+Warnings:
+Note 1265 Data truncated for column 'gcol_time_key' at row 1
+EXPLAIN SELECT
+gp1 . gcol_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . gcol_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . gcol_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . gcol_int_key = p2 . pk )
+)
+AND gp1 . col_varchar_nokey = 'b'
+HAVING g1 > 6;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+SELECT
+gp1 . gcol_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . gcol_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . gcol_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . gcol_int_key = p2 . pk )
+)
+AND gp1 . col_varchar_nokey = 'b'
+HAVING g1 > 6;
+g1
+DROP TABLE bb, c, cc;
+# Bug#21284646: Assertion !(table || table->read_set || bitmap_is_set())
+CREATE TABLE c (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_date_nokey DATE NOT NULL,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk,col_int_nokey),
+UNIQUE KEY (col_int_key),
+UNIQUE KEY (col_varchar_key),
+UNIQUE KEY (col_date_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+UNIQUE KEY (col_int_key, col_varchar_key),
+KEY (col_int_key, col_int_nokey),
+KEY(col_int_key,col_date_key),
+KEY(col_int_key, col_time_key),
+KEY(col_int_key, col_datetime_key),
+UNIQUE KEY (col_date_key,col_time_key,col_datetime_key),
+UNIQUE KEY (col_varchar_key, col_varchar_nokey),
+UNIQUE KEY (col_int_key, col_varchar_key, col_date_key, col_time_key, col_datetime_key)
+) ENGINE=INNODB;
+INSERT INTO c (col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey) VALUES
+(1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(2, '2002-10-13', '00:00:00', '1900-01-01 00:00:00', 's'),
+(4, '1900-01-01', '15:57:25.019666', '2005-08-15 00:00:00', 'r');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+Note 1265 Data truncated for column 'col_time_key' at row 3
+Note 1265 Data truncated for column 'col_time_key' at row 4
+Note 1265 Data truncated for column 'col_time_key' at row 5
+Note 1265 Data truncated for column 'col_time_key' at row 6
+ANALYZE TABLE c;
+Table Op Msg_type Msg_text
+test.c analyze status Engine-independent statistics collected
+test.c analyze status OK
+explain SELECT COUNT(DISTINCT col_varchar_key) AS x
+FROM c
+WHERE col_varchar_key IN ('rr', 'rr') OR
+col_int_nokey <> 9 AND
+pk >= 8
+HAVING x > '2000-02-06'
+ORDER BY col_time_nokey, pk;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE c index_merge PRIMARY,col_varchar_key,col_varchar_key_2 col_varchar_key,PRIMARY 5,4 NULL 2 Using union(col_varchar_key,PRIMARY); Using where
+SELECT COUNT(DISTINCT col_varchar_key) AS x
+FROM c
+WHERE col_varchar_key IN ('rr', 'rr') OR
+col_int_nokey <> 9 AND
+pk >= 8
+HAVING x > '2000-02-06'
+ORDER BY col_time_nokey, pk;
+x
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-06'
+DROP TABLE c;
+# Bug#21341044: Conditional jump at sort_param::make_sort_key
+CREATE TABLE t1 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_blob_nokey BLOB,
+col_blob_key BLOB GENERATED ALWAYS AS (REPEAT(col_blob_nokey,15)) VIRTUAL,
+col_longblob_nokey LONGBLOB,
+col_longtext_nokey LONGTEXT,
+col_longblob_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_longblob_nokey, 20)) VIRTUAL,
+col_longtext_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_longblob_nokey, 18)) VIRTUAL,
+col_text_nokey TEXT,
+col_text_key TEXT GENERATED ALWAYS AS (REPEAT(col_text_nokey, 30)) VIRTUAL,
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_text_key(50)),
+KEY (col_blob_key(200)),
+KEY (col_longtext_key(200)),
+KEY (col_longblob_key(200)),
+KEY (col_int_key, col_text_key(100)),
+KEY (col_int_key, col_longtext_key(100)),
+KEY (col_int_key, col_blob_key(100)),
+KEY (col_int_key, col_longblob_key(100)),
+KEY (col_longtext_key(10), col_longblob_key(100)),
+KEY (col_int_key, col_text_key(10), col_blob_key(100), col_longtext_key(50), col_longblob_key(50))
+) engine=innodb;
+INSERT INTO t1 (col_int_nokey,col_blob_nokey,col_longtext_nokey,col_longblob_nokey,col_text_nokey)
+VALUES
+(0, 'ijcszxw', 'ijcszxw', 'ijcszxw', 'ijcszxw'),
+(5, 'jcszxwb', 'jcszxwb', 'jcszxwb', 'jcszxwb'),
+(4, 'cszxwbjjvv', 'cszxwbjjvv', 'cszxwbjjvv', 'cszxwbjjvv'),
+(3, 'szxw', 'szxw', 'szxw', 'szxw'),
+(7, 'zxwb', 'zxwb', 'zxwb', 'zxwb'),
+(42, 'xwbjjvvky', 'xwbjjvvky', 'xwbjjvvky', 'xwbjjvvky'),
+(142, 'wbjj', 'wbjj', 'wbjj', 'wbjj'),
+(5, 'bjjv', 'bjjv', 'bjjv', 'bjjv'),
+(0, 'jjvvkymalu', 'jjvvkymalu', 'jjvvkymalu', 'jjvvkymalu'),
+(3, 'j', 'j', 'j', 'j');
+SELECT alias1.pk AS field1
+FROM t1 AS alias1 LEFT OUTER JOIN t1 AS alias2
+ON alias1.col_int_key = alias2.col_int_key
+WHERE alias2.col_int_key BETWEEN 8 AND (8 + 1 ) OR
+alias2.col_int_key BETWEEN 8 AND (8 + 5 ) AND
+alias2.col_int_key != 20 OR
+alias2.col_int_key IN (8, 5, 8) AND
+alias2.col_int_key >= 0 AND
+alias2.col_int_key <= ( 8 + 75 ) AND
+alias1.pk IS NOT NULL
+ORDER BY field1;
+field1
+2
+2
+3
+8
+8
+DROP TABLE t1;
+# bug#21487651: gcols: memory leak after failed alter table
+CREATE TABLE t(a int);
+ALTER TABLE t ADD COLUMN b int GENERATED ALWAYS AS (
+date_sub(a,interval a month)) VIRTUAL;
+ALTER TABLE t ADD COLUMN c int GENERATED ALWAYS AS (sum(a));
+ERROR HY000: Function or expression 'sum()' cannot be used in the GENERATED ALWAYS AS clause of `c`
+DROP TABLE t;
+#
+# Bug#21628840: CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
+# (II)
+#
+CREATE TABLE t1( a INT ) ENGINE = INNODB;
+INSERT INTO t1( a ) VALUES ( 1 ), ( 2 ), ( 3 ), ( 4 ), ( 5 );
+ALTER TABLE t1 ADD COLUMN b INT GENERATED ALWAYS AS (a - 1) STORED;
+ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS (b + 1) VIRTUAL;
+# Used to cause valgrind warning.
+ALTER TABLE t1 ADD INDEX( c );
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+# Make sure the index is correct. That's kinda important.
+EXPLAIN
+SELECT c FROM t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL c 5 NULL 5 Using index
+SELECT c FROM t1;
+c
+1
+2
+3
+4
+5
+DROP TABLE t1;
+#
+# Bug#21797776 ASSERTION `BIT < MAP->N_BITS' FAILED.
+#
+CREATE TABLE C (
+col_int_1 INT,
+col_int_2 INT GENERATED ALWAYS AS (col_int_1 + col_int_1) STORED,
+col_int_3 INT GENERATED ALWAYS AS (col_int_2 + col_int_1) VIRTUAL
+);
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS
+SELECT
+col_int_2 AS field1, col_int_2 AS field2,
+col_int_3 AS field3, col_int_3 AS field4
+FROM C;
+SELECT * FROM v1;
+field1 field2 field3 field4
+DROP TABLE C;
+DROP VIEW v1;
+#
+# Bug#21613615 GCOLS: ASSERTION FAILED: !TABLE || (!TABLE->READ_SET || BITMAP_IS_SET
+#
+CREATE TABLE t (a INT);
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL,
+KEY(c,b(1)));
+INSERT INTO v (a,c) VALUES (1,1);
+EXPLAIN SELECT 1 FROM t WHERE ( SELECT 1 FROM t ) >=ANY( SELECT c FROM v );
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
+SELECT 1 FROM t WHERE ( SELECT 1 FROM t ) >=ANY( SELECT c FROM v );
+1
+EXPLAIN SELECT (SELECT MAX(c) FROM v);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+SELECT (SELECT MAX(c) FROM v);
+(SELECT MAX(c) FROM v)
+1
+DROP TABLE t, v;
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL, KEY(c,b(1)));
+INSERT INTO v (a,c) VALUES (1,1);
+SELECT MAX(c), COUNT(b) FROM v;
+MAX(c) COUNT(b)
+1 1
+DROP TABLE v;
+CREATE TABLE v (
+a INT PRIMARY KEY,
+b INT, KEY(b));
+INSERT INTO v (a,b) VALUES (1,1);
+SELECT MAX(a) FROM v WHERE b=1;
+MAX(a)
+1
+DROP TABLE v;
+#
+# Bug#21824519: ASSERTION IN DROP TRIGGER WHEN TABLE HAS
+# VIRTUAL GENERATED COLUMN
+#
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL);
+CREATE TRIGGER tr BEFORE INSERT ON t FOR EACH ROW BEGIN END;
+INSERT INTO t (a) VALUES (1);
+SELECT * FROM t;
+a b
+1 1
+DROP TRIGGER tr;
+SELECT * FROM t;
+a b
+1 1
+CREATE FUNCTION f() RETURNS INT RETURN (SELECT COUNT(*) FROM t);
+SELECT f();
+f()
+1
+DROP FUNCTION f;
+SELECT * FROM t;
+a b
+1 1
+DROP TABLE t;
+#
+# Bug#21833760 CALC_DAYNR: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED.
+#
+CREATE TABLE C(
+c1 INT AUTO_INCREMENT,
+c8 DATETIME,
+c9 TIME,
+c11 TIME GENERATED ALWAYS AS(ADDTIME(c8,c9)) VIRTUAL,
+c13 TIME GENERATED ALWAYS AS(ADDTIME(c8,c11)) VIRTUAL,
+PRIMARY KEY(c1),
+UNIQUE KEY(c13)
+);
+INSERT INTO C (c8,c9) VALUES('1970-01-01',0),('1970-01-01',1);
+Warnings:
+Note 1265 Data truncated for column 'c11' at row 1
+Note 1265 Data truncated for column 'c13' at row 1
+Note 1265 Data truncated for column 'c11' at row 2
+Note 1265 Data truncated for column 'c13' at row 2
+CREATE VIEW view_C AS SELECT * FROM C;
+SELECT /*+ NO_BNL(t1) */ t1.c13 FROM C AS t2 STRAIGHT_JOIN C AS t1 FORCE INDEX(c13);
+c13
+00:00:00
+00:00:00
+00:00:01
+00:00:01
+SELECT DISTINCT t1.c13 FROM C AS t1, view_C AS t2;
+c13
+00:00:00
+00:00:01
+DROP TABLE C;
+DROP VIEW view_C;
+#
+# Bug#21810529: CRASH IN ITEM_FUNC::WALK WHEN CODE JUMPS TO GARBAGE
+# LOCATION
+#
+CREATE TABLE t (a TIME,b INT GENERATED ALWAYS AS (a=1) VIRTUAL);
+ALTER TABLE t CHANGE COLUMN q w INT;
+ERROR 42S22: Unknown column 'q' in 't'
+ALTER TABLE t CHANGE COLUMN q w INT;
+ERROR 42S22: Unknown column 'q' in 't'
+ALTER TABLE t CHANGE COLUMN q w INT;
+ERROR 42S22: Unknown column 'q' in 't'
+ALTER TABLE t CHANGE COLUMN q w INT;
+ERROR 42S22: Unknown column 'q' in 't'
+DROP TABLE t;
+#
+# Bug#21940542 TOO MUCH SPAM: INNODB: COMPUTE VIRTUAL COLUMN VALUES FAILED
+#
+CREATE TABLE t(b BLOB);
+ALTER TABLE t ADD COLUMN c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL;
+ERROR 21000: Operand should contain 1 column(s)
+DROP TABLE t;
+CREATE TABLE t(b BLOB, c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL);
+ERROR 21000: Operand should contain 1 column(s)
+#
+# Bug#21929967 GCOLS: GCOL VALUE CHANGES WHEN SESSION CHANGES SQL_MODE
+#
+CREATE TABLE t1(a CHAR(1), b CHAR(1), c CHAR(2) AS (a || b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(1) DEFAULT NULL,
+ `b` char(1) DEFAULT NULL,
+ `c` char(2) GENERATED ALWAYS AS (`a` <> 0 or `b` <> 0) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+INSERT INTO t1 (a,b) VALUES('1','1');
+SELECT * FROM t1;
+a b c
+1 1 1
+SET SQL_MODE=PIPES_AS_CONCAT;
+SELECT * FROM t1;
+a b c
+1 1 1
+FLUSH TABLES;
+SELECT * FROM t1;
+a b c
+1 1 1
+DROP TABLE t1;
+CREATE TABLE t1(a CHAR(1), b CHAR(1), c CHAR(2) AS (a || b));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(1) DEFAULT NULL,
+ `b` char(1) DEFAULT NULL,
+ `c` char(2) GENERATED ALWAYS AS (concat(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+INSERT INTO t1 (a,b) VALUES('1','1');
+SELECT * FROM t1;
+a b c
+1 1 11
+SET SQL_MODE=DEFAULT;
+SELECT * FROM t1;
+a b c
+1 1 11
+FLUSH TABLES;
+SELECT * FROM t1;
+a b c
+1 1 11
+DROP TABLE t1;
+# Bug#22018999: gcols: assertion failed: !error
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
+Warnings:
+Warning 1292 Truncated incorrect INTEGER value: 'a'
+DROP TABLE t;
+CREATE TABLE t (a INTEGER) engine=innodb;
+ALTER TABLE t ADD b INTEGER AS (SUBSTR('','a',1));
+Warnings:
+Warning 1292 Truncated incorrect INTEGER value: 'a'
+DROP TABLE t;
+set sql_mode= @save_old_sql_mode;
+# Bug#21875520 Problems with virtual column indexes
+CREATE TABLE t(
+a TIMESTAMP,
+b BLOB,
+c TIMESTAMP GENERATED ALWAYS AS (GREATEST(a, '2000-01-01 00:00:00')) VIRTUAL,
+UNIQUE KEY(c)
+);
+INSERT INTO t(b) VALUES ('');
+UPDATE t SET a='2001-01-01 00:00:00';
+SELECT c FROM t;
+c
+2001-01-01 00:00:00
+SELECT c, a FROM t;
+c a
+2001-01-01 00:00:00 2001-01-01 00:00:00
+UPDATE t SET b='xyz';
+DO (SELECT @c1:= c FROM t);
+DO (SELECT (@c2:= c) - a FROM t);
+SELECT @c2 - @c1;
+@c2 - @c1
+0
+DROP TABLE t;
+#
+# Bug#22133710 GCOLS: READ UNCOMMITTED: ASSERT !TABLE || (!TABLE->WRITE_SET || BITMAP_IS_SET(TA
+#
+CREATE TABLE t (
+a INT,
+b INT GENERATED ALWAYS AS (1) VIRTUAL,
+c INT GENERATED ALWAYS AS (1) VIRTUAL,
+d INT GENERATED ALWAYS AS (1) VIRTUAL,
+KEY (b,d)
+) ENGINE=INNODB;
+INSERT INTO t VALUES();
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
+SELECT 1 FROM t WHERE c GROUP BY b;
+1
+1
+COMMIT;
+DROP TABLE t;
+#
+# Bug #25793677 INNODB: FAILING ASSERTION: CLUST_TEMPL_FOR_SEC || LEN ....
+#
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL,
+KEY(c,b(1))) charset utf8mb4;
+INSERT INTO v (a,c) VALUES (1,1);
+SELECT (SELECT MAX(c) FROM v);
+(SELECT MAX(c) FROM v)
+1
+DROP TABLE v;
+#
+# MDEV-9255 Add generation_expression to information_schema.columns.
+#
+CREATE TABLE gcol_t1 (
+sidea DOUBLE,
+sideb DOUBLE,
+sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb))
+);
+SELECT table_schema,table_name,column_name,extra,is_generated,generation_expression
+FROM information_schema.columns WHERE table_name='gcol_t1';
+table_schema table_name column_name extra is_generated generation_expression
+test gcol_t1 sidea NEVER NULL
+test gcol_t1 sideb NEVER NULL
+test gcol_t1 sidec VIRTUAL GENERATED ALWAYS sqrt(`sidea` * `sidea` + `sideb` * `sideb`)
+DROP TABLE gcol_t1;
+#
+# MDEV-16039 Crash when selecting virtual columns
+# generated using functions with DAYNAME()
+#
+CREATE TABLE t1 (
+suppliersenttoday INT NOT NULL,
+suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05')))
+) COLLATE utf8_bin;
+INSERT INTO t1 (suppliersenttoday) VALUES (0);
+INSERT INTO t1 (suppliersenttoday) VALUES (0);
+SELECT * FROM t1;
+suppliersenttoday suppliercaptoday
+0 Wednesday
+0 Wednesday
+PREPARE STMT FROM 'INSERT INTO t1 (suppliersenttoday) VALUES (1)';
+CREATE OR REPLACE TABLE t1 (
+suppliersenttoday INT NOT NULL,
+suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05')))
+) COLLATE utf8_bin;
+EXECUTE STMT;
+EXECUTE STMT;
+SELECT * FROM t1;
+suppliersenttoday suppliercaptoday
+1 Wednesday
+1 Wednesday
+DROP TABLE t1;
+# (duplicate) MDEV-20380 Server crash during update
+CREATE TABLE gafld (
+nuigafld INTEGER NOT NULL,
+ucrgafld VARCHAR(30) COLLATE UTF8_BIN NOT NULL
+DEFAULT SUBSTRING_INDEX(USER(),'@',1)
+);
+EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE gafld ALL NULL NULL NULL NULL 1 Using where
+EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE gafld ALL NULL NULL NULL NULL 1 Using where
+DROP TABLE gafld;
+# (duplicate) MDEV-17653 replace into generated columns is unstable
+# Some columns are snipped from the MDEV test
+CREATE TABLE t (
+c0 TIMESTAMP NOT NULL DEFAULT current_timestamp()
+ON UPDATE current_timestamp(),
+c1 DECIMAL(27,25) GENERATED ALWAYS AS (DAYOFMONTH('2020-02-05')),
+c4 TIME NOT NULL,
+c8 SMALLINT(6) GENERATED ALWAYS AS
+(CONCAT_WS(CONVERT(C1 USING CP932),
+'900') <> (c4 = 1)),
+PRIMARY KEY (c4)
+) DEFAULT CHARSET=latin1;
+REPLACE INTO t SET c0 = '2018-06-03 10:31:43', c4 = '02:58:55';
+REPLACE INTO t SET c0 = '2018-06-03 10:31:44', c4 = '02:58:55';
+REPLACE INTO t SET c0 = '2018-06-03 10:31:45', c4 = '02:58:55';
+DROP TABLE t;
+# (duplicate) MDEV-17986 crash when I insert on a table
+CREATE OR REPLACE TABLE t2 (
+number BIGINT(20) NOT NULL,
+lrn BIGINT(20) NOT NULL DEFAULT 0,
+source VARCHAR(15) NOT NULL
+DEFAULT (REVERSE(SUBSTRING_INDEX(REVERSE(user()), '@', 1))),
+PRIMARY KEY (number)
+);
+REPLACE t2(number) VALUES('1');
+REPLACE t2(number) VALUES('1');
+DROP TABLE t2;
+# MDEV-24583 SELECT aborts after failed REPLACE into table with vcol
+CREATE TABLE t1 (pk INT, a VARCHAR(3), v VARCHAR(3) AS (CONCAT('x-',a)),
+PRIMARY KEY(pk)) ENGINE=MyISAM;
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (pk, a) VALUES (1,'foo');
+SET sql_mode=CONCAT(@@sql_mode,',STRICT_ALL_TABLES');
+REPLACE INTO t1 (pk,a) VALUES (1,'qux');
+SELECT * FROM v1;
+pk a v
+1 foo x-f
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (
+pk INT,
+a VARCHAR(1),
+v VARCHAR(1) AS (CONCAT('virt-',a)) VIRTUAL,
+PRIMARY KEY (pk)
+) ENGINE=InnoDB;
+INSERT INTO t1 (pk,a) VALUES
+(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'f');
+REPLACE INTO t1 (pk) VALUES (1);
+ERROR 22001: Data too long for column 'v' at row 1
+SELECT * FROM t1 ORDER BY a;
+pk a v
+1 a v
+2 b v
+3 c v
+4 d v
+5 e v
+6 f v
+SET SQL_MODE=DEFAULT;
+DROP TABLE t1;
+# (duplicate) MDEV-24656
+# [FATAL] InnoDB: Data field type 0, len 0, ASAN heap-buffer-overflow
+# upon LOAD DATA with virtual columns
+CREATE TABLE t1 (id INT PRIMARY KEY, a VARCHAR(2333),
+va VARCHAR(171) AS (a)) ENGINE=InnoDB;
+INSERT INTO t1 (id,a) VALUES (1,REPEAT('x',200));
+SELECT id, va INTO OUTFILE 'load_t1' FROM t1;
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id,va);
+ERROR 22001: Data too long for column 'va' at row 1
+SELECT * FROM t1;
+id a va
+1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+LOAD DATA INFILE 'load_t1' IGNORE INTO TABLE t1 (id,va);
+Warnings:
+Warning 1062 Duplicate entry '1' for key 'PRIMARY'
+DROP TABLE t1;
+CREATE TABLE t1 (id BIGINT PRIMARY KEY, a VARCHAR(2333),
+va VARCHAR(171) AS (a)) ENGINE=InnoDB;
+INSERT INTO t1 (id,a) VALUES (1,REPEAT('x',200));
+SELECT id, va INTO OUTFILE 'load_t1' FROM t1;
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id,va);
+ERROR 22001: Data too long for column 'va' at row 1
+SELECT * FROM t1;
+id a va
+1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+LOAD DATA INFILE 'load_t1' IGNORE INTO TABLE t1 (id,va);
+Warnings:
+Warning 1062 Duplicate entry '1' for key 'PRIMARY'
+DROP TABLE t1;
+# (duplicate) MDEV-24665
+# ASAN errors, assertion failures, corrupt values after failed
+# LOAD DATA into table with virtual/stored column
+CREATE TABLE t1 (id INT PRIMARY KEY,
+ts TIMESTAMP DEFAULT '1971-01-01 00:00:00',
+c VARBINARY(8) DEFAULT '', vc VARCHAR(3) AS (c) STORED);
+INSERT IGNORE INTO t1 (id,c) VALUES (1,'foobar');
+Warnings:
+Warning 1265 Data truncated for column 'vc' at row 1
+SELECT id, ts, vc INTO OUTFILE 'load_t1' FROM t1;
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id, ts, vc);
+INSERT IGNORE INTO t1 (id) VALUES (2);
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result b/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result
new file mode 100644
index 00000000..8c1925c9
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result
@@ -0,0 +1,736 @@
+SET @@session.default_storage_engine = 'InnoDB';
+#
+# Section 1. Wrong column definition options
+# - DEFAULT <value>
+# - AUTO_INCREMENT
+# NOT NULL
+create table t1 (a int, b int generated always as (a+1) virtual not null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored not null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual not null;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null' at line 1
+drop table t1;
+create table t1 (a int, b int generated always as (a+1) virtual null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'null)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual null;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'null' at line 1
+drop table t1;
+# Added columns mixed with virtual GC and other columns
+create table t1 (a int);
+insert into t1 values(1);
+alter table t1 add column (b int generated always as (a+1) virtual, c int);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (d int, e int generated always as (a+1) virtual);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (f int generated always as (a+1) virtual, g int as(5) stored);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (h int generated always as (a+1) virtual, i int as(5) virtual);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+drop table t1;
+# DEFAULT
+create table t1 (a int, b int generated always as (a+1) virtual default 0);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default 0)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual default 0;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default 0' at line 1
+drop table t1;
+# AUTO_INCREMENT
+create table t1 (a int, b int generated always as (a+1) virtual AUTO_INCREMENT);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AUTO_INCREMENT)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual AUTO_INCREMENT;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AUTO_INCREMENT' at line 1
+drop table t1;
+# [PRIMARY] KEY
+create table t1 (a int, b int generated always as (a+1) virtual key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key)' at line 1
+create table t1 (a int, b int generated always as (a+1) virtual primary key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored primary key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key' at line 1
+alter table t1 add column b int generated always as (a+1) stored key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key' at line 1
+alter table t1 add column c int generated always as (a+2) virtual primary key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key' at line 1
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+alter table t1 add column c int generated always as (a+2) stored primary key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key' at line 1
+drop table t1;
+# Section 2. Other column definition options
+# - COMMENT
+# - REFERENCES (only syntax testing here)
+# - STORED (only systax testing here)
+create table t1 (a int, b int generated always as (a % 2) virtual comment 'my comment');
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) virtual comment 'my comment';
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+insert into t1 (a) values (1);
+select * from t1;
+a b
+1 1
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+a b
+1 1
+2 0
+create table t2 like t1;
+show create table t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t2;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+insert into t2 (a) values (1);
+select * from t2;
+a b
+1 1
+insert into t2 values (2,default);
+select a,b from t2 order by a;
+a b
+1 1
+2 0
+drop table t2;
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL STORED GENERATED
+insert into t1 (a) values (1);
+select * from t1;
+a b
+1 1
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+a b
+1 1
+2 0
+drop table t1;
+create table t2 (a int);
+create table t1 (a int, b int generated always as (a % 2) stored references t2(a));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) stored references t2(a);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1
+alter table t1 modify b int generated always as (a % 2) stored;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+drop table t2;
+FK options
+create table t1(a int, b int as (a % 2), c int as (a) stored);
+create table t2 (a int);
+alter table t1 add constraint foreign key fk(d) references t2(a);
+ERROR 42000: Key column 'd' doesn't exist in table
+alter table t1 add constraint foreign key fk(c) references t2(a) on delete set null;
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+alter table t1 add constraint foreign key fk(c) references t2(a) on update set null;
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+alter table t1 add constraint foreign key fk(c) references t2(a) on update cascade;
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+drop table t1;
+drop table t2;
+Generated always is optional
+create table t1 (a int, b int as (a % 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL STORED GENERATED
+drop table t1;
+Default should be non-stored column
+create table t1 (a int, b int as (a % 2));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+Expression can be constant
+create table t1 (a int, b int as (5 * 2));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (5 * 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+Test generated columns referencing other generated columns
+create table t1 (a int unique, b int generated always as(-a) virtual, c int generated always as (b + 1) virtual);
+insert into t1 (a) values (1), (2);
+select * from t1;
+a b c
+1 -1 0
+2 -2 -1
+insert into t1(a) values (1) on duplicate key update a=3;
+select * from t1;
+a b c
+2 -2 -1
+3 -3 -2
+update t1 set a=4 where a=2;
+select * from t1;
+a b c
+3 -3 -2
+4 -4 -3
+drop table t1;
+create table t1 (a int, b int generated always as(-b) virtual, c int generated always as (b + 1) virtual);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
+create table t1 (a int, b int generated always as(-c) virtual, c int generated always as (b + 1) virtual);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `c`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
+ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
+ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `pk` int(11) NOT NULL AUTO_INCREMENT,
+ `col_int_nokey` int(11) GENERATED ALWAYS AS (`pk` + `col_int_key`) VIRTUAL,
+ `col_int_key` int(11) DEFAULT NULL,
+ PRIMARY KEY (`pk`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert t1 (col_int_key) values (10),(20),(30);
+select * from t1;
+pk col_int_nokey col_int_key
+1 11 10
+2 22 20
+3 33 30
+drop table t1;
+# Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
+create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
+insert into t1(a) values(1),(2);
+create table tt as select * from t1;
+select * from t1 order by a;
+a b c
+1 -1 0
+2 -2 -1
+select * from tt order by a;
+a b c
+1 -1 0
+2 -2 -1
+drop table t1,tt;
+# Bug#20745142: GENERATED COLUMNS: ASSERTION FAILED:
+# THD->CHANGE_LIST.IS_EMPTY()
+#
+CREATE TABLE t1(a bigint AS (a between 1 and 1));
+ERROR 01000: Expression for field `a` is referring to uninitialized field `a`
+# Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+# IN FIND_FIELD_IN_TABLE
+#
+CREATE TABLE t1(a int);
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `z`
+DROP TABLE t1;
+# Bug#20566243: ERROR WHILE DOING CREATE TABLE T1 SELECT (QUERY ON GC COLUMNS)
+CREATE TABLE t1(a int, b int as (a + 1),
+c varchar(12) as ("aaaabb") stored, d blob as (c));
+INSERT INTO t1(a) VALUES(1),(3);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL,
+ `c` varchar(12) GENERATED ALWAYS AS ('aaaabb') STORED,
+ `d` blob GENERATED ALWAYS AS (`c`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1 order by a;
+a b c d
+1 2 aaaabb aaaabb
+3 4 aaaabb aaaabb
+CREATE TABLE t2 LIKE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL,
+ `c` varchar(12) GENERATED ALWAYS AS ('aaaabb') STORED,
+ `d` blob GENERATED ALWAYS AS (`c`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+CREATE TABLE t3 AS SELECT * FROM t1;
+SHOW CREATE TABLE t3;
+Table Create Table
+t3 CREATE TABLE `t3` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(12) DEFAULT NULL,
+ `d` blob DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t3 order by a;
+a b c d
+1 2 aaaabb aaaabb
+3 4 aaaabb aaaabb
+CREATE TABLE t4 AS SELECT b,c,d FROM t1;
+SHOW CREATE TABLE t4;
+Table Create Table
+t4 CREATE TABLE `t4` (
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(12) DEFAULT NULL,
+ `d` blob DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t4 order by b;
+b c d
+2 aaaabb aaaabb
+4 aaaabb aaaabb
+DROP TABLE t1,t2,t3,t4;
+# Bug#21025003:WL8149:ASSERTION `CTX->NUM_TO_DROP_FK
+# == HA_ALTER_INFO->ALTER_INFO-> FAILED
+#
+CREATE TABLE t1 (
+col1 int(11) DEFAULT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) DEFAULT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col4 / col2) VIRTUAL,
+col6 text
+);
+INSERT INTO t1(col1,col2,col3,col4,col6) VALUES(NULL,1,4,0,REPEAT(2,1000));
+ALTER TABLE t1 DROP PRIMARY KEY , ADD KEY idx ( col5, col2 );
+ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists
+DROP TABLE t1;
+# Bug#20949226:i CAN ASSIGN NON-DEFAULT() VALUE TO GENERATED COLUMN
+#
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5 AS c2;
+Warnings:
+Warning 1906 The value specified for generated column 'c2' in table 't1' has been ignored
+CREATE TABLE t2 (a int);
+INSERT INTO t2 values(1);
+DROP TABLE t1;
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, a AS c2 from t2;
+Warnings:
+Warning 1906 The value specified for generated column 'c2' in table 't1' has been ignored
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5;
+SELECT * FROM t1;
+c2 c1 5
+2 1 5
+DROP TABLE t1, t2;
+# Bug#21074624:i WL8149:SIG 11 INNOBASE_GET_COMPUTED_VALUE |
+# INNOBASE/HANDLER/HA_INNODB.CC:19082
+CREATE TABLE t1 (
+col1 int(11) NOT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col2 % col4) VIRTUAL,
+col6 int(11) GENERATED ALWAYS AS (col3 + col3) VIRTUAL,
+col7 int(11) GENERATED ALWAYS AS (col5 / col5) VIRTUAL,
+col8 int(11) GENERATED ALWAYS AS (col6 / col5) VIRTUAL,
+col9 text,
+extra int(11) DEFAULT NULL,
+KEY idx (col5)
+);
+INSERT INTO t1(col1,col2,col3,col4,col9,extra)
+VALUES(0,6,3,4,REPEAT(4,1000),0);
+ALTER TABLE t1 DROP COLUMN col1;
+DROP TABLE t1;
+# Bug#21390605:VALGRIND ERROR ON DELETE FROM TABLE CONTAINING
+# AN INDEXED VIRTUAL COLUMN
+CREATE TABLE t1 (
+a INTEGER,
+b INTEGER GENERATED ALWAYS AS (a) VIRTUAL,
+c INTEGER GENERATED ALWAYS AS (b) VIRTUAL,
+INDEX idx (b,c)
+);
+INSERT INTO t1 (a) VALUES (42);
+DELETE FROM t1 WHERE c = 42;
+DROP TABLE t1;
+# Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+# IN FIND_FIELD_IN_TABLE
+#
+CREATE TABLE t1(a int);
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `z`
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM t1 WHERE not_exist_col)));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM dual)));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+DROP TABLE t1;
+# Bug#21142905: PARTITIONED GENERATED COLS -
+# !TABLE || (!TABLE->WRITE_SET || BITMAP_IS_SET
+#
+CREATE TABLE t1 (
+a int,
+b int generated always as (a) virtual,
+c int generated always as (b+a) virtual,
+d int generated always as (b+a) virtual
+) PARTITION BY LINEAR HASH (b);
+INSERT INTO t1(a) VALUES(0);
+DELETE FROM t1 WHERE c=1;
+DROP TABLE t1;
+CREATE TABLE t1 (c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar"));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c` char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin GENERATED ALWAYS AS ('foo bar') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1 (i INT);
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `i` int(11) DEFAULT NULL,
+ `c` char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin GENERATED ALWAYS AS ('foo bar') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1 (i INT COLLATE utf8_bin, c INT COLLATE utf8_bin GENERATED ALWAYS AS (10));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'GENERATED ALWAYS AS (10))' at line 1
+# Check for a charset mismatch processing:
+# Bug #21469535: VALGRIND ERROR (CONDITIONAL JUMP) WHEN INSERT
+# ROWS INTO A PARTITIONED TABLE
+#
+CREATE TABLE t1 (
+id INT NOT NULL,
+store_id INT NOT NULL,
+x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21)
+);
+INSERT INTO t1 VALUES(1, 2, default);
+DROP TABLE t1;
+# Bug#21465626:ASSERT/CRASH ON DROPPING/ADDING VIRTUAL COLUMN
+CREATE TABLE t (a int(11), b int(11),
+c int(11) GENERATED ALWAYS AS (a+b) VIRTUAL,
+d int(11) GENERATED ALWAYS AS (a+b) VIRTUAL);
+INSERT INTO t(a,b) VALUES(1,2);
+# Mixed drop/add/rename virtual with non-virtual columns,
+# ALGORITHM=INPLACE is not supported for InnoDB
+ALTER TABLE t DROP d, ADD e varchar(10);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD d int, ADD f char(10) AS ('aaa');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE d dd int, CHANGE f ff varchar(10) AS ('bbb');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# Only drop/add/change virtual, inplace is supported for Innodb
+ALTER TABLE t DROP c, DROP ff;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD c int(11) as (a+b), ADD f varchar(10) as ('aaa');
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE c c int(11) as (a), CHANGE f f varchar(10) as('bbb');
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+# Change order should be ALGORITHM=INPLACE on Innodb
+ALTER TABLE t CHANGE c c int(11) as (a) after f;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE b b int(11) after c;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# TODO: Changing virtual column type should be ALGORITHM=INPLACE on InnoDB, current it goes only with COPY method
+ALTER TABLE t CHANGE c c varchar(10) as ('a');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# Changing stored column type is ALGORITHM=COPY
+ALTER TABLE t CHANGE dd d varchar(10);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD INDEX idx(c), ADD INDEX idx1(d);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t DROP INDEX idx, DROP INDEX idx1;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+DROP TABLE t;
+# Bug#21854004: GCOLS:INNODB: FAILING ASSERTION: I < TABLE->N_DEF
+CREATE TABLE t1(
+col1 INTEGER PRIMARY KEY,
+col2 INTEGER,
+col3 INTEGER,
+col4 INTEGER,
+vgc1 INTEGER AS (col2 + col3) VIRTUAL,
+sgc1 INTEGER AS (col2 - col3) STORED
+);
+INSERT INTO t1(col1, col2, col3) VALUES
+(1, 10, 100), (2, 20, 200);
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 110 -90
+2 20 200 NULL 220 -180
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 0
+2 20 200 NULL 4000 0
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD INDEX vgc1 (vgc1);
+ALTER TABLE t1 ADD INDEX sgc1 (sgc1);
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+SELECT vgc1 FROM t1 order by vgc1;
+vgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 0
+2 20 200 NULL 4000 0
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+0
+0
+ALTER TABLE t1 DROP INDEX vgc1;
+ALTER TABLE t1 DROP INDEX sgc1;
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 ADD UNIQUE INDEX vgc1 (vgc1);
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD UNIQUE INDEX sgc1 (sgc1);
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR 23000: Duplicate entry '0' for key 'vgc1'
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+ERROR 23000: Duplicate entry '0' for key 'sgc1'
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+SELECT vgc1 FROM t1 order by col1;
+vgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 * col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 1000
+2 20 200 NULL 4000 4000
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) STORED;
+ERROR HY000: This is not yet supported for generated columns
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR HY000: This is not yet supported for generated columns
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER AS (col1 + col2 + col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 111 1000 1000
+2 20 200 222 4000 4000
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 111 1000 1000
+2 20 200 222 4000 4000
+DROP TABLE t1;
+#
+# bug#22018979: RECORD NOT FOUND ON UPDATE,
+# VIRTUAL COLUMN, ASSERTION 0
+SET @sql_mode_save= @@sql_mode;
+SET sql_mode= 'ANSI';
+CREATE TABLE t1 (
+a INT,
+b VARCHAR(10),
+c CHAR(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+PRIMARY KEY (a),
+KEY c(c)
+);
+INSERT INTO t1(a, b) values(1, 'bbbb'), (2, 'cc');
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE "t1" (
+ "a" int(11) NOT NULL,
+ "b" varchar(10) DEFAULT NULL,
+ "c" char(3) GENERATED ALWAYS AS (substr("b",1,3)) VIRTUAL,
+ PRIMARY KEY ("a"),
+ KEY "c" ("c")
+)
+SELECT * FROM t1 order by a;
+a b c
+1 bbbb bbb
+2 cc cc
+SET sql_mode= '';
+FLUSH TABLE t1;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) NOT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+ PRIMARY KEY (`a`),
+ KEY `c` (`c`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1 order by a;
+a b c
+1 bbbb bbb
+2 cc cc
+DELETE FROM t1 where a= 2;
+SET sql_mode= @sql_mode_save;
+DROP TABLE t1;
+#
+# Bug#22680839: DEFAULT IS NOT DETERMINISTIC AND SHOULD NOT BE
+# ALLOWED IN GENERATED COLUMNS
+#
+CREATE TABLE tzz(a INT DEFAULT 5,
+gc1 INT AS (a+DEFAULT(a)) VIRTUAL,
+gc2 INT AS (a+DEFAULT(a)) STORED,
+KEY k1(gc1));
+INSERT INTO tzz(A) VALUES (1);
+SELECT * FROM tzz;
+a gc1 gc2
+1 6 6
+SELECT gc1 FROM tzz;
+gc1
+6
+ALTER TABLE tzz MODIFY COLUMN a INT DEFAULT 6;
+SELECT * FROM tzz;
+a gc1 gc2
+1 7 7
+SELECT gc1 FROM tzz;
+gc1
+7
+DROP TABLE tzz;
+# Test 1: ALTER DEFAULT
+#
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5,
+b INT AS (1 + DEFAULT(a)) STORED,
+c INT AS (1 + DEFAULT(a)) VIRTUAL);
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 MODIFY COLUMN a INT DEFAULT 8;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 CHANGE COLUMN a a DOUBLE DEFAULT 5;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+DROP TABLE t1;
+# Test 2: ALTER DEFAULT + ADD GCOL
+#
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5);
+INSERT INTO t1 VALUES();
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN b1 INT AS (1 + DEFAULT(a)) STORED;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN c1 INT AS (1 + DEFAULT(a)) VIRTUAL;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN b INT AS (1 + DEFAULT(a)) STORED,
+ADD COLUMN c INT AS (1 + DEFAULT(a)) VIRTUAL;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+DROP TABLE t1;
+#
+# MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+#
+CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
+NOT FOUND /Incorrect information in file: './test/MDEV_26262.frm'/ in mysqld.1.err
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result b/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result
new file mode 100644
index 00000000..734e05bb
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result
@@ -0,0 +1,736 @@
+SET @@session.default_storage_engine = 'MyISAM';
+#
+# Section 1. Wrong column definition options
+# - DEFAULT <value>
+# - AUTO_INCREMENT
+# NOT NULL
+create table t1 (a int, b int generated always as (a+1) virtual not null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored not null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual not null;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'not null' at line 1
+drop table t1;
+create table t1 (a int, b int generated always as (a+1) virtual null);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'null)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual null;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'null' at line 1
+drop table t1;
+# Added columns mixed with virtual GC and other columns
+create table t1 (a int);
+insert into t1 values(1);
+alter table t1 add column (b int generated always as (a+1) virtual, c int);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (d int, e int generated always as (a+1) virtual);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (f int generated always as (a+1) virtual, g int as(5) stored);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+alter table t1 add column (h int generated always as (a+1) virtual, i int as(5) virtual);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+drop table t1;
+# DEFAULT
+create table t1 (a int, b int generated always as (a+1) virtual default 0);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default 0)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual default 0;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'default 0' at line 1
+drop table t1;
+# AUTO_INCREMENT
+create table t1 (a int, b int generated always as (a+1) virtual AUTO_INCREMENT);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AUTO_INCREMENT)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual AUTO_INCREMENT;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AUTO_INCREMENT' at line 1
+drop table t1;
+# [PRIMARY] KEY
+create table t1 (a int, b int generated always as (a+1) virtual key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key)' at line 1
+create table t1 (a int, b int generated always as (a+1) virtual primary key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key)' at line 1
+create table t1 (a int, b int generated always as (a+1) stored primary key);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key)' at line 1
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key' at line 1
+alter table t1 add column b int generated always as (a+1) stored key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key' at line 1
+alter table t1 add column c int generated always as (a+2) virtual primary key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key' at line 1
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+alter table t1 add column c int generated always as (a+2) stored primary key;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'primary key' at line 1
+drop table t1;
+# Section 2. Other column definition options
+# - COMMENT
+# - REFERENCES (only syntax testing here)
+# - STORED (only systax testing here)
+create table t1 (a int, b int generated always as (a % 2) virtual comment 'my comment');
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) virtual comment 'my comment';
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+insert into t1 (a) values (1);
+select * from t1;
+a b
+1 1
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+a b
+1 1
+2 0
+create table t2 like t1;
+show create table t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t2;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+insert into t2 (a) values (1);
+select * from t2;
+a b
+1 1
+insert into t2 values (2,default);
+select a,b from t2 order by a;
+a b
+1 1
+2 0
+drop table t2;
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL STORED GENERATED
+insert into t1 (a) values (1);
+select * from t1;
+a b
+1 1
+insert into t1 values (2,default);
+select a,b from t1 order by a;
+a b
+1 1
+2 0
+drop table t1;
+create table t2 (a int);
+create table t1 (a int, b int generated always as (a % 2) stored references t2(a));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
+create table t1 (a int, b int generated always as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) stored references t2(a);
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'references t2(a)' at line 1
+alter table t1 modify b int generated always as (a % 2) stored;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+drop table t2;
+FK options
+create table t1(a int, b int as (a % 2), c int as (a) stored);
+create table t2 (a int);
+alter table t1 add constraint foreign key fk(d) references t2(a);
+ERROR 42000: Key column 'd' doesn't exist in table
+alter table t1 add constraint foreign key fk(c) references t2(a) on delete set null;
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+alter table t1 add constraint foreign key fk(c) references t2(a) on update set null;
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+alter table t1 add constraint foreign key fk(c) references t2(a) on update cascade;
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+drop table t1;
+drop table t2;
+Generated always is optional
+create table t1 (a int, b int as (a % 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int as (a % 2) stored);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL STORED GENERATED
+drop table t1;
+Default should be non-stored column
+create table t1 (a int, b int as (a % 2));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+Expression can be constant
+create table t1 (a int, b int as (5 * 2));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (5 * 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL GENERATED
+drop table t1;
+Test generated columns referencing other generated columns
+create table t1 (a int unique, b int generated always as(-a) virtual, c int generated always as (b + 1) virtual);
+insert into t1 (a) values (1), (2);
+select * from t1;
+a b c
+1 -1 0
+2 -2 -1
+insert into t1(a) values (1) on duplicate key update a=3;
+select * from t1;
+a b c
+2 -2 -1
+3 -3 -2
+update t1 set a=4 where a=2;
+select * from t1;
+a b c
+3 -3 -2
+4 -4 -3
+drop table t1;
+create table t1 (a int, b int generated always as(-b) virtual, c int generated always as (b + 1) virtual);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
+create table t1 (a int, b int generated always as(-c) virtual, c int generated always as (b + 1) virtual);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `c`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) stored, col_int_key int);
+ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key) unique, col_int_key int);
+ERROR HY000: Function or expression 'AUTO_INCREMENT' cannot be used in the GENERATED ALWAYS AS clause of `pk`
+create table t1 (pk int auto_increment primary key, col_int_nokey int generated always as (pk + col_int_key), col_int_key int);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `pk` int(11) NOT NULL AUTO_INCREMENT,
+ `col_int_nokey` int(11) GENERATED ALWAYS AS (`pk` + `col_int_key`) VIRTUAL,
+ `col_int_key` int(11) DEFAULT NULL,
+ PRIMARY KEY (`pk`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert t1 (col_int_key) values (10),(20),(30);
+select * from t1;
+pk col_int_nokey col_int_key
+1 11 10
+2 22 20
+3 33 30
+drop table t1;
+# Bug#20339347: FAIL TO USE CREATE ....SELECT STATEMENT TO CREATE A NEW TABLE
+create table t1 (a int, b int generated always as(-a) virtual, c int generated always as (b + 1) stored);
+insert into t1(a) values(1),(2);
+create table tt as select * from t1;
+select * from t1 order by a;
+a b c
+1 -1 0
+2 -2 -1
+select * from tt order by a;
+a b c
+1 -1 0
+2 -2 -1
+drop table t1,tt;
+# Bug#20745142: GENERATED COLUMNS: ASSERTION FAILED:
+# THD->CHANGE_LIST.IS_EMPTY()
+#
+CREATE TABLE t1(a bigint AS (a between 1 and 1));
+ERROR 01000: Expression for field `a` is referring to uninitialized field `a`
+# Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+# IN FIND_FIELD_IN_TABLE
+#
+CREATE TABLE t1(a int);
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `z`
+DROP TABLE t1;
+# Bug#20566243: ERROR WHILE DOING CREATE TABLE T1 SELECT (QUERY ON GC COLUMNS)
+CREATE TABLE t1(a int, b int as (a + 1),
+c varchar(12) as ("aaaabb") stored, d blob as (c));
+INSERT INTO t1(a) VALUES(1),(3);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL,
+ `c` varchar(12) GENERATED ALWAYS AS ('aaaabb') STORED,
+ `d` blob GENERATED ALWAYS AS (`c`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1 order by a;
+a b c d
+1 2 aaaabb aaaabb
+3 4 aaaabb aaaabb
+CREATE TABLE t2 LIKE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL,
+ `c` varchar(12) GENERATED ALWAYS AS ('aaaabb') STORED,
+ `d` blob GENERATED ALWAYS AS (`c`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+CREATE TABLE t3 AS SELECT * FROM t1;
+SHOW CREATE TABLE t3;
+Table Create Table
+t3 CREATE TABLE `t3` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(12) DEFAULT NULL,
+ `d` blob DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t3 order by a;
+a b c d
+1 2 aaaabb aaaabb
+3 4 aaaabb aaaabb
+CREATE TABLE t4 AS SELECT b,c,d FROM t1;
+SHOW CREATE TABLE t4;
+Table Create Table
+t4 CREATE TABLE `t4` (
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(12) DEFAULT NULL,
+ `d` blob DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t4 order by b;
+b c d
+2 aaaabb aaaabb
+4 aaaabb aaaabb
+DROP TABLE t1,t2,t3,t4;
+# Bug#21025003:WL8149:ASSERTION `CTX->NUM_TO_DROP_FK
+# == HA_ALTER_INFO->ALTER_INFO-> FAILED
+#
+CREATE TABLE t1 (
+col1 int(11) DEFAULT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) DEFAULT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col4 / col2) VIRTUAL,
+col6 text
+);
+INSERT INTO t1(col1,col2,col3,col4,col6) VALUES(NULL,1,4,0,REPEAT(2,1000));
+ALTER TABLE t1 DROP PRIMARY KEY , ADD KEY idx ( col5, col2 );
+ERROR 42000: Can't DROP INDEX `PRIMARY`; check that it exists
+DROP TABLE t1;
+# Bug#20949226:i CAN ASSIGN NON-DEFAULT() VALUE TO GENERATED COLUMN
+#
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5 AS c2;
+Warnings:
+Warning 1906 The value specified for generated column 'c2' in table 't1' has been ignored
+CREATE TABLE t2 (a int);
+INSERT INTO t2 values(1);
+DROP TABLE t1;
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, a AS c2 from t2;
+Warnings:
+Warning 1906 The value specified for generated column 'c2' in table 't1' has been ignored
+DROP TABLE t1;
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5;
+SELECT * FROM t1;
+c2 c1 5
+2 1 5
+DROP TABLE t1, t2;
+# Bug#21074624:i WL8149:SIG 11 INNOBASE_GET_COMPUTED_VALUE |
+# INNOBASE/HANDLER/HA_INNODB.CC:19082
+CREATE TABLE t1 (
+col1 int(11) NOT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col2 % col4) VIRTUAL,
+col6 int(11) GENERATED ALWAYS AS (col3 + col3) VIRTUAL,
+col7 int(11) GENERATED ALWAYS AS (col5 / col5) VIRTUAL,
+col8 int(11) GENERATED ALWAYS AS (col6 / col5) VIRTUAL,
+col9 text,
+extra int(11) DEFAULT NULL,
+KEY idx (col5)
+);
+INSERT INTO t1(col1,col2,col3,col4,col9,extra)
+VALUES(0,6,3,4,REPEAT(4,1000),0);
+ALTER TABLE t1 DROP COLUMN col1;
+DROP TABLE t1;
+# Bug#21390605:VALGRIND ERROR ON DELETE FROM TABLE CONTAINING
+# AN INDEXED VIRTUAL COLUMN
+CREATE TABLE t1 (
+a INTEGER,
+b INTEGER GENERATED ALWAYS AS (a) VIRTUAL,
+c INTEGER GENERATED ALWAYS AS (b) VIRTUAL,
+INDEX idx (b,c)
+);
+INSERT INTO t1 (a) VALUES (42);
+DELETE FROM t1 WHERE c = 42;
+DROP TABLE t1;
+# Bug#20757211: GENERATED COLUMNS: ALTER TABLE CRASHES
+# IN FIND_FIELD_IN_TABLE
+#
+CREATE TABLE t1(a int);
+ALTER TABLE t1 ADD COLUMN z int GENERATED ALWAYS AS
+( 1 NOT IN (SELECT 1 FROM t1 WHERE c0006) ) virtual;
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `z`
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM t1 WHERE not_exist_col)));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+CREATE TABLE t2(a int, b int as (1 NOT IN (SELECT 1 FROM dual)));
+ERROR HY000: Function or expression 'select ...' cannot be used in the GENERATED ALWAYS AS clause of `b`
+DROP TABLE t1;
+# Bug#21142905: PARTITIONED GENERATED COLS -
+# !TABLE || (!TABLE->WRITE_SET || BITMAP_IS_SET
+#
+CREATE TABLE t1 (
+a int,
+b int generated always as (a) virtual,
+c int generated always as (b+a) virtual,
+d int generated always as (b+a) virtual
+) PARTITION BY LINEAR HASH (b);
+INSERT INTO t1(a) VALUES(0);
+DELETE FROM t1 WHERE c=1;
+DROP TABLE t1;
+CREATE TABLE t1 (c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar"));
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c` char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin GENERATED ALWAYS AS ('foo bar') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1 (i INT);
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `i` int(11) DEFAULT NULL,
+ `c` char(10) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin GENERATED ALWAYS AS ('foo bar') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1 (i INT COLLATE utf8_bin, c INT COLLATE utf8_bin GENERATED ALWAYS AS (10));
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'GENERATED ALWAYS AS (10))' at line 1
+# Check for a charset mismatch processing:
+# Bug #21469535: VALGRIND ERROR (CONDITIONAL JUMP) WHEN INSERT
+# ROWS INTO A PARTITIONED TABLE
+#
+CREATE TABLE t1 (
+id INT NOT NULL,
+store_id INT NOT NULL,
+x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21)
+);
+INSERT INTO t1 VALUES(1, 2, default);
+DROP TABLE t1;
+# Bug#21465626:ASSERT/CRASH ON DROPPING/ADDING VIRTUAL COLUMN
+CREATE TABLE t (a int(11), b int(11),
+c int(11) GENERATED ALWAYS AS (a+b) VIRTUAL,
+d int(11) GENERATED ALWAYS AS (a+b) VIRTUAL);
+INSERT INTO t(a,b) VALUES(1,2);
+# Mixed drop/add/rename virtual with non-virtual columns,
+# ALGORITHM=INPLACE is not supported for InnoDB
+ALTER TABLE t DROP d, ADD e varchar(10);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD d int, ADD f char(10) AS ('aaa');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE d dd int, CHANGE f ff varchar(10) AS ('bbb');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# Only drop/add/change virtual, inplace is supported for Innodb
+ALTER TABLE t DROP c, DROP ff;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD c int(11) as (a+b), ADD f varchar(10) as ('aaa');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE c c int(11) as (a), CHANGE f f varchar(10) as('bbb');
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+# Change order should be ALGORITHM=INPLACE on Innodb
+ALTER TABLE t CHANGE c c int(11) as (a) after f;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE b b int(11) after c;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# TODO: Changing virtual column type should be ALGORITHM=INPLACE on InnoDB, current it goes only with COPY method
+ALTER TABLE t CHANGE c c varchar(10) as ('a');
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+# Changing stored column type is ALGORITHM=COPY
+ALTER TABLE t CHANGE dd d varchar(10);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD INDEX idx(c), ADD INDEX idx1(d);
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t DROP INDEX idx, DROP INDEX idx1;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+DROP TABLE t;
+# Bug#21854004: GCOLS:INNODB: FAILING ASSERTION: I < TABLE->N_DEF
+CREATE TABLE t1(
+col1 INTEGER PRIMARY KEY,
+col2 INTEGER,
+col3 INTEGER,
+col4 INTEGER,
+vgc1 INTEGER AS (col2 + col3) VIRTUAL,
+sgc1 INTEGER AS (col2 - col3) STORED
+);
+INSERT INTO t1(col1, col2, col3) VALUES
+(1, 10, 100), (2, 20, 200);
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 110 -90
+2 20 200 NULL 220 -180
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 0
+2 20 200 NULL 4000 0
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD INDEX vgc1 (vgc1);
+ALTER TABLE t1 ADD INDEX sgc1 (sgc1);
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+SELECT vgc1 FROM t1 order by vgc1;
+vgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 0
+2 20 200 NULL 4000 0
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+0
+0
+ALTER TABLE t1 DROP INDEX vgc1;
+ALTER TABLE t1 DROP INDEX sgc1;
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 + col3) VIRTUAL;
+ALTER TABLE t1 ADD UNIQUE INDEX vgc1 (vgc1);
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD UNIQUE INDEX sgc1 (sgc1);
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR 23000: Duplicate entry '0' for key 'vgc1'
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) STORED;
+ERROR 23000: Duplicate entry '0' for key 'sgc1'
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) VIRTUAL;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 -90
+2 20 200 NULL 4000 -180
+SELECT vgc1 FROM t1 order by col1;
+vgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 * col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 NULL 1000 1000
+2 20 200 NULL 4000 4000
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+1000
+4000
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) STORED;
+ERROR HY000: This is not yet supported for generated columns
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR HY000: This is not yet supported for generated columns
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER AS (col1 + col2 + col3) STORED;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 111 1000 1000
+2 20 200 222 4000 4000
+ALTER TABLE t1 MODIFY COLUMN col4 INTEGER;
+SELECT * FROM t1 order by col1;
+col1 col2 col3 col4 vgc1 sgc1
+1 10 100 111 1000 1000
+2 20 200 222 4000 4000
+DROP TABLE t1;
+#
+# bug#22018979: RECORD NOT FOUND ON UPDATE,
+# VIRTUAL COLUMN, ASSERTION 0
+SET @sql_mode_save= @@sql_mode;
+SET sql_mode= 'ANSI';
+CREATE TABLE t1 (
+a INT,
+b VARCHAR(10),
+c CHAR(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+PRIMARY KEY (a),
+KEY c(c)
+);
+INSERT INTO t1(a, b) values(1, 'bbbb'), (2, 'cc');
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE "t1" (
+ "a" int(11) NOT NULL,
+ "b" varchar(10) DEFAULT NULL,
+ "c" char(3) GENERATED ALWAYS AS (substr("b",1,3)) VIRTUAL,
+ PRIMARY KEY ("a"),
+ KEY "c" ("c")
+)
+SELECT * FROM t1 order by a;
+a b c
+1 bbbb bbb
+2 cc cc
+SET sql_mode= '';
+FLUSH TABLE t1;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) NOT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+ PRIMARY KEY (`a`),
+ KEY `c` (`c`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1 order by a;
+a b c
+1 bbbb bbb
+2 cc cc
+DELETE FROM t1 where a= 2;
+SET sql_mode= @sql_mode_save;
+DROP TABLE t1;
+#
+# Bug#22680839: DEFAULT IS NOT DETERMINISTIC AND SHOULD NOT BE
+# ALLOWED IN GENERATED COLUMNS
+#
+CREATE TABLE tzz(a INT DEFAULT 5,
+gc1 INT AS (a+DEFAULT(a)) VIRTUAL,
+gc2 INT AS (a+DEFAULT(a)) STORED,
+KEY k1(gc1));
+INSERT INTO tzz(A) VALUES (1);
+SELECT * FROM tzz;
+a gc1 gc2
+1 6 6
+SELECT gc1 FROM tzz;
+gc1
+6
+ALTER TABLE tzz MODIFY COLUMN a INT DEFAULT 6;
+SELECT * FROM tzz;
+a gc1 gc2
+1 7 7
+SELECT gc1 FROM tzz;
+gc1
+7
+DROP TABLE tzz;
+# Test 1: ALTER DEFAULT
+#
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5,
+b INT AS (1 + DEFAULT(a)) STORED,
+c INT AS (1 + DEFAULT(a)) VIRTUAL);
+INSERT INTO t1 VALUES ();
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 MODIFY COLUMN a INT DEFAULT 8;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 CHANGE COLUMN a a DOUBLE DEFAULT 5;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+DROP TABLE t1;
+# Test 2: ALTER DEFAULT + ADD GCOL
+#
+CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 5);
+INSERT INTO t1 VALUES();
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN b1 INT AS (1 + DEFAULT(a)) STORED;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN c1 INT AS (1 + DEFAULT(a)) VIRTUAL;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 ALTER COLUMN a SET DEFAULT 7,
+ADD COLUMN b INT AS (1 + DEFAULT(a)) STORED,
+ADD COLUMN c INT AS (1 + DEFAULT(a)) VIRTUAL;
+affected rows: 1
+info: Records: 1 Duplicates: 0 Warnings: 0
+DROP TABLE t1;
+#
+# MDEV-26262 frm is corrupted after ER_EXPRESSION_REFERS_TO_UNINIT_FIELD
+#
+CREATE TABLE MDEV_26262 (a INT,b INT AS (b) VIRTUAL);
+ERROR 01000: Expression for field `b` is referring to uninitialized field `b`
+NOT FOUND /Incorrect information in file: './test/MDEV_26262.frm'/ in mysqld.1.err
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_csv.result b/mysql-test/suite/gcol/r/gcol_csv.result
new file mode 100644
index 00000000..e07b72ba
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_csv.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'CSV';
+create table t1 (a int, b virtual int as (a+1));
+ERROR HY000: 'Specified storage engine' is not yet supported for generated columns.
+create table t1 (a int not null);
+alter table t1 add column b virtual int as (a+1);
+ERROR HY000: 'Specified storage engine' is not yet supported for generated columns.
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_falcon.result b/mysql-test/suite/gcol/r/gcol_falcon.result
new file mode 100644
index 00000000..8948539a
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_falcon.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'falcon';
+create table t1 (a int, b virtual int as (a+1));
+ERROR HY000: 'Specified storage engine' is not yet supported for generated columns.
+create table t1 (a int);
+alter table t1 add column b virtual int as (a+1);
+ERROR HY000: 'Specified storage engine' is not yet supported for generated columns.
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_handler_innodb.result b/mysql-test/suite/gcol/r/gcol_handler_innodb.result
new file mode 100644
index 00000000..6de4c2ae
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_handler_innodb.result
@@ -0,0 +1,83 @@
+SET @@session.default_storage_engine = 'InnoDB';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+d char(1),
+index (a),
+index (c));
+insert into t1 (a,d) values (4,'a'), (2,'b'), (1,'c'), (3,'d');
+select * from t1;
+a b c d
+4 -4 -4 a
+2 -2 -2 b
+1 -1 -1 c
+3 -3 -3 d
+# HANDLER tbl_name OPEN
+handler t1 open;
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...)
+handler t1 read a > (2);
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read a > (2) where d='c';
+a b c d
+# HANDLER tbl_name READ gcol_index_name = (value1,value2,...)
+handler t1 read c = (-2);
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ gcol_index_name = (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read c = (-2) where d='c';
+a b c d
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read a > (2) where b=-3 && c=-3;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name <= (value1,value2,...)
+handler t1 read c <= (-2);
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read c <= (-2) where b=-3;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name FIRST
+handler t1 read c first;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ gcol_index_name NEXT
+handler t1 read c next;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name PREV
+handler t1 read c prev;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ gcol_index_name LAST
+handler t1 read c last;
+a b c d
+1 -1 -1 c
+# HANDLER tbl_name READ FIRST where non-gcol=expr
+handler t1 read FIRST where a >= 2;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ FIRST where gcol=expr
+handler t1 read FIRST where b >= -2;
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ NEXT where non-gcol=expr
+handler t1 read NEXT where d='c';
+a b c d
+1 -1 -1 c
+# HANDLER tbl_name READ NEXT where gcol=expr
+handler t1 read NEXT where b<=-4;
+a b c d
+# HANDLER tbl_name CLOSE
+handler t1 close;
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_handler_myisam.result b/mysql-test/suite/gcol/r/gcol_handler_myisam.result
new file mode 100644
index 00000000..3b03fd37
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_handler_myisam.result
@@ -0,0 +1,83 @@
+SET @@session.default_storage_engine = 'MyISAM';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+d char(1),
+index (a),
+index (c));
+insert into t1 (a,d) values (4,'a'), (2,'b'), (1,'c'), (3,'d');
+select * from t1;
+a b c d
+4 -4 -4 a
+2 -2 -2 b
+1 -1 -1 c
+3 -3 -3 d
+# HANDLER tbl_name OPEN
+handler t1 open;
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...)
+handler t1 read a > (2);
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read a > (2) where d='c';
+a b c d
+# HANDLER tbl_name READ gcol_index_name = (value1,value2,...)
+handler t1 read c = (-2);
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ gcol_index_name = (value1,value2,...) WHERE non-gcol_field=expr
+handler t1 read c = (-2) where d='c';
+a b c d
+# HANDLER tbl_name READ non-gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read a > (2) where b=-3 && c=-3;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name <= (value1,value2,...)
+handler t1 read c <= (-2);
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ gcol_index_name > (value1,value2,...) WHERE gcol_field=expr
+handler t1 read c <= (-2) where b=-3;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name FIRST
+handler t1 read c first;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ gcol_index_name NEXT
+handler t1 read c next;
+a b c d
+3 -3 -3 d
+# HANDLER tbl_name READ gcol_index_name PREV
+handler t1 read c prev;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ gcol_index_name LAST
+handler t1 read c last;
+a b c d
+1 -1 -1 c
+# HANDLER tbl_name READ FIRST where non-gcol=expr
+handler t1 read FIRST where a >= 2;
+a b c d
+4 -4 -4 a
+# HANDLER tbl_name READ FIRST where gcol=expr
+handler t1 read FIRST where b >= -2;
+a b c d
+2 -2 -2 b
+# HANDLER tbl_name READ NEXT where non-gcol=expr
+handler t1 read NEXT where d='c';
+a b c d
+1 -1 -1 c
+# HANDLER tbl_name READ NEXT where gcol=expr
+handler t1 read NEXT where b<=-4;
+a b c d
+# HANDLER tbl_name CLOSE
+handler t1 close;
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result
new file mode 100644
index 00000000..193ef064
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result
@@ -0,0 +1,823 @@
+SET @@session.default_storage_engine = 'InnoDB';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+set sql_warnings = 1;
+#
+# *** INSERT ***
+#
+# INSERT INTO tbl_name VALUES... DEFAULT is specified against gcols
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name VALUES... NULL is specified against gcols
+insert into t1 values (1,null,null);
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name VALUES... a non-NULL value is specified against gcols
+insert ignore into t1 values (1,2,3);
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<non_gcol_list>) VALUES...
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... DEFAULT is specified
+# against gcols
+insert into t1 (a,b) values (1,default), (2,default);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... NULL is specified against gcols
+insert into t1 (a,b) values (1,null), (2,null);
+select * from t1;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... a non-NULL value is specified
+# against gcols
+insert ignore into t1 (a,b) values (1,3), (2,4);
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+select * from t1;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+drop table t1;
+# Table with UNIQUE non-gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+# KEY UPDATE <non_gcol>=expr, <gcol>=expr
+create table t1 (a int unique,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+on duplicate key update a=2, b=default;
+select a,b,c from t1;
+a b c
+2 -2 -2
+delete from t1 where b in (1,2);
+select * from t1;
+a b c
+2 -2 -2
+drop table t1;
+# Table with UNIQUE gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+# KEY UPDATE <non_gcol>=expr, <gcol>=expr
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+on duplicate key update a=2, b=default;
+select a,b,c from t1;
+a b c
+2 -2 -2
+# CREATE new_table ... LIKE old_table
+# INSERT INTO new_table SELECT * from old_table
+create table t2 like t1;
+insert into t2(a) select a from t1;
+select * from t2;
+a b c
+2 -2 -2
+drop table t2;
+# CREATE new_table ... LIKE old_table INSERT INTO new_table (<non-gcols>, <gcols>)
+# SELECT <non-gcols>, <gcols> from old_table
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+2 -2 -2
+1 -1 -1
+create table t2 like t1;
+insert into t2 (a) select a from t1;
+select * from t2 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t2;
+drop table t1;
+#
+# *** UPDATE ***
+#
+# UPDATE tbl_name SET non-gcol=expr WHERE non-gcol=expr
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where a=2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET gcol=expr WHERE non-gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update ignore t1 set c=3 where a=2;
+Warnings:
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where b=-2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update ignore t1 set c=3 where b=-2;
+Warnings:
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+drop table t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=const
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where c=-2;
+select * from t1;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where c between -3 and -2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# No INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where b between -3 and -2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE gcol=between const1 and const2 ORDER BY gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where c between -1 and 0
+order by c;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1 where c between -6 and 0;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE gcol=between const1 and const2 ORDER BY gcol LIMIT 2
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where c between -1 and 0
+order by c limit 2;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1 where c between -2 and 0 order by c;
+select * from t1 order by a;
+a b c
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where (c between -2 and 0) and (b=-1);
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+# ORDER BY indexed gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where (c between -2 and 0) and (b=-1) order by c;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+drop table t1;
+#
+# Verify ON UPDATE/DELETE actions of FOREIGN KEYs
+create table t2 (a int primary key, name varchar(10));
+create table t1 (a int primary key, b int generated always as (a % 10) stored);
+insert into t2 values (1, 'value1'), (2,'value2'), (3,'value3');
+insert into t1 (a) values (1),(2),(3);
+select * from t1 order by a;
+a b
+1 1
+2 2
+3 3
+select * from t2 order by a;
+a name
+1 value1
+2 value2
+3 value3
+select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a order by t1.a;
+a b name
+1 1 value1
+2 2 value2
+3 3 value3
+# - ON UPDATE RESTRICT
+alter table t1 add foreign key (b) references t2(a) on update restrict;
+insert into t1 (a) values (4);
+ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`))
+update t2 set a=4 where a=3;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`))
+select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+a b name
+1 1 value1
+2 2 value2
+3 3 value3
+alter table t1 drop foreign key t1_ibfk_1;
+# - ON DELETE RESTRICT
+alter table t1 add foreign key (b) references t2(a) on delete restrict;
+delete from t2 where a=3;
+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`))
+select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+a b name
+1 1 value1
+2 2 value2
+3 3 value3
+select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a);
+a b name
+1 1 value1
+2 2 value2
+3 3 value3
+alter table t1 drop foreign key t1_ibfk_1;
+# - ON DELETE CASCADE
+alter table t1 add foreign key (b) references t2(a) on delete cascade;
+delete from t2 where a=3;
+select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
+a b name
+1 1 value1
+2 2 value2
+select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a);
+a b name
+1 1 value1
+2 2 value2
+alter table t1 drop foreign key t1_ibfk_1;
+drop table t1;
+drop table t2;
+#
+# *** REPLACE ***
+#
+# UNIQUE INDEX on gcol
+# REPLACE tbl_name (non-gcols) VALUES (non-gcols);
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique,
+d varchar(16));
+insert into t1 (a,d) values (1,'a'), (2,'b');
+select * from t1 order by a;
+a b c d
+1 -1 -1 a
+2 -2 -2 b
+replace t1 (a,d) values (1,'c');
+select * from t1 order by a;
+a b c d
+1 -1 -1 c
+2 -2 -2 b
+delete from t1;
+select * from t1;
+a b c d
+set sql_warnings = 0;
+drop table t1;
+Bug#20170778: WL411:FAILING ASSERTION `!TABLE || (!TABLE->WRITE_SET ||
+BITMAP_IS_SET(TABLE->WR
+#
+CREATE TABLE t1 (col1 INT, col2 INT, col3 INT, col4 INT, col5
+INT GENERATED ALWAYS AS (col3 * col2) VIRTUAL, col6 INT GENERATED ALWAYS AS
+(col4 * col1) STORED, col7 INT GENERATED ALWAYS AS (col6 + col6) VIRTUAL,
+col8 INT GENERATED ALWAYS AS (col6 / col5) STORED, col9 TEXT);
+SET @fill_amount = (@@innodb_page_size / 2 ) + 1;
+INSERT INTO t1 (col1,col2,col3,col4,col5,col6,col7,col8,col9) VALUES /* 3 */
+(3, 3 / 3, 3 + 3, 3 / 3, DEFAULT, DEFAULT, DEFAULT, DEFAULT ,REPEAT(CAST(3 AS
+CHAR(1)),@fill_amount)) , (3, 3 * 3, 3 + 3, 3 / 3, DEFAULT, DEFAULT, DEFAULT,
+DEFAULT ,REPEAT(CAST(3 AS CHAR(1)),@fill_amount));
+UPDATE t1 SET col1 = 2;
+UPDATE t1 SET col7 = DEFAULT;
+UPDATE t1 SET col8 = DEFAULT;
+DROP TABLE t1;
+Bug#20797344: WL#8149: ALLOCATED SPACE FOR INDEXED BLOB VGC CAN BE
+OVERWRITTEN FOR UPDATE
+#
+CREATE TABLE t (a varchar(100), b blob,
+c blob GENERATED ALWAYS AS (concat(a,b)) VIRTUAL,
+d blob GENERATED ALWAYS AS (b) VIRTUAL,
+e int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+h int(11) NOT NULL, PRIMARY KEY (h), key(c(20)));
+INSERT INTO t(a,b,h) VALUES('aaaaaaa','1111111', 11);
+INSERT INTO t(a,b,h) VALUES('bbbbbbb','2222222', 22);
+SELECT c FROM t;
+c
+aaaaaaa1111111
+bbbbbbb2222222
+UPDATE t SET a='ccccccc';
+SELECT c FROM t;
+c
+ccccccc1111111
+ccccccc2222222
+DROP TABLE t;
+# Bug#21081742: ASSERTION !TABLE || (!TABLE->WRITE_SET ||
+# BITMAP_IS_SET(TABLE->WRITE_SET
+#
+CREATE TABLE b (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT INTO b (col_varchar_nokey) VALUES ('v'),('v');
+CREATE TABLE d (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+) ;
+INSERT INTO d (col_varchar_nokey) VALUES ('q'),('g'),('e'),('l'),(NULL),('v'),('c'),('u'),('x');
+CREATE TABLE bb (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT INTO bb (col_varchar_nokey) VALUES ('j'),('h');
+EXPLAIN UPDATE
+d AS OUTR1, b AS OUTR2
+SET OUTR1.col_varchar_nokey = NULL
+WHERE
+( 't', 'b' ) IN
+(
+SELECT
+INNR1.col_varchar_nokey AS x,
+INNR1.col_varchar_key AS y
+FROM bb AS INNR1
+WHERE OUTR1.pk = 1
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY OUTR1 const PRIMARY PRIMARY 4 const 1
+1 PRIMARY INNR1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(OUTR1)
+1 PRIMARY OUTR2 index NULL PRIMARY 4 NULL 2 Using index
+DROP TABLE IF EXISTS b,bb,d;
+#
+# Bug#21216067 ASSERTION FAILED ROW_UPD_SEC_INDEX_ENTRY (INNOBASE/ROW/ROW0UPD.CC:2103)
+#
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1) STORED
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t2.y = 1, t1.x = 2;
+SELECT * FROM t;
+x y gc
+2 1 3
+DROP TABLE t;
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1), KEY (x,gc)
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t1.x = 1, t2.y = 2;
+SELECT * FROM t;
+x y gc
+1 2 2
+SELECT gc FROM t;
+gc
+2
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+# stored
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 ALL NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 ALL NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# stored, indexed
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 ALL NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 ALL NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# virtual
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 ALL NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 ALL NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# virtual, indexed
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 ALL NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 ALL NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+#
+# Bug #21530366 CRASH/ASSERTION, CORRUPTION WITH INDEXES +
+# VIRTUAL COLUMNS, BLOB
+#
+CREATE TABLE t (
+a INTEGER,
+b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+INDEX (b(57))
+);
+INSERT INTO t (a) VALUES (9);
+UPDATE t SET a = 10;
+DELETE FROM t WHERE a = 10;
+DROP TABLE t;
+# Bug#21807818: Generated columns not updated with empty insert list
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL,
+KEY (a(183),b)
+);
+ERROR HY000: Function or expression '''' cannot be used in the GENERATED ALWAYS AS clause of `b`
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL
+);
+INSERT IGNORE INTO t VALUES(), (), ();
+DELETE IGNORE FROM t;
+DROP TABLE t;
+#
+# Bug#22195458:GCOLS: ASSERTION 0 AND CORRUPTION...
+#
+CREATE TABLE t (
+a INT,
+b YEAR GENERATED ALWAYS AS ('a') VIRTUAL,
+c YEAR GENERATED ALWAYS AS ('aaaa') VIRTUAL,
+b1 YEAR GENERATED ALWAYS AS ('a') STORED,
+c1 YEAR GENERATED ALWAYS AS ('aaaa') STORED,
+UNIQUE(b),
+UNIQUE(b1)
+);
+INSERT IGNORE INTO t VALUES();
+SELECT b from t;
+b
+0000
+SELECT b1 from t;
+b1
+0000
+SELECT * from t;
+a b c b1 c1
+NULL 0000 0000 0000 0000
+DELETE FROM t;
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+# Bug#22195364:GCOLS: FAILING ASSERTION:
+# DFIELD_IS_NULL(DFIELD2) || DFIELD2->DATA
+CREATE TABLE t (
+a INT,
+c BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+UNIQUE KEY(c(1),a)
+);
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+a c
+1
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+a c
+2
+SELECT GROUP_CONCAT(c ORDER BY c) FROM t;
+GROUP_CONCAT(c ORDER BY c)
+
+DROP TABLE t;
+#Bug#21929967:GCOLS:GCOL VALUE CHANGES WHEN SESSION CHANGES SQL_MODE
+CREATE TABLE t(c1 INT GENERATED ALWAYS AS (1) VIRTUAL,
+c2 INT GENERATED ALWAYS AS(2) STORED);
+INSERT INTO t VALUES(DEFAULT, DEFAULT);
+SELECT * FROM t;
+c1 c2
+1 2
+CREATE TABLE t1(c1 INT, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t1(c2) VALUES(DEFAULT);
+SELECT * FROM t1;
+c1 c2
+NULL NULL
+CREATE TABLE t2(c1 INT DEFAULT 1, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t2(c2) VALUES(DEFAULT);
+SELECT * FROM t2;
+c1 c2
+1 2
+DROP TABLE t, t1, t2;
+# Bug#22179637: INSERT INTO TABLE FROM SELECT ACCEPTS TO INSERT INTO
+# GENERATED COLUMNS
+CREATE TABLE t1 (
+i1 INTEGER,
+i2 INTEGER GENERATED ALWAYS AS (i1 + i1)
+);
+INSERT INTO t1 (i1) SELECT 5;
+INSERT INTO t1 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t1;
+i1 i2
+5 10
+5 10
+CREATE TABLE t2 (
+i1 INTEGER,
+i2 INTEGER GENERATED ALWAYS AS (i1 + i1) STORED
+);
+INSERT INTO t2 (i1) SELECT 5;
+INSERT INTO t2 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t2;
+i1 i2
+5 10
+5 10
+DROP TABLE t1,t2;
+#
+# Bug#22070021 GCOL:ASSERTION `!TABLE || (!TABLE->WRITE_SET ||
+# BITMAP_IS_SET(TABLE->WRITE_SET,
+#
+CREATE TABLE t1(
+c1 INT,
+c2 INT GENERATED ALWAYS AS (c1 + c1) VIRTUAL,
+KEY(c2)
+);
+INSERT INTO t1(c1) VALUES(0);
+DELETE O1.* FROM t1 AS O1, t1 AS O2;
+SELECT * FROM t1;
+c1 c2
+DROP TABLE t1;
+#
+# Bug#21944199 SIMPLE DELETE QUERY CAUSES INNODB: FAILING ASSERTION: 0
+# & DATA CORRUPTION
+#
+CREATE TEMPORARY TABLE t1 (
+a INTEGER NOT NULL,
+b INTEGER GENERATED ALWAYS AS (a+1) VIRTUAL
+);
+INSERT INTO t1 (a) VALUES (0), (0), (0);
+ALTER TABLE t1 ADD INDEX idx (b);
+DELETE FROM t1;
+DROP TEMPORARY TABLE t1;
+#
+# Original test case from MDEV-17890
+#
+CREATE TABLE t1 (
+pk BIGINT AUTO_INCREMENT,
+b BIT(15),
+v BIT(10) AS (b) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(v)
+);
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+Warnings:
+Warning 1264 Out of range value for column 'v' at row 1
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+ERROR 22001: Data too long for column 'v' at row 1
+DROP TABLE t1;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (
+id INT NOT NULL AUTO_INCREMENT,
+f ENUM('a','b','c'),
+v ENUM('a','b','c') AS (f),
+KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+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;
+CREATE TABLE t1 (
+id INT NOT NULL AUTO_INCREMENT,
+f ENUM('a','b','c'),
+v ENUM('a','b','c') AS (f),
+KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+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;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result
new file mode 100644
index 00000000..98db88ab
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result
@@ -0,0 +1,745 @@
+SET @@session.default_storage_engine = 'MyISAM';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+set sql_warnings = 1;
+#
+# *** INSERT ***
+#
+# INSERT INTO tbl_name VALUES... DEFAULT is specified against gcols
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name VALUES... NULL is specified against gcols
+insert into t1 values (1,null,null);
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name VALUES... a non-NULL value is specified against gcols
+insert ignore into t1 values (1,2,3);
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1;
+a b c
+1 -1 -1
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<non_gcol_list>) VALUES...
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... DEFAULT is specified
+# against gcols
+insert into t1 (a,b) values (1,default), (2,default);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... NULL is specified against gcols
+insert into t1 (a,b) values (1,null), (2,null);
+select * from t1;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# INSERT INTO tbl_name (<normal+gcols>) VALUES... a non-NULL value is specified
+# against gcols
+insert ignore into t1 (a,b) values (1,3), (2,4);
+Warnings:
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+Warning 1906 The value specified for generated column 'b' in table 't1' has been ignored
+select * from t1;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+drop table t1;
+# Table with UNIQUE non-gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+# KEY UPDATE <non_gcol>=expr, <gcol>=expr
+create table t1 (a int unique,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+on duplicate key update a=2, b=default;
+select a,b,c from t1;
+a b c
+2 -2 -2
+delete from t1 where b in (1,2);
+select * from t1;
+a b c
+2 -2 -2
+drop table t1;
+# Table with UNIQUE gcol field. INSERT INTO tbl_name VALUES... ON DUPLICATE
+# KEY UPDATE <non_gcol>=expr, <gcol>=expr
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t1 values (1,default,default);
+insert into t1 values (1,default,default)
+on duplicate key update a=2, b=default;
+select a,b,c from t1;
+a b c
+2 -2 -2
+# CREATE new_table ... LIKE old_table
+# INSERT INTO new_table SELECT * from old_table
+create table t2 like t1;
+insert into t2(a) select a from t1;
+select * from t2;
+a b c
+2 -2 -2
+drop table t2;
+# CREATE new_table ... LIKE old_table INSERT INTO new_table (<non-gcols>, <gcols>)
+# SELECT <non-gcols>, <gcols> from old_table
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+2 -2 -2
+1 -1 -1
+create table t2 like t1;
+insert into t2 (a) select a from t1;
+select * from t2 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t2;
+drop table t1;
+#
+# *** UPDATE ***
+#
+# UPDATE tbl_name SET non-gcol=expr WHERE non-gcol=expr
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where a=2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET gcol=expr WHERE non-gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update ignore t1 set c=3 where a=2;
+Warnings:
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where b=-2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# UPDATE tbl_name SET gcol=expr WHERE gcol=expr
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update ignore t1 set c=3 where b=-2;
+Warnings:
+Warning 1906 The value specified for generated column 'c' in table 't1' has been ignored
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+delete from t1;
+select * from t1;
+a b c
+drop table t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=const
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where c=-2;
+select * from t1;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where c between -3 and -2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# No INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr WHERE gcol=between const1 and const2
+insert into t1 (a) values (1), (2);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+update t1 set a=3 where b between -3 and -2;
+select * from t1 order by a;
+a b c
+1 -1 -1
+3 -3 -3
+delete from t1;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE gcol=between const1 and const2 ORDER BY gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where c between -1 and 0
+order by c;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1 where c between -6 and 0;
+select * from t1;
+a b c
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE gcol=between const1 and const2 ORDER BY gcol LIMIT 2
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where c between -1 and 0
+order by c limit 2;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1 where c between -2 and 0 order by c;
+select * from t1 order by a;
+a b c
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where (c between -2 and 0) and (b=-1);
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+# INDEX created on gcol
+# UPDATE tbl_name SET non-gcol=expr
+# WHERE indexed gcol=between const1 and const2 and non-indexed gcol=const3
+# ORDER BY indexed gcol
+insert into t1 (a) values (1), (2), (3), (4), (5);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+update t1 set a=6 where (c between -2 and 0) and (b=-1) order by c;
+select * from t1 order by a;
+a b c
+2 -2 -2
+3 -3 -3
+4 -4 -4
+5 -5 -5
+6 -6 -6
+delete from t1;
+drop table t1;
+#
+# *** REPLACE ***
+#
+# UNIQUE INDEX on gcol
+# REPLACE tbl_name (non-gcols) VALUES (non-gcols);
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique,
+d varchar(16));
+insert into t1 (a,d) values (1,'a'), (2,'b');
+select * from t1 order by a;
+a b c d
+1 -1 -1 a
+2 -2 -2 b
+replace t1 (a,d) values (1,'c');
+select * from t1 order by a;
+a b c d
+1 -1 -1 c
+2 -2 -2 b
+delete from t1;
+select * from t1;
+a b c d
+set sql_warnings = 0;
+drop table t1;
+Bug#20797344: WL#8149: ALLOCATED SPACE FOR INDEXED BLOB VGC CAN BE
+OVERWRITTEN FOR UPDATE
+#
+CREATE TABLE t (a varchar(100), b blob,
+c blob GENERATED ALWAYS AS (concat(a,b)) VIRTUAL,
+d blob GENERATED ALWAYS AS (b) VIRTUAL,
+e int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+h int(11) NOT NULL, PRIMARY KEY (h), key(c(20)));
+INSERT INTO t(a,b,h) VALUES('aaaaaaa','1111111', 11);
+INSERT INTO t(a,b,h) VALUES('bbbbbbb','2222222', 22);
+SELECT c FROM t;
+c
+aaaaaaa1111111
+bbbbbbb2222222
+UPDATE t SET a='ccccccc';
+SELECT c FROM t;
+c
+ccccccc1111111
+ccccccc2222222
+DROP TABLE t;
+# Bug#21081742: ASSERTION !TABLE || (!TABLE->WRITE_SET ||
+# BITMAP_IS_SET(TABLE->WRITE_SET
+#
+CREATE TABLE b (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT INTO b (col_varchar_nokey) VALUES ('v'),('v');
+CREATE TABLE d (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+) ;
+INSERT INTO d (col_varchar_nokey) VALUES ('q'),('g'),('e'),('l'),(NULL),('v'),('c'),('u'),('x');
+CREATE TABLE bb (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT INTO bb (col_varchar_nokey) VALUES ('j'),('h');
+EXPLAIN UPDATE
+d AS OUTR1, b AS OUTR2
+SET OUTR1.col_varchar_nokey = NULL
+WHERE
+( 't', 'b' ) IN
+(
+SELECT
+INNR1.col_varchar_nokey AS x,
+INNR1.col_varchar_key AS y
+FROM bb AS INNR1
+WHERE OUTR1.pk = 1
+);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY OUTR1 const PRIMARY PRIMARY 4 const 1
+1 PRIMARY INNR1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(OUTR1)
+1 PRIMARY OUTR2 index NULL PRIMARY 4 NULL 2 Using index
+DROP TABLE IF EXISTS b,bb,d;
+#
+# Bug#21216067 ASSERTION FAILED ROW_UPD_SEC_INDEX_ENTRY (INNOBASE/ROW/ROW0UPD.CC:2103)
+#
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1) STORED
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t2.y = 1, t1.x = 2;
+SELECT * FROM t;
+x y gc
+2 1 3
+DROP TABLE t;
+CREATE TABLE t (
+x INT, y INT, gc INT GENERATED ALWAYS AS (x+1), KEY (x,gc)
+);
+INSERT INTO t VALUES ();
+UPDATE t t1, t t2 SET t1.x = 1, t2.y = 2;
+SELECT * FROM t;
+x y gc
+1 2 2
+SELECT gc FROM t;
+gc
+2
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+# stored
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 system NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 system NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# stored, indexed
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 system NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 system NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# virtual
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 system NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 system NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+# virtual, indexed
+CREATE TABLE C (
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO C (col_varchar_nokey) VALUES ('c');
+EXPLAIN UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE OUTR1 system NULL NULL NULL NULL 1
+1 SIMPLE OUTR2 system NULL NULL NULL NULL 1
+UPDATE C AS OUTR1, C AS OUTR2
+SET OUTR1.`col_varchar_nokey` = 'f',
+OUTR2.`col_varchar_nokey` = "a";
+SELECT * from C;
+col_varchar_nokey col_varchar_key
+a aa
+DROP TABLE C;
+#
+# Bug #21530366 CRASH/ASSERTION, CORRUPTION WITH INDEXES +
+# VIRTUAL COLUMNS, BLOB
+#
+CREATE TABLE t (
+a INTEGER,
+b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+INDEX (b(57))
+);
+INSERT INTO t (a) VALUES (9);
+UPDATE t SET a = 10;
+DELETE FROM t WHERE a = 10;
+DROP TABLE t;
+# Bug#21807818: Generated columns not updated with empty insert list
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL,
+KEY (a(183),b)
+);
+ERROR HY000: Function or expression '''' cannot be used in the GENERATED ALWAYS AS clause of `b`
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL
+);
+INSERT IGNORE INTO t VALUES(), (), ();
+DELETE IGNORE FROM t;
+DROP TABLE t;
+#
+# Bug#22195458:GCOLS: ASSERTION 0 AND CORRUPTION...
+#
+CREATE TABLE t (
+a INT,
+b YEAR GENERATED ALWAYS AS ('a') VIRTUAL,
+c YEAR GENERATED ALWAYS AS ('aaaa') VIRTUAL,
+b1 YEAR GENERATED ALWAYS AS ('a') STORED,
+c1 YEAR GENERATED ALWAYS AS ('aaaa') STORED,
+UNIQUE(b),
+UNIQUE(b1)
+);
+INSERT IGNORE INTO t VALUES();
+SELECT b from t;
+b
+0000
+SELECT b1 from t;
+b1
+0000
+SELECT * from t;
+a b c b1 c1
+NULL 0000 0000 0000 0000
+DELETE FROM t;
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+# Bug#22195364:GCOLS: FAILING ASSERTION:
+# DFIELD_IS_NULL(DFIELD2) || DFIELD2->DATA
+CREATE TABLE t (
+a INT,
+c BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+UNIQUE KEY(c(1),a)
+);
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+a c
+1
+INSERT INTO t(a) VALUES(1) ON DUPLICATE KEY UPDATE a=2;
+SELECT * FROM t;
+a c
+2
+SELECT GROUP_CONCAT(c ORDER BY c) FROM t;
+GROUP_CONCAT(c ORDER BY c)
+
+DROP TABLE t;
+#Bug#21929967:GCOLS:GCOL VALUE CHANGES WHEN SESSION CHANGES SQL_MODE
+CREATE TABLE t(c1 INT GENERATED ALWAYS AS (1) VIRTUAL,
+c2 INT GENERATED ALWAYS AS(2) STORED);
+INSERT INTO t VALUES(DEFAULT, DEFAULT);
+SELECT * FROM t;
+c1 c2
+1 2
+CREATE TABLE t1(c1 INT, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t1(c2) VALUES(DEFAULT);
+SELECT * FROM t1;
+c1 c2
+NULL NULL
+CREATE TABLE t2(c1 INT DEFAULT 1, c2 INT GENERATED ALWAYS AS(c1 + 1) STORED);
+INSERT INTO t2(c2) VALUES(DEFAULT);
+SELECT * FROM t2;
+c1 c2
+1 2
+DROP TABLE t, t1, t2;
+# Bug#22179637: INSERT INTO TABLE FROM SELECT ACCEPTS TO INSERT INTO
+# GENERATED COLUMNS
+CREATE TABLE t1 (
+i1 INTEGER,
+i2 INTEGER GENERATED ALWAYS AS (i1 + i1)
+);
+INSERT INTO t1 (i1) SELECT 5;
+INSERT INTO t1 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t1;
+i1 i2
+5 10
+5 10
+CREATE TABLE t2 (
+i1 INTEGER,
+i2 INTEGER GENERATED ALWAYS AS (i1 + i1) STORED
+);
+INSERT INTO t2 (i1) SELECT 5;
+INSERT INTO t2 (i1) SELECT 5 ON DUPLICATE KEY UPDATE i2= DEFAULT;
+SELECT * FROM t2;
+i1 i2
+5 10
+5 10
+DROP TABLE t1,t2;
+#
+# Bug#22070021 GCOL:ASSERTION `!TABLE || (!TABLE->WRITE_SET ||
+# BITMAP_IS_SET(TABLE->WRITE_SET,
+#
+CREATE TABLE t1(
+c1 INT,
+c2 INT GENERATED ALWAYS AS (c1 + c1) VIRTUAL,
+KEY(c2)
+);
+INSERT INTO t1(c1) VALUES(0);
+DELETE O1.* FROM t1 AS O1, t1 AS O2;
+SELECT * FROM t1;
+c1 c2
+DROP TABLE t1;
+#
+# Bug#21944199 SIMPLE DELETE QUERY CAUSES INNODB: FAILING ASSERTION: 0
+# & DATA CORRUPTION
+#
+CREATE TEMPORARY TABLE t1 (
+a INTEGER NOT NULL,
+b INTEGER GENERATED ALWAYS AS (a+1) VIRTUAL
+);
+INSERT INTO t1 (a) VALUES (0), (0), (0);
+ALTER TABLE t1 ADD INDEX idx (b);
+DELETE FROM t1;
+DROP TEMPORARY TABLE t1;
+#
+# Original test case from MDEV-17890
+#
+CREATE TABLE t1 (
+pk BIGINT AUTO_INCREMENT,
+b BIT(15),
+v BIT(10) AS (b) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(v)
+);
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+Warnings:
+Warning 1264 Out of range value for column 'v' at row 1
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+ERROR 22001: Data too long for column 'v' at row 1
+DROP TABLE t1;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (
+id INT NOT NULL AUTO_INCREMENT,
+f ENUM('a','b','c'),
+v ENUM('a','b','c') AS (f),
+KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+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;
+CREATE TABLE t1 (
+id INT NOT NULL AUTO_INCREMENT,
+f ENUM('a','b','c'),
+v ENUM('a','b','c') AS (f),
+KEY(v,id)
+) ENGINE=MyISAM;
+INSERT INTO t1 (f) VALUES ('a'),('b');
+INSERT IGNORE INTO t1 SELECT * FROM t1;
+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;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_keys_innodb.result b/mysql-test/suite/gcol/r/gcol_keys_innodb.result
new file mode 100644
index 00000000..0228f9be
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_keys_innodb.result
@@ -0,0 +1,956 @@
+SET @@session.default_storage_engine = 'InnoDB';
+# - UNIQUE KEY
+# - INDEX
+# - FULLTEXT INDEX
+# - SPATIAL INDEX (not supported)
+# - FOREIGN INDEX (partially supported)
+# - CHECK (allowed but not used)
+# UNIQUE
+create table t1 (a int, b int generated always as (a*2) virtual unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual, unique key (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, unique (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add unique key (b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add unique key (b);
+drop table t1;
+# Testing data manipulation operations involving UNIQUE keys
+# on generated columns can be found in:
+# - gcol_ins_upd.inc
+# - gcol_select.inc
+#
+# INDEX
+create table t1 (a int, b int generated always as (a*2) virtual, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual, index (a,b));
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, index (a,b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ KEY `a` (`a`,`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES MUL NULL
+b int(11) YES NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add index (b);
+alter table t1 add index (a,b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (a,b);
+create table t2 like t1;
+drop table t2;
+drop table t1;
+# Testing data manipulation operations involving INDEX
+# on generated columns can be found in:
+# - gcol_select.inc
+#
+# TODO: FULLTEXT INDEX
+# SPATIAL INDEX
+# FOREIGN KEY
+# Rejected FK options.
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on update set null);
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on update cascade);
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on delete set null);
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored);
+alter table t1 add foreign key (b) references t2(a) on update set null;
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+alter table t1 add foreign key (b) references t2(a) on update cascade;
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+alter table t1 add foreign key (b) references t2(a) on delete set null;
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+drop table t1;
+create table t1 (a int, b int generated always as (a+1) virtual,
+foreign key (b) references t2(a));
+ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
+create table t1 (a int, b int generated always as (a+1) virtual);
+alter table t1 add foreign key (b) references t2(a);
+ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
+drop table t1;
+# Allowed FK options.
+create table t2 (a int primary key, b char(5));
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on update restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on update no action);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete cascade);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete no action);
+drop table t1,t2;
+#
+# Bug#20553262: WL8149: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED
+#
+CREATE TABLE c (
+pk integer AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_datetime_key));
+INSERT INTO c ( col_time_nokey,col_datetime_nokey,col_varchar_nokey) values
+('14:03:03.042673','2001-11-28 00:50:27.051028', 'c'),
+('01:46:09.016386','2007-10-09 19:53:04.008332', NULL),
+('16:21:18.052408','2001-11-08 21:02:12.009395', 'x'),
+('18:56:33.027423','2003-04-01 00:00:00', 'i');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+Note 1265 Data truncated for column 'col_time_key' at row 3
+Note 1265 Data truncated for column 'col_time_key' at row 4
+EXPLAIN SELECT
+outr.col_time_key AS x
+FROM c as outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+outr.col_datetime_key = '2009-09-27');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE outr index_merge col_time_key,col_datetime_key col_time_key,col_datetime_key 4,6 NULL x x
+SELECT
+outr.col_time_key AS x
+FROM c AS outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+outr.col_datetime_key = '2009-09-27');
+x
+DROP TABLE c;
+#
+# Bug#20913803: WL8149: SIG 11 IN DFIELD_DUP |
+# INNOBASE/INCLUDE/DATA0DATA.IC:253
+#
+CREATE TABLE A (
+col_varchar_nokey TEXT ,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+KEY (col_varchar_key(50))
+);
+INSERT INTO A (col_varchar_nokey) VALUES ('');
+CREATE TABLE D (
+pk INTEGER AUTO_INCREMENT,
+col_date_nokey BLOB,
+col_date_key BLOB GENERATED ALWAYS AS (REPEAT(col_date_nokey,1000)) VIRTUAL,
+col_datetime_nokey LONGBLOB,
+col_time_nokey LONGTEXT,
+col_datetime_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+col_time_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+col_varchar_nokey TEXT,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+PRIMARY KEY (pk),
+KEY (col_varchar_key(50)),
+KEY (col_date_key(20)),
+KEY (col_time_key(20)),
+KEY (col_datetime_key(20)),
+KEY (col_varchar_key(10), col_date_key(10), col_time_key(5), col_datetime_key(5))
+);
+INSERT INTO D (
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES ('', '', '', ''),('', '', '', '');
+DELETE FROM OUTR1.* USING D AS OUTR1 RIGHT JOIN A AS OUTR2 ON
+( OUTR1 . `col_varchar_nokey` = OUTR2 . `col_varchar_nokey` );
+DROP TABLE IF EXISTS A,D;
+#
+# Bug#21024896: SIG 11 INNOBASE_ADD_ONE_VIRTUAL |
+# INNOBASE/HANDLER/HANDLER0ALTER.CC
+#
+CREATE TABLE t1 (
+col1 int(11) DEFAULT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col2 / col2) VIRTUAL,
+col7 int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
+col8 int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
+col9 text,
+col6 int(11) DEFAULT NULL,
+PRIMARY KEY (`col3`),
+UNIQUE KEY uidx (`col2`),
+KEY idx (`col5`)
+);
+INSERT INTO t1(col1,col2,col3,col4,col9,col6)
+VALUES(1,1,0,1,REPEAT(col1,1000),0), (3,2,1,1,REPEAT(col1,1000),NULL);
+ALTER TABLE t1 ADD COLUMN extra INT;
+DROP TABLE t1;
+#
+# Bug#21316860: WL8149:INNODB: FAILING ASSERTION:
+# TEMPL->CLUST_REC_FIELD_NO != ULINT_UNDEFINED
+#
+CREATE TABLE t1 (
+pk int(11) NOT NULL,
+col_int_nokey int(11),
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+col_date_nokey date,
+col_date_key date GENERATED ALWAYS AS (col_date_nokey) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY col_int_key (col_int_key)
+);
+ALTER TABLE t1 DROP COLUMN pk;
+DROP TABLE t1;
+# Remove the impact on PK choose by index on virtual generated column
+CREATE TABLE t1 (
+pk int(11) NOT NULL,
+col_int_nokey int(11) DEFAULT NULL,
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+UNIQUE KEY col_int_key (col_int_key)
+);
+ALTER TABLE t1 add unique index idx(pk);
+DESC t1;
+Field Type Null Key Default Extra
+pk int(11) NO PRI NULL
+col_int_nokey int(11) YES NULL
+col_int_key int(11) YES UNI NULL VIRTUAL GENERATED
+DROP TABLE t1;
+#
+# Bug#21320151 WL8149: WRONG RESULT WITH INDEX SCAN
+#
+CREATE TABLE t1 (
+id INTEGER NOT NULL,
+b INTEGER GENERATED ALWAYS AS (id+1) VIRTUAL,
+UNIQUE KEY (b)
+);
+INSERT INTO t1 (id) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 9 Using index
+SELECT b FROM t1 FORCE INDEX(b);
+b
+3
+4
+5
+6
+7
+8
+9
+10
+11
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range b b 5 NULL 3 Using where; Using index
+SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+b
+3
+4
+5
+DROP TABLE t1;
+
+# Testing data manipulation operations involving FOREIGN KEY
+# on generated columns can be found in:
+# - gcol_ins_upd.inc
+# - gcol_select.inc
+#
+# TODO: CHECK
+#
+# Test how optimizer picks indexes defined on a GC
+#
+CREATE TABLE t1 (f1 int, gc int AS (f1 + 1) STORED, UNIQUE(gc));
+INSERT INTO t1(f1) VALUES (1),(2),(0),(9),(3),(4),(8),(7),(5),(6);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+# Should use index
+SELECT * FROM t1 WHERE f1 + 1 > 7;
+f1 gc
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 = 7;
+f1 gc
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 = 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 IN (7,5);
+f1 gc
+4 5
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 IN(7,5);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+f1 gc
+4 5
+5 6
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+# Check that expression isn't transformed for a disabled key
+SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+f1 gc
+4 5
+5 6
+6 7
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+# Check that ORDER BY could be optimized
+SELECT * FROM t1 ORDER BY f1 + 1;
+f1 gc
+0 1
+1 2
+2 3
+3 4
+4 5
+5 6
+6 7
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) ORDER BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
+# Check that GROUP BY could be optimized
+SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+f1 + 1 MAX(GC)
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+8 8
+9 9
+10 10
+EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
+EXPLAIN SELECT f1 + 1, MAX(GC)
+FROM t1 IGNORE KEY (gc) GROUP BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
+# Shouldn't use index
+SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+f1 gc
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+DROP TABLE t1;
+# Pick index with proper type
+CREATE TABLE t1 (f1 int,
+gc_int int AS (f1 + 1) STORED,
+gc_date DATE AS (f1 + 1) STORED,
+KEY gc_int_idx(gc_int),
+KEY gc_date_idx(gc_date));
+INSERT INTO t1(f1) VALUES
+(030303),(040404),
+(050505),(060606),
+(010101),(020202),
+(030303),(040404),
+(050505),(060606),
+(010101),(020202),
+(090909),(101010),
+(010101),(020202),
+(070707),(080808);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+SELECT * FROM t1 WHERE f1 + 1 > 070707;
+f1 gc_int gc_date
+101010 101011 2010-10-11
+70707 70708 2007-07-08
+80808 80809 2008-08-09
+90909 90910 2009-09-10
+# INT column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 070707;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
+SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+f1 gc_int gc_date
+101010 101011 2010-10-11
+70707 70708 2007-07-08
+80808 80809 2008-08-09
+90909 90910 2009-09-10
+# DATE column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
+DROP TABLE t1;
+#
+# BUG#21229846: WL8170: SIGNAL 11 IN JOIN::MAKE_SUM_FUNC_LIST
+#
+CREATE TABLE t1 (
+pk int primary key auto_increment,
+col_int_key INTEGER ,
+col_int_gc_key INT GENERATED ALWAYS AS (col_int_key + 1) STORED,
+KEY col_int_gc_key(col_int_gc_key)
+);
+INSERT INTO t1 ( col_int_key) VALUES (7);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ORDER BY field1, field2;
+field1 field2
+8 7
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ORDER BY field1, field2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE table1 ALL PRIMARY NULL NULL NULL 1 Using temporary; Using filesort
+1 SIMPLE table2 eq_ref PRIMARY PRIMARY 4 test.table1.pk 1
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+GROUP BY field1, field2;
+field1 field2
+8 7
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+GROUP BY field1, field2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE table1 ALL PRIMARY NULL NULL NULL 1 Using temporary; Using filesort
+1 SIMPLE table2 eq_ref PRIMARY PRIMARY 4 test.table1.pk 1
+DROP TABLE t1;
+#
+# Bug#21391781 ASSERT WHEN RUNNING ALTER TABLE ON A TABLE WITH INDEX
+# ON VIRTUAL COLUMN
+#
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+col3 INTEGER NOT NULL,
+col4 INTEGER NOT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+col34 INTEGER DEFAULT NULL,
+col35 INTEGER DEFAULT NULL,
+col36 INTEGER DEFAULT NULL,
+col37 INTEGER DEFAULT NULL,
+col38 INTEGER DEFAULT NULL,
+col39 INTEGER DEFAULT NULL,
+col40 INTEGER DEFAULT NULL,
+col41 INTEGER DEFAULT NULL,
+col42 INTEGER DEFAULT NULL,
+col43 INTEGER DEFAULT NULL,
+col44 INTEGER DEFAULT NULL,
+col45 INTEGER DEFAULT NULL,
+col46 INTEGER DEFAULT NULL,
+col47 INTEGER DEFAULT NULL,
+col48 INTEGER DEFAULT NULL,
+col49 INTEGER DEFAULT NULL,
+col50 INTEGER DEFAULT NULL,
+col51 INTEGER DEFAULT NULL,
+col52 INTEGER DEFAULT NULL,
+col53 INTEGER DEFAULT NULL,
+col54 INTEGER DEFAULT NULL,
+col55 INTEGER DEFAULT NULL,
+col56 INTEGER DEFAULT NULL,
+col57 INTEGER DEFAULT NULL,
+col58 INTEGER DEFAULT NULL,
+col59 INTEGER DEFAULT NULL,
+col60 INTEGER DEFAULT NULL,
+col61 INTEGER DEFAULT NULL,
+col62 INTEGER DEFAULT NULL,
+col63 INTEGER DEFAULT NULL,
+col64 INTEGER DEFAULT NULL,
+col65 INTEGER DEFAULT NULL,
+gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+KEY idx1 (gcol1)
+);
+INSERT INTO t1 (col1, col2, col3, col4)
+VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+gcol1
+2
+4
+6
+8
+10
+DROP TABLE t1;
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+col3 INTEGER NOT NULL,
+col4 INTEGER NOT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+col34 INTEGER DEFAULT NULL,
+col35 INTEGER DEFAULT NULL,
+col36 INTEGER DEFAULT NULL,
+col37 INTEGER DEFAULT NULL,
+col38 INTEGER DEFAULT NULL,
+col39 INTEGER DEFAULT NULL,
+col40 INTEGER DEFAULT NULL,
+col41 INTEGER DEFAULT NULL,
+col42 INTEGER DEFAULT NULL,
+col43 INTEGER DEFAULT NULL,
+col44 INTEGER DEFAULT NULL,
+col45 INTEGER DEFAULT NULL,
+col46 INTEGER DEFAULT NULL,
+col47 INTEGER DEFAULT NULL,
+col48 INTEGER DEFAULT NULL,
+col49 INTEGER DEFAULT NULL,
+col50 INTEGER DEFAULT NULL,
+col51 INTEGER DEFAULT NULL,
+col52 INTEGER DEFAULT NULL,
+col53 INTEGER DEFAULT NULL,
+col54 INTEGER DEFAULT NULL,
+col55 INTEGER DEFAULT NULL,
+col56 INTEGER DEFAULT NULL,
+col57 INTEGER DEFAULT NULL,
+col58 INTEGER DEFAULT NULL,
+col59 INTEGER DEFAULT NULL,
+col60 INTEGER DEFAULT NULL,
+col61 INTEGER DEFAULT NULL,
+col62 INTEGER DEFAULT NULL,
+col63 INTEGER DEFAULT NULL,
+col64 INTEGER DEFAULT NULL,
+col65 INTEGER DEFAULT NULL,
+gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+KEY idx1 (gcol2)
+);
+INSERT INTO t1 (col1, col2, col3, col4)
+VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+SELECT gcol2 FROM t1 FORCE INDEX(idx1);
+gcol2
+1
+1
+1
+1
+1
+DROP TABLE t1;
+#
+# Bug#21628161 CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
+#
+CREATE TABLE t (a INT,
+b BOOLEAN GENERATED ALWAYS AS (a+10000) VIRTUAL,
+c BLOB GENERATED ALWAYS AS (b=2) VIRTUAL);
+INSERT INTO t(a) VALUES (1);
+SELECT * FROM t WHERE c = '0';
+a b c
+1 127 0
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD UNIQUE INDEX (c(1));
+Warnings:
+Warning 1264 Out of range value for column 'b' at row 0
+SELECT * FROM t WHERE c = '0';
+a b c
+1 127 0
+DROP TABLE t;
+#
+# Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD()
+# DID NOT RETURN TRUE WITH DIVIDE 0
+#
+CREATE TABLE t (a INT, b INT, h VARCHAR(10));
+INSERT INTO t VALUES (12, 3, "ss");
+INSERT INTO t VALUES (13, 4, "ss");
+INSERT INTO t VALUES (14, 0, "ss");
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD c INT GENERATED ALWAYS AS (a/b) VIRTUAL;
+CREATE INDEX idx ON t(c);
+ERROR 22012: Division by 0
+CALL mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual column values failed");
+DROP TABLE t;
+#
+# Bug#21770798 OPTIMIZER DOES NOT USE INDEX FOR GENERATED EXPRESSIONS
+# WITH LOGICAL OPERATORS
+#
+CREATE TABLE t (a INT, b INT,
+gc_and INT GENERATED ALWAYS AS (a AND b) STORED,
+gc_or INT GENERATED ALWAYS AS (a OR b) STORED,
+gc_xor INT GENERATED ALWAYS AS (a XOR b) STORED,
+gc_not INT GENERATED ALWAYS AS (NOT a) STORED,
+gc_case INT GENERATED ALWAYS AS
+(CASE WHEN (a AND b) THEN a ELSE b END) STORED,
+INDEX(gc_and), INDEX(gc_or), INDEX(gc_xor), INDEX(gc_not),
+INDEX(gc_case));
+INSERT INTO t (a, b) VALUES (0, 0), (0, 1), (1, 0), (1, 1);
+ANALYZE TABLE t;
+Table Op Msg_type Msg_text
+test.t analyze status Engine-independent statistics collected
+test.t analyze status OK
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a AND b) = 1;
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (a AND b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (a AND b);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a OR b) = 1;
+a b
+0 1
+1 0
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+a b
+0 1
+1 0
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a XOR b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a XOR b) = 1;
+a b
+0 1
+1 0
+EXPLAIN SELECT a FROM t WHERE (NOT a) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a FROM t WHERE (NOT a) = 1;
+a
+0
+0
+EXPLAIN SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+a
+0
+1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b AND a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (b AND a);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b OR a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (b OR a);
+a b
+0 1
+1 0
+1 1
+DROP TABLE t;
+#
+# Bug#22810883: ASSERTION FAILED:
+# !(USED_TABS & (~READ_TABLES & ~FILTER_FOR_TABLE))
+#
+CREATE TABLE t1 (a1 INTEGER GENERATED ALWAYS AS (1 AND 0) STORED,
+a2 INTEGER, KEY (a1));
+INSERT INTO t1 VALUES ();
+CREATE TABLE t2 (b INTEGER);
+INSERT INTO t2 VALUES (1);
+ANALYZE TABLE t1, t2;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+# Used to choose the index on a1 and get wrong results.
+EXPLAIN SELECT * FROM t1 WHERE (a2 AND a2) = 0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
+SELECT * FROM t1 WHERE (a2 AND a2) = 0;
+a1 a2
+# Used to get assertion or wrong results.
+EXPLAIN SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 1
+1 SIMPLE t2 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (flat, BNL join)
+SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
+a1 a2 b
+0 NULL 1
+DROP TABLE t1, t2;
+#
+# MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed
+# in row_upd_sec_index_entry
+#
+CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT,
+PRIMARY KEY (PK), UNIQUE KEY (VA));
+INSERT IGNORE INTO t1 VALUES ( '\r1','a',1);
+Warnings:
+Warning 1906 The value specified for generated column 'VA' in table 't1' has been ignored
+Warning 1264 Out of range value for column 'VA' at row 1
+REPLACE INTO t1 (PK) VALUES (1);
+ERROR 22001: Data too long for column 'VA' at row 1
+DROP TABLE t1;
+#
+# MDEV-17890 Record in index was not found on update, server crash in
+# row_upd_build_difference_binary or
+# Assertion `0' failed in row_upd_sec_index_entry
+#
+CREATE TABLE t1 (
+pk BIGINT AUTO_INCREMENT,
+b BIT(15),
+v BIT(10) AS (b) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(v)
+);
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+Warnings:
+Warning 1264 Out of range value for column 'v' at row 1
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+ERROR 22001: Data too long for column 'v' at row 1
+DROP TABLE t1;
+#
+# MDEV-17834 Server crashes in row_upd_build_difference_binary
+# on LOAD DATA into table with indexed virtual column
+#
+CREATE TABLE t1 (
+pk INT,
+i TINYINT,
+ts TIMESTAMP NULL,
+vi TINYINT AS (i+1) PERSISTENT,
+vts TIMESTAMP(5) AS (ts) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(vts)
+);
+INSERT IGNORE INTO t1 (pk,i) VALUES (1,127);
+Warnings:
+Warning 1264 Out of range value for column 'vi' at row 1
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts);
+ERROR 22003: Out of range value for column 'vi' at row 1
+DROP TABLE t1;
+# MDEV-19011 Assertion `file->s->base.reclength < file->s->vreclength'
+# failed in ha_myisam::setup_vcols_for_repair
+CREATE TABLE t1 (a INT GENERATED ALWAYS AS (1) VIRTUAL);
+ALTER TABLE t1 ADD KEY (a);
+DROP TABLE t1;
+#
+# BUG#21365158 WL8149:ASSERTION `!TABLE || (!TABLE->WRITE_SET
+#
+CREATE TABLE t1 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk)
+);
+INSERT INTO t1 ( col_int_nokey, col_varchar_nokey)
+VALUES (4, 'b'),(9, 'o'),(4, 'k'),(5, 'a'),(5, 'f'),
+(9, 't'),(3, 'c'),(8, 'c'),(0, 'r'),(98, 'k');
+CREATE TABLE t2 (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY (col_varchar_key)
+);
+INSERT INTO t2 ( col_int_nokey, col_varchar_nokey)
+VALUES (1, 'c'),(8, 'm'),(9, 'd'), (6, 'y'),(1, 't'),
+(2, 's'),(4, 'r');
+SELECT
+CONCAT( t2.col_varchar_nokey , t2.col_varchar_nokey ) AS f2,
+t1.col_varchar_key AS f5
+FROM
+t2 LEFT JOIN t1 ON t2.col_int_nokey > t1.col_int_nokey
+ORDER BY f2, f5;
+f2 f5
+cc rr
+dd aa
+dd bb
+dd cc
+dd cc
+dd ff
+dd kk
+dd rr
+mm aa
+mm bb
+mm cc
+mm ff
+mm kk
+mm rr
+rr cc
+rr rr
+ss rr
+tt rr
+yy aa
+yy bb
+yy cc
+yy ff
+yy kk
+yy rr
+DROP TABLE t1,t2;
+#
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_keys_myisam.result b/mysql-test/suite/gcol/r/gcol_keys_myisam.result
new file mode 100644
index 00000000..523ff3a3
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_keys_myisam.result
@@ -0,0 +1,897 @@
+SET @@session.default_storage_engine = 'MyISAM';
+# - UNIQUE KEY
+# - INDEX
+# - FULLTEXT INDEX
+# - SPATIAL INDEX (not supported)
+# - FOREIGN INDEX (partially supported)
+# - CHECK (allowed but not used)
+# UNIQUE
+create table t1 (a int, b int generated always as (a*2) virtual unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual, unique key (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, unique (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add unique key (b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add unique key (b);
+drop table t1;
+# Testing data manipulation operations involving UNIQUE keys
+# on generated columns can be found in:
+# - gcol_ins_upd.inc
+# - gcol_select.inc
+#
+# INDEX
+create table t1 (a int, b int generated always as (a*2) virtual, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) VIRTUAL,
+ KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL VIRTUAL GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual, index (a,b));
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored, index (a,b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` * 2) STORED,
+ KEY `a` (`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES MUL NULL
+b int(11) YES NULL STORED GENERATED
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) virtual);
+alter table t1 add index (b);
+alter table t1 add index (a,b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (b);
+drop table t1;
+create table t1 (a int, b int generated always as (a*2) stored);
+alter table t1 add index (a,b);
+create table t2 like t1;
+drop table t2;
+drop table t1;
+# Testing data manipulation operations involving INDEX
+# on generated columns can be found in:
+# - gcol_select.inc
+#
+# TODO: FULLTEXT INDEX
+# SPATIAL INDEX
+# Error "All parts of a SPATIAL index must be geometrical"
+create table t1 (a int, b int generated always as (a+1) stored, spatial index (b));
+ERROR HY000: Incorrect arguments to SPATIAL INDEX
+create table t1 (a int, b int generated always as (a+1) stored);
+alter table t1 add spatial index (b);
+ERROR HY000: Incorrect arguments to SPATIAL INDEX
+drop table t1;
+# FOREIGN KEY
+# Rejected FK options.
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on update set null);
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on update cascade);
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored,
+foreign key (b) references t2(a) on delete set null);
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+create table t1 (a int, b int generated always as (a+1) stored);
+alter table t1 add foreign key (b) references t2(a) on update set null;
+ERROR HY000: Cannot define foreign key with ON UPDATE SET NULL clause on a generated column
+alter table t1 add foreign key (b) references t2(a) on update cascade;
+ERROR HY000: Cannot define foreign key with ON UPDATE CASCADE clause on a generated column
+alter table t1 add foreign key (b) references t2(a) on delete set null;
+ERROR HY000: Cannot define foreign key with ON DELETE SET NULL clause on a generated column
+drop table t1;
+# Allowed FK options.
+create table t2 (a int primary key, b char(5));
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on update restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on update no action);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete restrict);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete cascade);
+drop table t1;
+create table t1 (a int, b int generated always as (a % 10) stored,
+foreign key (b) references t2(a) on delete no action);
+drop table t1,t2;
+#
+# Bug#20553262: WL8149: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED
+#
+CREATE TABLE c (
+pk integer AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_datetime_key));
+INSERT INTO c ( col_time_nokey,col_datetime_nokey,col_varchar_nokey) values
+('14:03:03.042673','2001-11-28 00:50:27.051028', 'c'),
+('01:46:09.016386','2007-10-09 19:53:04.008332', NULL),
+('16:21:18.052408','2001-11-08 21:02:12.009395', 'x'),
+('18:56:33.027423','2003-04-01 00:00:00', 'i');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+Note 1265 Data truncated for column 'col_time_key' at row 3
+Note 1265 Data truncated for column 'col_time_key' at row 4
+EXPLAIN SELECT
+outr.col_time_key AS x
+FROM c as outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+outr.col_datetime_key = '2009-09-27');
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE outr index_merge col_time_key,col_datetime_key col_time_key,col_datetime_key 4,6 NULL x x
+SELECT
+outr.col_time_key AS x
+FROM c AS outr
+WHERE
+outr.col_varchar_nokey in ('c', 'x', 'i')
+AND (outr.col_time_key IS NULL OR
+outr.col_datetime_key = '2009-09-27');
+x
+DROP TABLE c;
+#
+# Bug#20913803: WL8149: SIG 11 IN DFIELD_DUP |
+# INNOBASE/INCLUDE/DATA0DATA.IC:253
+#
+CREATE TABLE A (
+col_varchar_nokey TEXT ,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+KEY (col_varchar_key(50))
+);
+INSERT INTO A (col_varchar_nokey) VALUES ('');
+CREATE TABLE D (
+pk INTEGER AUTO_INCREMENT,
+col_date_nokey BLOB,
+col_date_key BLOB GENERATED ALWAYS AS (REPEAT(col_date_nokey,1000)) VIRTUAL,
+col_datetime_nokey LONGBLOB,
+col_time_nokey LONGTEXT,
+col_datetime_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+col_time_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_datetime_nokey, 1000)),
+col_varchar_nokey TEXT,
+col_varchar_key TEXT GENERATED ALWAYS AS (REPEAT(col_varchar_nokey, 1000)),
+PRIMARY KEY (pk),
+KEY (col_varchar_key(50)),
+KEY (col_date_key(20)),
+KEY (col_time_key(20)),
+KEY (col_datetime_key(20)),
+KEY (col_varchar_key(10), col_date_key(10), col_time_key(5), col_datetime_key(5))
+);
+INSERT INTO D (
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES ('', '', '', ''),('', '', '', '');
+DELETE FROM OUTR1.* USING D AS OUTR1 RIGHT JOIN A AS OUTR2 ON
+( OUTR1 . `col_varchar_nokey` = OUTR2 . `col_varchar_nokey` );
+DROP TABLE IF EXISTS A,D;
+#
+# Bug#21024896: SIG 11 INNOBASE_ADD_ONE_VIRTUAL |
+# INNOBASE/HANDLER/HANDLER0ALTER.CC
+#
+CREATE TABLE t1 (
+col1 int(11) DEFAULT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS (col2 / col2) VIRTUAL,
+col7 int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
+col8 int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
+col9 text,
+col6 int(11) DEFAULT NULL,
+PRIMARY KEY (`col3`),
+UNIQUE KEY uidx (`col2`),
+KEY idx (`col5`)
+);
+INSERT INTO t1(col1,col2,col3,col4,col9,col6)
+VALUES(1,1,0,1,REPEAT(col1,1000),0), (3,2,1,1,REPEAT(col1,1000),NULL);
+ALTER TABLE t1 ADD COLUMN extra INT;
+DROP TABLE t1;
+#
+# Bug#21316860: WL8149:INNODB: FAILING ASSERTION:
+# TEMPL->CLUST_REC_FIELD_NO != ULINT_UNDEFINED
+#
+CREATE TABLE t1 (
+pk int(11) NOT NULL,
+col_int_nokey int(11),
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+col_date_nokey date,
+col_date_key date GENERATED ALWAYS AS (col_date_nokey) VIRTUAL,
+PRIMARY KEY (pk),
+UNIQUE KEY col_int_key (col_int_key)
+);
+ALTER TABLE t1 DROP COLUMN pk;
+DROP TABLE t1;
+# Remove the impact on PK choose by index on virtual generated column
+CREATE TABLE t1 (
+pk int(11) NOT NULL,
+col_int_nokey int(11) DEFAULT NULL,
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+UNIQUE KEY col_int_key (col_int_key)
+);
+ALTER TABLE t1 add unique index idx(pk);
+DESC t1;
+Field Type Null Key Default Extra
+pk int(11) NO PRI NULL
+col_int_nokey int(11) YES NULL
+col_int_key int(11) YES UNI NULL VIRTUAL GENERATED
+DROP TABLE t1;
+#
+# Bug#21320151 WL8149: WRONG RESULT WITH INDEX SCAN
+#
+CREATE TABLE t1 (
+id INTEGER NOT NULL,
+b INTEGER GENERATED ALWAYS AS (id+1) VIRTUAL,
+UNIQUE KEY (b)
+);
+INSERT INTO t1 (id) VALUES (2),(3),(4),(5),(6),(7),(8),(9),(10);
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 9 Using index
+SELECT b FROM t1 FORCE INDEX(b);
+b
+3
+4
+5
+6
+7
+8
+9
+10
+11
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range b b 5 NULL 3 Using where; Using index
+SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+b
+3
+4
+5
+DROP TABLE t1;
+
+# Testing data manipulation operations involving FOREIGN KEY
+# on generated columns can be found in:
+# - gcol_ins_upd.inc
+# - gcol_select.inc
+#
+# TODO: CHECK
+#
+# Test how optimizer picks indexes defined on a GC
+#
+CREATE TABLE t1 (f1 int, gc int AS (f1 + 1) STORED, UNIQUE(gc));
+INSERT INTO t1(f1) VALUES (1),(2),(0),(9),(3),(4),(8),(7),(5),(6);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+# Should use index
+SELECT * FROM t1 WHERE f1 + 1 > 7;
+f1 gc
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 = 7;
+f1 gc
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 = 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 IN (7,5);
+f1 gc
+4 5
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 IN(7,5);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+f1 gc
+4 5
+5 6
+6 7
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 BETWEEN 5 AND 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+# Check that expression isn't transformed for a disabled key
+SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+f1 gc
+4 5
+5 6
+6 7
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) WHERE f1 + 1 BETWEEN 5 AND 7;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+# Check that ORDER BY could be optimized
+SELECT * FROM t1 ORDER BY f1 + 1;
+f1 gc
+0 1
+1 2
+2 3
+3 4
+4 5
+5 6
+6 7
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
+EXPLAIN SELECT * FROM t1 IGNORE KEY (gc) ORDER BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using filesort
+# Check that GROUP BY could be optimized
+SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+f1 + 1 MAX(GC)
+1 1
+2 2
+3 3
+4 4
+5 5
+6 6
+7 7
+8 8
+9 9
+10 10
+EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
+EXPLAIN SELECT f1 + 1, MAX(GC)
+FROM t1 IGNORE KEY (gc) GROUP BY f1 + 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort
+# Shouldn't use index
+SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+f1 gc
+7 8
+8 9
+9 10
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 7.0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
+DROP TABLE t1;
+# Pick index with proper type
+CREATE TABLE t1 (f1 int,
+gc_int int AS (f1 + 1) STORED,
+gc_date DATE AS (f1 + 1) STORED,
+KEY gc_int_idx(gc_int),
+KEY gc_date_idx(gc_date));
+INSERT INTO t1(f1) VALUES
+(030303),(040404),
+(050505),(060606),
+(010101),(020202),
+(030303),(040404),
+(050505),(060606),
+(010101),(020202),
+(090909),(101010),
+(010101),(020202),
+(070707),(080808);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+SELECT * FROM t1 WHERE f1 + 1 > 070707;
+f1 gc_int gc_date
+101010 101011 2010-10-11
+70707 70708 2007-07-08
+80808 80809 2008-08-09
+90909 90910 2009-09-10
+# INT column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > 070707;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
+SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+f1 gc_int gc_date
+101010 101011 2010-10-11
+70707 70708 2007-07-08
+80808 80809 2008-08-09
+90909 90910 2009-09-10
+# DATE column & index should be picked
+EXPLAIN SELECT * FROM t1 WHERE f1 + 1 > CAST(070707 AS DATE);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 18 Using where
+DROP TABLE t1;
+#
+# BUG#21229846: WL8170: SIGNAL 11 IN JOIN::MAKE_SUM_FUNC_LIST
+#
+CREATE TABLE t1 (
+pk int primary key auto_increment,
+col_int_key INTEGER ,
+col_int_gc_key INT GENERATED ALWAYS AS (col_int_key + 1) STORED,
+KEY col_int_gc_key(col_int_gc_key)
+);
+INSERT INTO t1 ( col_int_key) VALUES (7);
+ANALYZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ORDER BY field1, field2;
+field1 field2
+8 7
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+ORDER BY field1, field2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE table1 system PRIMARY NULL NULL NULL 1
+1 SIMPLE table2 system PRIMARY NULL NULL NULL 1
+SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+GROUP BY field1, field2;
+field1 field2
+8 7
+EXPLAIN SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
+FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
+GROUP BY field1, field2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE table1 system PRIMARY NULL NULL NULL 1
+1 SIMPLE table2 system PRIMARY NULL NULL NULL 1
+DROP TABLE t1;
+#
+# Bug#21391781 ASSERT WHEN RUNNING ALTER TABLE ON A TABLE WITH INDEX
+# ON VIRTUAL COLUMN
+#
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+col3 INTEGER NOT NULL,
+col4 INTEGER NOT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+col34 INTEGER DEFAULT NULL,
+col35 INTEGER DEFAULT NULL,
+col36 INTEGER DEFAULT NULL,
+col37 INTEGER DEFAULT NULL,
+col38 INTEGER DEFAULT NULL,
+col39 INTEGER DEFAULT NULL,
+col40 INTEGER DEFAULT NULL,
+col41 INTEGER DEFAULT NULL,
+col42 INTEGER DEFAULT NULL,
+col43 INTEGER DEFAULT NULL,
+col44 INTEGER DEFAULT NULL,
+col45 INTEGER DEFAULT NULL,
+col46 INTEGER DEFAULT NULL,
+col47 INTEGER DEFAULT NULL,
+col48 INTEGER DEFAULT NULL,
+col49 INTEGER DEFAULT NULL,
+col50 INTEGER DEFAULT NULL,
+col51 INTEGER DEFAULT NULL,
+col52 INTEGER DEFAULT NULL,
+col53 INTEGER DEFAULT NULL,
+col54 INTEGER DEFAULT NULL,
+col55 INTEGER DEFAULT NULL,
+col56 INTEGER DEFAULT NULL,
+col57 INTEGER DEFAULT NULL,
+col58 INTEGER DEFAULT NULL,
+col59 INTEGER DEFAULT NULL,
+col60 INTEGER DEFAULT NULL,
+col61 INTEGER DEFAULT NULL,
+col62 INTEGER DEFAULT NULL,
+col63 INTEGER DEFAULT NULL,
+col64 INTEGER DEFAULT NULL,
+col65 INTEGER DEFAULT NULL,
+gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+KEY idx1 (gcol1)
+);
+INSERT INTO t1 (col1, col2, col3, col4)
+VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+gcol1
+2
+4
+6
+8
+10
+DROP TABLE t1;
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+col3 INTEGER NOT NULL,
+col4 INTEGER NOT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+col34 INTEGER DEFAULT NULL,
+col35 INTEGER DEFAULT NULL,
+col36 INTEGER DEFAULT NULL,
+col37 INTEGER DEFAULT NULL,
+col38 INTEGER DEFAULT NULL,
+col39 INTEGER DEFAULT NULL,
+col40 INTEGER DEFAULT NULL,
+col41 INTEGER DEFAULT NULL,
+col42 INTEGER DEFAULT NULL,
+col43 INTEGER DEFAULT NULL,
+col44 INTEGER DEFAULT NULL,
+col45 INTEGER DEFAULT NULL,
+col46 INTEGER DEFAULT NULL,
+col47 INTEGER DEFAULT NULL,
+col48 INTEGER DEFAULT NULL,
+col49 INTEGER DEFAULT NULL,
+col50 INTEGER DEFAULT NULL,
+col51 INTEGER DEFAULT NULL,
+col52 INTEGER DEFAULT NULL,
+col53 INTEGER DEFAULT NULL,
+col54 INTEGER DEFAULT NULL,
+col55 INTEGER DEFAULT NULL,
+col56 INTEGER DEFAULT NULL,
+col57 INTEGER DEFAULT NULL,
+col58 INTEGER DEFAULT NULL,
+col59 INTEGER DEFAULT NULL,
+col60 INTEGER DEFAULT NULL,
+col61 INTEGER DEFAULT NULL,
+col62 INTEGER DEFAULT NULL,
+col63 INTEGER DEFAULT NULL,
+col64 INTEGER DEFAULT NULL,
+col65 INTEGER DEFAULT NULL,
+gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
+KEY idx1 (gcol2)
+);
+INSERT INTO t1 (col1, col2, col3, col4)
+VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+SELECT gcol2 FROM t1 FORCE INDEX(idx1);
+gcol2
+1
+1
+1
+1
+1
+DROP TABLE t1;
+#
+# Bug#21628161 CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
+#
+CREATE TABLE t (a INT,
+b BOOLEAN GENERATED ALWAYS AS (a+10000) VIRTUAL,
+c BLOB GENERATED ALWAYS AS (b=2) VIRTUAL);
+INSERT INTO t(a) VALUES (1);
+SELECT * FROM t WHERE c = '0';
+a b c
+1 127 0
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD UNIQUE INDEX (c(1));
+Warnings:
+Warning 1264 Out of range value for column 'b' at row 1
+SELECT * FROM t WHERE c = '0';
+a b c
+1 127 0
+DROP TABLE t;
+#
+# Bug#21688115 VIRTUAL COLUMN COMPUTATION SAVE_IN_FIELD()
+# DID NOT RETURN TRUE WITH DIVIDE 0
+#
+CREATE TABLE t (a INT, b INT, h VARCHAR(10));
+INSERT INTO t VALUES (12, 3, "ss");
+INSERT INTO t VALUES (13, 4, "ss");
+INSERT INTO t VALUES (14, 0, "ss");
+SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR
+ALTER TABLE t ADD c INT GENERATED ALWAYS AS (a/b) VIRTUAL;
+CREATE INDEX idx ON t(c);
+ERROR 22012: Division by 0
+CALL mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual column values failed");
+DROP TABLE t;
+#
+# Bug#21770798 OPTIMIZER DOES NOT USE INDEX FOR GENERATED EXPRESSIONS
+# WITH LOGICAL OPERATORS
+#
+CREATE TABLE t (a INT, b INT,
+gc_and INT GENERATED ALWAYS AS (a AND b) STORED,
+gc_or INT GENERATED ALWAYS AS (a OR b) STORED,
+gc_xor INT GENERATED ALWAYS AS (a XOR b) STORED,
+gc_not INT GENERATED ALWAYS AS (NOT a) STORED,
+gc_case INT GENERATED ALWAYS AS
+(CASE WHEN (a AND b) THEN a ELSE b END) STORED,
+INDEX(gc_and), INDEX(gc_or), INDEX(gc_xor), INDEX(gc_not),
+INDEX(gc_case));
+INSERT INTO t (a, b) VALUES (0, 0), (0, 1), (1, 0), (1, 1);
+ANALYZE TABLE t;
+Table Op Msg_type Msg_text
+test.t analyze status Engine-independent statistics collected
+test.t analyze status OK
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a AND b) = 1;
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (a AND b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (a AND b);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a AND b) IN (1, 2, 3);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a OR b) = 1;
+a b
+0 1
+1 0
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a OR b) BETWEEN 1 AND 10;
+a b
+0 1
+1 0
+1 1
+EXPLAIN SELECT a, b FROM t WHERE (a XOR b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE (a XOR b) = 1;
+a b
+0 1
+1 0
+EXPLAIN SELECT a FROM t WHERE (NOT a) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a FROM t WHERE (NOT a) = 1;
+a
+0
+0
+EXPLAIN SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a FROM t WHERE (CASE WHEN (a AND b) THEN a ELSE b END) = 1;
+a
+0
+1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b AND a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (b AND a);
+a b
+1 1
+EXPLAIN SELECT a, b FROM t WHERE 1 = (b OR a);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t ALL NULL NULL NULL NULL 4 Using where
+SELECT a, b FROM t WHERE 1 = (b OR a);
+a b
+0 1
+1 0
+1 1
+DROP TABLE t;
+#
+# Bug#22810883: ASSERTION FAILED:
+# !(USED_TABS & (~READ_TABLES & ~FILTER_FOR_TABLE))
+#
+CREATE TABLE t1 (a1 INTEGER GENERATED ALWAYS AS (1 AND 0) STORED,
+a2 INTEGER, KEY (a1));
+INSERT INTO t1 VALUES ();
+CREATE TABLE t2 (b INTEGER);
+INSERT INTO t2 VALUES (1);
+ANALYZE TABLE t1, t2;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+# Used to choose the index on a1 and get wrong results.
+EXPLAIN SELECT * FROM t1 WHERE (a2 AND a2) = 0;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+SELECT * FROM t1 WHERE (a2 AND a2) = 0;
+a1 a2
+# Used to get assertion or wrong results.
+EXPLAIN SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 system NULL NULL NULL NULL 1
+1 SIMPLE t2 system NULL NULL NULL NULL 1
+SELECT * FROM t1 STRAIGHT_JOIN t2 ON b WHERE (b AND b) = 1;
+a1 a2 b
+0 NULL 1
+DROP TABLE t1, t2;
+#
+# MDEV-20618 Assertion `btr_validate_index(index, 0, false)' failed
+# in row_upd_sec_index_entry
+#
+CREATE TABLE t1 (A BIT(15), VA BIT(10) GENERATED ALWAYS AS (A),PK INT,
+PRIMARY KEY (PK), UNIQUE KEY (VA));
+INSERT IGNORE INTO t1 VALUES ( '\r1','a',1);
+Warnings:
+Warning 1906 The value specified for generated column 'VA' in table 't1' has been ignored
+Warning 1264 Out of range value for column 'VA' at row 1
+REPLACE INTO t1 (PK) VALUES (1);
+ERROR 22001: Data too long for column 'VA' at row 1
+DROP TABLE t1;
+#
+# MDEV-17890 Record in index was not found on update, server crash in
+# row_upd_build_difference_binary or
+# Assertion `0' failed in row_upd_sec_index_entry
+#
+CREATE TABLE t1 (
+pk BIGINT AUTO_INCREMENT,
+b BIT(15),
+v BIT(10) AS (b) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(v)
+);
+INSERT IGNORE INTO t1 (b) VALUES (b'101110001110100'),(b'011101');
+Warnings:
+Warning 1264 Out of range value for column 'v' at row 1
+SELECT pk, b INTO OUTFILE 'load.data' FROM t1;
+LOAD DATA INFILE 'load.data' REPLACE INTO TABLE t1 (pk, b);
+ERROR 22001: Data too long for column 'v' at row 1
+DROP TABLE t1;
+#
+# MDEV-17834 Server crashes in row_upd_build_difference_binary
+# on LOAD DATA into table with indexed virtual column
+#
+CREATE TABLE t1 (
+pk INT,
+i TINYINT,
+ts TIMESTAMP NULL,
+vi TINYINT AS (i+1) PERSISTENT,
+vts TIMESTAMP(5) AS (ts) VIRTUAL,
+PRIMARY KEY(pk),
+UNIQUE(vts)
+);
+INSERT IGNORE INTO t1 (pk,i) VALUES (1,127);
+Warnings:
+Warning 1264 Out of range value for column 'vi' at row 1
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/load.data' REPLACE INTO TABLE t1 (pk,i,ts);
+ERROR 22003: Out of range value for column 'vi' at row 1
+DROP TABLE t1;
+# MDEV-19011 Assertion `file->s->base.reclength < file->s->vreclength'
+# failed in ha_myisam::setup_vcols_for_repair
+CREATE TABLE t1 (a INT GENERATED ALWAYS AS (1) VIRTUAL);
+ALTER TABLE t1 ADD KEY (a);
+DROP TABLE t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_memory.result b/mysql-test/suite/gcol/r/gcol_memory.result
new file mode 100644
index 00000000..b7ce08b6
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_memory.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'memory';
+create table t1 (a int, b int generated always as (a+1) virtual);
+ERROR HY000: MEMORY storage engine does not support generated columns
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual;
+ERROR HY000: MEMORY storage engine does not support generated columns
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_merge.result b/mysql-test/suite/gcol/r/gcol_merge.result
new file mode 100644
index 00000000..bffe6265
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_merge.result
@@ -0,0 +1,15 @@
+drop table if exists t1, t2, t3;
+create table t1 (a int, b int generated always as (a % 10) virtual);
+create table t2 (a int, b int generated always as (a % 10) virtual);
+insert into t1 values (1,default);
+insert into t2 values (2,default);
+create table t3 (a int, b int generated always as (a % 10) virtual) engine=MERGE UNION=(t1,t2);
+ERROR HY000: MRG_MyISAM storage engine does not support generated columns
+drop table t1,t2;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_ndb.result b/mysql-test/suite/gcol/r/gcol_ndb.result
new file mode 100644
index 00000000..4c1c2a44
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_ndb.result
@@ -0,0 +1,14 @@
+SET @@session.default_storage_engine = 'ndbcluster';
+create table t1 (a int, b int generated always as (a+1) virtual);
+ERROR HY000: 'Specified storage engine' is not supported for generated columns.
+create table t1 (a int);
+alter table t1 add column b int generated always as (a+1) virtual;
+ERROR HY000: 'Specified storage engine' is not supported for generated columns.
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_non_stored_columns_innodb.result b/mysql-test/suite/gcol/r/gcol_non_stored_columns_innodb.result
new file mode 100644
index 00000000..6527b50b
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_non_stored_columns_innodb.result
@@ -0,0 +1,237 @@
+SET @@session.default_storage_engine = 'InnoDB';
+# Case 1. All non-stored columns.
+create table t1 (a int generated always as (2+3) virtual);
+insert into t1 values (default);
+select * from t1;
+a
+5
+insert into t1 values (default);
+select * from t1;
+a
+5
+5
+drop table t1;
+# Case 2. CREATE
+# - Column1: "real"
+# - Column 2: virtual non-stored
+create table t1 (a int, b int generated always as (-a) virtual);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 -1
+insert into t1 values (2,default);
+select * from t1 order by a;
+a b
+1 -1
+2 -2
+drop table t1;
+# Case 3. CREATE
+# - Column1: "real"
+# - Column 2: virtual stored
+create table t1 (a int, b int generated always as (-a) stored);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 -1
+insert into t1 values (2,default);
+select * from t1 order by a;
+a b
+1 -1
+2 -2
+drop table t1;
+# Case 4. CREATE
+# - Column1: virtual non-stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) virtual, b int);
+insert into t1 values (default,1);
+select * from t1;
+a b
+-1 1
+insert into t1 values (default,2);
+select * from t1 order by a;
+a b
+-2 2
+-1 1
+drop table t1;
+# Case 5. CREATE
+# - Column1: virtual stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) stored, b int);
+insert into t1 values (default,1);
+select * from t1;
+a b
+-1 1
+insert into t1 values (default,2);
+select * from t1 order by a;
+a b
+-2 2
+-1 1
+drop table t1;
+# Case 6. CREATE
+# - Column1: "real"
+# - Column2: virtual non-stored
+# - Column3: virtual stored
+create table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+1 -1 -1
+insert into t1 values (2,default,default);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t1;
+# Case 7. ALTER. Modify virtual stored -> virtual non-stored
+create table t1 (a int, b int generated always as (a % 2) stored);
+alter table t1 modify b int generated always as (a % 2) virtual;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 8. ALTER. Modify virtual non-stored -> virtual stored
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) stored;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 9. CREATE LIKE
+# - Column1: "real"
+# - Column2: virtual non-stored
+# - Column3: virtual stored
+create table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+create table t2 like t1;
+insert into t2 values (1,default,default);
+select * from t2;
+a b c
+1 -1 -1
+insert into t2 values (2,default,default);
+select * from t2 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t2;
+drop table t1;
+# Case 10. ALTER. Dropping a virtual non-stored column.
+# - Column1: virtual non-stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) virtual, b int, c varchar(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+a b c
+-1 1 v1
+-2 2 v2
+alter table t1 drop column a;
+select * from t1 order by b;
+b c
+1 v1
+2 v2
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(5) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 11. ALTER. Dropping a virtual stored column.
+# - Column1: virtual stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) stored, b int, c char(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+a b c
+-1 1 v1
+-2 2 v2
+alter table t1 drop column a;
+select * from t1 order by b;
+b c
+1 v1
+2 v2
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `b` int(11) DEFAULT NULL,
+ `c` char(5) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 12. ALTER. Adding a new virtual non-stored column.
+create table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+a b
+1 2008-09-04 00:00:00
+2 2008-09-05 00:00:00
+alter table t1 add column c int generated always as (dayofyear(b)) virtual after a;
+select * from t1 order by a;
+a c b
+1 248 2008-09-04 00:00:00
+2 249 2008-09-05 00:00:00
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (dayofyear(`b`)) VIRTUAL,
+ `b` datetime DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 13. ALTER. Adding a new virtual stored column.
+create table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+a b
+1 2008-09-04 00:00:00
+2 2008-09-05 00:00:00
+alter table t1 add column c int generated always as (dayofyear(b)) stored after a;
+select * from t1 order by a;
+a c b
+1 248 2008-09-04 00:00:00
+2 249 2008-09-05 00:00:00
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (dayofyear(`b`)) STORED,
+ `b` datetime DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 15. ALTER. Changing the expression of a virtual non-stored column.
+create table t1 (a int, b datetime, c int generated always as (week(b)) virtual);
+insert into t1 values (1,'2008-09-04',default);
+insert into t1 values (2,'2008-09-05',default);
+select * from t1 order by a;
+a b c
+1 2008-09-04 00:00:00 35
+2 2008-09-05 00:00:00 35
+alter table t1 change column c c int generated always as (week(b,1)) virtual;
+select * from t1 order by a;
+a b c
+1 2008-09-04 00:00:00 36
+2 2008-09-05 00:00:00 36
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` datetime DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (week(`b`,1)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_non_stored_columns_myisam.result b/mysql-test/suite/gcol/r/gcol_non_stored_columns_myisam.result
new file mode 100644
index 00000000..3e3b12f1
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_non_stored_columns_myisam.result
@@ -0,0 +1,237 @@
+SET @@session.default_storage_engine = 'MyISAM';
+# Case 1. All non-stored columns.
+create table t1 (a int generated always as (2+3) virtual);
+insert into t1 values (default);
+select * from t1;
+a
+5
+insert into t1 values (default);
+select * from t1;
+a
+5
+5
+drop table t1;
+# Case 2. CREATE
+# - Column1: "real"
+# - Column 2: virtual non-stored
+create table t1 (a int, b int generated always as (-a) virtual);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 -1
+insert into t1 values (2,default);
+select * from t1 order by a;
+a b
+1 -1
+2 -2
+drop table t1;
+# Case 3. CREATE
+# - Column1: "real"
+# - Column 2: virtual stored
+create table t1 (a int, b int generated always as (-a) stored);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 -1
+insert into t1 values (2,default);
+select * from t1 order by a;
+a b
+1 -1
+2 -2
+drop table t1;
+# Case 4. CREATE
+# - Column1: virtual non-stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) virtual, b int);
+insert into t1 values (default,1);
+select * from t1;
+a b
+-1 1
+insert into t1 values (default,2);
+select * from t1 order by a;
+a b
+-2 2
+-1 1
+drop table t1;
+# Case 5. CREATE
+# - Column1: virtual stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) stored, b int);
+insert into t1 values (default,1);
+select * from t1;
+a b
+-1 1
+insert into t1 values (default,2);
+select * from t1 order by a;
+a b
+-2 2
+-1 1
+drop table t1;
+# Case 6. CREATE
+# - Column1: "real"
+# - Column2: virtual non-stored
+# - Column3: virtual stored
+create table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+insert into t1 values (1,default,default);
+select * from t1;
+a b c
+1 -1 -1
+insert into t1 values (2,default,default);
+select * from t1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t1;
+# Case 7. ALTER. Modify virtual stored -> virtual non-stored
+create table t1 (a int, b int generated always as (a % 2) stored);
+alter table t1 modify b int generated always as (a % 2) virtual;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) STORED
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 8. ALTER. Modify virtual non-stored -> virtual stored
+create table t1 (a int, b int generated always as (a % 2) virtual);
+alter table t1 modify b int generated always as (a % 2) stored;
+ERROR HY000: This is not yet supported for generated columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 9. CREATE LIKE
+# - Column1: "real"
+# - Column2: virtual non-stored
+# - Column3: virtual stored
+create table t1 (a int, b int generated always as (-a), c int generated always as (-a) stored);
+create table t2 like t1;
+insert into t2 values (1,default,default);
+select * from t2;
+a b c
+1 -1 -1
+insert into t2 values (2,default,default);
+select * from t2 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+drop table t2;
+drop table t1;
+# Case 10. ALTER. Dropping a virtual non-stored column.
+# - Column1: virtual non-stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) virtual, b int, c varchar(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+a b c
+-1 1 v1
+-2 2 v2
+alter table t1 drop column a;
+select * from t1 order by b;
+b c
+1 v1
+2 v2
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `b` int(11) DEFAULT NULL,
+ `c` varchar(5) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 11. ALTER. Dropping a virtual stored column.
+# - Column1: virtual stored
+# - Column2: "real"
+create table t1 (a int generated always as (-b) stored, b int, c char(5));
+insert into t1 values (default,1,'v1');
+insert into t1 values (default,2,'v2');
+select * from t1 order by b;
+a b c
+-1 1 v1
+-2 2 v2
+alter table t1 drop column a;
+select * from t1 order by b;
+b c
+1 v1
+2 v2
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `b` int(11) DEFAULT NULL,
+ `c` char(5) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 12. ALTER. Adding a new virtual non-stored column.
+create table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+a b
+1 2008-09-04 00:00:00
+2 2008-09-05 00:00:00
+alter table t1 add column c int generated always as (dayofyear(b)) virtual after a;
+select * from t1 order by a;
+a c b
+1 248 2008-09-04 00:00:00
+2 249 2008-09-05 00:00:00
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (dayofyear(`b`)) VIRTUAL,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 13. ALTER. Adding a new virtual stored column.
+create table t1 (a int, b datetime);
+insert into t1 values (1,'2008-09-04');
+insert into t1 values (2,'2008-09-05');
+select * from t1 order by a;
+a b
+1 2008-09-04 00:00:00
+2 2008-09-05 00:00:00
+alter table t1 add column c int generated always as (dayofyear(b)) stored after a;
+select * from t1 order by a;
+a c b
+1 248 2008-09-04 00:00:00
+2 249 2008-09-05 00:00:00
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (dayofyear(`b`)) STORED,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+# Case 15. ALTER. Changing the expression of a virtual non-stored column.
+create table t1 (a int, b datetime, c int generated always as (week(b)) virtual);
+insert into t1 values (1,'2008-09-04',default);
+insert into t1 values (2,'2008-09-05',default);
+select * from t1 order by a;
+a b c
+1 2008-09-04 00:00:00 35
+2 2008-09-05 00:00:00 35
+alter table t1 change column c c int generated always as (week(b,1)) virtual;
+select * from t1 order by a;
+a b c
+1 2008-09-04 00:00:00 36
+2 2008-09-05 00:00:00 36
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` datetime DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (week(`b`,1)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+drop table t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_partition_innodb.result b/mysql-test/suite/gcol/r/gcol_partition_innodb.result
new file mode 100644
index 00000000..2bff3305
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_partition_innodb.result
@@ -0,0 +1,135 @@
+SET @@session.default_storage_engine = 'InnoDB';
+drop table if exists t1;
+# Case 1. Partitioning by RANGE based on a non-stored generated column.
+CREATE TABLE t1 (
+a DATE NOT NULL,
+b int generated always as (year(a)) virtual
+)
+PARTITION BY RANGE( b ) (
+PARTITION p0 VALUES LESS THAN (2006),
+PARTITION p2 VALUES LESS THAN (2008)
+);
+insert into t1 values ('2006-01-01',default);
+insert into t1 values ('2007-01-01',default);
+insert into t1 values ('2005-01-01',default);
+select * from t1;
+a b
+2005-01-01 2005
+2006-01-01 2006
+2007-01-01 2007
+# Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+select * from t1;
+a b
+2005-01-01 2004
+2006-01-01 2005
+2007-01-01 2006
+drop table t1;
+# Case 2. Partitioning by LIST based on a stored generated column.
+CREATE TABLE t1 (a int, b int generated always as (a % 3 ) stored)
+PARTITION BY LIST (a+1)
+(PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 1
+select * from t1;
+a b
+1 1
+drop table t1;
+# Case 3. Partitioning by HASH based on a non-stored generated column.
+CREATE TABLE t1 (
+a DATE NOT NULL,
+b int generated always as (year(a)) virtual
+)
+PARTITION BY HASH( b % 3 ) PARTITIONS 3;
+insert into t1 values ('2005-01-01',default);
+insert into t1 values ('2006-01-01',default);
+select * from t1;
+a b
+2005-01-01 2005
+2006-01-01 2006
+# Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+select * from t1;
+a b
+2005-01-01 2004
+2006-01-01 2005
+drop table t1;
+#
+# Bug#21779011 INVALID READS AND SENDING RANDOM SERVER MEMORY BACK
+# TO CLIENT
+#
+CREATE TABLE t (
+c INTEGER GENERATED ALWAYS AS (2) VIRTUAL,
+d INTEGER,
+KEY (d)
+) PARTITION BY KEY (d) PARTITIONS 2;
+INSERT INTO t (d) VALUES (1),(1),(2),(2);
+SELECT c FROM t WHERE d >= 1 GROUP BY d LIMIT 2;
+c
+2
+2
+DROP TABLE t;
+#
+# Bug#21779554: CHECK_MISPLACED_ROWS BOGUS "FOUND A MISPLACED ROW"
+# AND CRASHES
+#
+CREATE TABLE t(a INT,b INT GENERATED ALWAYS AS (1) VIRTUAL,c INT)
+PARTITION BY KEY (b)PARTITIONS 6;
+INSERT INTO t VALUES();
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+FLUSH TABLES;
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (
+a INT,
+b INT,
+c BIT(4) NOT NULL DEFAULT b'0',
+pk INTEGER AUTO_INCREMENT,
+d BIT(4) AS (c) VIRTUAL,
+PRIMARY KEY(pk),
+KEY (b,d)
+) PARTITION BY HASH(pk);
+INSERT INTO t1 () VALUES (),();
+UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
+DROP TABLE t1;
+#
+# MDEV-26220 Server crashes with indexed by prefix virtual column
+#
+CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
+KEY (c(10),a)) PARTITION BY HASH(pk);
+INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
+SELECT a FROM t1;
+a
+11
+10
+DROP TABLE t1;
+#
+# MDEV-16980 Wrongly set tablename len while opening the
+# table for purge thread
+#
+CREATE TABLE t1(pk SERIAL, d DATE, vd DATE AS (d) VIRTUAL,
+PRIMARY KEY(pk), KEY (vd))ENGINE=InnoDB
+PARTITION BY HASH(pk) PARTITIONS 2;
+INSERT IGNORE INTO t1 (d) VALUES ('2015-04-14');
+SET sql_mode= '';
+REPLACE INTO t1 SELECT * FROM t1;
+Warnings:
+Warning 1906 The value specified for generated column 'vd' in table 't1' has been ignored
+DROP TABLE t1;
+InnoDB 0 transactions not purged
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_partition_myisam.result b/mysql-test/suite/gcol/r/gcol_partition_myisam.result
new file mode 100644
index 00000000..e54b0ad8
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_partition_myisam.result
@@ -0,0 +1,121 @@
+SET @@session.default_storage_engine = 'MyISAM';
+drop table if exists t1;
+# Case 1. Partitioning by RANGE based on a non-stored generated column.
+CREATE TABLE t1 (
+a DATE NOT NULL,
+b int generated always as (year(a)) virtual
+)
+PARTITION BY RANGE( b ) (
+PARTITION p0 VALUES LESS THAN (2006),
+PARTITION p2 VALUES LESS THAN (2008)
+);
+insert into t1 values ('2006-01-01',default);
+insert into t1 values ('2007-01-01',default);
+insert into t1 values ('2005-01-01',default);
+select * from t1;
+a b
+2005-01-01 2005
+2006-01-01 2006
+2007-01-01 2007
+# Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+select * from t1;
+a b
+2005-01-01 2004
+2006-01-01 2005
+2007-01-01 2006
+drop table t1;
+# Case 2. Partitioning by LIST based on a stored generated column.
+CREATE TABLE t1 (a int, b int generated always as (a % 3 ) stored)
+PARTITION BY LIST (a+1)
+(PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2));
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 1
+select * from t1;
+a b
+1 1
+drop table t1;
+# Case 3. Partitioning by HASH based on a non-stored generated column.
+CREATE TABLE t1 (
+a DATE NOT NULL,
+b int generated always as (year(a)) virtual
+)
+PARTITION BY HASH( b % 3 ) PARTITIONS 3;
+insert into t1 values ('2005-01-01',default);
+insert into t1 values ('2006-01-01',default);
+select * from t1;
+a b
+2005-01-01 2005
+2006-01-01 2006
+# Modify the expression of generated column b
+ALTER TABLE t1 modify b int generated always as (year(a)-1) virtual;
+select * from t1;
+a b
+2005-01-01 2004
+2006-01-01 2005
+drop table t1;
+#
+# Bug#21779011 INVALID READS AND SENDING RANDOM SERVER MEMORY BACK
+# TO CLIENT
+#
+CREATE TABLE t (
+c INTEGER GENERATED ALWAYS AS (2) VIRTUAL,
+d INTEGER,
+KEY (d)
+) PARTITION BY KEY (d) PARTITIONS 2;
+INSERT INTO t (d) VALUES (1),(1),(2),(2);
+SELECT c FROM t WHERE d >= 1 GROUP BY d LIMIT 2;
+c
+2
+2
+DROP TABLE t;
+#
+# Bug#21779554: CHECK_MISPLACED_ROWS BOGUS "FOUND A MISPLACED ROW"
+# AND CRASHES
+#
+CREATE TABLE t(a INT,b INT GENERATED ALWAYS AS (1) VIRTUAL,c INT)
+PARTITION BY KEY (b)PARTITIONS 6;
+INSERT INTO t VALUES();
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+FLUSH TABLES;
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (
+a INT,
+b INT,
+c BIT(4) NOT NULL DEFAULT b'0',
+pk INTEGER AUTO_INCREMENT,
+d BIT(4) AS (c) VIRTUAL,
+PRIMARY KEY(pk),
+KEY (b,d)
+) PARTITION BY HASH(pk);
+INSERT INTO t1 () VALUES (),();
+UPDATE t1 SET a = 0 WHERE b IS NULL ORDER BY pk;
+DROP TABLE t1;
+#
+# MDEV-26220 Server crashes with indexed by prefix virtual column
+#
+CREATE TABLE t1 (pk INT PRIMARY KEY, a INT, b CHAR(20), c CHAR(20) AS (b),
+KEY (c(10),a)) PARTITION BY HASH(pk);
+INSERT INTO t1 (pk,a,b) VALUES (1,10,'foo'),(2,11,'baz');
+SELECT a FROM t1;
+a
+11
+10
+DROP TABLE t1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_purge.result b/mysql-test/suite/gcol/r/gcol_purge.result
new file mode 100644
index 00000000..e16cf0df
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_purge.result
@@ -0,0 +1,24 @@
+SET @save_dbug=@@GLOBAL.debug_dbug;
+CREATE TABLE t1(f1 INT NOT NULL, f2 int not null,
+f3 int generated always as (f2 * 2) VIRTUAL,
+primary key(f1), INDEX (f3))ENGINE=InnoDB;
+connect con1,localhost,root,,,;
+InnoDB 0 transactions not purged
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+INSERT INTO t1(f1, f2) VALUES(1,2);
+DELETE from t1 where f1 = 1;
+connect con2,localhost,root,,,;
+begin;
+INSERT INTO t1 (f1, f2) VALUES(1,2);
+set global debug_dbug="+d,ib_purge_virtual_index_callback";
+connection con1;
+COMMIT;
+SET GLOBAL innodb_max_purge_lag_wait=1;
+connection con2;
+commit;
+disconnect con1;
+disconnect con2;
+connection default;
+SET GLOBAL debug_dbug=@save_dbug;
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/r/gcol_rejected_innodb.result b/mysql-test/suite/gcol/r/gcol_rejected_innodb.result
new file mode 100644
index 00000000..b8d0db56
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_rejected_innodb.result
@@ -0,0 +1,8 @@
+SET @@session.default_storage_engine = 'InnoDB';
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_rollback.result b/mysql-test/suite/gcol/r/gcol_rollback.result
new file mode 100644
index 00000000..0bbf0341
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_rollback.result
@@ -0,0 +1,107 @@
+CREATE TABLE t (
+a INTEGER,
+b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+INDEX (b(57))
+)ENGINE=INNODB;
+INSERT INTO t (a) VALUES (9);
+BEGIN;
+SAVEPOINT a;
+UPDATE t set a = 12;
+DELETE FROM t where a = 12;
+ROLLBACK TO SAVEPOINT a;
+COMMIT;
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+SELECT * FROM t;
+a b
+9 9
+BEGIN;
+INSERT INTO t (a) VALUES (10);
+# restart
+SELECT * FROM t;
+a b
+9 9
+DROP TABLE t;
+CREATE TABLE t (
+a INTEGER,
+b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+c INTEGER
+)ENGINE=INNODB;
+INSERT INTO t (a,c) VALUES (9, 10);
+SELECT * FROM t;
+a b c
+9 9 10
+connect con1,localhost,root,,;
+connection con1;
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+ALTER TABLE t ADD KEY(b(57)), ALGORITHM=INPLACE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t (a,c) VALUES (10, 12);
+SELECT * FROM t;
+a b c
+9 9 10
+10 10 12
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+connection con1;
+disconnect con1;
+connection default;
+SELECT * FROM t;
+a b c
+9 9 10
+DROP TABLE t;
+CREATE TABLE t (
+a INT,
+b INT,
+c INT GENERATED ALWAYS AS(a+b),
+d INT GENERATED ALWAYS AS(a+b+b),
+KEY(c, d)
+)ENGINE=INNODB;
+INSERT INTO t (a,b) VALUES (9, 10);
+SELECT * FROM t;
+a b c d
+9 10 19 29
+connect con1,localhost,root,,;
+connection con1;
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t (a,b) VALUES (10, 12);
+SELECT * FROM t;
+a b c d
+9 10 19 29
+10 12 22 34
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+connection con1;
+connection default;
+SELECT * FROM t;
+a b d
+9 10 29
+DROP TABLE t;
+SET DEBUG_SYNC = 'RESET';
+#
+# MDEV-30597 Assertion `flag == 1' failed in
+# row_build_index_entry_low
+#
+CREATE TABLE t1 (
+col1 INT PRIMARY KEY, col_text TEXT,
+col_text_g TEXT GENERATED ALWAYS AS (SUBSTR(col_text,1,499))
+) ENGINE = InnoDB ROW_FORMAT = Compact;
+connection con1;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+INSERT INTO t1 (col1) VALUES (1) ;
+DELETE FROM t1 WHERE col1 = 1;
+ALTER TABLE t1 ADD UNIQUE INDEX (col_text_g(9));
+BEGIN;
+INSERT INTO t1 (col1) VALUES (1);
+ROLLBACK;
+disconnect con1;
+DROP TABLE t1;
+# End of 10.4 tests
diff --git a/mysql-test/suite/gcol/r/gcol_select_innodb.result b/mysql-test/suite/gcol/r/gcol_select_innodb.result
new file mode 100644
index 00000000..72d1e9f3
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_select_innodb.result
@@ -0,0 +1,981 @@
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
+SET @@session.default_storage_engine = 'InnoDB';
+SET optimizer_switch='derived_merge=off';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+index (c));
+insert into t1 (a) values (2), (1), (1), (3), (NULL);
+create table t2 like t1;
+insert into t2 (a) values (1);
+create table t3 (a int primary key,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t3 (a) values (2),(1),(3),(5),(4),(7);
+analyze table t1,t2,t3;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+test.t3 analyze status Engine-independent statistics collected
+test.t3 analyze status OK
+# select_type=SIMPLE, type=system
+select * from t2;
+a b c
+1 -1 -1
+explain select * from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ALL NULL NULL NULL NULL 1
+select * from t2 where c=-1;
+a b c
+1 -1 -1
+explain select * from t2 where c=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ref c c 5 const 1
+# select_type=SIMPLE, type=ALL
+select * from t1 where b=-1;
+a b c
+1 -1 -1
+1 -1 -1
+explain select * from t1 where b=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where
+# select_type=SIMPLE, type=const
+select * from t3 where a=1;
+a b c
+1 -1 -1
+explain select * from t3 where a=1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
+# select_type=SIMPLE, type=range
+select * from t3 where c>=-1;
+a b c
+1 -1 -1
+explain select * from t3 where c>=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 1 Using index condition
+# select_type=SIMPLE, type=ref
+select * from t1,t3 where t1.c=t3.c and t3.c=-1;
+a b c a b c
+1 -1 -1 1 -1 -1
+1 -1 -1 1 -1 -1
+explain select * from t1,t3 where t1.c=t3.c and t3.c=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 const c c 5 const 1
+1 SIMPLE t1 ref c c 5 const 2
+# select_type=PRIMARY, type=index,ALL
+select * from t1 where b in (select c from t3);
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+3 -3 -3
+explain select * from t1 where b in (select c from t3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t3 eq_ref c c 5 test.t1.b 1 Using index
+# select_type=PRIMARY, type=range,ref
+select * from t1 where c in (select c from t3 where c between -2 and -1);
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+explain select * from t1 where c in (select c from t3 where c between -2 and -1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 range c c 5 NULL 2 Using where; Using index
+1 PRIMARY t1 ref c c 5 test.t3.c 1
+# select_type=UNION, type=system
+# select_type=UNION RESULT, type=<union1,2>
+select * from t1 union select * from t2;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+NULL NULL NULL
+explain select * from t1 union select * from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5
+2 UNION t2 ALL NULL NULL NULL NULL 1
+NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
+# select_type=DERIVED, type=system
+select * from (select a,b,c from t1) as t11;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+3 -3 -3
+NULL NULL NULL
+explain select * from (select a,b,c from t1) as t11;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5
+2 DERIVED t1 ALL NULL NULL NULL NULL 5
+###
+### Using aggregate functions with/without DISTINCT
+###
+# SELECT COUNT(*) FROM tbl_name
+select count(*) from t1;
+count(*)
+5
+explain select count(*) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL c 5 NULL 5 Using index
+# SELECT COUNT(DISTINCT <non-gcol>) FROM tbl_name
+select count(distinct a) from t1;
+count(distinct a)
+3
+explain select count(distinct a) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5
+# SELECT COUNT(DISTINCT <non-stored gcol>) FROM tbl_name
+select count(distinct b) from t1;
+count(distinct b)
+3
+explain select count(distinct b) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5
+# SELECT COUNT(DISTINCT <stored gcol>) FROM tbl_name
+select count(distinct c) from t1;
+count(distinct c)
+3
+explain select count(distinct c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range NULL c 5 NULL 6 Using index for group-by
+###
+### filesort & range-based utils
+###
+# SELECT * FROM tbl_name WHERE <gcol expr>
+select * from t3 where c >= -2;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where c >= -2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# SELECT * FROM tbl_name WHERE <non-gcol expr>
+select * from t3 where a between 1 and 2;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where a between 1 and 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr>
+select * from t3 where b between -2 and -1;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where b between -2 and -1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where
+# SELECT * FROM tbl_name WHERE <indexed gcol expr>
+select * from t3 where c between -2 and -1;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where c between -2 and -1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed gcol>
+select * from t3 where a between 1 and 2 order by b;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where a between 1 and 2 order by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort
+# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC
+# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <non-indexed stored gcol>
+select * from t3 where a between 1 and 2 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where a between 1 and 2 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort
+# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC
+CREATE TABLE t4 (
+`pk` int(11) NOT NULL ,
+`col_int_nokey` int(11) GENERATED ALWAYS AS (pk + col_int_key) STORED,
+`col_int_key` int(11) DEFAULT NULL,
+`col_date_nokey` date DEFAULT NULL,
+`col_datetime_key` datetime DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `col_int_key` (`col_int_key`),
+KEY `col_datetime_key` (`col_datetime_key`)
+);
+INSERT INTO t4 VALUES
+(1,default,4,'2008-12-05','1900-01-01 00:00:00');
+SELECT
+SQL_BIG_RESULT
+GRANDPARENT1 . `col_int_nokey` AS g1
+FROM t4 AS GRANDPARENT1 LEFT JOIN t4 AS GRANDPARENT2 ON ( GRANDPARENT2 .
+`col_datetime_key` <= GRANDPARENT1 . `col_date_nokey` )
+GROUP BY GRANDPARENT1 . `pk`;
+g1
+5
+DROP TABLE t4;
+# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <indexed gcol>
+select * from t3 where a between 1 and 2 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where a between 1 and 2 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-gcol>
+select * from t3 where b between -2 and -1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where b between -2 and -1 order by a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 index NULL PRIMARY 4 NULL 6 Using where
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-indexed gcol>
+select * from t3 where b between -2 and -1 order by b;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where b between -2 and -1 order by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-indexed gcol>
+select * from t3 where c between -2 and -1 order by b;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where c between -2 and -1 order by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition; Using filesort
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <indexed gcol>
+select * from t3 where b between -2 and -1 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where b between -2 and -1 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <indexed gcol>
+select * from t3 where c between -2 and -1 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where c between -2 and -1 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+select sum(b) from t1 group by b;
+sum(b)
+NULL
+-3
+-2
+-2
+explain select sum(b) from t1 group by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+select sum(c) from t1 group by c;
+sum(c)
+NULL
+-3
+-2
+-2
+explain select sum(c) from t1 group by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL c 5 NULL 5 Using index
+# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+select sum(b) from t1 group by c;
+sum(b)
+NULL
+-3
+-2
+-2
+explain select sum(b) from t1 group by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL c 5 NULL 5
+# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+select sum(c) from t1 group by b;
+sum(c)
+NULL
+-3
+-2
+-2
+explain select sum(c) from t1 group by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+drop table t1;
+#
+# Bug#20241655: WL411:FAILING ASSERTION ASSERTION
+#
+CREATE TABLE BB (
+col_time_key time NOT NULL,
+col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+col_datetime_key datetime NOT NULL);
+INSERT INTO BB VALUES('23:28:02', default, '2005-03-15 22:48:25');
+Warnings:
+Note 1265 Data truncated for column 'col_time_nokey' at row 1
+CREATE TABLE CC (
+col_time_key time NOT NULL,
+col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+col_datetime_key datetime NOT NULL
+);
+INSERT INTO CC VALUES('16:22:51', default, '1900-01-01 00:00:00');
+Warnings:
+Note 1265 Data truncated for column 'col_time_nokey' at row 1
+SELECT 1 AS g1 FROM BB AS gp1 LEFT JOIN BB AS gp2 USING ( col_time_nokey);
+g1
+1
+DROP TABLE BB, CC;
+#
+# Bug#20328786: WL411:VALGRIND WARNINGS OF CONDITIONAL
+# JUMP WHILE SELECTING FROM VIEW
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+PRIMARY KEY (pk)
+);
+CREATE TABLE C (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key, col_int_key)
+);
+INSERT INTO C (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (4, 'v'),(62, 'v'),(7, 'c'),(1, NULL),(0, 'x'),(7, 'i'),(7, 'e'),(1, 'p'),(7, 's'),(1, 'j'),(5, 'z'),(2, 'c'),(0, 'a'),(1, 'q'),(8, 'y'),(1, NULL),(1, 'r'),(9, 'v'),(1, NULL),(5, 'r');
+CREATE OR REPLACE ALGORITHM=MERGE VIEW V1 AS SELECT alias1.
+col_varchar_key AS field1 , alias1.pk AS field2, alias2.
+col_int_nokey AS field3 FROM C AS alias1 LEFT JOIN A AS alias2 ON
+alias1.pk = alias2.col_int_key WHERE alias1.pk > 8 AND alias1
+.pk < ( 9 + 2 ) AND alias1.col_int_key <> 1 OR alias1.col_int_key
+> 0 AND alias1.col_int_key <= ( 3 + 2 ) ORDER BY field1, field2, field3
+LIMIT 100 OFFSET 6;
+Warnings:
+Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm)
+SELECT * FROM V1;
+field1 field2 field3
+qq 14 NULL
+rr 17 NULL
+ss 9 NULL
+xx 5 NULL
+DROP VIEW V1;
+DROP TABLE A,C;
+#
+# Bug#20406510: WL411:VALGRIND WARNINGS WITH
+# COUNT DISTINCT QUERY ON VIRTUAL GC VARCHAR COLUMN
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_time_key TIME NOT NULL,
+col_datetime_key DATETIME NOT NULL,
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_datetime_key)
+);
+CREATE TABLE C (
+pk INTEGER AUTO_INCREMENT,
+col_int_key INTEGER NOT NULL,
+col_varchar_key VARCHAR(1) NOT NULL,
+col_varchar_nokey VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_key, col_varchar_key)),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key, col_int_key)
+);
+INSERT INTO C (col_int_key,col_varchar_key) VALUES (0, 'j'),(8, 'v'),(1, 'c'),(8, 'm'),(9, 'd');
+SELECT MIN( alias2 . col_int_key ) AS field1,
+COUNT( DISTINCT alias2 . col_varchar_nokey ) AS field2
+FROM ( A AS alias1 , C AS alias2 )
+ORDER BY alias1.col_time_key, alias1.col_datetime_key, alias1.pk ASC;
+field1 field2
+NULL 0
+DROP TABLE A,C;
+#
+# Bug#20566325: WL8149: INNODB: FAILING ASSERTION:
+# COL_NR < TABLE->N_DEF
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT /*! IGNORE */ INTO A (col_varchar_nokey) VALUES ('k');
+CREATE TABLE CC (
+pk INTEGER AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk));
+INSERT INTO CC (col_time_nokey,col_datetime_nokey,col_varchar_nokey) VALUES
+('13:06:13.033877','1900-01-01 00:00:00', 'p'),
+(NULL, '2007-05-25 11:58:54.015689', 'g');
+SELECT
+table1.col_time_key AS field1,
+'z' AS field2
+FROM
+(CC AS table1 LEFT OUTER JOIN (A AS table2 STRAIGHT_JOIN CC AS table3 ON
+(table3.col_varchar_key = table2.col_varchar_nokey)) ON
+(table3.col_varchar_key = table2.col_varchar_nokey))
+WHERE
+table2.pk != 6
+AND table1.col_varchar_key IN ('l', 's' , 'b' )
+AND table3.col_varchar_key != table1.col_varchar_key
+ORDER BY table1.col_varchar_key , field1 , field2;
+field1 field2
+DROP TABLE A,CC;
+CREATE TABLE cc (
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_nokey int(11) NOT NULL,
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) STORED,
+col_date_nokey date NOT NULL,
+col_date_key date GENERATED ALWAYS AS (col_date_nokey) STORED,
+col_datetime_nokey datetime NOT NULL,
+col_time_nokey time NOT NULL,
+col_datetime_key datetime GENERATED ALWAYS AS (col_datetime_nokey)STORED,
+col_time_key time GENERATED ALWAYS AS (col_time_nokey) STORED,
+col_varchar_nokey varchar(1) NOT NULL,
+col_varchar_key varchar(1) GENERATED ALWAYS AS (col_varchar_nokey)STORED,
+PRIMARY KEY (pk),
+KEY gc_idx1 (col_int_key),
+KEY gc_idx2 (col_varchar_key),
+KEY gc_idx3 (col_date_key),
+KEY gc_idx4 (col_time_key),
+KEY gc_idx5 (col_datetime_key),
+KEY gc_idx6 (col_varchar_key,col_int_key),
+KEY gc_idx7 (col_date_key,col_datetime_key,col_time_key),
+KEY gc_idx8(col_int_key,col_varchar_key,col_date_key,col_time_key,
+col_datetime_key)
+);
+INSERT INTO cc (
+col_int_nokey,
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES (1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't');
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+SELECT DISTINCT alias1.col_varchar_key AS field1
+FROM ( cc AS alias1 STRAIGHT_JOIN
+(( cc AS alias2 STRAIGHT_JOIN cc AS alias3 ON
+(alias3.col_varchar_key > alias2.col_varchar_key ) ) ) ON
+(( alias3 .pk >= alias2.col_int_nokey ) AND
+(alias3 .pk >= alias2.col_int_nokey ) ))
+WHERE alias1.col_varchar_key <= 'v'
+GROUP BY field1 HAVING field1 = 91
+ORDER BY field1, alias1.col_date_key, field1 ASC, field1 DESC,
+alias1.col_time_key ASC, field1;
+field1
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'c'
+Warning 1292 Truncated incorrect DECIMAL value: 't'
+Warning 1292 Truncated incorrect DECIMAL value: 'm'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
+DROP TABLE cc;
+SET sql_mode=@save_old_sql_mode;
+#
+# Bug#20797941: WL8149:ASSERTION !TABLE ||
+# (!TABLE->READ_SET || BITMAP_IS_SET(TABLE->READ_SET
+#
+CREATE TABLE t(a int, b int as(a+1));
+INSERT INTO t(a) values(1),(2);
+SELECT * FROM t ORDER BY b;
+a b
+1 2
+2 3
+DROP TABLE t;
+DROP TABLE t2, t3;
+#
+# Bug#21317507:GC: STORED COLUMN REJECTED, BUT VIRTUAL IS ACCEPTED
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN b;
+ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN c;
+ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL;
+ALTER TABLE t1 DROP COLUMN d;
+ALTER TABLE t1 ADD COLUMN c INT AS(a) VIRTUAL;
+ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL;
+ERROR 22003: Out of range value for column 'c' at row 1
+ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL;
+ERROR 22003: Out of range value for column 'c' at row 1
+SELECT * FROM t1;
+a c
+2147483647 2147483647
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN h INT AS (a) VIRTUAL;
+ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, ALGORITHM=COPY;
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
+ALTER TABLE t1 ADD COLUMN e SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
+ALTER TABLE t1 ADD COLUMN f SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED;
+ERROR 22003: Out of range value for column 'f' at row 1
+ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=EXCLUSIVE;
+ERROR 22003: Out of range value for column 'g' at row 1
+DROP TABLE t1;
+#
+# Bug#21980430 GCOLS: CRASHING
+#
+CREATE TABLE t (
+a INT,
+b BLOB,
+c BLOB GENERATED ALWAYS AS (a+b) VIRTUAL,
+UNIQUE KEY i0008 (a)
+);
+INSERT INTO t(a,b) VALUES(1,'cccc');
+EXPLAIN SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
+WHERE b.b>c.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE b ALL i0008 NULL NULL NULL 1
+1 SIMPLE c ALL i0008 NULL NULL NULL 1 Range checked for each record (index map: 0x1)
+SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
+WHERE b.b>c.a;
+c
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'cccc'
+DROP TABLE t;
+set @optimizer_switch_save = @@optimizer_switch;
+set optimizer_switch='mrr_cost_based=off';
+set @read_rnd_buffer_size_save= @@read_rnd_buffer_size;
+set read_rnd_buffer_size=32;
+CREATE TABLE t0 (
+i1 INTEGER NOT NULL
+);
+INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+CREATE TABLE t1 (
+pk INTEGER NOT NULL,
+i1 INTEGER NOT NULL,
+i2 INTEGER NOT NULL,
+v1 INTEGER GENERATED ALWAYS AS (i2 + 1) VIRTUAL,
+v2 INTEGER GENERATED ALWAYS AS (i1 / (i1 - i2 + 57)) VIRTUAL,
+PRIMARY KEY (pk),
+INDEX idx(i1)
+);
+INSERT INTO t1 (pk, i1, i2)
+SELECT a0.i1 + a1.i1*10 + a2.i1*100,
+a0.i1 + a1.i1*10,
+a0.i1 + a1.i1*10
+FROM t0 AS a0, t0 AS a1, t0 AS a2;
+EXPLAIN SELECT * FROM t1
+WHERE i1 > 41 AND i1 <= 43;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range idx idx 4 NULL 20 Using index condition
+SELECT * FROM t1
+WHERE i1 > 41 AND i1 <= 43;
+pk i1 i2 v1 v2
+142 42 42 43 1
+143 43 43 44 1
+242 42 42 43 1
+243 43 43 44 1
+342 42 42 43 1
+343 43 43 44 1
+42 42 42 43 1
+43 43 43 44 1
+442 42 42 43 1
+443 43 43 44 1
+542 42 42 43 1
+543 43 43 44 1
+642 42 42 43 1
+643 43 43 44 1
+742 42 42 43 1
+743 43 43 44 1
+842 42 42 43 1
+843 43 43 44 1
+942 42 42 43 1
+943 43 43 44 1
+EXPLAIN SELECT * FROM t1
+WHERE v1 > 41 AND v1 <= 43;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where
+SELECT * FROM t1
+WHERE v1 > 41 AND v1 <= 43;
+pk i1 i2 v1 v2
+141 41 41 42 1
+142 42 42 43 1
+241 41 41 42 1
+242 42 42 43 1
+341 41 41 42 1
+342 42 42 43 1
+41 41 41 42 1
+42 42 42 43 1
+441 41 41 42 1
+442 42 42 43 1
+541 41 41 42 1
+542 42 42 43 1
+641 41 41 42 1
+642 42 42 43 1
+741 41 41 42 1
+742 42 42 43 1
+841 41 41 42 1
+842 42 42 43 1
+941 41 41 42 1
+942 42 42 43 1
+DROP TABLE t0, t1;
+set optimizer_switch= @optimizer_switch_save;
+set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
+#
+# Bug#21872184 CONDITIONAL JUMP AT JOIN_CACHE::WRITE_RECORD_DATA IN
+# SQL_JOIN_BUFFER.CC
+#
+#
+# Test 1: Dynamic range scan with one covering index
+#
+CREATE TABLE t1 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t1
+VALUES (10, 'c'), (10, 'i'), (2, 't'), (4, 'g');
+CREATE TABLE t2 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t2
+VALUES (2, 'k'), (9, 'k'), (7, 'o'), (5, 'n'), (7, 'e');
+CREATE TABLE t3 (
+pk INTEGER NOT NULL,
+i1 INTEGER,
+i2_key INTEGER GENERATED ALWAYS AS (i1 + i1) VIRTUAL,
+PRIMARY KEY (pk)
+);
+INSERT INTO t3 (pk, i1)
+VALUES (1, 1), (2, 48), (3, 228), (4, 3), (5, 5),
+(6, 39), (7, 6), (8, 8), (9, 3);
+CREATE TABLE t4 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t4
+VALUES (1, 'j'), (2, 'c'), (0, 'a');
+ANALYZE TABLE t1, t2, t3, t4;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+test.t3 analyze status Engine-independent statistics collected
+test.t3 analyze status OK
+test.t4 analyze status Engine-independent statistics collected
+test.t4 analyze status OK
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 2: Two alternative covering indexes for the range scan
+#
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 3: One covering index including the base column for the virtual
+# column
+#
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 4: One non-covering index
+#
+# Add more data to the table so that it will run the dynamic range scan
+# as both table scan and range scan (the purpose of this is to make the
+# table scan more expensive).
+INSERT INTO t3 (pk, i1)
+VALUES (10,1), (11,1), (12,1), (13,1), (14,1),(15,1), (16,1),(17,1), (18,1),
+(19,1), (20,1), (21,1), (22,1), (23,1), (24,1),(25,1),(26,1),(27,1),
+(28,1), (29,1);
+# Change the query to read an extra column (t3.i1) making the index
+# non-covering.
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1 i1
+c 2 48
+c 5 48
+c 7 48
+c 7 48
+c 9 48
+g 2 48
+g 5 48
+g 7 48
+g 7 48
+g 9 48
+i 2 48
+i 5 48
+i 7 48
+i 7 48
+i 9 48
+t 2 1
+t 2 48
+t 5 1
+t 5 48
+t 7 1
+t 7 1
+t 7 48
+t 7 48
+t 9 1
+t 9 48
+#
+# Test 5: Test where the added primary key to secondary indexes is
+# used after it has been included in the join buffer
+#
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1)
+)
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using where; Start temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
+1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where; End temporary; Using join buffer (flat, BNL join)
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1)
+)
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+DROP TABLE t1, t2, t3, t4;
+SET optimizer_switch='derived_merge=default';
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_select_myisam.result b/mysql-test/suite/gcol/r/gcol_select_myisam.result
new file mode 100644
index 00000000..0d18976f
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_select_myisam.result
@@ -0,0 +1,1613 @@
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
+SET @@session.default_storage_engine = 'MyISAM';
+SET optimizer_switch='derived_merge=off';
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+index (c));
+insert into t1 (a) values (2), (1), (1), (3), (NULL);
+create table t2 like t1;
+insert into t2 (a) values (1);
+create table t3 (a int primary key,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored unique);
+insert into t3 (a) values (2),(1),(3),(5),(4),(7);
+analyze table t1,t2,t3;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+test.t3 analyze status Engine-independent statistics collected
+test.t3 analyze status OK
+# select_type=SIMPLE, type=system
+select * from t2;
+a b c
+1 -1 -1
+explain select * from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 system NULL NULL NULL NULL 1
+select * from t2 where c=-1;
+a b c
+1 -1 -1
+explain select * from t2 where c=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 system c NULL NULL NULL 1
+# select_type=SIMPLE, type=ALL
+select * from t1 where b=-1;
+a b c
+1 -1 -1
+1 -1 -1
+explain select * from t1 where b=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where
+# select_type=SIMPLE, type=const
+select * from t3 where a=1;
+a b c
+1 -1 -1
+explain select * from t3 where a=1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 const PRIMARY PRIMARY 4 const 1
+# select_type=SIMPLE, type=range
+select * from t3 where c>=-1;
+a b c
+1 -1 -1
+explain select * from t3 where c>=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 1 Using index condition
+# select_type=SIMPLE, type=ref
+select * from t1,t3 where t1.c=t3.c and t3.c=-1;
+a b c a b c
+1 -1 -1 1 -1 -1
+1 -1 -1 1 -1 -1
+explain select * from t1,t3 where t1.c=t3.c and t3.c=-1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 const c c 5 const 1
+1 SIMPLE t1 ref c c 5 const 2
+# select_type=PRIMARY, type=index,ALL
+select * from t1 where b in (select c from t3);
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+3 -3 -3
+explain select * from t1 where b in (select c from t3);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where
+1 PRIMARY t3 eq_ref c c 5 test.t1.b 1 Using index
+# select_type=PRIMARY, type=range,ref
+select * from t1 where c in (select c from t3 where c between -2 and -1);
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+explain select * from t1 where c in (select c from t3 where c between -2 and -1);
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t3 range c c 5 NULL 2 Using where; Using index
+1 PRIMARY t1 ref c c 5 test.t3.c 1
+# select_type=UNION, type=system
+# select_type=UNION RESULT, type=<union1,2>
+select * from t1 union select * from t2;
+a b c
+1 -1 -1
+2 -2 -2
+3 -3 -3
+NULL NULL NULL
+explain select * from t1 union select * from t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5
+2 UNION t2 system NULL NULL NULL NULL 1
+NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
+# select_type=DERIVED, type=system
+select * from (select a,b,c from t1) as t11;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+3 -3 -3
+NULL NULL NULL
+explain select * from (select a,b,c from t1) as t11;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL 5
+2 DERIVED t1 ALL NULL NULL NULL NULL 5
+###
+### Using aggregate functions with/without DISTINCT
+###
+# SELECT COUNT(*) FROM tbl_name
+select count(*) from t1;
+count(*)
+5
+explain select count(*) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+# SELECT COUNT(DISTINCT <non-gcol>) FROM tbl_name
+select count(distinct a) from t1;
+count(distinct a)
+3
+explain select count(distinct a) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5
+# SELECT COUNT(DISTINCT <non-stored gcol>) FROM tbl_name
+select count(distinct b) from t1;
+count(distinct b)
+3
+explain select count(distinct b) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5
+# SELECT COUNT(DISTINCT <stored gcol>) FROM tbl_name
+select count(distinct c) from t1;
+count(distinct c)
+3
+explain select count(distinct c) from t1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range NULL c 5 NULL 6 Using index for group-by
+###
+### filesort & range-based utils
+###
+# SELECT * FROM tbl_name WHERE <gcol expr>
+select * from t3 where c >= -2;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where c >= -2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# SELECT * FROM tbl_name WHERE <non-gcol expr>
+select * from t3 where a between 1 and 2;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where a between 1 and 2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using index condition
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr>
+select * from t3 where b between -2 and -1;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where b between -2 and -1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where
+# SELECT * FROM tbl_name WHERE <indexed gcol expr>
+select * from t3 where c between -2 and -1;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where c between -2 and -1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# bug#20022189: WL411:DEBUG ASSERT AT FIELD_LONG::VAL_INT IN SQL/FIELD.CC
+CREATE TABLE t4 (
+`pk` int(11) NOT NULL ,
+`col_int_nokey` int(11) GENERATED ALWAYS AS (pk + col_int_key) STORED,
+`col_int_key` int(11) DEFAULT NULL,
+`col_date_nokey` date DEFAULT NULL,
+`col_datetime_key` datetime DEFAULT NULL,
+PRIMARY KEY (`pk`),
+KEY `col_int_key` (`col_int_key`),
+KEY `col_datetime_key` (`col_datetime_key`)
+);
+INSERT INTO t4 VALUES
+(1,default,4,'2008-12-05','1900-01-01 00:00:00');
+SELECT
+SQL_BIG_RESULT
+GRANDPARENT1 . `col_int_nokey` AS g1
+FROM t4 AS GRANDPARENT1 LEFT JOIN t4 AS GRANDPARENT2 ON ( GRANDPARENT2 .
+`col_datetime_key` <= GRANDPARENT1 . `col_date_nokey` )
+GROUP BY GRANDPARENT1 . `pk`;
+g1
+5
+DROP TABLE t4;
+# SELECT * FROM tbl_name WHERE <non-gcol expr> ORDER BY <indexed gcol>
+select * from t3 where a between 1 and 2 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where a between 1 and 2 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using filesort
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-gcol>
+select * from t3 where b between -2 and -1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where b between -2 and -1 order by a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-gcol>
+select * from t3 where c between -2 and -1 order by a;
+a b c
+1 -1 -1
+2 -2 -2
+explain select * from t3 where c between -2 and -1 order by a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition; Using filesort
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <non-indexed gcol>
+select * from t3 where b between -2 and -1 order by b;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where b between -2 and -1 order by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <non-indexed gcol>
+select * from t3 where c between -2 and -1 order by b;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where c between -2 and -1 order by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition; Using filesort
+# SELECT * FROM tbl_name WHERE <non-indexed gcol expr> ORDER BY <indexed gcol>
+select * from t3 where b between -2 and -1 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where b between -2 and -1 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where; Using filesort
+# SELECT * FROM tbl_name WHERE <indexed gcol expr> ORDER BY <indexed gcol>
+select * from t3 where c between -2 and -1 order by c;
+a b c
+2 -2 -2
+1 -1 -1
+explain select * from t3 where c between -2 and -1 order by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t3 range c c 5 NULL 2 Using index condition
+# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+select sum(b) from t1 group by b;
+sum(b)
+NULL
+-3
+-2
+-2
+explain select sum(b) from t1 group by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+select sum(c) from t1 group by c;
+sum(c)
+NULL
+-3
+-2
+-2
+explain select sum(c) from t1 group by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL c 5 NULL 5 Using index
+# SELECT sum(<non-indexed gcol>) FROM tbl_name GROUP BY <indexed gcol>
+select sum(b) from t1 group by c;
+sum(b)
+NULL
+-3
+-2
+-2
+explain select sum(b) from t1 group by c;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+# SELECT sum(<indexed gcol>) FROM tbl_name GROUP BY <non-indexed gcol>
+select sum(c) from t1 group by b;
+sum(c)
+NULL
+-3
+-2
+-2
+explain select sum(c) from t1 group by b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using temporary; Using filesort
+drop table t1;
+#
+# Bug#20241655: WL411:FAILING ASSERTION ASSERTION
+#
+CREATE TABLE BB (
+col_time_key time NOT NULL,
+col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+col_datetime_key datetime NOT NULL);
+INSERT INTO BB VALUES('23:28:02', default, '2005-03-15 22:48:25');
+Warnings:
+Note 1265 Data truncated for column 'col_time_nokey' at row 1
+CREATE TABLE CC (
+col_time_key time NOT NULL,
+col_time_nokey time GENERATED ALWAYS AS (ADDTIME(col_datetime_key, col_time_key)) VIRTUAL,
+col_datetime_key datetime NOT NULL
+);
+INSERT INTO CC VALUES('16:22:51', default, '1900-01-01 00:00:00');
+Warnings:
+Note 1265 Data truncated for column 'col_time_nokey' at row 1
+SELECT 1 AS g1 FROM BB AS gp1 LEFT JOIN BB AS gp2 USING ( col_time_nokey);
+g1
+1
+DROP TABLE BB, CC;
+#
+# Bug#20328786: WL411:VALGRIND WARNINGS OF CONDITIONAL
+# JUMP WHILE SELECTING FROM VIEW
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+PRIMARY KEY (pk)
+);
+CREATE TABLE C (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS (2 + 2 + col_int_nokey) STORED,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) STORED,
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key, col_int_key)
+);
+INSERT INTO C (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (4, 'v'),(62, 'v'),(7, 'c'),(1, NULL),(0, 'x'),(7, 'i'),(7, 'e'),(1, 'p'),(7, 's'),(1, 'j'),(5, 'z'),(2, 'c'),(0, 'a'),(1, 'q'),(8, 'y'),(1, NULL),(1, 'r'),(9, 'v'),(1, NULL),(5, 'r');
+CREATE OR REPLACE ALGORITHM=MERGE VIEW V1 AS SELECT alias1.
+col_varchar_key AS field1 , alias1.pk AS field2, alias2.
+col_int_nokey AS field3 FROM C AS alias1 LEFT JOIN A AS alias2 ON
+alias1.pk = alias2.col_int_key WHERE alias1.pk > 8 AND alias1
+.pk < ( 9 + 2 ) AND alias1.col_int_key <> 1 OR alias1.col_int_key
+> 0 AND alias1.col_int_key <= ( 3 + 2 ) ORDER BY field1, field2, field3
+LIMIT 100 OFFSET 6;
+Warnings:
+Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm)
+SELECT * FROM V1;
+field1 field2 field3
+qq 14 NULL
+rr 17 NULL
+ss 9 NULL
+xx 5 NULL
+DROP VIEW V1;
+DROP TABLE A,C;
+#
+# Bug#20406510: WL411:VALGRIND WARNINGS WITH
+# COUNT DISTINCT QUERY ON VIRTUAL GC VARCHAR COLUMN
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_time_key TIME NOT NULL,
+col_datetime_key DATETIME NOT NULL,
+PRIMARY KEY (pk),
+KEY (col_time_key),
+KEY (col_datetime_key)
+);
+CREATE TABLE C (
+pk INTEGER AUTO_INCREMENT,
+col_int_key INTEGER NOT NULL,
+col_varchar_key VARCHAR(1) NOT NULL,
+col_varchar_nokey VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_key, col_varchar_key)),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key, col_int_key)
+);
+INSERT INTO C (col_int_key,col_varchar_key) VALUES (0, 'j'),(8, 'v'),(1, 'c'),(8, 'm'),(9, 'd');
+SELECT MIN( alias2 . col_int_key ) AS field1,
+COUNT( DISTINCT alias2 . col_varchar_nokey ) AS field2
+FROM ( A AS alias1 , C AS alias2 )
+ORDER BY alias1.col_time_key, alias1.col_datetime_key, alias1.pk ASC;
+field1 field2
+NULL 0
+DROP TABLE A,C;
+#
+# Bug#20566325: WL8149: INNODB: FAILING ASSERTION:
+# COL_NR < TABLE->N_DEF
+#
+CREATE TABLE A (
+pk INTEGER AUTO_INCREMENT,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk)
+);
+INSERT /*! IGNORE */ INTO A (col_varchar_nokey) VALUES ('k');
+CREATE TABLE CC (
+pk INTEGER AUTO_INCREMENT,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk));
+INSERT INTO CC (col_time_nokey,col_datetime_nokey,col_varchar_nokey) VALUES
+('13:06:13.033877','1900-01-01 00:00:00', 'p'),
+(NULL, '2007-05-25 11:58:54.015689', 'g');
+SELECT
+table1.col_time_key AS field1,
+'z' AS field2
+FROM
+(CC AS table1 LEFT OUTER JOIN (A AS table2 STRAIGHT_JOIN CC AS table3 ON
+(table3.col_varchar_key = table2.col_varchar_nokey)) ON
+(table3.col_varchar_key = table2.col_varchar_nokey))
+WHERE
+table2.pk != 6
+AND table1.col_varchar_key IN ('l', 's' , 'b' )
+AND table3.col_varchar_key != table1.col_varchar_key
+ORDER BY table1.col_varchar_key , field1 , field2;
+field1 field2
+DROP TABLE A,CC;
+#
+# Bug#20573302: WL8149: SEGV IN HA_INNOBASE::
+# BUILD_TEMPLATE AT INNOBASE/HANDLER/HA_INNODB.CC:665
+#
+CREATE TABLE c (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+col_date_nokey DATE NOT NULL,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key),
+KEY (col_date_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+KEY (col_int_key, col_varchar_key),
+KEY (col_int_key, col_varchar_key, col_date_key,
+col_time_key, col_datetime_key));
+INSERT /*! IGNORE */ INTO c (
+col_int_nokey,
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES
+(1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't'),
+(6, '2007-06-18', NULL, '2002-08-20 22:48:00.035785', 'd'),
+(2, '2002-10-13', '00:00:00', '1900-01-01 00:00:00', 's'),
+(4, '1900-01-01', '15:57:25.019666', '2005-08-15 00:00:00', 'r'),
+(8, NULL, '07:05:51.006712', '1900-01-01 00:00:00', 'm'),
+(4, '2006-03-09', '19:22:21.057406', '2008-05-16 08:09:06.002924', 'b'),
+(4, '2001-06-05', '03:53:16.001370', '2001-01-20 12:47:23.022022', 'x'),
+(7, '2006-05-28', '09:16:38.034570', '2008-07-02 00:00:00', 'g'),
+(4, '2001-04-19', '15:37:26.028315', '1900-01-01 00:00:00', 'p'),
+(1, '1900-01-01', '00:00:00', '2002-12-08 11:34:58.001571', 'q'),
+(9, '2004-08-20', '05:03:03.047452', '1900-01-01 00:00:00', 'w'),
+(4, '2004-10-10', '02:59:24.063764', '1900-01-01 00:00:00', 'd'),
+(8, '2000-04-02', '00:01:58.064243', '2002-08-25 20:35:06.064634', 'e'),
+(4, '2006-11-02', '00:00:00', '2001-10-22 11:13:24.048128', 'b'),
+(8, '2009-01-28', '02:20:16.024931', '2003-03-12 02:00:34.029335', 'y');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+Note 1265 Data truncated for column 'col_time_key' at row 3
+Note 1265 Data truncated for column 'col_time_key' at row 4
+Note 1265 Data truncated for column 'col_time_key' at row 5
+Note 1265 Data truncated for column 'col_time_key' at row 6
+Warning 1048 Column 'col_time_nokey' cannot be null
+Note 1265 Data truncated for column 'col_time_key' at row 7
+Note 1265 Data truncated for column 'col_time_key' at row 8
+Note 1265 Data truncated for column 'col_time_key' at row 9
+Warning 1048 Column 'col_date_nokey' cannot be null
+Warning 1292 Incorrect datetime value: '0000-00-00'
+Note 1265 Data truncated for column 'col_time_key' at row 10
+Note 1265 Data truncated for column 'col_time_key' at row 11
+Note 1265 Data truncated for column 'col_time_key' at row 12
+Note 1265 Data truncated for column 'col_time_key' at row 13
+Note 1265 Data truncated for column 'col_time_key' at row 14
+Note 1265 Data truncated for column 'col_time_key' at row 15
+Note 1265 Data truncated for column 'col_time_key' at row 16
+Note 1265 Data truncated for column 'col_time_key' at row 17
+Note 1265 Data truncated for column 'col_time_key' at row 18
+Note 1265 Data truncated for column 'col_time_key' at row 19
+Note 1265 Data truncated for column 'col_time_key' at row 20
+CREATE TABLE cc (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey) VIRTUAL,
+col_date_nokey DATE NOT NULL,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key),
+KEY (col_date_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+KEY (col_int_key, col_varchar_key),
+KEY (col_int_key, col_varchar_key, col_date_key,
+col_time_key, col_datetime_key));
+INSERT /*! IGNORE */ INTO cc (
+col_int_nokey,
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES
+(0, '2003-02-06', '22:02:09.059926', '2003-08-07 14:43:09.011144', 'x'),
+(0, '2005-04-16', '19:33:15.014160', '2005-12-11 00:00:00', 'n'),
+(1, '2005-07-23', '22:03:16.058787', '2005-12-26 20:48:07.043628', 'w'),
+(7, '2001-11-15', '06:31:23.027263', '2008-06-12 06:41:21.012493', 's'),
+(0, '2006-03-24', '02:19:08.013275', '2007-10-11 18:46:28.030000', 'a'),
+(4, '2008-07-10', NULL, '2006-04-04 22:22:40.057947', 'd'),
+(1, '2009-12-07', NULL, '2002-08-10 20:52:58.035137', 'w'),
+(1, '2008-05-01', '10:28:01.038587', '2008-10-03 11:17:23.005299', 'j'),
+(1, '2008-06-22', '00:00:00', '2009-01-06 20:11:01.034339', 'm'),
+(4, '2001-11-11', '15:02:50.048785', '2009-09-19 00:00:00', 'k'),
+(7, '2000-12-21', '05:29:13.012729', '2007-09-02 12:14:27.029187', 't'),
+(4, '2007-09-03', '23:45:33.048507', '2003-09-26 00:00:00', 'k'),
+(2, '2003-02-18', '19:10:53.057455', '2001-11-18 18:10:16.063189', 'e'),
+(0, '2008-12-01', '01:45:27.037313', '2005-02-15 04:08:17.015554', 'i'),
+(1, '2008-10-18', '03:56:03.060218', '2009-06-13 23:04:40.013006', 't'),
+(91, '2004-08-28', '12:43:17.023797', '1900-01-01 00:00:00', 'm'),
+(6, '2006-10-05', '13:33:46.053634', '2005-03-20 02:48:24.045653', 'z'),
+(3, '2003-05-16', NULL, '2002-03-16 11:47:27.045297', 'c'),
+(6, '2008-10-10', NULL, '2000-05-22 00:00:00', 'i'),
+(8, '2002-01-19', '05:18:40.006865', '2009-02-12 00:00:00', 'v');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+Note 1265 Data truncated for column 'col_time_key' at row 3
+Note 1265 Data truncated for column 'col_time_key' at row 4
+Note 1265 Data truncated for column 'col_time_key' at row 5
+Warning 1048 Column 'col_time_nokey' cannot be null
+Note 1265 Data truncated for column 'col_time_key' at row 6
+Warning 1048 Column 'col_time_nokey' cannot be null
+Note 1265 Data truncated for column 'col_time_key' at row 7
+Note 1265 Data truncated for column 'col_time_key' at row 8
+Note 1265 Data truncated for column 'col_time_key' at row 9
+Note 1265 Data truncated for column 'col_time_key' at row 10
+Note 1265 Data truncated for column 'col_time_key' at row 11
+Note 1265 Data truncated for column 'col_time_key' at row 12
+Note 1265 Data truncated for column 'col_time_key' at row 13
+Note 1265 Data truncated for column 'col_time_key' at row 14
+Note 1265 Data truncated for column 'col_time_key' at row 15
+Note 1265 Data truncated for column 'col_time_key' at row 16
+Note 1265 Data truncated for column 'col_time_key' at row 17
+Warning 1048 Column 'col_time_nokey' cannot be null
+Note 1265 Data truncated for column 'col_time_key' at row 18
+Warning 1048 Column 'col_time_nokey' cannot be null
+Note 1265 Data truncated for column 'col_time_key' at row 19
+Note 1265 Data truncated for column 'col_time_key' at row 20
+EXPLAIN
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE subquery2_t2 index NULL col_int_key_2 10 NULL # #
+1 SIMPLE subquery2_t3 ALL NULL NULL NULL NULL # #
+1 SIMPLE subquery2_t1 index NULL PRIMARY 4 NULL # #
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+subquery2_field1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+2
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+6
+6
+6
+6
+7
+7
+8
+8
+8
+8
+9
+9
+24
+SELECT subquery2_t2.col_int_key AS subquery2_field1
+FROM (c AS subquery2_t1 RIGHT JOIN
+(c AS subquery2_t2 LEFT JOIN cc AS subquery2_t3 ON
+(subquery2_t3.col_int_nokey = subquery2_t2.col_int_key )) ON
+(subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key))
+ORDER BY subquery2_field1;
+subquery2_field1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+2
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+4
+6
+6
+6
+6
+7
+7
+8
+8
+8
+8
+9
+9
+24
+DROP TABLE c,cc;
+#
+# Bug#2081065: WL8149:RESULT DIFF SEEN FOR SIMPLE
+# RANGE QUERIES WITH ORDER BY
+#
+CREATE TABLE cc (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL,
+PRIMARY KEY (pk),
+KEY (col_int_key)
+);
+INSERT INTO cc (col_int_nokey) VALUES (0),(1),(7),(0),(4),(5);
+EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE cc range col_int_key col_int_key 5 NULL # #
+SELECT pk FROM cc WHERE col_int_key > 3;
+pk
+5
+6
+3
+EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE cc range col_int_key col_int_key 5 NULL # #
+SELECT pk FROM cc WHERE col_int_key > 3 ORDER BY 1;
+pk
+3
+5
+6
+DROP TABLE cc;
+#
+# Bug#20849676 :WL8149:ASSERTION `!TABLE || (!TABLE->READ_SET
+# || BITMAP_IS_SET(TABLE->READ_SET
+#
+CREATE TABLE c (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk),
+KEY (col_int_key),
+KEY (col_varchar_key),
+KEY (col_int_key, col_varchar_key)
+) ;
+INSERT INTO c (col_int_nokey, col_varchar_nokey) VALUES
+(1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'),(6, 'd'),
+(2, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'),(1, 'q'),
+(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y');
+CREATE TABLE a (
+pk INTEGER AUTO_INCREMENT,
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)),
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+PRIMARY KEY (pk),
+KEY (col_varchar_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+KEY (col_varchar_key, col_time_key, col_datetime_key)
+);
+INSERT INTO a (
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey) VALUES
+('04:08:02.046897', '2001-11-04 19:07:55.051133', 'k');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+ANALYZE TABLE a, c;
+Table Op Msg_type Msg_text
+test.a analyze status Engine-independent statistics collected
+test.a analyze status OK
+test.c analyze status Engine-independent statistics collected
+test.c analyze status OK
+EXPLAIN
+SELECT
+table1.pk AS field1 ,
+table1.col_datetime_key AS field2
+FROM
+( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT
+SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2
+STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key =
+SUBQUERY1_t2.col_varchar_key ) )
+ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key
+OR SUBQUERY1_t1.col_int_key <> 1 ) )
+WHERE SUBQUERY1_t2.pk >= 9 ) AS table3
+ON (table3.col_int_key = table2.col_int_key ) ) )
+ON (table3.col_int_nokey = table2.pk ) )
+GROUP BY field1, field2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY table1 system NULL NULL NULL NULL #
+1 PRIMARY table2 ALL PRIMARY,col_int_key,col_int_key_2 NULL NULL NULL # Using where
+1 PRIMARY <derived2> ref key0 key0 9 test.table2.pk,test.table2.col_int_key #
+2 DERIVED SUBQUERY1_t2 ALL PRIMARY,col_int_key,col_varchar_key,col_int_key_2 NULL NULL NULL # Using where
+2 DERIVED SUBQUERY1_t3 ref PRIMARY,col_varchar_key col_varchar_key 5 test.SUBQUERY1_t2.col_varchar_key #
+2 DERIVED SUBQUERY1_t1 ALL col_int_key,col_int_key_2 NULL NULL NULL # Using where; Using join buffer (flat, BNL join)
+SELECT
+table1.pk AS field1 ,
+table1.col_datetime_key AS field2
+FROM
+( a AS table1 LEFT JOIN ( ( c AS table2 STRAIGHT_JOIN ( SELECT
+SUBQUERY1_t1.* FROM ( c AS SUBQUERY1_t1 INNER JOIN ( c AS SUBQUERY1_t2
+STRAIGHT_JOIN c AS SUBQUERY1_t3 ON (SUBQUERY1_t3.col_varchar_key =
+SUBQUERY1_t2.col_varchar_key ) )
+ON (SUBQUERY1_t3.pk = SUBQUERY1_t2.col_int_key
+OR SUBQUERY1_t1.col_int_key <> 1 ) )
+WHERE SUBQUERY1_t2.pk >= 9 ) AS table3
+ON (table3.col_int_key = table2.col_int_key ) ) )
+ON (table3.col_int_nokey = table2.pk ) )
+GROUP BY field1, field2;
+field1 field2
+1 2001-11-04 23:15:57
+DROP TABLE IF EXISTS c,a;
+CREATE TABLE c (
+col_int_nokey INTEGER NOT NULL,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL,
+col_varchar_nokey VARCHAR(1) NOT NULL,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+KEY (col_int_key),
+KEY (col_int_key, col_varchar_key)
+) ;
+INSERT INTO c (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (1, 'c'),(8, 'm'),(9, 'd'),(24, 'd'),(6, 'y'),(1, 't'),
+(6, 'd'),(2, 's'),(4, 'r'),(8, 'm'),(4, 'b'),(4, 'x'),(7, 'g'),(4, 'p'),
+(1, 'q'),(9, 'w'),(4, 'd'),(8, 'e'),(4, 'b'),(8, 'y');
+CREATE TABLE cc (
+col_int_nokey INTEGER,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL,
+col_varchar_nokey VARCHAR(1),
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)),
+KEY (col_int_key),
+KEY (col_varchar_key),
+KEY (col_int_key, col_varchar_key),
+KEY (col_int_key, col_int_nokey),
+KEY (col_varchar_key, col_varchar_nokey)
+);
+INSERT INTO cc (
+col_int_nokey,
+col_varchar_nokey
+) VALUES (8, 'p'),(9, 'g'),(9, 'i'),(4, 'p'),(7, 'h'),(1, 'e'),(8, 'e'),(6, 'u'),
+(6, 'j'),(6, 'e'),(1, 'z'),(227, 'w'),(NULL, 't'),(9, 'i'),(1, 'i'),(8, 'i'),
+(5, 'b'),(8,'m'),(7, 'j'),(2, 'v');
+ANALYZE TABLE c, cc;
+Table Op Msg_type Msg_text
+test.c analyze status Engine-independent statistics collected
+test.c analyze status OK
+test.cc analyze status Engine-independent statistics collected
+test.cc analyze status OK
+EXPLAIN SELECT
+alias2 . col_varchar_key AS field1
+FROM ( cc AS alias1 , cc AS alias2 )
+WHERE
+( alias2 . col_int_key , alias1 . col_int_nokey )
+NOT IN
+(
+SELECT
+DISTINCT SQ1_alias2 . col_int_nokey AS SQ1_field1 ,
+SQ1_alias1 . col_int_key AS SQ1_field2
+FROM ( cc AS SQ1_alias1 , c AS SQ1_alias2 )
+GROUP BY SQ1_field1 , SQ1_field2
+)
+GROUP BY field1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY alias1 index NULL col_int_key_3 10 NULL # Using index; Using temporary; Using filesort
+1 PRIMARY alias2 index NULL col_int_key_2 10 NULL # Using where; Using index; Using join buffer (flat, BNL join)
+2 MATERIALIZED SQ1_alias1 index col_int_key,col_int_key_2,col_int_key_3 col_int_key 5 NULL # Using index
+2 MATERIALIZED SQ1_alias2 ALL NULL NULL NULL NULL # Using join buffer (flat, BNL join)
+SELECT
+alias2 . col_varchar_key AS field1
+FROM ( cc AS alias1 , cc AS alias2 )
+WHERE
+( alias2 . col_int_key , alias1 . col_int_nokey )
+NOT IN
+(
+SELECT
+DISTINCT SQ1_alias2 . col_int_nokey AS SQ1_field1 ,
+SQ1_alias1 . col_int_key AS SQ1_field2
+FROM ( cc AS SQ1_alias1 , c AS SQ1_alias2 )
+GROUP BY SQ1_field1 , SQ1_field2
+)
+GROUP BY field1;
+field1
+bb
+ee
+gg
+hh
+ii
+jj
+mm
+pp
+uu
+ww
+DROP TABLE IF EXISTS c,cc;
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+CREATE TABLE d (
+col_int int(11) DEFAULT NULL,
+col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL,
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_key int(11) GENERATED ALWAYS AS (col_int+col_int) VIRTUAL,
+col_varchar_10_utf8_key varchar(10) CHARACTER SET utf8 GENERATED ALWAYS AS (REPEAT(SUBSTRING(col_varchar_10_utf8, -1), 5)) VIRTUAL,
+PRIMARY KEY (pk),
+KEY col_int_key (col_int_key),
+KEY col_varchar_10_utf8_key (col_varchar_10_utf8_key),
+KEY cover_key1 (col_int_key, col_varchar_10_utf8_key)
+);
+INSERT INTO d (col_int, col_varchar_10_utf8) VALUES ('qhlhtrovam',1),('how',2),('htrovamzqr',3),('rovamzqrdc',4),('well',5),('g',6),('rdcenchyhu',7),('want',8);
+SELECT table1.pk AS field1 FROM d AS table1 LEFT JOIN d AS table2 ON table1.col_varchar_10_utf8_key = table2.col_varchar_10_utf8_key WHERE table1.col_int_key IS NULL GROUP BY table1.pk ;
+field1
+DROP TABLE d;
+#
+# Bug#21153237: WL8149: QUERIES USING FILESORT
+# ON VIRTUAL GC HAVING INDEX GIVES WRONG RESULTS
+#
+CREATE TABLE j (
+col_int int(11),
+pk int(11) NOT NULL,
+col_varchar_10_utf8 varchar(10) CHARACTER SET utf8 DEFAULT NULL,
+col_varchar_255_utf8_key varchar(255) CHARACTER SET utf8 GENERATED ALWAYS AS
+(col_varchar_10_utf8) VIRTUAL,
+PRIMARY KEY (pk),
+KEY cover_key1 (col_int, col_varchar_255_utf8_key));
+INSERT INTO j(col_int, pk, col_varchar_10_utf8) VALUES(9, 1, '951910400'),
+(-1934295040, 2, '1235025920'),(-584581120, 3, '-1176633344'),(3, 4, '1074462720');
+EXPLAIN SELECT col_varchar_255_utf8_key FROM j ORDER BY 1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE j index NULL cover_key1 773 NULL # Using index; Using filesort
+SELECT col_varchar_255_utf8_key FROM j ORDER BY col_varchar_255_utf8_key;
+col_varchar_255_utf8_key
+-117663334
+1074462720
+1235025920
+951910400
+DROP TABLE j;
+set sql_mode= @save_old_sql_mode;
+CREATE TABLE cc (
+pk int(11) NOT NULL AUTO_INCREMENT,
+col_int_nokey int(11) NOT NULL,
+col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey) STORED,
+col_date_nokey date NOT NULL,
+col_date_key date GENERATED ALWAYS AS (col_date_nokey) STORED,
+col_datetime_nokey datetime NOT NULL,
+col_time_nokey time NOT NULL,
+col_datetime_key datetime GENERATED ALWAYS AS (col_datetime_nokey)STORED,
+col_time_key time GENERATED ALWAYS AS (col_time_nokey) STORED,
+col_varchar_nokey varchar(1) NOT NULL,
+col_varchar_key varchar(1) GENERATED ALWAYS AS (col_varchar_nokey)STORED,
+PRIMARY KEY (pk),
+KEY gc_idx1 (col_int_key),
+KEY gc_idx2 (col_varchar_key),
+KEY gc_idx3 (col_date_key),
+KEY gc_idx4 (col_time_key),
+KEY gc_idx5 (col_datetime_key),
+KEY gc_idx6 (col_varchar_key,col_int_key),
+KEY gc_idx7 (col_date_key,col_datetime_key,col_time_key),
+KEY gc_idx8(col_int_key,col_varchar_key,col_date_key,col_time_key,
+col_datetime_key)
+);
+INSERT INTO cc (
+col_int_nokey,
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_varchar_nokey
+) VALUES (1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(24, '2000-10-08', '10:14:58.018534', '2006-10-12 04:32:53.031976', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(1, '2008-01-23', '11:14:24.032949', '2004-10-02 20:31:15.022553', 't');
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+SELECT DISTINCT alias1.col_varchar_key AS field1
+FROM ( cc AS alias1 STRAIGHT_JOIN
+(( cc AS alias2 STRAIGHT_JOIN cc AS alias3 ON
+(alias3.col_varchar_key > alias2.col_varchar_key ) ) ) ON
+(( alias3 .pk >= alias2.col_int_nokey ) AND
+(alias3 .pk >= alias2.col_int_nokey ) ))
+WHERE alias1.col_varchar_key <= 'v'
+GROUP BY field1 HAVING field1 = 91
+ORDER BY field1, alias1.col_date_key, field1 ASC, field1 DESC,
+alias1.col_time_key ASC, field1;
+field1
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: 'c'
+Warning 1292 Truncated incorrect DECIMAL value: 't'
+Warning 1292 Truncated incorrect DECIMAL value: 'm'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
+Warning 1292 Truncated incorrect DECIMAL value: 'd'
+DROP TABLE cc;
+SET sql_mode=@save_old_sql_mode;
+#
+# Bug#20797941: WL8149:ASSERTION !TABLE ||
+# (!TABLE->READ_SET || BITMAP_IS_SET(TABLE->READ_SET
+#
+CREATE TABLE t(a int, b int as(a+1));
+INSERT INTO t(a) values(1),(2);
+SELECT * FROM t ORDER BY b;
+a b
+1 2
+2 3
+DROP TABLE t;
+#
+# Testing a few index-based accesses on the virtual column
+#
+CREATE TABLE t1 (
+id int(11) NOT NULL,
+b int(11) GENERATED ALWAYS AS (id+1) VIRTUAL,
+UNIQUE KEY (b) );
+INSERT INTO t1 (id) VALUES(NULL);
+ERROR 23000: Column 'id' cannot be null
+INSERT INTO t1 (id) VALUES(2),(3);
+EXPLAIN SELECT * FROM t1 FORCE INDEX(b) WHERE b=3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 const b b 5 const 1
+EXPLAIN SELECT * FROM t1 AS t2 STRAIGHT_JOIN t1 FORCE INDEX(b) WHERE t1.b=t2.b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where
+1 SIMPLE t1 eq_ref b b 5 test.t2.b 1
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b);
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 index NULL b 5 NULL 2 Using index
+INSERT INTO t1 (id) VALUES(4),(5),(6),(7),(8),(9),(10);
+EXPLAIN SELECT b FROM t1 FORCE INDEX(b) WHERE b BETWEEN 1 AND 5;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range b b 5 NULL 3 Using where; Using index
+EXPLAIN SELECT * FROM t2 AS t1 WHERE b NOT IN (SELECT b FROM t1 FORCE INDEX(b));
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 1
+2 SUBQUERY t1 index_subquery b b 5 func 3 Using index; Full scan on NULL key
+DROP TABLE t1;
+DROP TABLE t2, t3;
+#
+# Bug#21317507:GC: STORED COLUMN REJECTED, BUT VIRTUAL IS ACCEPTED
+#
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL;
+ERROR 22003: Out of range value for column 'b' at row 1
+ALTER TABLE t1 DROP COLUMN b;
+ERROR 42000: Can't DROP COLUMN `b`; check that it exists
+ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL;
+ERROR 22003: Out of range value for column 'c' at row 1
+ALTER TABLE t1 DROP COLUMN c;
+ERROR 42000: Can't DROP COLUMN `c`; check that it exists
+ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL;
+ERROR 22003: Out of range value for column 'd' at row 1
+ALTER TABLE t1 DROP COLUMN d;
+ERROR 42000: Can't DROP COLUMN `d`; check that it exists
+ALTER TABLE t1 ADD COLUMN c INT AS(a) VIRTUAL;
+ALTER TABLE t1 CHANGE c c SMALLINT AS(a) VIRTUAL;
+ERROR 22003: Out of range value for column 'c' at row 1
+ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL;
+ERROR 22003: Out of range value for column 'c' at row 1
+SELECT * FROM t1;
+a c
+2147483647 2147483647
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(2147483647);
+ALTER TABLE t1 ADD COLUMN h INT AS (a) VIRTUAL;
+ALTER TABLE t1 CHANGE h i INT AS (a) VIRTUAL, ALGORITHM=COPY;
+ALTER TABLE t1 ADD COLUMN b SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
+ALTER TABLE t1 ADD COLUMN e SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED
+ALTER TABLE t1 ADD COLUMN f SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=SHARED;
+ERROR 22003: Out of range value for column 'f' at row 1
+ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=EXCLUSIVE;
+ERROR 22003: Out of range value for column 'g' at row 1
+DROP TABLE t1;
+#
+# Bug#21980430 GCOLS: CRASHING
+#
+CREATE TABLE t (
+a INT,
+b BLOB,
+c BLOB GENERATED ALWAYS AS (a+b) VIRTUAL,
+UNIQUE KEY i0008 (a)
+);
+INSERT INTO t(a,b) VALUES(1,'cccc');
+EXPLAIN SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
+WHERE b.b>c.a;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'cccc'
+Warning 1292 Truncated incorrect DECIMAL value: 'cccc'
+SELECT /*+ bka() */ 1 AS c FROM t AS b RIGHT JOIN t AS c ON b.a > c.c
+WHERE b.b>c.a;
+c
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'cccc'
+Warning 1292 Truncated incorrect DECIMAL value: 'cccc'
+DROP TABLE t;
+set @optimizer_switch_save = @@optimizer_switch;
+set optimizer_switch='mrr_cost_based=off';
+set @read_rnd_buffer_size_save= @@read_rnd_buffer_size;
+set read_rnd_buffer_size=32;
+CREATE TABLE t0 (
+i1 INTEGER NOT NULL
+);
+INSERT INTO t0 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+CREATE TABLE t1 (
+pk INTEGER NOT NULL,
+i1 INTEGER NOT NULL,
+i2 INTEGER NOT NULL,
+v1 INTEGER GENERATED ALWAYS AS (i2 + 1) VIRTUAL,
+v2 INTEGER GENERATED ALWAYS AS (i1 / (i1 - i2 + 57)) VIRTUAL,
+PRIMARY KEY (pk),
+INDEX idx(i1)
+);
+INSERT INTO t1 (pk, i1, i2)
+SELECT a0.i1 + a1.i1*10 + a2.i1*100,
+a0.i1 + a1.i1*10,
+a0.i1 + a1.i1*10
+FROM t0 AS a0, t0 AS a1, t0 AS a2;
+EXPLAIN SELECT * FROM t1
+WHERE i1 > 41 AND i1 <= 43;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range idx idx 4 NULL 20 Using index condition
+SELECT * FROM t1
+WHERE i1 > 41 AND i1 <= 43;
+pk i1 i2 v1 v2
+142 42 42 43 1
+143 43 43 44 1
+242 42 42 43 1
+243 43 43 44 1
+342 42 42 43 1
+343 43 43 44 1
+42 42 42 43 1
+43 43 43 44 1
+442 42 42 43 1
+443 43 43 44 1
+542 42 42 43 1
+543 43 43 44 1
+642 42 42 43 1
+643 43 43 44 1
+742 42 42 43 1
+743 43 43 44 1
+842 42 42 43 1
+843 43 43 44 1
+942 42 42 43 1
+943 43 43 44 1
+ALTER TABLE t1 ADD INDEX idx2(v1);
+EXPLAIN SELECT * FROM t1
+WHERE v1 > 41 AND v1 <= 43;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 range idx2 idx2 5 NULL # Using index condition
+SELECT * FROM t1
+WHERE v1 > 41 AND v1 <= 43;
+pk i1 i2 v1 v2
+141 41 41 42 1
+142 42 42 43 1
+241 41 41 42 1
+242 42 42 43 1
+341 41 41 42 1
+342 42 42 43 1
+41 41 41 42 1
+42 42 42 43 1
+441 41 41 42 1
+442 42 42 43 1
+541 41 41 42 1
+542 42 42 43 1
+641 41 41 42 1
+642 42 42 43 1
+741 41 41 42 1
+742 42 42 43 1
+841 41 41 42 1
+842 42 42 43 1
+941 41 41 42 1
+942 42 42 43 1
+DROP TABLE t0, t1;
+set optimizer_switch= @optimizer_switch_save;
+set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
+#
+# Bug#21872184 CONDITIONAL JUMP AT JOIN_CACHE::WRITE_RECORD_DATA IN
+# SQL_JOIN_BUFFER.CC
+#
+#
+# Test 1: Dynamic range scan with one covering index
+#
+CREATE TABLE t1 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t1
+VALUES (10, 'c'), (10, 'i'), (2, 't'), (4, 'g');
+CREATE TABLE t2 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t2
+VALUES (2, 'k'), (9, 'k'), (7, 'o'), (5, 'n'), (7, 'e');
+CREATE TABLE t3 (
+pk INTEGER NOT NULL,
+i1 INTEGER,
+i2_key INTEGER GENERATED ALWAYS AS (i1 + i1) VIRTUAL,
+PRIMARY KEY (pk)
+);
+# Add a covering index. The reason for this index being covering is that
+# secondary indexes in InnoDB include the primary key.
+ALTER TABLE t3 ADD INDEX v_idx (i2_key);
+INSERT INTO t3 (pk, i1)
+VALUES (1, 1), (2, 48), (3, 228), (4, 3), (5, 5),
+(6, 39), (7, 6), (8, 8), (9, 3);
+CREATE TABLE t4 (
+i1 INTEGER NOT NULL,
+c1 VARCHAR(1) NOT NULL
+);
+INSERT INTO t4
+VALUES (1, 'j'), (2, 'c'), (0, 'a');
+ANALYZE TABLE t1, t2, t3, t4;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+test.t2 analyze status Engine-independent statistics collected
+test.t2 analyze status OK
+test.t3 analyze status Engine-independent statistics collected
+test.t3 analyze status OK
+test.t4 analyze status Engine-independent statistics collected
+test.t4 analyze status OK
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY,v_idx PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 2: Two alternative covering indexes for the range scan
+#
+ALTER TABLE t3 ADD INDEX v_idx2 (i2_key, i1);
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY,v_idx,v_idx2 PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 3: One covering index including the base column for the virtual
+# column
+#
+# Drop the index with only the virtual column
+ALTER TABLE t3 DROP INDEX v_idx;
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY,v_idx2 PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+#
+# Test 4: One non-covering index
+#
+# Drop the index on two columns, add index on just one virtual column
+ALTER TABLE t3 DROP INDEX v_idx2;
+ALTER TABLE t3 ADD INDEX v_idx (i2_key);
+# Add more data to the table so that it will run the dynamic range scan
+# as both table scan and range scan (the purpose of this is to make the
+# table scan more expensive).
+INSERT INTO t3 (pk, i1)
+VALUES (10,1), (11,1), (12,1), (13,1), (14,1),(15,1), (16,1),(17,1), (18,1),
+(19,1), (20,1), (21,1), (22,1), (23,1), (24,1),(25,1),(26,1),(27,1),
+(28,1), (29,1);
+# Change the query to read an extra column (t3.i1) making the index
+# non-covering.
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4
+1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
+1 PRIMARY t3 eq_ref PRIMARY,v_idx PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using join buffer (flat, BNL join)
+2 MATERIALIZED t4 ALL NULL NULL NULL NULL 3 Using where
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1, t3.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o'
+ )
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1 i1
+c 2 48
+c 5 48
+c 7 48
+c 7 48
+c 9 48
+g 2 48
+g 5 48
+g 7 48
+g 7 48
+g 9 48
+i 2 48
+i 5 48
+i 7 48
+i 7 48
+i 9 48
+t 2 1
+t 2 48
+t 5 1
+t 5 48
+t 7 1
+t 7 1
+t 7 48
+t 7 48
+t 9 1
+t 9 48
+#
+# Test 5: Test where the added primary key to secondary indexes is
+# used after it has been included in the join buffer
+#
+EXPLAIN SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1)
+)
+)
+AND t1.i1 <= t3.i2_key;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using where; Start temporary
+1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join)
+1 PRIMARY t3 eq_ref PRIMARY,v_idx PRIMARY 4 test.t4.i1 1 Using where
+1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where; End temporary; Using join buffer (flat, BNL join)
+SELECT /*+ NO_SEMIJOIN(@subq1) */ t1.c1, t2.i1
+FROM t1 STRAIGHT_JOIN t3 STRAIGHT_JOIN t2
+WHERE ( t3.pk IN
+(
+SELECT /*+ QB_NAME(subq1) */ t4.i1
+FROM t4
+WHERE t4.c1 < 'o' and t4.i1 < (t2.i1 + 1)
+)
+)
+AND t1.i1 <= t3.i2_key;
+c1 i1
+c 2
+c 5
+c 7
+c 7
+c 9
+g 2
+g 5
+g 7
+g 7
+g 9
+i 2
+i 5
+i 7
+i 7
+i 9
+t 2
+t 2
+t 5
+t 5
+t 7
+t 7
+t 7
+t 7
+t 9
+t 9
+DROP TABLE t1, t2, t3, t4;
+SET optimizer_switch='derived_merge=default';
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result
new file mode 100644
index 00000000..1b12e0a9
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result
@@ -0,0 +1,3003 @@
+SET @@session.default_storage_engine = 'InnoDB';
+set time_zone="+03:00";
+#
+# NUMERIC FUNCTIONS
+#
+# ABS()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (abs(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (abs(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1, default);
+select * from t1;
+a b
+-1 1
+drop table t1;
+set sql_warnings = 0;
+# ACOS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(acos(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(acos(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1, default);
+insert into t1 values (1.0001,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+0 1.570796
+1 0
+1.0001 NULL
+drop table t1;
+set sql_warnings = 0;
+# ASIN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(asin(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(asin(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0.2, default);
+insert into t1 values (1.0001,default);
+select * from t1;
+a b
+0.2 0.201358
+1.0001 NULL
+drop table t1;
+set sql_warnings = 0;
+#ATAN
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(atan(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`,`b`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,2,default);
+insert into t1 values (format(PI(),6),0,default);
+select * from t1;
+a b c
+-2 2 -0.785398
+3.141593 0 1.570796
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, c double generated always as (format(atan(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,default);
+insert into t1 values (format(PI(),6),default);
+select * from t1;
+a c
+-2 -1.107149
+3.141593 1.262627
+drop table t1;
+set sql_warnings = 0;
+# ATAN2
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(atan2(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`,`b`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,2,default);
+insert into t1 values (format(PI(),6),0,default);
+select * from t1;
+a b c
+-2 2 -0.785398
+3.141593 0 1.570796
+drop table t1;
+set sql_warnings = 0;
+# CEIL()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (ceil(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (ceiling(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.23,default);
+insert into t1 values (-1.23,default);
+select * from t1;
+a b
+-1.23 -1
+1.23 2
+drop table t1;
+set sql_warnings = 0;
+# CONV()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int, c int, d varchar(10) generated always as (conv(a,b,c)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(10) GENERATED ALWAYS AS (conv(`a`,`b`,`c`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a',16,2,default);
+insert into t1 values ('6e',18,8,default);
+insert into t1 values (-17,10,-18,default);
+insert into t1 values (10+'10'+'10'+0xa,10,10,default);
+select * from t1;
+a b c d
+-17 10 -18 -H
+40 10 10 40
+6e 18 8 172
+a 16 2 1010
+drop table t1;
+set sql_warnings = 0;
+# COS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(cos(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(cos(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+select * from t1;
+a b
+3.141593 -1
+drop table t1;
+set sql_warnings = 0;
+# COT()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(cot(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(cot(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 -1.572673
+drop table t1;
+set sql_warnings = 0;
+# CRC32()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (crc32(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (crc32(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+insert into t1 values ('mysql',default);
+select * from t1;
+a b
+MySQL 3259397556
+mysql 2501908538
+drop table t1;
+set sql_warnings = 0;
+# DEGREES()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(degrees(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(degrees(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+insert into t1 values (format(PI()/2,6),default);
+select * from t1;
+a b
+1.570796 89.999981
+3.141593 180.00002
+drop table t1;
+set sql_warnings = 0;
+# /
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a/2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` / 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+select * from t1;
+a b
+2 1
+drop table t1;
+set sql_warnings = 0;
+# EXP()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(exp(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(exp(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+-2 0.135335
+0 1
+2 7.389056
+drop table t1;
+set sql_warnings = 0;
+# FLOOR()
+set sql_warnings = 1;
+create table t1 (a double, b bigint generated always as (floor(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (floor(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.23,default);
+insert into t1 values (-1.23,default);
+select * from t1;
+a b
+-1.23 -2
+1.23 1
+drop table t1;
+set sql_warnings = 0;
+# LN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(ln(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(ln(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG()
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(log(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(log(`a`,`b`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,65536,default);
+insert into t1 values (10,100,default);
+insert into t1 values (1,100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b c
+1 100 NULL
+10 100 2
+2 65536 16
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG2()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log2(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log2(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (65536,default);
+insert into t1 values (-100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-100 NULL
+65536 16
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG10()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log10(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log10(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (100,default);
+insert into t1 values (-100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-100 NULL
+100 2
+2 0.30103
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# -
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a-1) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` - 1) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+select * from t1;
+a b
+2 1
+drop table t1;
+set sql_warnings = 0;
+# MOD()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (mod(a,10)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 10) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (11,default);
+select * from t1;
+a b
+1 1
+11 1
+drop table t1;
+set sql_warnings = 0;
+# %
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a % 10) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 10) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (11,default);
+select * from t1;
+a b
+1 1
+11 1
+drop table t1;
+set sql_warnings = 0;
+# OCT()
+set sql_warnings = 1;
+create table t1 (a double, b varchar(10) generated always as (oct(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (conv(`a`,10,8)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 14
+drop table t1;
+set sql_warnings = 0;
+# PI()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(PI()*a*a,6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(pi() * `a` * `a`,6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 3.141593
+drop table t1;
+set sql_warnings = 0;
+# +
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a+1) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 2
+drop table t1;
+set sql_warnings = 0;
+# POW, POWER
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (pow(a,2)) virtual, c int generated always as (power(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (pow(`a`,2)) VIRTUAL,
+ `c` int(11) GENERATED ALWAYS AS (pow(`a`,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default,default);
+insert into t1 values (2,default,default);
+select * from t1;
+a b c
+1 1 1
+2 4 4
+drop table t1;
+set sql_warnings = 0;
+# RADIANS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(radians(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(radians(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (90,default);
+select * from t1;
+a b
+90 1.570796
+drop table t1;
+set sql_warnings = 0;
+# ROUND()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (round(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (round(`a`,0)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1.23,default);
+insert into t1 values (-1.58,default);
+insert into t1 values (1.58,default);
+select * from t1;
+a b
+-1.23 -1
+-1.58 -2
+1.58 2
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, b double, c int generated always as (round(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (round(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.298,1,default);
+insert into t1 values (1.298,0,default);
+insert into t1 values (23.298,-1,default);
+select * from t1;
+a b c
+1.298 0 1
+1.298 1 1
+23.298 -1 20
+drop table t1;
+set sql_warnings = 0;
+# SIGN()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (sign(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (sign(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-32,default);
+insert into t1 values (0,default);
+insert into t1 values (234,default);
+select * from t1;
+a b
+-32 -1
+0 0
+234 1
+drop table t1;
+set sql_warnings = 0;
+# SIN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(sin(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(sin(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI()/2,6),default);
+select * from t1;
+a b
+1.570796 1
+drop table t1;
+set sql_warnings = 0;
+# SQRT()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(sqrt(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(sqrt(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (4,default);
+insert into t1 values (20,default);
+insert into t1 values (-16,default);
+select * from t1;
+a b
+-16 NULL
+20 4.472136
+4 2
+drop table t1;
+set sql_warnings = 0;
+# TAN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(tan(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(tan(`a`),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+insert into t1 values (format(PI()+1,6),default);
+select * from t1;
+a b
+3.141593 0
+4.141593 1.557409
+drop table t1;
+set sql_warnings = 0;
+# *
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a*3) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` * 3) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 0
+1 3
+2 6
+drop table t1;
+set sql_warnings = 0;
+# TRUNCATE()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (truncate(a,4)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (truncate(`a`,4)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.223,default);
+insert into t1 values (1.999,default);
+insert into t1 values (1.999,default);
+insert into t1 values (122,default);
+select * from t1;
+a b
+1.223 1.223
+1.999 1.999
+1.999 1.999
+122 122
+drop table t1;
+set sql_warnings = 0;
+# Unary -
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (-a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (-`a`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+select * from t1;
+a b
+-1 1
+1 -1
+drop table t1;
+set sql_warnings = 0;
+#
+# STRING FUNCTIONS
+#
+# ASCII()
+set sql_warnings = 1;
+create table t1 (a char(2), b int generated always as (ascii(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(2) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (ascii(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2',default);
+insert into t1 values (2,default);
+insert into t1 values ('dx',default);
+select * from t1;
+a b
+2 50
+2 50
+dx 100
+drop table t1;
+set sql_warnings = 0;
+# BIN()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (bin(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (conv(`a`,10,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 1100
+drop table t1;
+set sql_warnings = 0;
+# BIT_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (bit_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (bit_length(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 32
+drop table t1;
+set sql_warnings = 0;
+# CHAR_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (char_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (char_length(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# CHAR()
+set sql_warnings = 1;
+create table t1 (a int, b int, c varbinary(10) generated always as (char(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` varbinary(10) GENERATED ALWAYS AS (char(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (77,121,default);
+select * from t1;
+a b c
+77 121 My
+drop table t1;
+set sql_warnings = 0;
+# CHARACTER_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (character_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (char_length(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# CONCAT_WS()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (concat_ws(',',a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (concat_ws(',',`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',default);
+select * from t1;
+a b c
+value1 value2 value1,value2
+drop table t1;
+set sql_warnings = 0;
+# CONCAT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (concat(a,',',b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (concat(`a`,',',`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',default);
+select * from t1;
+a b c
+value1 value2 value1,value2
+drop table t1;
+set sql_warnings = 0;
+# ELT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int, d varchar(10) generated always as (elt(c,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(10) GENERATED ALWAYS AS (elt(`c`,`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',1,default);
+insert into t1 values ('value1','value2',2,default);
+select * from t1;
+a b c d
+value1 value2 1 value1
+value1 value2 2 value2
+drop table t1;
+set sql_warnings = 0;
+# EXPORT_SET()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (export_set(a,'1','0','',10)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (export_set(`a`,'1','0','',10)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (6,default);
+select * from t1;
+a b
+6 0110000000
+drop table t1;
+set sql_warnings = 0;
+# FIELD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (field('aa',a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (field('aa',`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('aa','bb',default);
+insert into t1 values ('bb','aa',default);
+select * from t1;
+a b c
+aa bb 1
+bb aa 2
+drop table t1;
+set sql_warnings = 0;
+# FIND_IN_SET()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (find_in_set(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (find_in_set(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('aa','aa,bb,cc',default);
+insert into t1 values ('aa','bb,aa,cc',default);
+select * from t1;
+a b c
+aa aa,bb,cc 1
+aa bb,aa,cc 2
+drop table t1;
+set sql_warnings = 0;
+# FORMAT()
+set sql_warnings = 1;
+create table t1 (a double, b varchar(20) generated always as (format(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` varchar(20) GENERATED ALWAYS AS (format(`a`,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12332.123456,default);
+select * from t1;
+a b
+12332.123456 12,332.12
+drop table t1;
+set sql_warnings = 0;
+# HEX()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (hex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (hex(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (17,default);
+select * from t1;
+a b
+17 11
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (hex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (hex(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 616263
+drop table t1;
+set sql_warnings = 0;
+# INSERT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (insert(a,length(a),length(b),b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (insert(`a`,octet_length(`a`),octet_length(`b`),`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('start,','end',default);
+select * from t1;
+a b c
+start, end startend
+drop table t1;
+set sql_warnings = 0;
+# INSTR()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (instr(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (locate(`b`,`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar,','bar',default);
+insert into t1 values ('xbar,','foobar',default);
+select * from t1;
+a b c
+foobarbar, bar 4
+xbar, foobar 0
+drop table t1;
+set sql_warnings = 0;
+# LCASE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lcase(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lcase(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL mysql
+drop table t1;
+set sql_warnings = 0;
+# LEFT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(5) generated always as (left(a,5)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(5) GENERATED ALWAYS AS (left(`a`,5)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar fooba
+drop table t1;
+set sql_warnings = 0;
+# LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int generated always as (length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (octet_length(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a like 'H%o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` like 'H%o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 1
+MySQL 0
+drop table t1;
+set sql_warnings = 0;
+# LOCATE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (locate('bar',a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (locate('bar',`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar 4
+drop table t1;
+set sql_warnings = 0;
+# LOWER()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lower(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lcase(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL mysql
+drop table t1;
+set sql_warnings = 0;
+# LPAD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lpad(a,4,' ')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lpad(`a`,4,' ')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+insert into t1 values ('M',default);
+select * from t1;
+a b
+M M
+MySQL MySQ
+drop table t1;
+set sql_warnings = 0;
+# LTRIM()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (ltrim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ltrim(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (' MySQL',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+ MySQL MySQL
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# MAKE_SET()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int, d varchar(30) generated always as (make_set(c,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(30) GENERATED ALWAYS AS (make_set(`c`,`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',1,default);
+insert into t1 values ('a','b',3,default);
+select * from t1;
+a b c d
+a b 1 a
+a b 3 a,b
+drop table t1;
+set sql_warnings = 0;
+# MID()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (mid(a,1,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,1,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar fo
+drop table t1;
+set sql_warnings = 0;
+# NOT LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a not like 'H%o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` not like 'H%o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 0
+MySQL 1
+drop table t1;
+set sql_warnings = 0;
+# NOT REGEXP
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a not regexp 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (!(`a` regexp 'H.+o')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('hello',default);
+select * from t1;
+a b
+Hello 0
+hello 0
+drop table t1;
+set sql_warnings = 0;
+# OCTET_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int generated always as (octet_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (octet_length(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# ORD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (ord(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (ord(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2',default);
+select * from t1;
+a b
+2 50
+drop table t1;
+set sql_warnings = 0;
+# POSITION()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (position('bar' in a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (locate('bar',`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar 4
+drop table t1;
+set sql_warnings = 0;
+# QUOTE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (quote(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (quote(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Don\'t',default);
+select * from t1;
+a b
+Don't 'Don\'t'
+drop table t1;
+set sql_warnings = 0;
+# REGEXP()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a regexp 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` regexp 'H.+o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('hello',default);
+select * from t1;
+a b
+Hello 1
+hello 1
+drop table t1;
+set sql_warnings = 0;
+# REPEAT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (repeat(a,3)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (repeat(`a`,3)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQLMySQLMySQL
+drop table t1;
+set sql_warnings = 0;
+# REPLACE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (replace(a,'aa','bb')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (replace(`a`,'aa','bb')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('maa',default);
+select * from t1;
+a b
+maa mbb
+drop table t1;
+set sql_warnings = 0;
+# REVERSE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (reverse(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (reverse(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('maa',default);
+select * from t1;
+a b
+maa aam
+drop table t1;
+set sql_warnings = 0;
+# RIGHT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (right(a,4)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (right(`a`,4)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar rbar
+drop table t1;
+set sql_warnings = 0;
+# RLIKE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a rlike 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` regexp 'H.+o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 1
+MySQL 0
+drop table t1;
+set sql_warnings = 0;
+# RPAD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (rpad(a,4,'??')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (rpad(`a`,4,'??')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('He',default);
+select * from t1;
+a b
+He He??
+drop table t1;
+set sql_warnings = 0;
+# RTRIM();
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (rtrim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello ',default);
+select * from t1;
+a b
+Hello Hello
+drop table t1;
+set sql_warnings = 0;
+# SOUNDEX()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(20) generated always as (soundex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(20) GENERATED ALWAYS AS (soundex(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello H400
+drop table t1;
+set sql_warnings = 0;
+# SOUNDS LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a sounds like b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (soundex(`a`) = soundex(`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello','Hello',default);
+insert into t1 values ('Hello','MySQL',default);
+insert into t1 values ('Hello','hello',default);
+select * from t1;
+a b c
+Hello Hello 1
+Hello MySQL 0
+Hello hello 1
+drop table t1;
+set sql_warnings = 0;
+# SPACE()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (concat(a,space(5))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (concat(`a`,space(5))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello', default);
+select * from t1;
+a b
+Hello Hello
+drop table t1;
+set sql_warnings = 0;
+# STRCMP()
+set sql_warnings = 1;
+create table t1 (a varchar(9), b varchar(9), c tinyint(1) generated always as (strcmp(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(9) DEFAULT NULL,
+ `b` varchar(9) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (strcmp(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello','Hello', default);
+insert into t1 values ('Hello','Hello1', default);
+select * from t1;
+a b c
+Hello Hello 0
+Hello Hello1 -1
+drop table t1;
+set sql_warnings = 0;
+# SUBSTR()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (substr(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello ello
+drop table t1;
+set sql_warnings = 0;
+# SUBSTRING_INDEX()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (substring_index(a,'.',2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substring_index(`a`,'.',2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('www.mysql.com',default);
+select * from t1;
+a b
+www.mysql.com www.mysql
+drop table t1;
+set sql_warnings = 0;
+# SUBSTRING()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (substring(a from 2 for 2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,2,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello el
+drop table t1;
+set sql_warnings = 0;
+# TRIM()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (trim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (trim(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (' aa ',default);
+select * from t1;
+a b
+ aa aa
+drop table t1;
+set sql_warnings = 0;
+# UCASE()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (ucase(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ucase(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQL
+drop table t1;
+set sql_warnings = 0;
+# UNHEX()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (unhex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (unhex(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('4D7953514C',default);
+select * from t1;
+a b
+4D7953514C MySQL
+drop table t1;
+set sql_warnings = 0;
+# UPPER()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (upper(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ucase(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQL
+drop table t1;
+set sql_warnings = 0;
+# WEIGHT_STRING()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (weight_string(a as char(4))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (weight_string(`a`,0,4,65)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQ
+drop table t1;
+set sql_warnings = 0;
+#
+# CONTROL FLOW FUNCTIONS
+#
+# CASE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(16) generated always as (case a when NULL then 'asd' when 'b' then 'B' else a end) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(16) GENERATED ALWAYS AS (case `a` when NULL then 'asd' when 'b' then 'B' else `a` end) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (NULL,default);
+insert into t1 values ('b',default);
+insert into t1 values ('c',default);
+select * from t1;
+a b
+NULL NULL
+b B
+c c
+drop table t1;
+set sql_warnings = 0;
+# IF
+set sql_warnings = 1;
+create table t1 (a int, b int, c int generated always as (if(a=1,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (if(`a` = 1,`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,2,default);
+insert into t1 values (3,4,default);
+select * from t1;
+a b c
+1 2 1
+3 4 4
+drop table t1;
+set sql_warnings = 0;
+# IFNULL
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(10) generated always as (ifnull(a,'DEFAULT')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(10) GENERATED ALWAYS AS (ifnull(`a`,'DEFAULT')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (NULL,'adf',default);
+insert into t1 values ('a','adf',default);
+select * from t1;
+a b c
+NULL adf DEFAULT
+a adf a
+drop table t1;
+set sql_warnings = 0;
+# NULLIF
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (nullif(a,'DEFAULT')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (nullif(`a`,'DEFAULT')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('DEFAULT',default);
+insert into t1 values ('a',default);
+select * from t1;
+a b
+DEFAULT NULL
+a a
+drop table t1;
+set sql_warnings = 0;
+#
+# OPERATORS
+#
+# AND, &&
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a>0 && a<2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` > 0 and `a` < 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# BETWEEN ... AND ...
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a between 0 and 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` between 0 and 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# BINARY
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varbinary(10) generated always as (binary a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varbinary(10) GENERATED ALWAYS AS (cast(`a` as char charset binary)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('11',default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 1
+11 11
+drop table t1;
+set sql_warnings = 0;
+# &
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a & 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` & 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+0 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# ~
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (~a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (~`a`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+Warnings:
+Warning 1264 Out of range value for column 'b' at row 1
+select * from t1;
+a b
+1 2147483647
+drop table t1;
+set sql_warnings = 0;
+# |
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a | 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` | 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 5
+1 5
+2 7
+drop table t1;
+set sql_warnings = 0;
+# ^
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a ^ 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` ^ 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 5
+1 4
+2 7
+drop table t1;
+set sql_warnings = 0;
+# DIV
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a div 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` DIV 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (7,default);
+select * from t1;
+a b
+1 0
+7 1
+drop table t1;
+set sql_warnings = 0;
+# <=>
+set sql_warnings = 1;
+create table t1 (a int, b int, c bool generated always as (a <=> b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <=> `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,1,default);
+insert into t1 values (NULL,NULL,default);
+insert into t1 values (1,NULL,default);
+select * from t1;
+a b c
+1 1 1
+1 NULL 0
+NULL NULL 1
+drop table t1;
+set sql_warnings = 0;
+# =
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a=b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` = `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 1
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# >=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a >= b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` >= `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 1
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# >
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a > b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` > `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 0
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# IS NOT NULL
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a is not null) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` is not null) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (NULL,default);
+select * from t1;
+a b
+1 1
+NULL 0
+drop table t1;
+set sql_warnings = 0;
+# IS NULL
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a is null) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` is null) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (NULL,default);
+select * from t1;
+a b
+1 0
+NULL 1
+drop table t1;
+set sql_warnings = 0;
+# <<
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a << 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` << 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (3,default);
+select * from t1;
+a b
+1 4
+3 12
+drop table t1;
+set sql_warnings = 0;
+# <=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a <= b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <= `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 0
+b b 1
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# <
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a < b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` < `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 0
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# NOT BETWEEN ... AND ...
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a not between 0 and 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` not between 0 and 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 1
+1 0
+drop table t1;
+set sql_warnings = 0;
+# <>
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a <> b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <> `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 1
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# !=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a != b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <> `b`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 1
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# ||, OR
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a>5 || a<3) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` > 5 or `a` < 3) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (4,default);
+select * from t1;
+a b
+1 1
+4 0
+drop table t1;
+set sql_warnings = 0;
+# >>
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a >> 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` >> 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (8,default);
+insert into t1 values (3,default);
+select * from t1;
+a b
+3 0
+8 2
+drop table t1;
+set sql_warnings = 0;
+# XOR
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a xor 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` xor 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 1
+1 0
+2 0
+drop table t1;
+set sql_warnings = 0;
+#
+# DATE AND TIME FUNCTIONS
+#
+# ADDDATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (adddate(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` + interval 1 month) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-09-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# ADDTIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (addtime(a,'02:00:00')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (addtime(`a`,'02:00:00')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-31 02:00:00
+drop table t1;
+set sql_warnings = 0;
+# CONVERT_TZ()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (convert_tz(a,'MET','UTC')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (convert_tz(`a`,'MET','UTC')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-30 22:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE_ADD()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date_add(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` + interval 1 month) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-09-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(64) generated always as (date_format(a,'%W %M %D')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(64) GENERATED ALWAYS AS (date_format(`a`,'%W %M %D')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 Sunday August 31st
+drop table t1;
+set sql_warnings = 0;
+# DATE_SUB()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date_sub(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` - interval 1 month) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-07-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (cast(`a` as date)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:00:00',default);
+select * from t1;
+a b
+2008-08-31 02:00:00 2008-08-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATEDIFF()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (datediff(a,'2000-01-01')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (to_days(`a`) - to_days('2000-01-01')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 3165
+drop table t1;
+set sql_warnings = 0;
+# DAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (day(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofmonth(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31
+drop table t1;
+set sql_warnings = 0;
+# DAYNAME()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(10) generated always as (dayname(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (dayname(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 Sunday
+drop table t1;
+set sql_warnings = 0;
+# DAYOFMONTH()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofmonth(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofmonth(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31
+drop table t1;
+set sql_warnings = 0;
+# DAYOFWEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofweek(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofweek(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 1
+drop table t1;
+set sql_warnings = 0;
+# DAYOFYEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofyear(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofyear(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 244
+drop table t1;
+set sql_warnings = 0;
+# EXTRACT
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (extract(year from a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (extract(year from `a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008
+drop table t1;
+set sql_warnings = 0;
+# FROM_DAYS()
+set sql_warnings = 1;
+create table t1 (a bigint, b datetime generated always as (from_days(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (from_days(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (730669,default);
+select * from t1;
+a b
+730669 2000-07-03 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# FROM_UNIXTIME()
+set sql_warnings = 1;
+create table t1 (a bigint, b datetime generated always as (from_unixtime(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (from_unixtime(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1196440219,default);
+select * from t1;
+a b
+1196440219 2007-11-30 19:30:19
+drop table t1;
+set sql_warnings = 0;
+# GET_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(32) generated always as (date_format(a,get_format(DATE,'EUR'))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(32) GENERATED ALWAYS AS (date_format(`a`,get_format(DATE, 'EUR'))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31.08.2008
+drop table t1;
+set sql_warnings = 0;
+# HOUR()
+set sql_warnings = 1;
+create table t1 (a time, b bigint generated always as (hour(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` time DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (hour(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('10:05:03',default);
+select * from t1;
+a b
+10:05:03 10
+drop table t1;
+set sql_warnings = 0;
+# LAST_DAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (last_day(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (last_day(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-02-05',default);
+insert into t1 values ('2003-02-32',default);
+select * from t1;
+a b
+2003-02-05 00:00:00 2003-02-28 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# MAKEDATE()
+set sql_warnings = 1;
+create table t1 (a int, b datetime generated always as (makedate(a,1)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (makedate(`a`,1)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2001,default);
+select * from t1;
+a b
+2001 2001-01-01 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# MAKETIME()
+set sql_warnings = 1;
+create table t1 (a int, b time generated always as (maketime(a,1,3)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (maketime(`a`,1,3)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 12:01:03
+drop table t1;
+set sql_warnings = 0;
+# MICROSECOND()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (microsecond(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (microsecond(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 12:00:00.123456',default);
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 12:00:00 0
+2009-12-31 23:59:59 0
+drop table t1;
+set sql_warnings = 0;
+# MINUTE()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (minute(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (minute(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 59
+drop table t1;
+set sql_warnings = 0;
+# MONTH()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (month(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (month(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 12
+drop table t1;
+set sql_warnings = 0;
+# MONTHNAME()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(16) generated always as (monthname(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(16) GENERATED ALWAYS AS (monthname(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 December
+drop table t1;
+set sql_warnings = 0;
+# PERIOD_ADD()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (period_add(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (period_add(`a`,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (200801,default);
+select * from t1;
+a b
+200801 200803
+drop table t1;
+set sql_warnings = 0;
+# PERIOD_DIFF()
+set sql_warnings = 1;
+create table t1 (a int, b int, c int generated always as (period_diff(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (period_diff(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (200802,200703,default);
+select * from t1;
+a b c
+200802 200703 11
+drop table t1;
+set sql_warnings = 0;
+# QUARTER()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (quarter(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (quarter(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 3
+drop table t1;
+set sql_warnings = 0;
+# SEC_TO_TIME()
+set sql_warnings = 1;
+create table t1 (a bigint, b time generated always as (sec_to_time(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (sec_to_time(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2378,default);
+select * from t1;
+a b
+2378 00:39:38
+drop table t1;
+set sql_warnings = 0;
+# SECOND()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (second(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (second(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('10:05:03',default);
+select * from t1;
+a b
+2010-05-03 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# STR_TO_DATE()
+set sql_warnings = 1;
+create table t1 (a varchar(64), b datetime generated always as (str_to_date(a,'%m/%d/%Y')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(64) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (str_to_date(`a`,'%m/%d/%Y')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('04/30/2004',default);
+select * from t1;
+a b
+04/30/2004 2004-04-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# SUBDATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (subdate(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` - interval 1 month) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-07-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# SUBTIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (subtime(a,'02:00:00')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (subtime(`a`,'02:00:00')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-30 22:00:00
+drop table t1;
+set sql_warnings = 0;
+# TIME_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(32) generated always as (time_format(a,'%r')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(32) GENERATED ALWAYS AS (time_format(`a`,'%r')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:03:04',default);
+select * from t1;
+a b
+2008-08-31 02:03:04 02:03:04 AM
+drop table t1;
+set sql_warnings = 0;
+# TIME_TO_SEC()
+set sql_warnings = 1;
+create table t1 (a time, b bigint generated always as (time_to_sec(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` time DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (time_to_sec(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('22:23:00',default);
+select * from t1;
+a b
+22:23:00 80580
+drop table t1;
+set sql_warnings = 0;
+# TIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b time generated always as (time(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (cast(`a` as time)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:03:04',default);
+select * from t1;
+a b
+2008-08-31 02:03:04 02:03:04
+drop table t1;
+set sql_warnings = 0;
+# TIMEDIFF()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime, c time generated always as (timediff(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime DEFAULT NULL,
+ `c` time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',default);
+select * from t1;
+a b c
+2008-12-31 23:59:59 2008-12-30 01:01:01 46:58:58
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMP()
+set sql_warnings = 1;
+create table t1 (a datetime, b timestamp generated always as (timestamp(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` timestamp GENERATED ALWAYS AS (cast(`a` as datetime)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-12-31',default);
+select * from t1;
+a b
+2008-12-31 00:00:00 2008-12-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMPADD()
+set sql_warnings = 1;
+create table t1 (a datetime, b timestamp generated always as (timestampadd(minute,1,a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` timestamp GENERATED ALWAYS AS (`a` + interval 1 minute) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-01-02',default);
+select * from t1;
+a b
+2003-01-02 00:00:00 2003-01-02 00:01:00
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMPDIFF()
+set sql_warnings = 1;
+create table t1 (a timestamp, c bigint generated always as (timestampdiff(MONTH, a, a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` timestamp NULL DEFAULT NULL,
+ `c` bigint(20) GENERATED ALWAYS AS (timestampdiff(MONTH,`a`,`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-02-01',default);
+select * from t1;
+a c
+2003-02-01 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# TO_DAYS()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (to_days(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (to_days(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2007-10-07',default);
+select * from t1;
+a b
+2007-10-07 00:00:00 733321
+drop table t1;
+set sql_warnings = 0;
+# WEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (week(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (week(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 35
+drop table t1;
+set sql_warnings = 0;
+# WEEKDAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (weekday(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (weekday(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# WEEKOFYEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (weekofyear(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (week(`a`,3)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 36
+drop table t1;
+set sql_warnings = 0;
+# YEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (year(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (year(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 2008
+drop table t1;
+set sql_warnings = 0;
+# YEARWEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (yearweek(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (yearweek(`a`,0)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 200835
+drop table t1;
+set sql_warnings = 0;
+#
+# FULL TEXT SEARCH FUNCTIONS
+#
+# None.
+#
+# CAST FUNCTIONS AND OPERATORS
+#
+# CAST()
+set sql_warnings = 1;
+create table t1 (a int, b bigint unsigned generated always as (cast(a as unsigned)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` bigint(20) unsigned GENERATED ALWAYS AS (cast(`a` as unsigned)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+Warnings:
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+select * from t1;
+a b
+-1 18446744073709551615
+1 1
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# Convert()
+set sql_warnings = 1;
+create table t1 (a int, b bigint unsigned generated always as (convert(a,unsigned)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` bigint(20) unsigned GENERATED ALWAYS AS (cast(`a` as unsigned)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+Warnings:
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+select * from t1;
+a b
+-1 18446744073709551615
+1 1
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+#
+# XML FUNCTIONS
+#
+# ExtractValue()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (ExtractValue(a,'/b')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (extractvalue(`a`,'/b')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('<b>text</b>',default);
+select * from t1;
+a b
+<b>text</b> text
+drop table t1;
+set sql_warnings = 0;
+# None.
+#
+# OTHER FUNCTIONS
+#
+# AES_DECRYPT(), AES_ENCRYPT()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (aes_encrypt(aes_decrypt(a,'adf'),'adf')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (aes_encrypt(aes_decrypt(`a`,'adf'),'adf')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL NULL
+drop table t1;
+set sql_warnings = 0;
+# BIT_COUNT()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (bit_count(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (bit_count(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (5,default);
+select * from t1;
+a b
+5 2
+drop table t1;
+set sql_warnings = 0;
+# CHARSET()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (charset(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (charset(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc latin1
+drop table t1;
+set sql_warnings = 0;
+# COERCIBILITY()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b int generated always as (coercibility(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (coercibility(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 2
+drop table t1;
+set sql_warnings = 0;
+# COLLATION()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (collation(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (collation(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc latin1_swedish_ci
+drop table t1;
+set sql_warnings = 0;
+# COMPRESS(), UNCOMPRESS()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (uncompress(compress(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (uncompress(compress(`a`))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# ENCODE(), DECODE()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (decode(encode(a,'abc'),'abc')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (decode(encode(`a`,'abc'),'abc')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# DEFAULT()
+set sql_warnings = 1;
+create table t1 (a varchar(1024) default 'aaa', b varchar(1024) generated always as (ifnull(a,default(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT 'aaa',
+ `b` varchar(1024) GENERATED ALWAYS AS (ifnull(`a`,default(`a`))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('any value',default);
+select * from t1;
+a b
+any value any value
+drop table t1;
+set sql_warnings = 0;
+# INET_ATON(), INET_NTOA()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (inet_ntoa(inet_aton(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (inet_ntoa(inet_aton(`a`))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('127.0.0.1',default);
+select * from t1;
+a b
+127.0.0.1 127.0.0.1
+drop table t1;
+set sql_warnings = 0;
+# MD5()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varbinary(32) generated always as (md5(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varbinary(32) GENERATED ALWAYS AS (md5(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('testing',default);
+select * from t1;
+a b
+testing ae2b1fca515949e5d54fb22b8ed95575
+drop table t1;
+set sql_warnings = 0;
+# PASSWORD()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (password(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (password(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('badpwd',default);
+select * from t1;
+a b
+badpwd *AAB3E285149C0135D51A520E1940DD3263DC008C
+drop table t1;
+set sql_warnings = 0;
+# SHA1()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha1(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc a9993e364706816aba3e25717850c26c9cd0d89d
+drop table t1;
+set sql_warnings = 0;
+# SHA()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha(`a`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc a9993e364706816aba3e25717850c26c9cd0d89d
+drop table t1;
+set sql_warnings = 0;
+# SHA2()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha2(a,224)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha2(`a`,224)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7
+drop table t1;
+set sql_warnings = 0;
+# UNCOMPRESSED_LENGTH()
+set sql_warnings = 1;
+create table t1 (a char, b varchar(1024) generated always as (uncompressed_length(compress(repeat(a,30)))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(1) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (uncompressed_length(compress(repeat(`a`,30)))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a',default);
+select * from t1;
+a b
+a 30
+drop table t1;
+set sql_warnings = 0;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result
new file mode 100644
index 00000000..8553f87d
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result
@@ -0,0 +1,3003 @@
+SET @@session.default_storage_engine = 'MyISAM';
+set time_zone="+03:00";
+#
+# NUMERIC FUNCTIONS
+#
+# ABS()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (abs(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (abs(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1, default);
+select * from t1;
+a b
+-1 1
+drop table t1;
+set sql_warnings = 0;
+# ACOS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(acos(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(acos(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1, default);
+insert into t1 values (1.0001,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+0 1.570796
+1 0
+1.0001 NULL
+drop table t1;
+set sql_warnings = 0;
+# ASIN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(asin(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(asin(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0.2, default);
+insert into t1 values (1.0001,default);
+select * from t1;
+a b
+0.2 0.201358
+1.0001 NULL
+drop table t1;
+set sql_warnings = 0;
+#ATAN
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(atan(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`,`b`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,2,default);
+insert into t1 values (format(PI(),6),0,default);
+select * from t1;
+a b c
+-2 2 -0.785398
+3.141593 0 1.570796
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, c double generated always as (format(atan(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,default);
+insert into t1 values (format(PI(),6),default);
+select * from t1;
+a c
+-2 -1.107149
+3.141593 1.262627
+drop table t1;
+set sql_warnings = 0;
+# ATAN2
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(atan2(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(atan(`a`,`b`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-2,2,default);
+insert into t1 values (format(PI(),6),0,default);
+select * from t1;
+a b c
+-2 2 -0.785398
+3.141593 0 1.570796
+drop table t1;
+set sql_warnings = 0;
+# CEIL()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (ceil(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (ceiling(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.23,default);
+insert into t1 values (-1.23,default);
+select * from t1;
+a b
+-1.23 -1
+1.23 2
+drop table t1;
+set sql_warnings = 0;
+# CONV()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int, c int, d varchar(10) generated always as (conv(a,b,c)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(10) GENERATED ALWAYS AS (conv(`a`,`b`,`c`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a',16,2,default);
+insert into t1 values ('6e',18,8,default);
+insert into t1 values (-17,10,-18,default);
+insert into t1 values (10+'10'+'10'+0xa,10,10,default);
+select * from t1;
+a b c d
+-17 10 -18 -H
+40 10 10 40
+6e 18 8 172
+a 16 2 1010
+drop table t1;
+set sql_warnings = 0;
+# COS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(cos(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(cos(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+select * from t1;
+a b
+3.141593 -1
+drop table t1;
+set sql_warnings = 0;
+# COT()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(cot(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(cot(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 -1.572673
+drop table t1;
+set sql_warnings = 0;
+# CRC32()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (crc32(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (crc32(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+insert into t1 values ('mysql',default);
+select * from t1;
+a b
+MySQL 3259397556
+mysql 2501908538
+drop table t1;
+set sql_warnings = 0;
+# DEGREES()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(degrees(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(degrees(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+insert into t1 values (format(PI()/2,6),default);
+select * from t1;
+a b
+1.570796 89.999981
+3.141593 180.00002
+drop table t1;
+set sql_warnings = 0;
+# /
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a/2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` / 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+select * from t1;
+a b
+2 1
+drop table t1;
+set sql_warnings = 0;
+# EXP()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(exp(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(exp(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+-2 0.135335
+0 1
+2 7.389056
+drop table t1;
+set sql_warnings = 0;
+# FLOOR()
+set sql_warnings = 1;
+create table t1 (a double, b bigint generated always as (floor(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (floor(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.23,default);
+insert into t1 values (-1.23,default);
+select * from t1;
+a b
+-1.23 -2
+1.23 1
+drop table t1;
+set sql_warnings = 0;
+# LN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(ln(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(ln(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG()
+set sql_warnings = 1;
+create table t1 (a double, b double, c double generated always as (format(log(a,b),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` double GENERATED ALWAYS AS (format(log(`a`,`b`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,65536,default);
+insert into t1 values (10,100,default);
+insert into t1 values (1,100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b c
+1 100 NULL
+10 100 2
+2 65536 16
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG2()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log2(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log2(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (65536,default);
+insert into t1 values (-100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-100 NULL
+65536 16
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# LOG10()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(log10(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(log10(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+insert into t1 values (100,default);
+insert into t1 values (-100,default);
+Warnings:
+Warning 1365 Division by 0
+select * from t1;
+a b
+-100 NULL
+100 2
+2 0.30103
+Warning 1365 Division by 0
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# -
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a-1) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` - 1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2,default);
+select * from t1;
+a b
+2 1
+drop table t1;
+set sql_warnings = 0;
+# MOD()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (mod(a,10)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 10) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (11,default);
+select * from t1;
+a b
+1 1
+11 1
+drop table t1;
+set sql_warnings = 0;
+# %
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a % 10) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` MOD 10) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (11,default);
+select * from t1;
+a b
+1 1
+11 1
+drop table t1;
+set sql_warnings = 0;
+# OCT()
+set sql_warnings = 1;
+create table t1 (a double, b varchar(10) generated always as (oct(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (conv(`a`,10,8)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 14
+drop table t1;
+set sql_warnings = 0;
+# PI()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(PI()*a*a,6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(pi() * `a` * `a`,6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 3.141593
+drop table t1;
+set sql_warnings = 0;
+# +
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a+1) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 2
+drop table t1;
+set sql_warnings = 0;
+# POW, POWER
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (pow(a,2)) virtual, c int generated always as (power(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (pow(`a`,2)) VIRTUAL,
+ `c` int(11) GENERATED ALWAYS AS (pow(`a`,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default,default);
+insert into t1 values (2,default,default);
+select * from t1;
+a b c
+1 1 1
+2 4 4
+drop table t1;
+set sql_warnings = 0;
+# RADIANS()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(radians(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(radians(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (90,default);
+select * from t1;
+a b
+90 1.570796
+drop table t1;
+set sql_warnings = 0;
+# ROUND()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (round(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (round(`a`,0)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1.23,default);
+insert into t1 values (-1.58,default);
+insert into t1 values (1.58,default);
+select * from t1;
+a b
+-1.23 -1
+-1.58 -2
+1.58 2
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a double, b double, c int generated always as (round(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (round(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.298,1,default);
+insert into t1 values (1.298,0,default);
+insert into t1 values (23.298,-1,default);
+select * from t1;
+a b c
+1.298 0 1
+1.298 1 1
+23.298 -1 20
+drop table t1;
+set sql_warnings = 0;
+# SIGN()
+set sql_warnings = 1;
+create table t1 (a double, b int generated always as (sign(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (sign(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-32,default);
+insert into t1 values (0,default);
+insert into t1 values (234,default);
+select * from t1;
+a b
+-32 -1
+0 0
+234 1
+drop table t1;
+set sql_warnings = 0;
+# SIN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(sin(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(sin(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI()/2,6),default);
+select * from t1;
+a b
+1.570796 1
+drop table t1;
+set sql_warnings = 0;
+# SQRT()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(sqrt(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(sqrt(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (4,default);
+insert into t1 values (20,default);
+insert into t1 values (-16,default);
+select * from t1;
+a b
+-16 NULL
+20 4.472136
+4 2
+drop table t1;
+set sql_warnings = 0;
+# TAN()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (format(tan(a),6)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (format(tan(`a`),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (format(PI(),6),default);
+insert into t1 values (format(PI()+1,6),default);
+select * from t1;
+a b
+3.141593 0
+4.141593 1.557409
+drop table t1;
+set sql_warnings = 0;
+# *
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (a*3) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (`a` * 3) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 0
+1 3
+2 6
+drop table t1;
+set sql_warnings = 0;
+# TRUNCATE()
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (truncate(a,4)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (truncate(`a`,4)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1.223,default);
+insert into t1 values (1.999,default);
+insert into t1 values (1.999,default);
+insert into t1 values (122,default);
+select * from t1;
+a b
+1.223 1.223
+1.999 1.999
+1.999 1.999
+122 122
+drop table t1;
+set sql_warnings = 0;
+# Unary -
+set sql_warnings = 1;
+create table t1 (a double, b double generated always as (-a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` double GENERATED ALWAYS AS (-`a`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+select * from t1;
+a b
+-1 1
+1 -1
+drop table t1;
+set sql_warnings = 0;
+#
+# STRING FUNCTIONS
+#
+# ASCII()
+set sql_warnings = 1;
+create table t1 (a char(2), b int generated always as (ascii(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(2) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (ascii(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2',default);
+insert into t1 values (2,default);
+insert into t1 values ('dx',default);
+select * from t1;
+a b
+2 50
+2 50
+dx 100
+drop table t1;
+set sql_warnings = 0;
+# BIN()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (bin(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (conv(`a`,10,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 1100
+drop table t1;
+set sql_warnings = 0;
+# BIT_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (bit_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (bit_length(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 32
+drop table t1;
+set sql_warnings = 0;
+# CHAR_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (char_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (char_length(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# CHAR()
+set sql_warnings = 1;
+create table t1 (a int, b int, c varbinary(10) generated always as (char(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` varbinary(10) GENERATED ALWAYS AS (char(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (77,121,default);
+select * from t1;
+a b c
+77 121 My
+drop table t1;
+set sql_warnings = 0;
+# CHARACTER_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (character_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (char_length(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# CONCAT_WS()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (concat_ws(',',a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (concat_ws(',',`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',default);
+select * from t1;
+a b c
+value1 value2 value1,value2
+drop table t1;
+set sql_warnings = 0;
+# CONCAT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (concat(a,',',b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (concat(`a`,',',`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',default);
+select * from t1;
+a b c
+value1 value2 value1,value2
+drop table t1;
+set sql_warnings = 0;
+# ELT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int, d varchar(10) generated always as (elt(c,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(10) GENERATED ALWAYS AS (elt(`c`,`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('value1','value2',1,default);
+insert into t1 values ('value1','value2',2,default);
+select * from t1;
+a b c d
+value1 value2 1 value1
+value1 value2 2 value2
+drop table t1;
+set sql_warnings = 0;
+# EXPORT_SET()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (export_set(a,'1','0','',10)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (export_set(`a`,'1','0','',10)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (6,default);
+select * from t1;
+a b
+6 0110000000
+drop table t1;
+set sql_warnings = 0;
+# FIELD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (field('aa',a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (field('aa',`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('aa','bb',default);
+insert into t1 values ('bb','aa',default);
+select * from t1;
+a b c
+aa bb 1
+bb aa 2
+drop table t1;
+set sql_warnings = 0;
+# FIND_IN_SET()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (find_in_set(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (find_in_set(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('aa','aa,bb,cc',default);
+insert into t1 values ('aa','bb,aa,cc',default);
+select * from t1;
+a b c
+aa aa,bb,cc 1
+aa bb,aa,cc 2
+drop table t1;
+set sql_warnings = 0;
+# FORMAT()
+set sql_warnings = 1;
+create table t1 (a double, b varchar(20) generated always as (format(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` double DEFAULT NULL,
+ `b` varchar(20) GENERATED ALWAYS AS (format(`a`,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12332.123456,default);
+select * from t1;
+a b
+12332.123456 12,332.12
+drop table t1;
+set sql_warnings = 0;
+# HEX()
+set sql_warnings = 1;
+create table t1 (a int, b varchar(10) generated always as (hex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (hex(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (17,default);
+select * from t1;
+a b
+17 11
+drop table t1;
+set sql_warnings = 0;
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (hex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (hex(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 616263
+drop table t1;
+set sql_warnings = 0;
+# INSERT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(20) generated always as (insert(a,length(a),length(b),b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(20) GENERATED ALWAYS AS (insert(`a`,octet_length(`a`),octet_length(`b`),`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('start,','end',default);
+select * from t1;
+a b c
+start, end startend
+drop table t1;
+set sql_warnings = 0;
+# INSTR()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int generated always as (instr(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (locate(`b`,`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar,','bar',default);
+insert into t1 values ('xbar,','foobar',default);
+select * from t1;
+a b c
+foobarbar, bar 4
+xbar, foobar 0
+drop table t1;
+set sql_warnings = 0;
+# LCASE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lcase(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lcase(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL mysql
+drop table t1;
+set sql_warnings = 0;
+# LEFT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(5) generated always as (left(a,5)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(5) GENERATED ALWAYS AS (left(`a`,5)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar fooba
+drop table t1;
+set sql_warnings = 0;
+# LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int generated always as (length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (octet_length(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a like 'H%o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` like 'H%o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 1
+MySQL 0
+drop table t1;
+set sql_warnings = 0;
+# LOCATE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (locate('bar',a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (locate('bar',`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar 4
+drop table t1;
+set sql_warnings = 0;
+# LOWER()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lower(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lcase(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL mysql
+drop table t1;
+set sql_warnings = 0;
+# LPAD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (lpad(a,4,' ')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (lpad(`a`,4,' ')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+insert into t1 values ('M',default);
+select * from t1;
+a b
+M M
+MySQL MySQ
+drop table t1;
+set sql_warnings = 0;
+# LTRIM()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (ltrim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ltrim(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (' MySQL',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+ MySQL MySQL
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# MAKE_SET()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c int, d varchar(30) generated always as (make_set(c,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` int(11) DEFAULT NULL,
+ `d` varchar(30) GENERATED ALWAYS AS (make_set(`c`,`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',1,default);
+insert into t1 values ('a','b',3,default);
+select * from t1;
+a b c d
+a b 1 a
+a b 3 a,b
+drop table t1;
+set sql_warnings = 0;
+# MID()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (mid(a,1,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,1,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar fo
+drop table t1;
+set sql_warnings = 0;
+# NOT LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a not like 'H%o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` not like 'H%o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 0
+MySQL 1
+drop table t1;
+set sql_warnings = 0;
+# NOT REGEXP
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a not regexp 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (!(`a` regexp 'H.+o')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('hello',default);
+select * from t1;
+a b
+Hello 0
+hello 0
+drop table t1;
+set sql_warnings = 0;
+# OCTET_LENGTH()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b int generated always as (octet_length(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (octet_length(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('text',default);
+select * from t1;
+a b
+text 4
+drop table t1;
+set sql_warnings = 0;
+# ORD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bigint generated always as (ord(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (ord(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2',default);
+select * from t1;
+a b
+2 50
+drop table t1;
+set sql_warnings = 0;
+# POSITION()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (position('bar' in a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (locate('bar',`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar 4
+drop table t1;
+set sql_warnings = 0;
+# QUOTE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (quote(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (quote(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Don\'t',default);
+select * from t1;
+a b
+Don't 'Don\'t'
+drop table t1;
+set sql_warnings = 0;
+# REGEXP()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a regexp 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` regexp 'H.+o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('hello',default);
+select * from t1;
+a b
+Hello 1
+hello 1
+drop table t1;
+set sql_warnings = 0;
+# REPEAT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (repeat(a,3)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (repeat(`a`,3)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQLMySQLMySQL
+drop table t1;
+set sql_warnings = 0;
+# REPLACE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (replace(a,'aa','bb')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (replace(`a`,'aa','bb')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('maa',default);
+select * from t1;
+a b
+maa mbb
+drop table t1;
+set sql_warnings = 0;
+# REVERSE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(30) generated always as (reverse(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(30) GENERATED ALWAYS AS (reverse(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('maa',default);
+select * from t1;
+a b
+maa aam
+drop table t1;
+set sql_warnings = 0;
+# RIGHT()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (right(a,4)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (right(`a`,4)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('foobarbar',default);
+select * from t1;
+a b
+foobarbar rbar
+drop table t1;
+set sql_warnings = 0;
+# RLIKE()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b bool generated always as (a rlike 'H.+o') virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` regexp 'H.+o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+Hello 1
+MySQL 0
+drop table t1;
+set sql_warnings = 0;
+# RPAD()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (rpad(a,4,'??')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (rpad(`a`,4,'??')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('He',default);
+select * from t1;
+a b
+He He??
+drop table t1;
+set sql_warnings = 0;
+# RTRIM();
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (rtrim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (rtrim(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello ',default);
+select * from t1;
+a b
+Hello Hello
+drop table t1;
+set sql_warnings = 0;
+# SOUNDEX()
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(20) generated always as (soundex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(20) GENERATED ALWAYS AS (soundex(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello H400
+drop table t1;
+set sql_warnings = 0;
+# SOUNDS LIKE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a sounds like b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (soundex(`a`) = soundex(`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello','Hello',default);
+insert into t1 values ('Hello','MySQL',default);
+insert into t1 values ('Hello','hello',default);
+select * from t1;
+a b c
+Hello Hello 1
+Hello MySQL 0
+Hello hello 1
+drop table t1;
+set sql_warnings = 0;
+# SPACE()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (concat(a,space(5))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (concat(`a`,space(5))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello', default);
+select * from t1;
+a b
+Hello Hello
+drop table t1;
+set sql_warnings = 0;
+# STRCMP()
+set sql_warnings = 1;
+create table t1 (a varchar(9), b varchar(9), c tinyint(1) generated always as (strcmp(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(9) DEFAULT NULL,
+ `b` varchar(9) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (strcmp(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello','Hello', default);
+insert into t1 values ('Hello','Hello1', default);
+select * from t1;
+a b c
+Hello Hello 0
+Hello Hello1 -1
+drop table t1;
+set sql_warnings = 0;
+# SUBSTR()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (substr(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello ello
+drop table t1;
+set sql_warnings = 0;
+# SUBSTRING_INDEX()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (substring_index(a,'.',2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substring_index(`a`,'.',2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('www.mysql.com',default);
+select * from t1;
+a b
+www.mysql.com www.mysql
+drop table t1;
+set sql_warnings = 0;
+# SUBSTRING()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (substring(a from 2 for 2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (substr(`a`,2,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('Hello',default);
+select * from t1;
+a b
+Hello el
+drop table t1;
+set sql_warnings = 0;
+# TRIM()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (trim(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (trim(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (' aa ',default);
+select * from t1;
+a b
+ aa aa
+drop table t1;
+set sql_warnings = 0;
+# UCASE()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (ucase(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ucase(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQL
+drop table t1;
+set sql_warnings = 0;
+# UNHEX()
+set sql_warnings = 1;
+create table t1 (a varchar(15), b varchar(10) generated always as (unhex(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(15) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (unhex(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('4D7953514C',default);
+select * from t1;
+a b
+4D7953514C MySQL
+drop table t1;
+set sql_warnings = 0;
+# UPPER()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (upper(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (ucase(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQL
+drop table t1;
+set sql_warnings = 0;
+# WEIGHT_STRING()
+set sql_warnings = 1;
+create table t1 (a varchar(5), b varchar(10) generated always as (weight_string(a as char(4))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(5) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (weight_string(`a`,0,4,65)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MYSQ
+drop table t1;
+set sql_warnings = 0;
+#
+# CONTROL FLOW FUNCTIONS
+#
+# CASE
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(16) generated always as (case a when NULL then 'asd' when 'b' then 'B' else a end) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(16) GENERATED ALWAYS AS (case `a` when NULL then 'asd' when 'b' then 'B' else `a` end) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (NULL,default);
+insert into t1 values ('b',default);
+insert into t1 values ('c',default);
+select * from t1;
+a b
+NULL NULL
+b B
+c c
+drop table t1;
+set sql_warnings = 0;
+# IF
+set sql_warnings = 1;
+create table t1 (a int, b int, c int generated always as (if(a=1,a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (if(`a` = 1,`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,2,default);
+insert into t1 values (3,4,default);
+select * from t1;
+a b c
+1 2 1
+3 4 4
+drop table t1;
+set sql_warnings = 0;
+# IFNULL
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c varchar(10) generated always as (ifnull(a,'DEFAULT')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` varchar(10) GENERATED ALWAYS AS (ifnull(`a`,'DEFAULT')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (NULL,'adf',default);
+insert into t1 values ('a','adf',default);
+select * from t1;
+a b c
+NULL adf DEFAULT
+a adf a
+drop table t1;
+set sql_warnings = 0;
+# NULLIF
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10) generated always as (nullif(a,'DEFAULT')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (nullif(`a`,'DEFAULT')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('DEFAULT',default);
+insert into t1 values ('a',default);
+select * from t1;
+a b
+DEFAULT NULL
+a a
+drop table t1;
+set sql_warnings = 0;
+#
+# OPERATORS
+#
+# AND, &&
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a>0 && a<2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` > 0 and `a` < 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# BETWEEN ... AND ...
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a between 0 and 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` between 0 and 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# BINARY
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varbinary(10) generated always as (binary a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varbinary(10) GENERATED ALWAYS AS (cast(`a` as char charset binary)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('11',default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+1 1
+11 11
+drop table t1;
+set sql_warnings = 0;
+# &
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a & 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` & 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+select * from t1;
+a b
+0 0
+1 1
+drop table t1;
+set sql_warnings = 0;
+# ~
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (~a) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (~`a`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+Warnings:
+Warning 1264 Out of range value for column 'b' at row 1
+select * from t1;
+a b
+1 2147483647
+drop table t1;
+set sql_warnings = 0;
+# |
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a | 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` | 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 5
+1 5
+2 7
+drop table t1;
+set sql_warnings = 0;
+# ^
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a ^ 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` ^ 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (0,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 5
+1 4
+2 7
+drop table t1;
+set sql_warnings = 0;
+# DIV
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a div 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` DIV 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (7,default);
+select * from t1;
+a b
+1 0
+7 1
+drop table t1;
+set sql_warnings = 0;
+# <=>
+set sql_warnings = 1;
+create table t1 (a int, b int, c bool generated always as (a <=> b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <=> `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,1,default);
+insert into t1 values (NULL,NULL,default);
+insert into t1 values (1,NULL,default);
+select * from t1;
+a b c
+1 1 1
+1 NULL 0
+NULL NULL 1
+drop table t1;
+set sql_warnings = 0;
+# =
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a=b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` = `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 1
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# >=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a >= b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` >= `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 1
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# >
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a > b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` > `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a','b',default);
+insert into t1 values ('a','a',default);
+select * from t1;
+a b c
+a a 0
+a b 0
+drop table t1;
+set sql_warnings = 0;
+# IS NOT NULL
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a is not null) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` is not null) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (NULL,default);
+select * from t1;
+a b
+1 1
+NULL 0
+drop table t1;
+set sql_warnings = 0;
+# IS NULL
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a is null) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` is null) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (NULL,default);
+select * from t1;
+a b
+1 0
+NULL 1
+drop table t1;
+set sql_warnings = 0;
+# <<
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a << 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` << 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (3,default);
+select * from t1;
+a b
+1 4
+3 12
+drop table t1;
+set sql_warnings = 0;
+# <=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a <= b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <= `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 0
+b b 1
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# <
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a < b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` < `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 0
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# NOT BETWEEN ... AND ...
+set sql_warnings = 1;
+create table t1 (a int, b bool generated always as (a not between 0 and 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` tinyint(1) GENERATED ALWAYS AS (`a` not between 0 and 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (-1,default);
+insert into t1 values (1,default);
+select * from t1;
+a b
+-1 1
+1 0
+drop table t1;
+set sql_warnings = 0;
+# <>
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a <> b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <> `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 1
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# !=
+set sql_warnings = 1;
+create table t1 (a varchar(10), b varchar(10), c bool generated always as (a != b) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(10) DEFAULT NULL,
+ `b` varchar(10) DEFAULT NULL,
+ `c` tinyint(1) GENERATED ALWAYS AS (`a` <> `b`) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('b','a',default);
+insert into t1 values ('b','b',default);
+insert into t1 values ('b','c',default);
+select * from t1;
+a b c
+b a 1
+b b 0
+b c 1
+drop table t1;
+set sql_warnings = 0;
+# ||, OR
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a>5 || a<3) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` > 5 or `a` < 3) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (4,default);
+select * from t1;
+a b
+1 1
+4 0
+drop table t1;
+set sql_warnings = 0;
+# >>
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a >> 2) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` >> 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (8,default);
+insert into t1 values (3,default);
+select * from t1;
+a b
+3 0
+8 2
+drop table t1;
+set sql_warnings = 0;
+# XOR
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (a xor 5) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` xor 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (0,default);
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+0 1
+1 0
+2 0
+drop table t1;
+set sql_warnings = 0;
+#
+# DATE AND TIME FUNCTIONS
+#
+# ADDDATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (adddate(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` + interval 1 month) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-09-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# ADDTIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (addtime(a,'02:00:00')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (addtime(`a`,'02:00:00')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-31 02:00:00
+drop table t1;
+set sql_warnings = 0;
+# CONVERT_TZ()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (convert_tz(a,'MET','UTC')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (convert_tz(`a`,'MET','UTC')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-30 22:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE_ADD()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date_add(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` + interval 1 month) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-09-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(64) generated always as (date_format(a,'%W %M %D')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(64) GENERATED ALWAYS AS (date_format(`a`,'%W %M %D')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 Sunday August 31st
+drop table t1;
+set sql_warnings = 0;
+# DATE_SUB()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date_sub(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` - interval 1 month) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-07-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (date(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (cast(`a` as date)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:00:00',default);
+select * from t1;
+a b
+2008-08-31 02:00:00 2008-08-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# DATEDIFF()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (datediff(a,'2000-01-01')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (to_days(`a`) - to_days('2000-01-01')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 3165
+drop table t1;
+set sql_warnings = 0;
+# DAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (day(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofmonth(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31
+drop table t1;
+set sql_warnings = 0;
+# DAYNAME()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(10) generated always as (dayname(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(10) GENERATED ALWAYS AS (dayname(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 Sunday
+drop table t1;
+set sql_warnings = 0;
+# DAYOFMONTH()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofmonth(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofmonth(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31
+drop table t1;
+set sql_warnings = 0;
+# DAYOFWEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofweek(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofweek(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 1
+drop table t1;
+set sql_warnings = 0;
+# DAYOFYEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (dayofyear(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (dayofyear(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 244
+drop table t1;
+set sql_warnings = 0;
+# EXTRACT
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (extract(year from a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (extract(year from `a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008
+drop table t1;
+set sql_warnings = 0;
+# FROM_DAYS()
+set sql_warnings = 1;
+create table t1 (a bigint, b datetime generated always as (from_days(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (from_days(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (730669,default);
+select * from t1;
+a b
+730669 2000-07-03 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# FROM_UNIXTIME()
+set sql_warnings = 1;
+create table t1 (a bigint, b datetime generated always as (from_unixtime(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (from_unixtime(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1196440219,default);
+select * from t1;
+a b
+1196440219 2007-11-30 19:30:19
+drop table t1;
+set sql_warnings = 0;
+# GET_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(32) generated always as (date_format(a,get_format(DATE,'EUR'))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(32) GENERATED ALWAYS AS (date_format(`a`,get_format(DATE, 'EUR'))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 31.08.2008
+drop table t1;
+set sql_warnings = 0;
+# HOUR()
+set sql_warnings = 1;
+create table t1 (a time, b bigint generated always as (hour(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` time DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (hour(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('10:05:03',default);
+select * from t1;
+a b
+10:05:03 10
+drop table t1;
+set sql_warnings = 0;
+# LAST_DAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (last_day(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (last_day(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-02-05',default);
+insert into t1 values ('2003-02-32',default);
+select * from t1;
+a b
+2003-02-05 00:00:00 2003-02-28 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# MAKEDATE()
+set sql_warnings = 1;
+create table t1 (a int, b datetime generated always as (makedate(a,1)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (makedate(`a`,1)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2001,default);
+select * from t1;
+a b
+2001 2001-01-01 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# MAKETIME()
+set sql_warnings = 1;
+create table t1 (a int, b time generated always as (maketime(a,1,3)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (maketime(`a`,1,3)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (12,default);
+select * from t1;
+a b
+12 12:01:03
+drop table t1;
+set sql_warnings = 0;
+# MICROSECOND()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (microsecond(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (microsecond(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 12:00:00.123456',default);
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 12:00:00 0
+2009-12-31 23:59:59 0
+drop table t1;
+set sql_warnings = 0;
+# MINUTE()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (minute(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (minute(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 59
+drop table t1;
+set sql_warnings = 0;
+# MONTH()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (month(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (month(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 12
+drop table t1;
+set sql_warnings = 0;
+# MONTHNAME()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(16) generated always as (monthname(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(16) GENERATED ALWAYS AS (monthname(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2009-12-31 23:59:59.000010',default);
+select * from t1;
+a b
+2009-12-31 23:59:59 December
+drop table t1;
+set sql_warnings = 0;
+# PERIOD_ADD()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (period_add(a,2)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (period_add(`a`,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (200801,default);
+select * from t1;
+a b
+200801 200803
+drop table t1;
+set sql_warnings = 0;
+# PERIOD_DIFF()
+set sql_warnings = 1;
+create table t1 (a int, b int, c int generated always as (period_diff(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (period_diff(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (200802,200703,default);
+select * from t1;
+a b c
+200802 200703 11
+drop table t1;
+set sql_warnings = 0;
+# QUARTER()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (quarter(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (quarter(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 3
+drop table t1;
+set sql_warnings = 0;
+# SEC_TO_TIME()
+set sql_warnings = 1;
+create table t1 (a bigint, b time generated always as (sec_to_time(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` bigint(20) DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (sec_to_time(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (2378,default);
+select * from t1;
+a b
+2378 00:39:38
+drop table t1;
+set sql_warnings = 0;
+# SECOND()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (second(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (second(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('10:05:03',default);
+select * from t1;
+a b
+2010-05-03 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# STR_TO_DATE()
+set sql_warnings = 1;
+create table t1 (a varchar(64), b datetime generated always as (str_to_date(a,'%m/%d/%Y')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(64) DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (str_to_date(`a`,'%m/%d/%Y')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('04/30/2004',default);
+select * from t1;
+a b
+04/30/2004 2004-04-30 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# SUBDATE()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (subdate(a,interval 1 month)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (`a` - interval 1 month) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-07-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# SUBTIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime generated always as (subtime(a,'02:00:00')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime GENERATED ALWAYS AS (subtime(`a`,'02:00:00')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31',default);
+select * from t1;
+a b
+2008-08-31 00:00:00 2008-08-30 22:00:00
+drop table t1;
+set sql_warnings = 0;
+# TIME_FORMAT()
+set sql_warnings = 1;
+create table t1 (a datetime, b varchar(32) generated always as (time_format(a,'%r')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` varchar(32) GENERATED ALWAYS AS (time_format(`a`,'%r')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:03:04',default);
+select * from t1;
+a b
+2008-08-31 02:03:04 02:03:04 AM
+drop table t1;
+set sql_warnings = 0;
+# TIME_TO_SEC()
+set sql_warnings = 1;
+create table t1 (a time, b bigint generated always as (time_to_sec(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` time DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (time_to_sec(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('22:23:00',default);
+select * from t1;
+a b
+22:23:00 80580
+drop table t1;
+set sql_warnings = 0;
+# TIME()
+set sql_warnings = 1;
+create table t1 (a datetime, b time generated always as (time(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` time GENERATED ALWAYS AS (cast(`a` as time)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-08-31 02:03:04',default);
+select * from t1;
+a b
+2008-08-31 02:03:04 02:03:04
+drop table t1;
+set sql_warnings = 0;
+# TIMEDIFF()
+set sql_warnings = 1;
+create table t1 (a datetime, b datetime, c time generated always as (timediff(a,b)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` datetime DEFAULT NULL,
+ `c` time GENERATED ALWAYS AS (timediff(`a`,`b`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-12-31 23:59:59.000001','2008-12-30 01:01:01.000002',default);
+select * from t1;
+a b c
+2008-12-31 23:59:59 2008-12-30 01:01:01 46:58:58
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMP()
+set sql_warnings = 1;
+create table t1 (a datetime, b timestamp generated always as (timestamp(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` timestamp GENERATED ALWAYS AS (cast(`a` as datetime)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-12-31',default);
+select * from t1;
+a b
+2008-12-31 00:00:00 2008-12-31 00:00:00
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMPADD()
+set sql_warnings = 1;
+create table t1 (a datetime, b timestamp generated always as (timestampadd(minute,1,a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` timestamp GENERATED ALWAYS AS (`a` + interval 1 minute) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-01-02',default);
+select * from t1;
+a b
+2003-01-02 00:00:00 2003-01-02 00:01:00
+drop table t1;
+set sql_warnings = 0;
+# TIMESTAMPDIFF()
+set sql_warnings = 1;
+create table t1 (a timestamp, c bigint generated always as (timestampdiff(MONTH, a, a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` timestamp NULL DEFAULT NULL,
+ `c` bigint(20) GENERATED ALWAYS AS (timestampdiff(MONTH,`a`,`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2003-02-01',default);
+select * from t1;
+a c
+2003-02-01 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# TO_DAYS()
+set sql_warnings = 1;
+create table t1 (a datetime, b bigint generated always as (to_days(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` bigint(20) GENERATED ALWAYS AS (to_days(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2007-10-07',default);
+select * from t1;
+a b
+2007-10-07 00:00:00 733321
+drop table t1;
+set sql_warnings = 0;
+# WEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (week(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (week(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 35
+drop table t1;
+set sql_warnings = 0;
+# WEEKDAY()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (weekday(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (weekday(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 0
+drop table t1;
+set sql_warnings = 0;
+# WEEKOFYEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (weekofyear(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (week(`a`,3)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 36
+drop table t1;
+set sql_warnings = 0;
+# YEAR()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (year(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (year(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 2008
+drop table t1;
+set sql_warnings = 0;
+# YEARWEEK()
+set sql_warnings = 1;
+create table t1 (a datetime, b int generated always as (yearweek(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` datetime DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (yearweek(`a`,0)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('2008-09-01',default);
+select * from t1;
+a b
+2008-09-01 00:00:00 200835
+drop table t1;
+set sql_warnings = 0;
+#
+# FULL TEXT SEARCH FUNCTIONS
+#
+# None.
+#
+# CAST FUNCTIONS AND OPERATORS
+#
+# CAST()
+set sql_warnings = 1;
+create table t1 (a int, b bigint unsigned generated always as (cast(a as unsigned)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` bigint(20) unsigned GENERATED ALWAYS AS (cast(`a` as unsigned)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+Warnings:
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+select * from t1;
+a b
+-1 18446744073709551615
+1 1
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+# Convert()
+set sql_warnings = 1;
+create table t1 (a int, b bigint unsigned generated always as (convert(a,unsigned)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` bigint(20) unsigned GENERATED ALWAYS AS (cast(`a` as unsigned)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (-1,default);
+Warnings:
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+select * from t1;
+a b
+-1 18446744073709551615
+1 1
+Note 1105 Cast to unsigned converted negative integer to it's positive complement
+Warnings:
+drop table t1;
+set sql_warnings = 0;
+#
+# XML FUNCTIONS
+#
+# ExtractValue()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (ExtractValue(a,'/b')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (extractvalue(`a`,'/b')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('<b>text</b>',default);
+select * from t1;
+a b
+<b>text</b> text
+drop table t1;
+set sql_warnings = 0;
+# None.
+#
+# OTHER FUNCTIONS
+#
+# AES_DECRYPT(), AES_ENCRYPT()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (aes_encrypt(aes_decrypt(a,'adf'),'adf')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (aes_encrypt(aes_decrypt(`a`,'adf'),'adf')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL NULL
+drop table t1;
+set sql_warnings = 0;
+# BIT_COUNT()
+set sql_warnings = 1;
+create table t1 (a int, b int generated always as (bit_count(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (bit_count(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (5,default);
+select * from t1;
+a b
+5 2
+drop table t1;
+set sql_warnings = 0;
+# CHARSET()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (charset(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (charset(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc latin1
+drop table t1;
+set sql_warnings = 0;
+# COERCIBILITY()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b int generated always as (coercibility(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (coercibility(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 2
+drop table t1;
+set sql_warnings = 0;
+# COLLATION()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (collation(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (collation(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc latin1_swedish_ci
+drop table t1;
+set sql_warnings = 0;
+# COMPRESS(), UNCOMPRESS()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (uncompress(compress(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (uncompress(compress(`a`))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# ENCODE(), DECODE()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (decode(encode(a,'abc'),'abc')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (decode(encode(`a`,'abc'),'abc')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL MySQL
+drop table t1;
+set sql_warnings = 0;
+# DEFAULT()
+set sql_warnings = 1;
+create table t1 (a varchar(1024) default 'aaa', b varchar(1024) generated always as (ifnull(a,default(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT 'aaa',
+ `b` varchar(1024) GENERATED ALWAYS AS (ifnull(`a`,default(`a`))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('any value',default);
+select * from t1;
+a b
+any value any value
+drop table t1;
+set sql_warnings = 0;
+# INET_ATON(), INET_NTOA()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (inet_ntoa(inet_aton(a))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (inet_ntoa(inet_aton(`a`))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('127.0.0.1',default);
+select * from t1;
+a b
+127.0.0.1 127.0.0.1
+drop table t1;
+set sql_warnings = 0;
+# MD5()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varbinary(32) generated always as (md5(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varbinary(32) GENERATED ALWAYS AS (md5(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('testing',default);
+select * from t1;
+a b
+testing ae2b1fca515949e5d54fb22b8ed95575
+drop table t1;
+set sql_warnings = 0;
+# PASSWORD()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (password(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (password(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('badpwd',default);
+select * from t1;
+a b
+badpwd *AAB3E285149C0135D51A520E1940DD3263DC008C
+drop table t1;
+set sql_warnings = 0;
+# SHA1()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha1(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc a9993e364706816aba3e25717850c26c9cd0d89d
+drop table t1;
+set sql_warnings = 0;
+# SHA()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha(a)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha(`a`)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc a9993e364706816aba3e25717850c26c9cd0d89d
+drop table t1;
+set sql_warnings = 0;
+# SHA2()
+set sql_warnings = 1;
+create table t1 (a varchar(1024), b varchar(1024) generated always as (sha2(a,224)) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (sha2(`a`,224)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('abc',default);
+select * from t1;
+a b
+abc 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7
+drop table t1;
+set sql_warnings = 0;
+# UNCOMPRESSED_LENGTH()
+set sql_warnings = 1;
+create table t1 (a char, b varchar(1024) generated always as (uncompressed_length(compress(repeat(a,30)))) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` char(1) DEFAULT NULL,
+ `b` varchar(1024) GENERATED ALWAYS AS (uncompressed_length(compress(repeat(`a`,30)))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values ('a',default);
+select * from t1;
+a b
+a 30
+drop table t1;
+set sql_warnings = 0;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_trigger_sp_innodb.result b/mysql-test/suite/gcol/r/gcol_trigger_sp_innodb.result
new file mode 100644
index 00000000..60dce012
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_trigger_sp_innodb.result
@@ -0,0 +1,94 @@
+SET @@session.default_storage_engine = 'InnoDB';
+create table t1 (a int,
+b int generated always as (a/10) virtual,
+c int generated always as (a/10) stored);
+create table t2 (a timestamp);
+create trigger trg1 before insert on t1 for each row
+begin
+if (new.b < 10) then
+set new.a:= 100;
+set new.b:= 9;
+set new.c:= 9;
+end if;
+if (new.c > 50) then
+set new.a:= 500;
+end if;
+end|
+create trigger trg2 after insert on t1 for each row
+begin
+if (new.b >= 60) then
+insert into t2 values (now());
+end if;
+end|
+create function f1()
+returns int
+begin
+declare sum1 int default '0';
+declare cur1 cursor for select sum(b) from t1;
+open cur1;
+fetch cur1 into sum1;
+close cur1;
+return sum1;
+end|
+set sql_warnings = 1;
+insert into t1 (a) values (200);
+select * from t1;
+a b c
+200 20 20
+select * from t2;
+a
+insert into t1 (a) values (10);
+select * from t1;
+a b c
+100 10 10
+200 20 20
+select * from t2;
+a
+insert into t1 (a) values (600);
+select * from t1;
+a b c
+100 10 10
+200 20 20
+500 50 50
+select * from t2;
+a
+select f1();
+f1()
+80
+set sql_warnings = 0;
+drop trigger trg1;
+drop trigger trg2;
+drop table t2;
+create procedure p1()
+begin
+declare i int default '0';
+create table t2 like t1;
+insert into t2 (a) values (100), (200);
+begin
+declare cur1 cursor for select sum(c) from t2;
+open cur1;
+fetch cur1 into i;
+close cur1;
+if (i=30) then
+insert into t1 values (300,default,default);
+end if;
+end;
+end|
+delete from t1;
+call p1();
+select * from t2;
+a b c
+100 10 10
+200 20 20
+select * from t1;
+a b c
+300 30 30
+drop table t1,t2;
+drop procedure p1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_trigger_sp_myisam.result b/mysql-test/suite/gcol/r/gcol_trigger_sp_myisam.result
new file mode 100644
index 00000000..a5e3bda2
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_trigger_sp_myisam.result
@@ -0,0 +1,94 @@
+SET @@session.default_storage_engine = 'MyISAM';
+create table t1 (a int,
+b int generated always as (a/10) virtual,
+c int generated always as (a/10) stored);
+create table t2 (a timestamp);
+create trigger trg1 before insert on t1 for each row
+begin
+if (new.b < 10) then
+set new.a:= 100;
+set new.b:= 9;
+set new.c:= 9;
+end if;
+if (new.c > 50) then
+set new.a:= 500;
+end if;
+end|
+create trigger trg2 after insert on t1 for each row
+begin
+if (new.b >= 60) then
+insert into t2 values (now());
+end if;
+end|
+create function f1()
+returns int
+begin
+declare sum1 int default '0';
+declare cur1 cursor for select sum(b) from t1;
+open cur1;
+fetch cur1 into sum1;
+close cur1;
+return sum1;
+end|
+set sql_warnings = 1;
+insert into t1 (a) values (200);
+select * from t1;
+a b c
+200 20 20
+select * from t2;
+a
+insert into t1 (a) values (10);
+select * from t1;
+a b c
+100 10 10
+200 20 20
+select * from t2;
+a
+insert into t1 (a) values (600);
+select * from t1;
+a b c
+100 10 10
+200 20 20
+500 50 50
+select * from t2;
+a
+select f1();
+f1()
+80
+set sql_warnings = 0;
+drop trigger trg1;
+drop trigger trg2;
+drop table t2;
+create procedure p1()
+begin
+declare i int default '0';
+create table t2 like t1;
+insert into t2 (a) values (100), (200);
+begin
+declare cur1 cursor for select sum(c) from t2;
+open cur1;
+fetch cur1 into i;
+close cur1;
+if (i=30) then
+insert into t1 values (300,default,default);
+end if;
+end;
+end|
+delete from t1;
+call p1();
+select * from t2;
+a b c
+100 10 10
+200 20 20
+select * from t1;
+a b c
+300 30 30
+drop table t1,t2;
+drop procedure p1;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_update.result b/mysql-test/suite/gcol/r/gcol_update.result
new file mode 100644
index 00000000..35e0b3e8
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_update.result
@@ -0,0 +1,39 @@
+connect purge_control,localhost,root;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+vchar char(2) as (substr(f3,2,2)) virtual,
+primary key(f1, f3(5)), index(vchar))engine=innodb;
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+connection purge_control;
+COMMIT;
+InnoDB 0 transactions not purged
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+drop table t1;
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+vchar char(2) as (substr(f3,2,2)) virtual,
+primary key(f1, f3(5)), index(vchar, f3(2)))engine=innodb;
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+connection purge_control;
+COMMIT;
+InnoDB 0 transactions not purged
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+drop table t1;
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+vchar blob as (f3) virtual,
+primary key(f1, f3(5)), index(vchar(3)))engine=innodb;
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+connection purge_control;
+COMMIT;
+InnoDB 0 transactions not purged
+disconnect purge_control;
+connection default;
+drop table t1;
diff --git a/mysql-test/suite/gcol/r/gcol_view_innodb.result b/mysql-test/suite/gcol/r/gcol_view_innodb.result
new file mode 100644
index 00000000..15e1cfeb
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_view_innodb.result
@@ -0,0 +1,322 @@
+SET @@session.default_storage_engine = 'InnoDB';
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (1), (2), (2), (3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create view v1 (d,e) as select abs(b), abs(c) from t1;
+select d,e from v1;
+d e
+1 1
+1 1
+2 2
+2 2
+3 3
+select is_updatable from information_schema.views where table_name='v1';
+is_updatable
+NO
+explain select d,e from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL X
+create algorithm=temptable view v2 (d,e) as select abs(b), abs(c) from t1;
+show create view v2;
+View Create View character_set_client collation_connection
+v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select abs(`t1`.`b`) AS `d`,abs(`t1`.`c`) AS `e` from `t1` latin1 latin1_swedish_ci
+select d,e from v2;
+d e
+1 1
+1 1
+2 2
+2 2
+3 3
+explain select d,e from v2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X
+create view v3 (d,e) as select d*2, e*2 from v1;
+select * from v3;
+d e
+2 2
+2 2
+4 4
+4 4
+6 6
+explain select * from v3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL X
+drop view v1,v2,v3;
+drop table t1;
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (1), (2), (3);
+create view v1 as select distinct b from t1;
+select * from v1;
+b
+-1
+-2
+-3
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using temporary
+select * from t1;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+2 -2 -2
+3 -3 -3
+3 -3 -3
+drop view v1;
+create view v1 as select distinct c from t1;
+select * from v1;
+c
+-1
+-2
+-3
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using temporary
+select * from t1;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+2 -2 -2
+3 -3 -3
+3 -3 -3
+drop view v1;
+drop table t1;
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (4);
+create view v1 as select b+1 from t1 order by 1 desc limit 2;
+select * from v1;
+b+1
+0
+-1
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using filesort
+drop view v1;
+create view v1 as select c+1 from t1 order by 1 desc limit 2;
+select * from v1;
+c+1
+-1
+0
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using filesort
+drop view v1;
+drop table t1;
+create table t1 (a int,
+b int,
+c int generated always as (-a) virtual,
+d int generated always as (-a) stored,
+primary key(a));
+insert into t1 (a,b) values (10,2), (20,3), (30,4), (40,5), (50,10);
+create view v1 (a,e,f,g) as select a, b+1,c+1,d+1 from t1;
+update v1 set a=a+e;
+select * from v1 order by a;
+a e f g
+13 3 -12 -12
+24 4 -23 -23
+35 5 -34 -34
+46 6 -45 -45
+61 11 -60 -60
+select * from t1 order by a;
+a b c d
+13 2 -13 -13
+24 3 -24 -24
+35 4 -35 -35
+46 5 -46 -46
+61 10 -61 -61
+delete from v1;
+select * from v1;
+a e f g
+select * from t1;
+a b c d
+insert into v1 (a,e) values (60,15);
+ERROR HY000: The target table v1 of the INSERT is not insertable-into
+drop table t1;
+drop view v1;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+primary key(a));
+insert into t1 (a) values (1), (2), (3);
+create view v1 (x,y,z) as select a,b,c from t1 where b < -1;
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.b= v1.y);
+a x y z
+1 NULL NULL NULL
+2 2 -2 -2
+3 3 -3 -3
+drop view v1;
+create view v1 (x,y,z) as select a,b,c from t1 where c < -1;
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.c= v1.z);
+a x y z
+1 NULL NULL NULL
+2 2 -2 -2
+3 3 -3 -3
+drop view v1;
+drop table t1;
+create table t1 (a1 int,
+b1 int generated always as (-a1) virtual,
+c1 int generated always as (-a1) stored);
+create table t2 (a2 int,
+b2 int generated always as (-a2) virtual,
+c2 int generated always as (-a2) stored);
+insert into t1 (a1) values (1), (2);
+insert into t2 (a2) values (2), (3);
+create view v1 as select * from t1,t2 union all select * from t1,t2;
+select * from v1;
+a1 b1 c1 a2 b2 c2
+1 -1 -1 2 -2 -2
+1 -1 -1 2 -2 -2
+1 -1 -1 3 -3 -3
+1 -1 -1 3 -3 -3
+2 -2 -2 2 -2 -2
+2 -2 -2 2 -2 -2
+2 -2 -2 3 -3 -3
+2 -2 -2 3 -3 -3
+drop view v1;
+drop table t1, t2;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+create table t2 like t1;
+create view v1 as select a,b,c from t1;
+create view v2 as select a,b,c from t2 where b in (select b from v1);
+show create view v2;
+View Create View character_set_client collation_connection
+v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from `t2` where `t2`.`b` in (select `v1`.`b` from `v1`) latin1 latin1_swedish_ci
+drop view v2, v1;
+drop table t1, t2;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1),(1),(2),(2),(3),(3);
+create view v1 as select b from t1;
+select distinct b from v1;
+b
+-1
+-2
+-3
+select distinct b from v1 order by b limit 2;
+b
+-3
+-2
+select distinct b from t1 order by b limit 2;
+b
+-3
+-2
+prepare stmt1 from "select distinct b from v1 order by b limit 2";
+execute stmt1;
+b
+-3
+-2
+execute stmt1;
+b
+-3
+-2
+deallocate prepare stmt1;
+drop view v1;
+create view v1 as select c from t1;
+select distinct c from v1;
+c
+-1
+-2
+-3
+select distinct c from v1 order by c limit 2;
+c
+-3
+-2
+select distinct c from t1 order by c limit 2;
+c
+-3
+-2
+prepare stmt1 from "select distinct c from v1 order by c limit 2";
+execute stmt1;
+c
+-3
+-2
+execute stmt1;
+c
+-3
+-2
+deallocate prepare stmt1;
+drop view v1;
+drop table t1;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+create view v1 as select * from t1 where b > -2 && c >-2 with check option;
+insert into v1 (a) values (1);
+insert into v1 (a) values (3);
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+insert ignore into v1 (a) values (2),(3),(0);
+Warnings:
+Warning 1369 CHECK OPTION failed `test`.`v1`
+Warning 1369 CHECK OPTION failed `test`.`v1`
+select * from t1;
+a b c
+0 0 0
+1 -1 -1
+drop view v1;
+drop table t1;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
+('1985-12-24 10:15:08.456');
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
+# Field_blob::val_str with virtual columns and views
+#
+CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (a) VALUES ('foo'),('bar');
+DELETE FROM v1 ORDER BY b LIMIT 2;
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (d INT, v TINYINT AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004'),('1985') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (d VARCHAR(64), v VARCHAR(63) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),('1985-12-24 10:15:08.456') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP TABLE t1;
+DROP VIEW v1;
+#
+# MDEV-18249 ASSERT_COLUMN_MARKED_FOR_READ failed in ANALYZE TABLE
+#
+create table t1 (c varchar(3) not null, v varchar(4) as (c) virtual);
+insert into t1 (c) values ('a'),('b');
+analyze table t1 persistent for columns (v) indexes ();
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/gcol_view_myisam.result b/mysql-test/suite/gcol/r/gcol_view_myisam.result
new file mode 100644
index 00000000..d266405d
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_view_myisam.result
@@ -0,0 +1,322 @@
+SET @@session.default_storage_engine = 'MyISAM';
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (1), (2), (2), (3);
+analyze table t1;
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+create view v1 (d,e) as select abs(b), abs(c) from t1;
+select d,e from v1;
+d e
+1 1
+1 1
+2 2
+2 2
+3 3
+select is_updatable from information_schema.views where table_name='v1';
+is_updatable
+NO
+explain select d,e from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL X
+create algorithm=temptable view v2 (d,e) as select abs(b), abs(c) from t1;
+show create view v2;
+View Create View character_set_client collation_connection
+v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select abs(`t1`.`b`) AS `d`,abs(`t1`.`c`) AS `e` from `t1` latin1 latin1_swedish_ci
+select d,e from v2;
+d e
+1 1
+1 1
+2 2
+2 2
+3 3
+explain select d,e from v2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X
+create view v3 (d,e) as select d*2, e*2 from v1;
+select * from v3;
+d e
+2 2
+2 2
+4 4
+4 4
+6 6
+explain select * from v3;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL NULL NULL NULL NULL X
+drop view v1,v2,v3;
+drop table t1;
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (1), (2), (3);
+create view v1 as select distinct b from t1;
+select * from v1;
+b
+-1
+-2
+-3
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using temporary
+select * from t1;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+2 -2 -2
+3 -3 -3
+3 -3 -3
+drop view v1;
+create view v1 as select distinct c from t1;
+select * from v1;
+c
+-1
+-2
+-3
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using temporary
+select * from t1;
+a b c
+1 -1 -1
+1 -1 -1
+2 -2 -2
+2 -2 -2
+3 -3 -3
+3 -3 -3
+drop view v1;
+drop table t1;
+create table t1 (a int not null,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1), (2), (3), (4);
+create view v1 as select b+1 from t1 order by 1 desc limit 2;
+select * from v1;
+b+1
+0
+-1
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using filesort
+drop view v1;
+create view v1 as select c+1 from t1 order by 1 desc limit 2;
+select * from v1;
+c+1
+-1
+0
+explain select * from v1;
+id select_type table type possible_keys key key_len ref rows Extra
+1 PRIMARY <derived2> ALL NULL NULL NULL NULL X
+2 DERIVED t1 ALL NULL NULL NULL NULL X Using filesort
+drop view v1;
+drop table t1;
+create table t1 (a int,
+b int,
+c int generated always as (-a) virtual,
+d int generated always as (-a) stored,
+primary key(a));
+insert into t1 (a,b) values (10,2), (20,3), (30,4), (40,5), (50,10);
+create view v1 (a,e,f,g) as select a, b+1,c+1,d+1 from t1;
+update v1 set a=a+e;
+select * from v1 order by a;
+a e f g
+13 3 -12 -12
+24 4 -23 -23
+35 5 -34 -34
+46 6 -45 -45
+61 11 -60 -60
+select * from t1 order by a;
+a b c d
+13 2 -13 -13
+24 3 -24 -24
+35 4 -35 -35
+46 5 -46 -46
+61 10 -61 -61
+delete from v1;
+select * from v1;
+a e f g
+select * from t1;
+a b c d
+insert into v1 (a,e) values (60,15);
+ERROR HY000: The target table v1 of the INSERT is not insertable-into
+drop table t1;
+drop view v1;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored,
+primary key(a));
+insert into t1 (a) values (1), (2), (3);
+create view v1 (x,y,z) as select a,b,c from t1 where b < -1;
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.b= v1.y);
+a x y z
+1 NULL NULL NULL
+2 2 -2 -2
+3 3 -3 -3
+drop view v1;
+create view v1 (x,y,z) as select a,b,c from t1 where c < -1;
+select t1.a, v1.x, v1.y, v1.z from t1 left join v1 on (t1.c= v1.z);
+a x y z
+1 NULL NULL NULL
+2 2 -2 -2
+3 3 -3 -3
+drop view v1;
+drop table t1;
+create table t1 (a1 int,
+b1 int generated always as (-a1) virtual,
+c1 int generated always as (-a1) stored);
+create table t2 (a2 int,
+b2 int generated always as (-a2) virtual,
+c2 int generated always as (-a2) stored);
+insert into t1 (a1) values (1), (2);
+insert into t2 (a2) values (2), (3);
+create view v1 as select * from t1,t2 union all select * from t1,t2;
+select * from v1;
+a1 b1 c1 a2 b2 c2
+1 -1 -1 2 -2 -2
+1 -1 -1 2 -2 -2
+1 -1 -1 3 -3 -3
+1 -1 -1 3 -3 -3
+2 -2 -2 2 -2 -2
+2 -2 -2 2 -2 -2
+2 -2 -2 3 -3 -3
+2 -2 -2 3 -3 -3
+drop view v1;
+drop table t1, t2;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+create table t2 like t1;
+create view v1 as select a,b,c from t1;
+create view v2 as select a,b,c from t2 where b in (select b from v1);
+show create view v2;
+View Create View character_set_client collation_connection
+v2 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t2`.`a` AS `a`,`t2`.`b` AS `b`,`t2`.`c` AS `c` from `t2` where `t2`.`b` in (select `v1`.`b` from `v1`) latin1 latin1_swedish_ci
+drop view v2, v1;
+drop table t1, t2;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+insert into t1 (a) values (1),(1),(2),(2),(3),(3);
+create view v1 as select b from t1;
+select distinct b from v1;
+b
+-1
+-2
+-3
+select distinct b from v1 order by b limit 2;
+b
+-3
+-2
+select distinct b from t1 order by b limit 2;
+b
+-3
+-2
+prepare stmt1 from "select distinct b from v1 order by b limit 2";
+execute stmt1;
+b
+-3
+-2
+execute stmt1;
+b
+-3
+-2
+deallocate prepare stmt1;
+drop view v1;
+create view v1 as select c from t1;
+select distinct c from v1;
+c
+-1
+-2
+-3
+select distinct c from v1 order by c limit 2;
+c
+-3
+-2
+select distinct c from t1 order by c limit 2;
+c
+-3
+-2
+prepare stmt1 from "select distinct c from v1 order by c limit 2";
+execute stmt1;
+c
+-3
+-2
+execute stmt1;
+c
+-3
+-2
+deallocate prepare stmt1;
+drop view v1;
+drop table t1;
+create table t1 (a int,
+b int generated always as (-a) virtual,
+c int generated always as (-a) stored);
+create view v1 as select * from t1 where b > -2 && c >-2 with check option;
+insert into v1 (a) values (1);
+insert into v1 (a) values (3);
+ERROR 44000: CHECK OPTION failed `test`.`v1`
+insert ignore into v1 (a) values (2),(3),(0);
+Warnings:
+Warning 1369 CHECK OPTION failed `test`.`v1`
+Warning 1369 CHECK OPTION failed `test`.`v1`
+select * from t1;
+a b c
+0 0 0
+1 -1 -1
+drop view v1;
+drop table t1;
+#
+# MDEV-18166 ASSERT_COLUMN_MARKED_FOR_READ failed on tables with vcols
+#
+CREATE TABLE t1 (d DATETIME(3), v DATETIME(2) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),
+('1985-12-24 10:15:08.456');
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP VIEW v1;
+DROP TABLE t1;
+#
+# [duplicate] MDEV-19306 Assertion `marked_for_read()' failed in
+# Field_blob::val_str with virtual columns and views
+#
+CREATE TABLE t1 (a BLOB, b TEXT AS (a) VIRTUAL);
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (a) VALUES ('foo'),('bar');
+DELETE FROM v1 ORDER BY b LIMIT 2;
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (d INT, v TINYINT AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004'),('1985') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (d VARCHAR(64), v VARCHAR(63) AS (d));
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (d) VALUES ('2004-04-19 15:37:39.123'),('1985-12-24 10:15:08.456') ;
+DELETE FROM v1 ORDER BY v LIMIT 4;
+DROP TABLE t1;
+DROP VIEW v1;
+#
+# MDEV-18249 ASSERT_COLUMN_MARKED_FOR_READ failed in ANALYZE TABLE
+#
+create table t1 (c varchar(3) not null, v varchar(4) as (c) virtual);
+insert into t1 (c) values ('a'),('b');
+analyze table t1 persistent for columns (v) indexes ();
+Table Op Msg_type Msg_text
+test.t1 analyze status Engine-independent statistics collected
+test.t1 analyze status OK
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
diff --git a/mysql-test/suite/gcol/r/innodb_partition.result b/mysql-test/suite/gcol/r/innodb_partition.result
new file mode 100644
index 00000000..8cdf8d41
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_partition.result
@@ -0,0 +1,26 @@
+#
+# Bug#22444530 - GCOLS + PARTITIONED TABLE, CRASH IN
+#
+set sql_mode='';
+create table t (
+a int not null,
+b int generated always as (1) virtual,
+c int generated always as (1) virtual,
+key (c)
+) engine=innodb partition by key (a) partitions 2;
+insert into t(a) values(1);
+select b from t group by c;
+b
+1
+drop table t;
+create table t (
+a int not null,
+b blob generated always as ("a") virtual,
+c int generated always as (1) virtual,
+key (c)
+) engine=innodb partition by key (a) partitions 2;
+insert into t(a) values(1);
+select b from t group by c;
+b
+a
+drop table t;
diff --git a/mysql-test/suite/gcol/r/innodb_prefix_index_check.result b/mysql-test/suite/gcol/r/innodb_prefix_index_check.result
new file mode 100644
index 00000000..01dbe4a6
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_prefix_index_check.result
@@ -0,0 +1,15 @@
+#Bug #22445211 GCOLS: SIMPLE DML, FAILING ASSERTION:
+#!CURSOR->INDEX->IS_COMMITTED()
+#Create and alter table examples for virtual column for full
+#column index followed by prefix index.
+CREATE TABLE t1(
+f1 INT DEFAULT NULL,
+f2 CHAR(2) GENERATED ALWAYS AS ('11') VIRTUAL,
+f3 INT,
+UNIQUE KEY(f1),
+UNIQUE KEY(f3,f1),
+KEY(f2,f1),
+key(f1,f2(1))
+)ENGINE=INNODB;
+REPLACE INTO t1(f3) VALUES (1),(1);
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_basic.result b/mysql-test/suite/gcol/r/innodb_virtual_basic.result
new file mode 100644
index 00000000..38238871
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_basic.result
@@ -0,0 +1,1495 @@
+call mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual");
+set default_storage_engine=innodb;
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c CHAR(10), d CHAR(20), e CHAR(10) GENERATED ALWAYS AS (c), g INT);
+INSERT INTO t VALUES(10, DEFAULT, "aa", "bb", DEFAULT, 20);
+INSERT INTO t VALUES(11, DEFAULT, "jj", "kk", DEFAULT, 21);
+CREATE INDEX idx ON t(e) algorithm=inplace;
+INSERT INTO t VALUES(12, DEFAULT, 'mm', "nn", DEFAULT, 22);
+SELECT e FROM t;
+e
+aa
+jj
+mm
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c);
+SELECT c FROM t;
+c
+NULL
+14
+19
+29
+UPDATE t SET a = 10 WHERE a = 11;
+SELECT c FROM t;
+c
+NULL
+13
+19
+29
+SELECT * FROM t;
+a b c h
+10 3 13 mm
+18 1 19 mm
+28 1 29 mm
+NULL NULL NULL mm
+DELETE FROM t WHERE a = 18;
+SELECT c FROM t;
+c
+NULL
+13
+29
+START TRANSACTION;
+INSERT INTO t VALUES (128, 22, DEFAULT, "xx");
+INSERT INTO t VALUES (1290, 212, DEFAULT, "xmx");
+ROLLBACK;
+SELECT c FROM t;
+c
+NULL
+13
+29
+SELECT * FROM t;
+a b c h
+10 3 13 mm
+28 1 29 mm
+NULL NULL NULL mm
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+SELECT c FROM t;
+c
+3
+7
+33
+SELECT m FROM t;
+m
+5
+11
+30
+SELECT p FROM t;
+p
+ummuooo
+uuuuu
+XXXAAA
+SELECT * FROM t;
+a b c h j m n p
+11 22 33 AAA 8 30 XXX XXXAAA
+1 2 3 uuu 9 11 uu uuuuu
+3 4 7 uooo 1 5 umm ummuooo
+update t set a = 13 where a =11;
+delete from t where a =13;
+DROP INDEX idx1 ON t;
+DROP INDEX idx2 ON t;
+DROP TABLE t;
+/* Test large BLOB data */
+CREATE TABLE `t` (
+`a` BLOB,
+`b` BLOB,
+`c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`h` VARCHAR(10) DEFAULT NULL
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk");
+CREATE INDEX idx ON t(c(100));
+SELECT length(c) FROM t;
+length(c)
+32000
+START TRANSACTION;
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+ROLLBACK;
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+START TRANSACTION;
+UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
+ROLLBACK;
+SELECT COUNT(*) FROM t WHERE c like "aaa%";
+COUNT(*)
+1
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c);
+START TRANSACTION;
+UPDATE t SET a = 100 WHERE a = 11;
+UPDATE t SET a =22 WHERE a = 18;
+UPDATE t SET a = 33 WHERE a = 22;
+SELECT c FROM t;
+c
+29
+34
+103
+ROLLBACK;
+SELECT c FROM t;
+c
+14
+19
+29
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c);
+SELECT c FROM t;
+c
+14
+19
+29
+connect con1,localhost,root,,test;
+START TRANSACTION;
+SELECT c FROM t;
+c
+14
+19
+29
+connection default;
+UPDATE t SET a = 19 WHERE a = 11;
+connection con1;
+SELECT c FROM t;
+c
+14
+19
+29
+ROLLBACK;
+SELECT c FROM t;
+c
+19
+22
+29
+connection default;
+disconnect con1;
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + x), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, RTRIM(y))), x INT, y CHAR(20), z INT, INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+INSERT INTO t VALUES(1, 2, DEFAULT, "hhh", 3, DEFAULT, "nnn", DEFAULT, 4, "yyy", 5);
+INSERT INTO t VALUES(2, 3, DEFAULT, "hhha", 4, DEFAULT, "nnna", DEFAULT, 5, "yyya", 6);
+INSERT INTO t VALUES(12, 13, DEFAULT, "hhhb", 14, DEFAULT, "nnnb", DEFAULT, 15, "yyyb", 16);
+CREATE INDEX idx6 ON t(p, c);
+SELECT p, c FROM t;
+p c
+nnnayyya 5
+nnnbyyyb 25
+nnnyyy 3
+START TRANSACTION;
+INSERT INTO t VALUES(32, 33, DEFAULT, "hhhb", 34, DEFAULT, "nnnb", DEFAULT, 35, "yyyb", 36);
+ROLLBACK;
+UPDATE t SET a = 100 WHERE a = 1;
+START TRANSACTION;
+UPDATE t SET a = 1 WHERE a = 100;
+ROLLBACK;
+DROP TABLE t;
+CREATE TABLE t1(a INT);
+ALTER TABLE t1 add COLUMN (b INT generated always as (a+1) virtual, c INT as(5) virtual);
+ALTER TABLE t1 add COLUMN (d INT generated always as (a+1) virtual, e INT as(5) virtual);
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+pos base_pos
+65537 0
+196611 0
+ALTER TABLE t1 add COLUMN (f INT generated always as (a+1) virtual, g INT as(5) virtual), DROP COLUMN e;
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+pos base_pos
+65537 0
+196611 0
+262148 0
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(1);
+ALTER TABLE t1 add COLUMN (f INT generated always as (a+1) virtual, g INT );
+ALTER TABLE t1 add COLUMN (h INT generated always as (a+1) virtual), add INDEX idx (h), algorithm=inplace;
+ALTER TABLE t1 add COLUMN (h1 INT generated always as (a+1) virtual), add INDEX idx1 (h1);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 DROP COLUMN h1, DROP INDEX idx;
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+CREATE INDEX idx ON t1(a);
+CREATE TABLE t3(a INT, b INT , INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a));
+CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a));
+ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
+CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b));
+DROP TABLE t3;
+DROP TABLE t2;
+DROP TABLE t1;
+CREATE TABLE t1(a INT);
+ALTER TABLE t1 add COLUMN (b INT generated always as (a+1) virtual, c INT as(5) virtual);
+ALTER TABLE t1 change b x INT generated always as (a+1) virtual;
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+pos base_pos
+65537 0
+DROP TABLE t1;
+CREATE TABLE t (a TEXT, b TEXT GENERATED ALWAYS AS (a), fulltext INDEX idx (b));
+ERROR HY000: This is not yet supported for generated columns
+CREATE TABLE t (a TEXT, b TEXT GENERATED ALWAYS AS (a));
+ALTER TABLE t ADD FULLTEXT INDEX (b);
+ERROR HY000: This is not yet supported for generated columns
+DROP TABLE t;
+CREATE TABLE t (a geometry not null, b geometry GENERATED ALWAYS AS (a), spatial INDEX idx (b));
+ERROR 42000: All parts of a SPATIAL index must be NOT NULL
+CREATE TABLE t (a geometry not null, b geometry GENERATED ALWAYS AS (a));
+ALTER TABLE t ADD SPATIAL INDEX (b);
+ERROR 42000: All parts of a SPATIAL index must be NOT NULL
+DROP TABLE t;
+CREATE TABLE t (a INT DEFAULT 1, b INT DEFAULT 2, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+CREATE INDEX idx ON t(c);
+INSERT INTO t(h)VALUES ('mm');
+SELECT c FROM t;
+c
+3
+CREATE unique INDEX idx1 ON t(c);
+INSERT INTO t(h)VALUES ('mm');
+ERROR 23000: Duplicate entry '3' for key 'idx1'
+DROP TABLE t;
+CREATE TABLE `t1` ( `a` INT(11) DEFAULT NULL, `b` INT(11) DEFAULT NULL, `c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL, `x` INT(11) NOT NULL, `h` VARCHAR(10) DEFAULT NULL, PRIMARY KEY (`x`), KEY `idx` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1, 2, DEFAULT, 3, 'mm');
+INSERT INTO t1 VALUES (11, 22, DEFAULT, 23, 'mm');
+connect con1,localhost,root,,test;
+UPDATE t1 SET x = 4 WHERE x =3;
+DROP TABLE t1;
+CREATE TABLE `t1` ( `a` INT(11) DEFAULT NULL, `b` INT(11) DEFAULT NULL, `c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL, `x` INT(11) NOT NULL, `h` VARCHAR(10) DEFAULT NULL, KEY `idx` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t1 VALUES (1, 2, DEFAULT, 3, 'mm');
+INSERT INTO t1 VALUES (11, 22, DEFAULT, 23, 'mm');
+START TRANSACTION;
+SELECT * FROM t1;
+a b c x h
+1 2 3 3 mm
+11 22 33 23 mm
+connection con1;
+START TRANSACTION;
+UPDATE t1 SET x = 15 WHERE x = 3;
+UPDATE t1 SET b = 10 WHERE b=2;
+ROLLBACK;
+connection default;
+SELECT c FROM t1;
+c
+3
+33
+disconnect con1;
+DROP TABLE t1;
+CREATE TABLE `t` (
+`a` INT(11) DEFAULT NULL,
+`b` INT(11) DEFAULT NULL,
+`c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL,
+`d` INT(11) GENERATED ALWAYS AS (a) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`),
+KEY `idx` (`c`)
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (11, 3, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (18, 1, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (28, 1, DEFAULT, DEFAULT, 3);
+INSERT INTO t VALUES (null, null, DEFAULT, DEFAULT, 4);
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 2000) DO
+UPDATE t SET a = 100 + i WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 2000) DO
+UPDATE t SET a = 100 + i WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+SELECT c FROM t;
+c
+NULL
+19
+29
+2103
+CALL DELETE_insert_t();
+SELECT c FROM t;
+c
+NULL
+19
+29
+2103
+DROP INDEX idx ON t;
+CALL UPDATE_t();
+SELECT c FROM t;
+c
+2103
+19
+29
+NULL
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+# Bug#20767937: WL8149:ASSERTION FAILED IN ROW_UPD_SEC_INDEX_ENTRY
+CREATE TABLE b (
+col_INT_nokey INTEGER NOT NULL,
+col_INT_key INTEGER GENERATED ALWAYS AS (col_INT_nokey) VIRTUAL,
+col_date_nokey DATE,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,
+INTerval 30 day)) VIRTUAL,
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey,
+col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey,
+col_time_nokey)),
+col_VARCHAR_nokey VARCHAR(1) NOT NULL,
+col_VARCHAR_key VARCHAR(2) GENERATED ALWAYS AS(CONCAT(col_VARCHAR_nokey,
+col_VARCHAR_nokey)),
+KEY (col_INT_key),
+KEY (col_VARCHAR_key),
+KEY (col_date_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+KEY (col_INT_key, col_VARCHAR_key),
+KEY (col_INT_key, col_VARCHAR_key, col_date_key,
+col_time_key, col_datetime_key)
+);
+INSERT INTO b (
+col_INT_nokey,
+col_date_nokey,
+col_time_nokey,
+col_datetime_nokey,
+col_VARCHAR_nokey
+) VALUES
+(0, NULL, '21:22:34.025509', '2002-02-13 17:30:06.013935', 'j'),
+(8, '2004-09-18', '10:50:38.059966', '2008-09-27
+00:34:58.026613', 'v');
+Warnings:
+Note 1265 Data truncated for column 'col_time_key' at row 1
+Note 1265 Data truncated for column 'col_time_key' at row 2
+EXPLAIN SELECT col_INT_key FROM b;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE b index NULL col_INT_key 5 NULL 2 Using index
+SELECT col_INT_key FROM b;
+col_INT_key
+0
+8
+SELECT col_INT_nokey, col_INT_key FROM b;
+col_INT_nokey col_INT_key
+0 0
+8 8
+DELETE FROM b;
+DROP TABLE b;
+CREATE TABLE `t` (
+`a` VARCHAR(10000), `b` VARCHAR(3000),
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`) ) ROW_FORMAT=COMPACT ENGINE=InnoDB;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` varchar(10000) DEFAULT NULL,
+ `b` varchar(3000) DEFAULT NULL,
+ `c` varchar(14000) GENERATED ALWAYS AS (concat(`a`,`b`)) VIRTUAL,
+ `d` varchar(5000) GENERATED ALWAYS AS (`b`) VIRTUAL,
+ `e` int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` int(11) NOT NULL,
+ PRIMARY KEY (`h`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=COMPACT
+INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+DELETE FROM t WHERE h = 1;
+INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+UPDATE t SET a = NULL WHERE h=1;
+START TRANSACTION;
+CALL UPDATE_t();
+ROLLBACK;
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+CREATE TABLE `t` (
+`a` BLOB,
+`b` BLOB,
+`c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` BLOB GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`)
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 32000), REPEAT('b', 11000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 18000), REPEAT('n', 46000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = NULL WHERE h=1;
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 1000) WHERE h = 1;
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 200) DO
+UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 200) DO
+DELETE FROM t WHERE h = 1;
+INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+UPDATE t SET a = NULL WHERE h=1;
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+CREATE TABLE `t` (
+`m1` INT(11) DEFAULT NULL,
+`m2` INT(11) DEFAULT NULL,
+`m3` INT(11) GENERATED ALWAYS AS (m1 + m2) VIRTUAL,
+`m4` INT(11) DEFAULT NULL,
+`m5` CHAR(10) DEFAULT NULL,
+`m6` CHAR(12) GENERATED ALWAYS AS (m5) VIRTUAL,
+`a` VARCHAR(10000) DEFAULT NULL,
+`b` VARCHAR(3000) DEFAULT NULL,
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`),
+KEY `m3` (`m3`),
+KEY `c` (`c`(100)),
+KEY `e` (`e`,`d`(20))
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (1, 2, DEFAULT, 3, "aaa", DEFAULT, REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (11, 21, DEFAULT, 31, "bbb", DEFAULT, REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (21, 31, DEFAULT, 41, "zzz", DEFAULT, REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+ALTER TABLE t DROP COLUMN c;
+DELETE FROM t;
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+CREATE INDEX idx ON t(a, c);
+SELECT a, c FROM t;
+a c
+NULL NULL
+11 14
+18 19
+28 29
+START TRANSACTION;
+UPDATE t SET a = 13 where a = 11;
+ROLLBACK;
+DELETE FROM t;
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), m int);
+INSERT INTO t VALUES (11, 3, DEFAULT, "a", 1);
+INSERT INTO t VALUES (18, 1, DEFAULT, "b", 2);
+INSERT INTO t VALUES (28, 1, DEFAULT, "c", 3 );
+INSERT INTO t VALUES (null, null, DEFAULT, "d", 4);
+CREATE INDEX idx ON t(a, c, h);
+SELECT a, c FROM t;
+a c
+NULL NULL
+11 14
+18 19
+28 29
+START TRANSACTION;
+UPDATE t SET m =10 WHERE m = 1;
+UPDATE t SET h = "e" WHERE h="a";
+ROLLBACK;
+SELECT a, c, h FROM t;
+a c h
+NULL NULL d
+11 14 a
+18 19 b
+28 29 c
+DROP TABLE t;
+CREATE TABLE `t1` (
+`col1` int(11) NOT NULL,
+`col2` int(11) NOT NULL,
+`col3` int(11) NOT NULL,
+`col4` int(11) DEFAULT NULL,
+`col5` int(11) GENERATED ALWAYS AS (col2 % col3) VIRTUAL,
+`col7` int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
+`col8` int(11) GENERATED ALWAYS AS (col5 % col5) VIRTUAL,
+`col9` text,
+`extra` int(11) DEFAULT NULL,
+UNIQUE KEY `uidx` (`col5`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ALTER TABLE t1 CHANGE COLUMN extra col6 INT;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `col1` int(11) NOT NULL,
+ `col2` int(11) NOT NULL,
+ `col3` int(11) NOT NULL,
+ `col4` int(11) DEFAULT NULL,
+ `col5` int(11) GENERATED ALWAYS AS (`col2` MOD `col3`) VIRTUAL,
+ `col7` int(11) GENERATED ALWAYS AS (`col5` * `col5`) VIRTUAL,
+ `col8` int(11) GENERATED ALWAYS AS (`col5` MOD `col5`) VIRTUAL,
+ `col9` text DEFAULT NULL,
+ `col6` int(11) DEFAULT NULL,
+ UNIQUE KEY `uidx` (`col5`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c point, d point GENERATED ALWAYS AS (c), spatial index idx (d));
+ERROR 42000: All parts of a SPATIAL index must be NOT NULL
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c CHAR(10), d char(20) GENERATED ALWAYS AS (c), fulltext index idx (d));
+ERROR HY000: This is not yet supported for generated columns
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+alter table t add x int, add xx int generated ALWAYS AS(x);
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+ALTER TABLE t DROP COLUMN c, algorithm=inplace;
+ALTER TABLE t DROP COLUMN p, ADD COLUMN s VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), algorithm=inplace;
+SELECT s FROM t;
+s
+XXXAAA
+uuuuu
+ummuooo
+ALTER TABLE t ADD x VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), ADD INDEX idx (x), algorithm=inplace;
+DROP TABLE t;
+CREATE TABLE `t1` (
+`col1` int(11) DEFAULT NULL,
+`col2` int(11) DEFAULT NULL,
+`col3` int(11) DEFAULT NULL,
+`col4` int(11) DEFAULT NULL,
+`col5` int(11) GENERATED ALWAYS AS (col4 * col2) VIRTUAL,
+`col6` int(11) GENERATED ALWAYS AS (col2 % col4) VIRTUAL,
+`col7` int(11) GENERATED ALWAYS AS (col5 / col6) VIRTUAL,
+`col8` int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
+`col9` text,
+`extra` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ALTER TABLE t1 DROP COLUMN col7;
+DROP TABLE t1;
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+gv_col INTEGER GENERATED ALWAYS AS (col1) VIRTUAL,
+txt1 TEXT,
+FULLTEXT INDEX fi(txt1)
+);
+select * from t1;
+col1 gv_col txt1
+DROP TABLE t1;
+CREATE TABLE t1 (
+col1 INTEGER NOT NULL,
+col2 INTEGER NOT NULL,
+col3 INTEGER DEFAULT NULL,
+col4 INTEGER DEFAULT NULL,
+col5 INTEGER DEFAULT NULL,
+col6 INTEGER DEFAULT NULL,
+col7 INTEGER DEFAULT NULL,
+col8 INTEGER DEFAULT NULL,
+col9 INTEGER DEFAULT NULL,
+col10 INTEGER DEFAULT NULL,
+col11 INTEGER DEFAULT NULL,
+col12 INTEGER DEFAULT NULL,
+col13 INTEGER DEFAULT NULL,
+col14 INTEGER DEFAULT NULL,
+col15 INTEGER DEFAULT NULL,
+col16 INTEGER DEFAULT NULL,
+col17 INTEGER DEFAULT NULL,
+col18 INTEGER DEFAULT NULL,
+col19 INTEGER DEFAULT NULL,
+col20 INTEGER DEFAULT NULL,
+col21 INTEGER DEFAULT NULL,
+col22 INTEGER DEFAULT NULL,
+col23 INTEGER DEFAULT NULL,
+col24 INTEGER DEFAULT NULL,
+col25 INTEGER DEFAULT NULL,
+col26 INTEGER DEFAULT NULL,
+col27 INTEGER DEFAULT NULL,
+col28 INTEGER DEFAULT NULL,
+col29 INTEGER DEFAULT NULL,
+col30 INTEGER DEFAULT NULL,
+col31 INTEGER DEFAULT NULL,
+col32 INTEGER DEFAULT NULL,
+col33 INTEGER DEFAULT NULL,
+gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+KEY idx1 (gcol1)
+);
+INSERT INTO t1 (col1, col2)
+VALUES (0,1), (1,2), (2,3), (3,4), (4,5);
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+gcol1
+1
+3
+5
+7
+9
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+gcol1
+1
+3
+5
+7
+9
+DROP TABLE t1;
+CREATE TABLE t1 (
+id INT NOT NULL,
+store_id INT NOT NULL,
+x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21)
+);
+INSERT INTO t1 VALUES(1, 2, default);
+INSERT INTO t1 VALUES(3, 4, default);
+INSERT INTO t1 VALUES(3, 12, default);
+INSERT INTO t1 VALUES(4, 18, default);
+CREATE INDEX idx ON t1(x);
+SELECT x FROM t1;
+x
+3
+7
+15
+22
+DROP TABLE t1;
+CREATE TABLE t1 (
+id INT NOT NULL,
+store_id INT NOT NULL,
+x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (x) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21)
+);
+insert into t1 values(1, 2, default);
+insert into t1 values(3, 4, default);
+insert into t1 values(3, 12, default);
+insert into t1 values(4, 18, default);
+ERROR HY000: Table has no partition for value 22
+CREATE INDEX idx ON t1(x);
+SELECT x FROM t1;
+x
+3
+7
+15
+DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a+1) ,c int) PARTITION BY RANGE (b) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21) );
+INSERT INTO t1 VALUES (10,DEFAULT,2);
+INSERT INTO t1 VALUES (19,DEFAULT,8);
+CREATE INDEX idx ON t1 (b);
+INSERT INTO t1 VALUES (5,DEFAULT,9);
+SELECT * FROM t1;
+a b c
+5 6 9
+10 11 2
+19 20 8
+ALTER TABLE t1 REMOVE PARTITIONING;
+DROP TABLE t1;
+CREATE TABLE `t#P#1` (a INT, bt INT GENERATED ALWAYS AS (a+1) ,c int)
+PARTITION BY RANGE (bt)
+subpartition by hash (bt)
+(
+PARTITION p0 VALUES LESS THAN (6) (
+SUBPARTITION s0,
+SUBPARTITION s1),
+PARTITION p1 VALUES LESS THAN (11) (
+SUBPARTITION s2,
+SUBPARTITION s3),
+PARTITION p2 VALUES LESS THAN (16) (
+SUBPARTITION s4,
+SUBPARTITION s5),
+PARTITION p3 VALUES LESS THAN (21) (
+SUBPARTITION s6,
+SUBPARTITION s7)
+);
+insert into `t#P#1` values (10,DEFAULT,2);
+insert into `t#P#1` values (19,DEFAULT,8);
+create index idx on `t#P#1` (bt);
+insert into `t#P#1` values (5,DEFAULT,9);
+select * from `t#P#1`;
+a bt c
+5 6 9
+10 11 2
+19 20 8
+alter table `t#P#1` remove partitioning;
+drop table `t#P#1`;
+CREATE TABLE `t` (
+`a` VARCHAR(10000), `b` VARCHAR(3000),
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`) ) ROW_FORMAT=DYNAMIC ENGINE=InnoDB;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` varchar(10000) DEFAULT NULL,
+ `b` varchar(3000) DEFAULT NULL,
+ `c` varchar(14000) GENERATED ALWAYS AS (concat(`a`,`b`)) VIRTUAL,
+ `d` varchar(5000) GENERATED ALWAYS AS (`b`) VIRTUAL,
+ `e` int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` int(11) NOT NULL,
+ PRIMARY KEY (`h`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=DYNAMIC
+INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+DELETE FROM t WHERE h = 1;
+INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+UPDATE t SET a = NULL WHERE h=1;
+START TRANSACTION;
+CALL UPDATE_t();
+ROLLBACK;
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+CREATE TABLE `t` (
+`a` VARCHAR(10000), `b` VARCHAR(3000),
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`) ) ROW_FORMAT=REDUNDANT ENGINE=InnoDB;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` varchar(10000) DEFAULT NULL,
+ `b` varchar(3000) DEFAULT NULL,
+ `c` varchar(14000) GENERATED ALWAYS AS (concat(`a`,`b`)) VIRTUAL,
+ `d` varchar(5000) GENERATED ALWAYS AS (`b`) VIRTUAL,
+ `e` int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` int(11) NOT NULL,
+ PRIMARY KEY (`h`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=REDUNDANT
+INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+DELETE FROM t WHERE h = 1;
+INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+UPDATE t SET a = NULL WHERE h=1;
+START TRANSACTION;
+CALL UPDATE_t();
+ROLLBACK;
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+CREATE TABLE `t` (
+`a` VARCHAR(10000), `b` VARCHAR(3000),
+`c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+`e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+`h` INT(11) NOT NULL,
+PRIMARY KEY (`h`) ) ROW_FORMAT=COMPRESSED ENGINE=InnoDB;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` varchar(10000) DEFAULT NULL,
+ `b` varchar(3000) DEFAULT NULL,
+ `c` varchar(14000) GENERATED ALWAYS AS (concat(`a`,`b`)) VIRTUAL,
+ `d` varchar(5000) GENERATED ALWAYS AS (`b`) VIRTUAL,
+ `e` int(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` int(11) NOT NULL,
+ PRIMARY KEY (`h`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ROW_FORMAT=COMPRESSED
+INSERT INTO t VALUES (REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+CREATE INDEX idx ON t(c(100), d(20));
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+CREATE PROCEDURE UPDATE_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+SET i = i + 1;
+END WHILE;
+END|
+CREATE PROCEDURE DELETE_insert_t()
+begin
+DECLARE i INT DEFAULT 1;
+WHILE (i <= 100) DO
+DELETE FROM t WHERE h = 1;
+INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+SET i = i + 1;
+END WHILE;
+END|
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+UPDATE t SET a = NULL WHERE h=1;
+START TRANSACTION;
+CALL UPDATE_t();
+ROLLBACK;
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+CREATE TABLE t(a TEXT CHARSET UTF8)ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN b BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+ALTER TABLE t ADD FULLTEXT INDEX (a) ;
+ALTER TABLE t ADD INDEX (b(1)) ;
+DROP TABLE t;
+CREATE TABLE t(a TEXT CHARSET UTF8, FULLTEXT INDEX(a))ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN b BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+ALTER TABLE t ADD INDEX (b(1)) ;
+DROP TABLE t;
+CREATE TABLE t(a TEXT CHARSET UTF8)ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN FTS_DOC_ID BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+ALTER TABLE t ADD FULLTEXT INDEX (a) ;
+ERROR HY000: Column 'FTS_DOC_ID' is of wrong type for an InnoDB FULLTEXT index
+DROP TABLE t;
+create table t (a int,b int,c int,d int,e int,
+f int generated always as (a+b) virtual,
+g int,h blob,i int,unique key (d,h(25))) engine=innodb;
+select h from t where d is null;
+h
+drop table t;
+create table t(a blob not null) engine=innodb;
+alter table t add column b int;
+alter table t add column c varbinary (1000) generated always as (a) virtual;
+alter table t add unique index (c(39));
+replace into t set a = 'a',b =1;
+replace into t set a = 'a',b =1;
+drop table t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+ALTER TABLE t ADD COLUMN xs INT GENERATED ALWAYS AS(a+b), ADD COLUMN mm INT
+GENERATED ALWAYS AS(a+b) STORED, ALGORITHM = INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ALGORITHM = INPLACE;
+ALTER TABLE t DROP COLUMN x, ALGORITHM = INPLACE;
+ALTER TABLE t ADD COLUMN x1 INT GENERATED ALWAYS AS(a+b), DROP COLUMN c,
+ALGORITHM = INPLACE;
+DROP TABLE t;
+CREATE TABLE t (a INT GENERATED ALWAYS AS(1) VIRTUAL,KEY(a)) ENGINE=INNODB;
+INSERT INTO t VALUES(default);
+SELECT a FROM t FOR UPDATE;
+a
+1
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x);
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+SELECT x FROM t;
+x
+NULL
+14
+19
+29
+DROP TABLE t;
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t1 VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t1 VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t1 VALUES (28, 1, DEFAULT, 'mm');
+ALTER TABLE t1 ADD INDEX idx12 (c) , FORCE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t1 ADD INDEX idx12 (c), LOCK=NONE;
+ALTER TABLE t1 DROP COLUMN h, ADD INDEX idx (c) , FORCE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t1 DROP COLUMN h, ADD INDEX idx (c), LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+DROP TABLE t1 ;
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), d INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t1 VALUES (11, 3, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t1 VALUES (18, 1, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t1 VALUES (28, 1, DEFAULT, DEFAULT, 'mm');
+ALTER TABLE t1 CHANGE d d INT GENERATED ALWAYS AS(a+b) FIRST, ALGORITHM = INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+ALTER TABLE t1 CHANGE d d VARCHAR(10) GENERATED ALWAYS AS(h), ALGORITHM = INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
+ALTER TABLE t1 CHANGE d d INT GENERATED ALWAYS AS(a+b) FIRST;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `d` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE parent (id INT PRIMARY KEY) ENGINE=INNODB;
+CREATE TABLE child (
+id INT,
+parent_id INT,
+x int(11) GENERATED ALWAYS AS (parent_id+1),
+INDEX par_ind (parent_id),
+FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE
+) ENGINE=INNODB;
+ALTER TABLE child ADD INDEX `i1` (x);
+CREATE TABLE child_1 (
+id INT,
+parent_id INT,
+x int(11) GENERATED ALWAYS AS (parent_id+1),
+INDEX par_ind (parent_id),
+FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+) ENGINE=INNODB;
+ALTER TABLE child_1 ADD INDEX `i1` (x);
+DROP TABLE child_1;
+DROP TABLE child;
+CREATE TABLE child (
+id INT,
+parent_id INT,
+x int(11) GENERATED ALWAYS AS (parent_id+1),
+INDEX par_ind (parent_id),
+INDEX i1 (x),
+FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE
+) ENGINE=INNODB;
+DROP TABLE child;
+CREATE TABLE child (
+id INT,
+parent_id INT,
+x int(11) GENERATED ALWAYS AS (parent_id+1),
+INDEX par_ind (parent_id),
+INDEX `i1` (x)
+) ENGINE=INNODB;
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE;
+SET foreign_key_checks = 0;
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE;
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE SET NULL;
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON UPDATE CASCADE;
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id);
+SET foreign_key_checks = 1;
+DROP TABLE child;
+DROP TABLE parent;
+CREATE TABLE `ibstd_16` (
+`a` int(11) DEFAULT NULL,
+`d` int(11) DEFAULT NULL,
+`b` varchar(198) DEFAULT NULL,
+`c` char(179) DEFAULT NULL,
+`vadcol` int(11) GENERATED ALWAYS AS (a+length(d)) STORED,
+`vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+UNIQUE KEY `b` (`b`(10),`d`),
+KEY `d` (`d`),
+KEY `a` (`a`),
+KEY `c` (`c`(99),`b`(33)),
+KEY `b_2` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `a_2` (`a`,`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=INNODB;
+CREATE TABLE `ibstd_16_fk` (
+`a` int(11) DEFAULT NULL,
+`d` int(11) DEFAULT NULL,
+`b` varchar(198) DEFAULT NULL,
+`c` char(179) DEFAULT NULL,
+`vadcol` int(11) GENERATED ALWAYS AS (a+length(d)) STORED,
+`vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+UNIQUE KEY `b` (`b`(10),`a`,`d`),
+KEY `d` (`d`),
+KEY `a` (`a`),
+KEY `c` (`c`(99),`b`(33)),
+KEY `b_2` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `a_2` (`a`,`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`,`d`),
+CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL
+) ENGINE=InnoDB;
+ERROR HY000: Function or expression 'a' cannot be used in the GENERATED ALWAYS AS clause of `vadcol`
+CREATE TABLE `ibstd_16_fk` (
+`a` int(11) DEFAULT NULL,
+`d` int(11) DEFAULT NULL,
+`b` varchar(198) DEFAULT NULL,
+`c` char(179) DEFAULT NULL,
+`vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+UNIQUE KEY `b` (`b`(10),`a`,`d`),
+KEY `d` (`d`),
+KEY `a` (`a`),
+KEY `c` (`c`(99),`b`(33)),
+KEY `b_2` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`,`d`),
+CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL
+) ENGINE=InnoDB;
+ALTER TABLE ibstd_16_fk ADD INDEX `a_2` (`a`,`vbidxcol`);
+DROP TABLE ibstd_16_fk;
+CREATE TABLE `ibstd_16_fk` (
+`a` int(11) DEFAULT NULL,
+`d` int(11) DEFAULT NULL,
+`b` varchar(198) DEFAULT NULL,
+`c` char(179) DEFAULT NULL,
+`vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+UNIQUE KEY `b` (`b`(10),`a`,`d`),
+KEY `d` (`d`),
+KEY `a` (`a`),
+KEY `c` (`c`(99),`b`(33)),
+KEY `b_2` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `a_2` (`a`,`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=InnoDB;
+ALTER TABLE `ibstd_16_fk` ADD CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL;
+DROP INDEX a_2 ON ibstd_16_fk;
+INSERT INTO ibstd_16 VALUES (1, 2, "aaa", "bbb", default, default, default);
+INSERT INTO ibstd_16_fk VALUES(1, 3, "mmm", "SSS", default, default);
+DELETE FROM ibstd_16 WHERE a = 1;
+DROP TABLE ibstd_16_fk;
+DROP TABLE ibstd_16;
+create table t(a int) engine=innodb;
+insert into t set a=1;
+alter table t add column c int generated always as (1) virtual;
+insert into t set a=2;
+alter table t add unique index(c);
+ERROR 23000: Duplicate entry '1' for key 'c'
+insert into t set a=1;
+drop table t;
+create table t (
+x int,
+a int generated always as (x) virtual,
+b int generated always as (1) stored,
+c int not null,
+unique (b),
+unique (a,b)
+) engine=innodb;
+insert into t(x, c) values(1, 3);
+replace into t(x, c) values(1, 0);
+drop table t;
+CREATE TABLE t(
+c7c CHAR(1)GENERATED ALWAYS AS (c3) VIRTUAL,
+c1 int(1),
+c2 int(1),
+c3 int(1),
+c4 int(1),
+c5 int(1)GENERATED ALWAYS AS ((c2 - c4)) VIRTUAL,
+UNIQUE KEY c5_9(c5)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ALTER TABLE t CHANGE COLUMN c5 c5 INT(1) GENERATED ALWAYS AS(c2 -
+c4)VIRTUAL AFTER c3,ALGORITHM=INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
+ALTER TABLE t CHANGE COLUMN c7c c7c INT(1) GENERATED ALWAYS AS(c3)
+VIRTUAL AFTER c5,ALGORITHM=INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
+ALTER TABLE t DROP COLUMN c7c,ADD COLUMN c5c INT GENERATED ALWAYS AS(c4/
+c3)VIRTUAL AFTER c3,ALGORITHM=INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+DROP TABLE t;
+CREATE TABLE `t` (
+`col1` int(11) DEFAULT NULL,
+`col2` int(11) DEFAULT NULL,
+`col4` int(11) DEFAULT NULL,
+`col5` int(11) GENERATED ALWAYS AS ((`col2` % `col4`)) VIRTUAL,
+`col6` int(11) GENERATED ALWAYS AS ((`col2` - `col2`)) VIRTUAL,
+`col5x` int(11) GENERATED ALWAYS AS ((`col1` / `col1`)) VIRTUAL,
+`col6x` int(11) GENERATED ALWAYS AS ((`col2` / `col4`)) VIRTUAL,
+`col7x` int(11) GENERATED ALWAYS AS ((`col6` % `col6x`)) VIRTUAL,
+`col8x` int(11) GENERATED ALWAYS AS ((`col6` / `col6`)) VIRTUAL,
+`col9` text,
+`col7c` int(11) GENERATED ALWAYS AS ((`col6x` % `col6x`)) VIRTUAL,
+`col1b` varchar(20) GENERATED ALWAYS AS (`col1`) VIRTUAL,
+`col3` int(11) DEFAULT NULL,
+`col7` int(11) DEFAULT NULL,
+`col5c` int(11) GENERATED ALWAYS AS ((`col5x` * `col6`)) VIRTUAL,
+`col6c` varchar(20) GENERATED ALWAYS AS (`col5x`) VIRTUAL,
+`col3b` bigint(20) GENERATED ALWAYS AS ((`col6x` * `col6`)) VIRTUAL,
+`col1a` varchar(20) GENERATED ALWAYS AS (`col1`) VIRTUAL,
+`col8` int(11) DEFAULT NULL,
+UNIQUE KEY `col5` (`col5`),
+UNIQUE KEY `col6x` (`col6x`),
+UNIQUE KEY `col5_2` (`col5`),
+KEY `idx2` (`col9`(10)),
+KEY `idx4` (`col2`),
+KEY `idx8` (`col9`(10),`col5`),
+KEY `idx9` (`col6`),
+KEY `idx6` (`col6`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+Warnings:
+Note 1831 Duplicate index `col5_2`. This is deprecated and will be disallowed in a future release
+Note 1831 Duplicate index `idx6`. This is deprecated and will be disallowed in a future release
+ALTER TABLE t CHANGE COLUMN col3b col8a BIGINT GENERATED ALWAYS AS
+(col6x * col6) VIRTUAL, ADD UNIQUE KEY uidx ( col8a );
+DROP TABLE t;
+#
+# Bug 22141031 - GCOLS: PURGED THREAD DIES: TRIED TO PURGE
+# NON-DELETE-MARKED RECORD IN INDEX
+#
+create table t (
+a int,b int,c text,d int,e int,f int,g int,
+h text generated always as ('1') virtual,
+i int,j int,k int,l int,m int,
+primary key (c(1)),unique key (c(1)),
+key (i),key (h(1))
+) engine=innodb default charset latin1;
+replace into t(c) values ('');
+replace into t(c) values ('');
+alter table t drop column d ;
+drop table t;
+#
+# Bug 22139917 - ASSERTION: DICT_TABLE_GET_NTH_COL(USER_TABLE, NTH_COL)
+# ->LEN < NEW_LEN
+#
+create table t (
+a int generated always as (1) virtual,
+b varbinary(1),
+c varbinary(1) generated always as (b) virtual
+) engine=innodb;
+alter table t change column b b varbinary(2), algorithm=inplace;
+alter table t change column c c varbinary(2) generated always as (b) virtual, algorithm=inplace;
+drop table t;
+SET @@SESSION.sql_mode=0;
+CREATE TABLE t(
+c1 INT AUTO_INCREMENT,
+c2 INT,
+c3 INT GENERATED ALWAYS AS(c2 + c2)VIRTUAL,
+c3k INT GENERATED ALWAYS AS(c2 + c3)VIRTUAL,
+c4 DATE,
+c5 DATE GENERATED ALWAYS AS(DATE_ADD(c4,interval 30 day)) VIRTUAL,
+c5k DATE GENERATED ALWAYS AS(DATE_ADD(c4,interval 30 day)) VIRTUAL,
+c5time_gckey DATE,
+c6 TIME,
+c5time DATE GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c6)) VIRTUAL,
+c7 TIME GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c6)) VIRTUAL,
+c5timek DATE GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c7)) VIRTUAL,
+c7k TIME GENERATED ALWAYS AS(ADDTIME(c5time,c6)) VIRTUAL,
+c8 CHAR(10),
+c9 CHAR(20)GENERATED ALWAYS AS (CONCAT(RTRIM(c8),RTRIM(c8))) VIRTUAL,
+c9k CHAR(15)GENERATED ALWAYS AS (CONCAT(RTRIM(c8),0)) VIRTUAL,
+PRIMARY KEY(c1),
+KEY(c3),
+KEY(c9(10)),
+UNIQUE KEY(c9k),
+UNIQUE KEY(c3k,c9k(5),c5k,c7k,c5timek,c3,c9(5),c5,c7,c5time)
+)ENGINE=INNODB;
+INSERT INTO
+t(c2,c4,c6,c5time_gckey,c8)VALUES(1,0,0,0,0),(0,0,0,0,'ityzg'),(0,0,1,0,'tyzgk
+t'),(0,1,0,1,'yzgktb'),(0,0,0,0,'zgktb'),(0,0,0,0,'gktbkj'),(0,0,0,0,0),(0,0,1
+,0,1),(0,0,0,0,1),(0,0,0,0,'tbkjrkm'),(0,0,0,0,'bkjr'),(0,0,0,0,0),(0,0,0,0,0)
+,(0,0,0,0,'rk'),(0,0,0,0,'kmqmknbtoe'),(1,0,0,0,'mqmknbt'),(0,1,0,0,'qmknb'),(
+0,0,0,0,'mkn'),(0,0,0,0,'knbtoervql'),(0,0,1,0,1),(0,0,0,0,'nbtoerv'),(0,0,0,0
+,'btoerv'),(0,0,1,0,'toer'),(1,0,0,0,0),(0,0,0,0,'ervq'),(0,0,0,0,'rvqlzsvasu'
+),(0,0,0,0,'vqlzs'),(0,0,0,0,0),(0,1,0,0,'lzsvasu'),(0,0,0,0,'zsvasurq');
+ERROR 23000: Duplicate entry '00' for key 'c9k'
+SELECT
+DISTINCT * FROM t
+FORCE KEY(PRIMARY,c3k,c3,c9k,c9)
+WHERE
+(c9 IS NULL AND (c9=0))
+OR(
+(c9k NOT IN ('ixfq','xfq','New Mexico','fq')OR c9 IS NULL)
+)
+OR(c9 BETWEEN 'hwstqua' AND 'wstquadcji' OR (c9k=0))
+AND(c3 IS NULL OR c3 IN (0,0,0));
+c1 c2 c3 c3k c4 c5 c5k c5time_gckey c6 c5time c7 c5timek c7k c8 c9 c9k
+drop table t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), d INT
+GENERATED ALWAYS AS(a+b+b), e INT GENERATED ALWAYS AS(a), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, DEFAULT, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c, d);
+CREATE INDEX idx1 ON t(c);
+CREATE INDEX idx2 ON t(e, c, d);
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+SELECT d FROM t;
+d
+NULL
+17
+20
+30
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `d` int(11) GENERATED ALWAYS AS (`a` + `b` + `b`) VIRTUAL,
+ `e` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ KEY `idx` (`d`),
+ KEY `idx2` (`e`,`d`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t DROP COLUMN d, ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+ALTER TABLE t DROP COLUMN d, ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (e), ALGORITHM=INPLACE, LOCK=NONE;
+Warnings:
+Note 1831 Duplicate index `idx`. This is deprecated and will be disallowed in a future release
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `e` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ KEY `idx2` (`e`),
+ KEY `idx` (`e`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t ADD INDEX idx4(c, e), ADD COLUMN x VARCHAR(10) GENERATED ALWAYS AS(h), DROP INDEX idx, ALGORITHM=INPLACE, LOCK=NONE;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `e` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `x` varchar(10) GENERATED ALWAYS AS (`h`) VIRTUAL,
+ KEY `idx2` (`e`),
+ KEY `idx4` (`c`,`e`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD COLUMN j INT, ALGORITHM=INPLACE;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+ALTER TABLE t ADD INDEX (x), ADD COLUMN j INT, ALGORITHM=INPLACE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t ADD INDEX (x), ADD COLUMN j INT, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `e` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `x` varchar(10) GENERATED ALWAYS AS (`h`) VIRTUAL,
+ `j` int(11) DEFAULT NULL,
+ KEY `idx2` (`e`),
+ KEY `idx4` (`c`,`e`),
+ KEY `x` (`x`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD INDEX (i), ALGORITHM=INPLACE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try LOCK=SHARED
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD INDEX (i), ALGORITHM=INPLACE, LOCK=SHARED;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `e` int(11) GENERATED ALWAYS AS (`a`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `x` varchar(10) GENERATED ALWAYS AS (`h`) VIRTUAL,
+ `j` int(11) DEFAULT NULL,
+ `i` int(11) GENERATED ALWAYS AS (`a` + `a` + `b`) VIRTUAL,
+ KEY `idx2` (`e`),
+ KEY `idx4` (`c`,`e`),
+ KEY `x` (`x`),
+ KEY `i` (`i`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT i FROM t;
+i
+NULL
+25
+37
+57
+SELECT * FROM t;
+a b e h c x j i
+11 3 11 mm 14 mm NULL 25
+18 1 18 mm 19 mm NULL 37
+28 1 28 mm 29 mm NULL 57
+NULL NULL NULL mm NULL mm NULL NULL
+DROP TABLE t;
+CREATE TABLE t (
+a INT,
+b INT,
+c INT GENERATED ALWAYS AS(a+b),
+d INT GENERATED ALWAYS AS(a+b+b),
+KEY vidx (c, d)
+)ENGINE=INNODB;
+INSERT INTO t (a,b) VALUES (0, 0), (1, NULL), (NULL, 2), (NULL, NULL);
+SELECT c, d FROM t;
+c d
+NULL NULL
+NULL NULL
+NULL NULL
+0 0
+SELECT * FROM t;
+a b c d
+0 0 0 0
+1 NULL NULL NULL
+NULL 2 NULL NULL
+NULL NULL NULL NULL
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+SELECT d FROM t;
+d
+NULL
+NULL
+NULL
+0
+SELECT * FROM t;
+a b d
+0 0 0
+1 NULL NULL
+NULL 2 NULL
+NULL NULL NULL
+DROP TABLE t;
+CREATE TABLE t (
+a INT,
+b INT,
+c INT GENERATED ALWAYS AS(a+b),
+d INT GENERATED ALWAYS AS(a+b+b)
+)ENGINE=INNODB;
+INSERT INTO t (a,b) VALUES (0, 0), (1, NULL), (NULL, 2), (NULL, NULL);
+SELECT * FROM t;
+a b c d
+0 0 0 0
+1 NULL NULL NULL
+NULL 2 NULL NULL
+NULL NULL NULL NULL
+ALTER TABLE t DROP COLUMN c, ADD INDEX vidx(d), ALGORITHM=INPLACE;
+SELECT d FROM t;
+d
+NULL
+NULL
+NULL
+0
+SELECT * FROM t WHERE d > 0;
+a b d
+SELECT * FROM t;
+a b d
+0 0 0
+1 NULL NULL
+NULL 2 NULL
+NULL NULL NULL
+DROP TABLE t;
+#
+# Bug #22162200 MEMORY LEAK IN HA_INNOPART_SHARE
+# ::SET_V_TEMPL PARTITIONED ON VIRTUAL COLUMN
+#
+create table t (
+c tinyint,
+d longblob generated always as (c) virtual
+) engine=innodb partition by key (c) partitions 2;
+select d in(select d from t)from t group by d;
+d in(select d from t)
+drop table t;
+#
+# BUG#23052231 - ASSERTION FAILURE: ROW0MERGE.CC:2100:ADD_AUTOINC
+# < DICT_TABLE_GET_N_USER_COLS
+#
+CREATE TABLE `t` (
+`a` int(11) NOT NULL,
+`d` int(11) NOT NULL,
+`b` varchar(198) NOT NULL,
+`c` char(177) DEFAULT NULL,
+`vadcol` int(11) GENERATED ALWAYS AS ((`a` + length(`d`))) STORED,
+`vbcol` char(2) GENERATED ALWAYS AS (substr(`b`,2,2)) VIRTUAL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+PRIMARY KEY (`b`(10),`a`,`d`),
+KEY `d` (`d`),
+KEY `a` (`a`),
+KEY `c_renamed` (`c`(99),`b`(35)),
+KEY `b` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `a_2` (`a`,`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t values (11, 1, "11", "aa", default, default, default);
+ALTER TABLE t ADD COLUMN nc01128 BIGINT AUTO_INCREMENT NOT NULL, ADD KEY auto_nc01128(nc01128);
+DROP TABLE t;
+#
+#Bug #22965271 NEEDS REBUILD FOR COLUMN LENGTH CHANGE THAT IS
+#PART OF VIRTUAL INDEX.
+#
+CREATE TABLE t1(
+a VARCHAR(45) CHARACTER SET LATIN1,
+b VARCHAR(115) CHARACTER SET UTF8 GENERATED ALWAYS AS ('f1') VIRTUAL,
+UNIQUE KEY (b,a))ENGINE=INNODB;
+INSERT INTO t1(a) VALUES ('');
+ALTER TABLE t1 CHANGE COLUMN a a VARCHAR(85);
+SELECT * FROM t1;
+a b
+ f1
+DROP TABLE t1;
+CREATE TABLE t1 (a INT GENERATED ALWAYS AS(1) VIRTUAL) ENGINE=InnoDB;
+ALTER TABLE t1 ADD b INT GENERATED ALWAYS AS (2) VIRTUAL;
+ALTER TABLE t1 ADD c INT;
+SELECT * FROM t1;
+a b c
+INSERT INTO t1 SET c=3;
+SELECT * FROM t1;
+a b c
+1 2 3
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_blob.result b/mysql-test/suite/gcol/r/innodb_virtual_blob.result
new file mode 100644
index 00000000..f44716ea
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_blob.result
@@ -0,0 +1,12 @@
+#
+# Bug#22046353 ALTER: ASSERT PAGE_SIZE.EQUALS_TO(SPACE_PAGE_SIZE),
+# BTR_COPY_BLOB_PREFIX
+#
+CREATE TABLE t1
+( f1 int primary key, f2 blob,
+f3 blob generated always as (f2))
+row_format=compressed, engine=innodb;
+insert into t1 (f1, f2) values (1, repeat('&', 50000));
+alter table t1 add index i1 (f3(200)) ;
+alter table t1 row_format=compact;
+drop table t1;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_debug.result b/mysql-test/suite/gcol/r/innodb_virtual_debug.result
new file mode 100644
index 00000000..3f3e3ea3
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_debug.result
@@ -0,0 +1,147 @@
+set default_storage_engine=innodb;
+CREATE TABLE `t` (
+`a` VARCHAR(100),
+`b` VARCHAR(100),
+`c` VARCHAR(200) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`h` VARCHAR(10) DEFAULT NULL,
+`i` int
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 10), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
+CREATE INDEX idx ON t(c(100));
+SET session debug_dbug="+d,ib_alter_add_virtual_fail";
+ALTER TABLE t ADD COLUMN x VARCHAR(200) GENERATED ALWAYS AS (a) VIRTUAL,
+ALGORITHM = INPLACE;
+ERROR 42000: The storage engine InnoDB can't index column `x`
+ALTER TABLE t DROP COLUMN c, ALGORITHM = INPLACE;
+ERROR 42000: The storage engine InnoDB can't index column `c`
+SET session debug_dbug="";
+DROP TABLE t;
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, "mx");
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+CREATE INDEX idx ON t(c);
+connect con1,localhost,root,,;
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+update t set a=0 where a = 11;
+start transaction;
+update t set a=1 where a = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+connection default;
+SELECT c FROM t;
+c
+NULL
+3
+19
+29
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ KEY `idx` (`c`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t;
+a b c h
+0 3 3 mm
+18 1 19 mm
+28 1 29 mm
+NULL NULL NULL mx
+ALTER TABLE t FORCE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+disconnect con1;
+DROP TABLE t;
+SET DEBUG_SYNC = 'RESET';
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+CREATE INDEX idx_1 on t(c);
+SET @saved_dbug = @@SESSION.debug_dbug;
+SET debug_dbug = '+d,create_index_fail';
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x),
+ADD INDEX idcx (c,x);
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+UPDATE t SET a=a+1;
+affected rows: 3
+info: Rows matched: 4 Changed: 3 Warnings: 0
+ALTER TABLE t ADD INDEX idc(c);
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+SET debug_dbug = @saved_dbug;
+affected rows: 0
+UPDATE t SET b=b-1;
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ `h` varchar(10) DEFAULT NULL,
+ KEY `idx_1` (`c`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT c FROM t;
+c
+NULL
+14
+19
+29
+DROP TABLE t;
+SET DEBUG_SYNC = 'RESET';
+#
+# Bug#28825718 - ASSERTION FAILURE: TRX0REC.CC:NNN:N_IDX > 0 WHILE DOING REPLACE/INSERT
+#
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, c INT GENERATED ALWAYS AS(b+1) VIRTUAL) ENGINE=InnoDB;
+INSERT INTO t1(a, b) VALUES(1, 1);
+connect con1,localhost,root,,;
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL s1 WAIT_FOR s2';
+SET lock_wait_timeout = 1;
+ALTER TABLE t1 ADD UNIQUE INDEX(c, b);
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR s1';
+SET DEBUG_SYNC = 'row_log_insert_handle SIGNAL s2 WAIT_FOR s3';
+INSERT INTO t1(a, b) VALUES(2, 2);
+connection con1;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC = 'now SIGNAL s3';
+disconnect con1;
+connection default;
+SET DEBUG_SYNC = 'RESET';
+ALTER TABLE t1 ADD KEY(b);
+INSERT INTO t1(a, b) VALUES(3, 3);
+SELECT * FROM t1;
+a b c
+1 1 2
+2 2 3
+3 3 4
+CHECK TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+DROP TABLE t1;
+#
+# MDEV-28806 Assertion `flag == 1' failure in
+# row_build_index_entry_low upon concurrent ALTER and UPDATE
+#
+CREATE TABLE t1(a CHAR(8), b INT, c INT AS (b), KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1(b) VALUES (1),(2);
+connect con1,localhost,root,,test;
+SET DEBUG_SYNC="alter_table_inplace_before_lock_upgrade SIGNAL dml_start WAIT_FOR dml_commit";
+ALTER TABLE t1 ADD KEY ind (c);
+connection default;
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+UPDATE t1 SET a ='foo';
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+connection con1;
+CHECK TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+DROP TABLE t1;
+disconnect con1;
+connection default;
+SET DEBUG_SYNC=RESET;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_debug_purge.result b/mysql-test/suite/gcol/r/innodb_virtual_debug_purge.result
new file mode 100644
index 00000000..63ea5b1d
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_debug_purge.result
@@ -0,0 +1,205 @@
+set default_storage_engine=innodb;
+set @old_dbug=@@global.debug_dbug;
+SET @saved_stats_persistent = @@GLOBAL.innodb_stats_persistent;
+SET GLOBAL innodb_stats_persistent = OFF;
+CREATE TABLE `t` (
+`a` BLOB,
+`b` BLOB,
+`c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+`h` VARCHAR(10) DEFAULT NULL,
+`i` int
+) ENGINE=InnoDB;
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, "mm", 2);
+CREATE INDEX idx ON t(c(100));
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
+InnoDB 0 transactions not purged
+SET global debug_dbug=@old_dbug;
+DROP TABLE t;
+CREATE TABLE t (
+a TINYBLOB,
+b TINYBLOB,
+c TINYBLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+h VARCHAR(10) DEFAULT NULL,
+i INT
+) ROW_FORMAT=COMPACT ENGINE=InnoDB;
+INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 100), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
+CREATE INDEX idx ON t(c(100));
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t SET a = REPEAT('m', 100) WHERE a like "aaa%";
+InnoDB 0 transactions not purged
+SET global debug_dbug=@old_dbug;
+DROP TABLE t;
+CREATE TABLE t1 (
+id INT NOT NULL,
+store_id INT NOT NULL,
+x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21)
+);
+insert into t1 values(1, 2, default);
+insert into t1 values(3, 4, default);
+insert into t1 values(3, 12, default);
+insert into t1 values(4, 18, default);
+CREATE INDEX idx ON t1(x);
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t1 SET id = 10 WHERE id = 1;
+InnoDB 0 transactions not purged
+SET global debug_dbug=@old_dbug;
+DROP TABLE t1;
+connect con1,localhost,root,,;
+connection default;
+CREATE TABLE t1 (a INT, b INT);
+INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3);
+connection con1;
+# disable purge
+CREATE TABLE t0 (a INT) ENGINE=InnoDB;
+BEGIN;
+SELECT * FROM t0;
+a
+connection default;
+DELETE FROM t1 WHERE a = 1;
+UPDATE t1 SET a = 4, b = 4 WHERE a = 3;
+INSERT INTO t1(a, b) VALUES (5, 5);
+SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
+ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try LOCK=SHARED
+ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
+# enable purge
+COMMIT;
+# wait for purge to process the deleted records.
+InnoDB 1 transactions not purged
+SET DEBUG_SYNC= 'now SIGNAL purged';
+connection default;
+/* connection default */ ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ KEY `idx` (`c`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1;
+a b c
+2 2 4
+4 4 8
+5 5 10
+DROP TABLE t1;
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b));
+INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3), (4, 4);
+connection con1;
+# disable purge
+BEGIN;
+SELECT * FROM t0;
+a
+connection default;
+DELETE FROM t1 WHERE a = 1;
+UPDATE t1 SET a = 2, b = 2 WHERE a = 5;
+INSERT INTO t1(a, b) VALUES (6, 6);
+SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
+ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
+DELETE FROM t1 WHERE a = 3;
+UPDATE t1 SET a = 7, b = 7 WHERE a = 4;
+INSERT INTO t1(a, b) VALUES (8, 8);
+# enable purge
+COMMIT;
+# wait for purge to process the deleted/updated records.
+InnoDB 2 transactions not purged
+SET DEBUG_SYNC= 'now SIGNAL purged';
+disconnect con1;
+connection default;
+/* connection default */ ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) DEFAULT NULL,
+ `c` int(11) GENERATED ALWAYS AS (`a` + `b`) VIRTUAL,
+ KEY `idx` (`c`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+SELECT * FROM t1;
+a b c
+2 2 4
+7 7 14
+6 6 12
+8 8 16
+DROP TABLE t0, t1;
+create table t (a blob, b blob, c blob as (concat(a,b)), h varchar(10), index (c(100)));
+insert t(a,b,h) values (repeat('g', 16000), repeat('x', 16000), "kk");
+insert t(a,b,h) values (repeat('a', 16000), repeat('b', 16000), "mm");
+set global debug_dbug="d,ib_purge_virtual_index_callback";
+connect prevent_purge, localhost, root;
+start transaction with consistent snapshot;
+connection default;
+update t set a = repeat('m', 16000) where a like "aaa%";
+connect lock_table, localhost, root;
+lock table t write;
+connection prevent_purge;
+commit;
+connection default;
+disconnect lock_table;
+InnoDB 0 transactions not purged
+set global debug_dbug=@old_dbug;
+drop table t;
+#
+# MDEV-15165 InnoDB purge for index on virtual column
+# is trying to access an incomplete record
+#
+CREATE TABLE t1(
+u INT PRIMARY KEY, b BLOB, ug INT GENERATED ALWAYS AS (u) VIRTUAL,
+INDEX bug(b(100),ug)
+) ENGINE=InnoDB;
+INSERT INTO t1 (u,b) VALUES(1,REPEAT('a',16384));
+connection prevent_purge;
+start transaction with consistent snapshot;
+connection default;
+DELETE FROM t1;
+SET DEBUG_SYNC='blob_write_middle SIGNAL halfway WAIT_FOR purged';
+INSERT INTO t1 (u,b) VALUES(1,REPEAT('a',16384));
+connection prevent_purge;
+SET DEBUG_SYNC='now WAIT_FOR halfway';
+COMMIT;
+InnoDB 0 transactions not purged
+SET DEBUG_SYNC='now SIGNAL purged';
+connection default;
+DROP TABLE t1;
+CREATE TABLE t1 (y YEAR, vy YEAR AS (y) VIRTUAL UNIQUE, pk INT PRIMARY KEY)
+ENGINE=InnoDB;
+INSERT INTO t1 (pk,y) VALUES (1,2022);
+CREATE TABLE t2(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
+SET GLOBAL debug_dbug = 'd,ib_purge_virtual_index_callback';
+BEGIN;
+INSERT INTO t2(f1) VALUES(1);
+connection prevent_purge;
+SET DEBUG_SYNC=RESET;
+start transaction with consistent snapshot;
+connection default;
+COMMIT;
+connect truncate,localhost,root,,;
+REPLACE INTO t1(pk, y) SELECT pk,y FROM t1;
+TRUNCATE TABLE t1;
+connection prevent_purge;
+COMMIT;
+SET DEBUG_SYNC='now SIGNAL purge_start';
+disconnect prevent_purge;
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR purge_start';
+InnoDB 0 transactions not purged
+SET GLOBAL debug_dbug=@old_dbug;
+connection truncate;
+disconnect truncate;
+connection default;
+DROP TABLE t1, t2;
+set debug_sync=reset;
+SET GLOBAL innodb_stats_persistent = @saved_stats_persistent;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_fk.result b/mysql-test/suite/gcol/r/innodb_virtual_fk.result
new file mode 100644
index 00000000..97058bc2
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_fk.result
@@ -0,0 +1,1028 @@
+set default_storage_engine=innodb;
+#
+# Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
+# WHEN A VIRTUAL INDEX EXISTS.
+# UPDATE CASCADE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# UPDATE SET NULL
+CREATE TABLE t1(fld1 INT NOT NULL, fld2 INT NOT NULL PRIMARY KEY,
+KEY(fld1));
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE SET NULL);
+INSERT INTO t1 VALUES(1, 2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+NULL
+SELECT * FROM t2;
+fld1 fld2
+NULL NULL
+DROP TABLE t2, t1;
+# DELETE CASCADE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t1 VALUES(2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+INSERT INTO t2 VALUES(2, DEFAULT);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# DELETE SET NULL
+CREATE TABLE t1(fld1 INT NOT NULL, fld2 INT NOT NULL PRIMARY KEY, KEY(fld1));
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE SET NULL);
+INSERT INTO t1 VALUES(1, 1);
+INSERT INTO t1 VALUES(2, 2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+INSERT INTO t2 VALUES(2, DEFAULT);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2 FROM t2;
+fld2
+NULL
+2
+SELECT * FROM t2;
+fld1 fld2
+NULL NULL
+2 2
+DROP TABLE t2, t1;
+# VIRTUAL INDEX CONTAINS FK CONSTRAINT COLUMN
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT, fld3 INT AS (fld2) VIRTUAL,
+KEY(fld3, fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 3);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+3 2
+SELECT * FROM t2;
+fld1 fld2 fld3
+2 3 3
+DROP TABLE t2, t1;
+# Multiple level of VIRTUAL columns.
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld3), KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT fld3 FROM t2;
+fld3
+2
+SELECT * FROM t2;
+fld1 fld2 fld3
+2 2 2
+DROP TABLE t2, t1;
+# Drop the VIRTUAL INDEX using alter copy ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL, KEY vk(fld2),
+KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+3 3
+DROP TABLE t2, t1;
+# Drop the VIRTUAL INDEX using INPLACE alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY vk(fld2), KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+3 3
+DROP TABLE t2, t1;
+# Add the VIRTUAL INDEX using COPY alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+3 3
+DROP TABLE t2, t1;
+# Add the VIRTUAL INDEX using INPLACE alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,fld2 INT AS (fld1) VIRTUAL,
+KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM= INPLACE;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+3 3
+DROP TABLE t2, t1;
+# Drop the VIRTUAL INDEX contains fk constraint column
+# using alter copy ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY vk(fld3, fld1),
+KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 2
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 3
+DROP TABLE t2, t1;
+# Drop the VIRTUAL INDEX which contains fk constraint column
+# using INPLACE alter operation
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY vk(fld3, fld1),
+KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 2
+alter TABLE t2 DROP INDEX vk, ALGORITHM= INPLACE;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 3
+DROP TABLE t2, t1;
+# Add the VIRTUAL INDEX contains fk constraint column
+# using copy alter operatiON
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 2
+alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 3
+DROP TABLE t2, t1;
+# Cascading UPDATEs and DELETEs for the multiple
+# fk dependent TABLEs
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY(fld1), KEY(fld2, fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY(fld2, fld1),
+FOREIGN KEY(fld1) REFERENCES t2(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2(fld1) VALUES(1), (2);
+INSERT INTO t3(fld1) VALUES(1), (2);
+UPDATE t1 SET fld1= 4 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+4 4
+SELECT fld2, fld1 FROM t3;
+fld2 fld1
+2 2
+4 4
+DROP TABLE t3, t2, t1;
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1), KEY(fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1),
+FOREIGN KEY(fld1) REFERENCES t2(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, 1, DEFAULT), (2, 2, default);
+INSERT INTO t3 VALUES(1, 1, DEFAULT), (2, 2, default);
+UPDATE t1 SET fld1= 4 WHERE fld1= 1;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+1 4
+2 2
+SELECT fld3, fld1 FROM t3;
+fld3 fld1
+1 4
+2 2
+DROP TABLE t3, t2, t1;
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY(fld1), KEY(fld2, fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+KEY(fld2, fld1), FOREIGN KEY(fld1) REFERENCES t2(fld1)
+ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2(fld1) VALUES(1), (2);
+INSERT INTO t3(fld1) VALUES(1), (2);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t2;
+fld2 fld1
+2 2
+SELECT fld2, fld1 FROM t3;
+fld2 fld1
+2 2
+DROP TABLE t3, t2, t1;
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL,
+KEY(fld3, fld1), KEY(fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON DELETE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1),
+FOREIGN KEY(fld1) REFERENCES t2(fld1)
+ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, 1, DEFAULT), (2, 2, default);
+INSERT INTO t3 VALUES(1, 1, DEFAULT), (2, 2, default);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 2
+SELECT fld3, fld1 FROM t3;
+fld3 fld1
+2 2
+DROP TABLE t3, t2, t1;
+# RENAME TABLE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY(fld2, fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+RENAME TABLE t2 to t3;
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t3;
+fld2 fld1
+2 2
+DROP TABLE t3, t1;
+# FOREIGN_KEY_CHECKS disabled DURING INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 3 WHERE fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+3
+DROP TABLE t2, t1;
+# GENERATED COLUMN COMPUTATION FAILS when SQL_MODE
+# is set to ERROR_FOR_DIVISION_BY_ZERO
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (100/fld1) VIRTUAL,
+KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+UPDATE IGNORE t1 SET fld1= 0 WHERE fld1= 2;
+Warnings:
+Warning 1365 Division by 0
+SELECT fld2 FROM t2;
+fld2
+NULL
+100
+DROP TABLE t2, t1;
+# CHANGE SQL_MODE and try the ERROR_FOR_DIVISION_BY_ZERO
+SET sql_mode = STRICT_ALL_TABLES;
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (100/fld1) VIRTUAL,
+KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+UPDATE t1 SET fld1= 0 WHERE fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+NULL
+100
+SELECT * FROM t2;
+fld1 fld2
+1 100
+0 NULL
+DROP TABLE t2, t1;
+SET sql_mode = default;
+# ADD FOREIGN CONSTRAINT USING COPY
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL, KEY(fld2));
+ALTER TABLE t2 ADD FOREIGN KEY (fld1)
+REFERENCES t1(fld1) ON UPDATE CASCADE,
+ALGORITHM=copy;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# ADD FOREIGN CONSTRAINT USING INPLACE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL, KEY(fld2));
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD FOREIGN KEY (fld1)
+REFERENCES t1(fld1) ON UPDATE CASCADE,
+ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# DROP FOREIGN CONSTRAINT USING COPY
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+CONSTRAINT fidx FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP FOREIGN KEY fidx, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+# DROP FOREIGN CONSTRAINT USING INPLACE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+CONSTRAINT fidx FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP FOREIGN KEY fidx, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+# ADD VC INDEX and ADD FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 ADD INDEX(fld2), ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE, ALGORITHM=copy;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# ADD VC INDEX and ADD FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX(fld2), ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE, ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# ADD VC INDEX and DROP FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 ADD INDEX(fld2), DROP FOREIGN KEY fidx, ALGORITHM=copy;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+# ADD VC INDEX and DROP FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX(fld2), DROP FOREIGN KEY fidx, ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+# DROP VC INDEX and ADD FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY idx(fld2));
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP INDEX idx, ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# DROP VC INDEX and ADD FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY idx(fld2));
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP INDEX idx, ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+2
+SELECT * FROM t2;
+fld1 fld2
+2 2
+DROP TABLE t2, t1;
+# DROP VC INDEX and DROP FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY idx(fld2),
+CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP KEY idx, DROP FOREIGN KEY fidx, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+# DROP VC INDEX and DROP FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY idx(fld2),
+CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP KEY idx, DROP FOREIGN KEY fidx, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+fld2
+1
+SELECT * FROM t2;
+fld1 fld2
+1 1
+DROP TABLE t2, t1;
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+KEY (f1, f2), FOREIGN KEY(f1) REFERENCES t1(f1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+EXPLAIN SELECT f1, f2 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL f1 9 NULL 1 Using index
+SELECT f1, f2 FROM t2;
+f1 f2
+1 1
+INSERT INTO t2(f1) VALUES(2);
+ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`))
+DROP TABLE t2, t1;
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+KEY (f1, f2), FOREIGN KEY(f1) REFERENCES t1(f1)
+ON UPDATE CASCADE)ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+EXPLAIN SELECT f1, f2 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL f1 9 NULL 1 Using index
+SELECT f1, f2 FROM t2;
+f1 f2
+1 1
+UPDATE t1 SET f1 = 2 WHERE f1 = 1;
+EXPLAIN SELECT f1, f2 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL f1 9 NULL 1 Using index
+SELECT f1, f2 FROM t2;
+f1 f2
+2 2
+DROP TABLE t2, t1;
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+KEY (f1, f2))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+SET FOREIGN_KEY_CHECKS = 0;
+ALTER TABLE t2 ADD FOREIGN KEY (f1) REFERENCES t1(f1)
+ON UPDATE CASCADE, ALGORITHM=INPLACE;
+SET FOREIGN_KEY_CHECKS = 1;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f2 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL f1 9 NULL 1 Using index
+SELECT f1, f2 FROM t2;
+f1 f2
+3 3
+DROP TABLE t2, t1;
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+KEY (f1, f2))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 ADD FOREIGN KEY (f1) REFERENCES t1(f1)
+ON UPDATE CASCADE, ALGORITHM=COPY;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f2 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL f1 9 NULL 1 Using index
+SELECT f1, f2 FROM t2;
+f1 f2
+3 3
+DROP TABLE t2, t1;
+CREATE TABLE t1(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=INNODB;
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT AS (1) VIRTUAL,
+f3 INT AS (2) VIRTUAL,
+FOREIGN KEY idx (f1) REFERENCES t1(f1) ON UPDATE CASCADE,
+KEY idx1 (f2, f1, f3))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 DROP COLUMN f2, ALGORITHM=INPLACE;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f3 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL idx1 9 NULL 1 Using index
+SELECT f1, f3 FROM t2;
+f1 f3
+3 2
+DROP TABLE t2, t1;
+CREATE TABLE t1(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=INNODB;
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT AS (1) VIRTUAL,
+f3 INT AS (2) VIRTUAL,
+FOREIGN KEY idx (f1) REFERENCES t1(f1) ON UPDATE CASCADE,
+KEY idx1 (f2, f1, f3))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 DROP COLUMN f2, ALGORITHM=COPY;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f3 FROM t2;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t2 index NULL idx1 9 NULL 1 Using index
+SELECT f1, f3 FROM t2;
+f1 f3
+3 2
+DROP TABLE t2, t1;
+#
+# MDEV-15553 Assertion failed in dict_table_get_col_name
+#
+CREATE TABLE t1 (
+c1 TIMESTAMP,
+c2 YEAR,
+c3 TIME,
+c4 CHAR(10),
+v1 TIMESTAMP AS (c1) VIRTUAL,
+v2 YEAR AS (c2) VIRTUAL,
+v3 TIME AS (c3) VIRTUAL,
+v4 CHAR(10) AS (c4) VIRTUAL
+) ENGINE=InnoDB;
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
+SET foreign_key_checks=0;
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk' in the foreign table 't1'
+ALTER TABLE t1 ADD INDEX(v4);
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+SET foreign_key_checks=1;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` timestamp NULL DEFAULT NULL,
+ `c2` year(4) DEFAULT NULL,
+ `c3` time DEFAULT NULL,
+ `c4` char(10) DEFAULT NULL,
+ `v1` timestamp GENERATED ALWAYS AS (`c1`) VIRTUAL,
+ `v2` year(4) GENERATED ALWAYS AS (`c2`) VIRTUAL,
+ `v3` time GENERATED ALWAYS AS (`c3`) VIRTUAL,
+ `v4` char(10) GENERATED ALWAYS AS (`c4`) VIRTUAL,
+ KEY `v4` (`v4`),
+ CONSTRAINT `fk` FOREIGN KEY (`v4`) REFERENCES `nosuch` (`col`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t1 DROP FOREIGN KEY fk;
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `c1` timestamp NULL DEFAULT NULL,
+ `c2` year(4) DEFAULT NULL,
+ `c3` time DEFAULT NULL,
+ `c4` char(10) DEFAULT NULL,
+ `v1` timestamp GENERATED ALWAYS AS (`c1`) VIRTUAL,
+ `v2` year(4) GENERATED ALWAYS AS (`c2`) VIRTUAL,
+ `v3` time GENERATED ALWAYS AS (`c3`) VIRTUAL,
+ `v4` char(10) GENERATED ALWAYS AS (`c4`) VIRTUAL,
+ KEY `v4` (`v4`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+#
+# MDEV-20396 Server crashes after DELETE with SEL NULL Foreign key and a
+# virtual column in index
+#
+CREATE TABLE parent
+(
+ID int unsigned NOT NULL,
+PRIMARY KEY (ID)
+);
+CREATE TABLE child
+(
+ID int unsigned NOT NULL,
+ParentID int unsigned NULL,
+Value int unsigned NOT NULL DEFAULT 0,
+Flag int unsigned AS (Value) VIRTUAL,
+PRIMARY KEY (ID),
+KEY (ParentID, Flag),
+FOREIGN KEY (ParentID) REFERENCES parent (ID) ON DELETE SET NULL
+ON UPDATE CASCADE
+);
+INSERT INTO parent (ID) VALUES (100);
+INSERT INTO child (ID,ParentID,Value) VALUES (123123,100,1);
+DELETE FROM parent WHERE ID=100;
+select * from child;
+ID ParentID Value Flag
+123123 NULL 1 1
+INSERT INTO parent (ID) VALUES (100);
+UPDATE child SET ParentID=100 WHERE ID=123123;
+DROP TABLE child, parent;
+#
+# MDEV-23387 dict_load_foreign() fails to load the table during alter
+#
+SET FOREIGN_KEY_CHECKS=0;
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+f3 INT AS (f1) VIRTUAL,
+INDEX(f1), INDEX(f2))ENGINE=InnoDB;
+ALTER TABLE t1 ADD CONSTRAINT r FOREIGN KEY(f2) REFERENCES t1(f1), LOCK=NONE;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) NOT NULL,
+ `f2` int(11) NOT NULL,
+ `f3` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
+ KEY `f1` (`f1`),
+ KEY `f2` (`f2`),
+ CONSTRAINT `r` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+ALTER TABLE t1 DROP INDEX f1;
+ALTER TABLE t1 DROP f3;
+DROP TABLE t1;
+#
+# MDEV-24041 Generated column DELETE with FOREIGN KEY crash InnoDB
+#
+SET FOREIGN_KEY_CHECKS=1;
+CREATE DATABASE `a-b`;
+USE `a-b`;
+CREATE TABLE emails (
+id int,
+PRIMARY KEY (id)
+) ENGINE=InnoDB;
+CREATE TABLE email_stats (
+id int,
+email_id int,
+date_sent char(4),
+generated_email_id int as (email_id),
+#generated_sent_date DATE GENERATED ALWAYS AS (date_sent),
+PRIMARY KEY (id),
+KEY mautic_generated_sent_date_email_id (generated_email_id),
+FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+ON UPDATE CASCADE
+) ENGINE=InnoDB;
+CREATE TABLE emails_metadata (
+email_id int,
+PRIMARY KEY (email_id),
+CONSTRAINT FK FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE CASCADE
+ON UPDATE CASCADE
+) ENGINE=InnoDB;
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent) VALUES (1,1,'Jan');
+INSERT INTO emails_metadata VALUES (1);
+UPDATE emails SET id=2;
+DELETE FROM emails;
+DROP TABLE email_stats;
+DROP TABLE emails_metadata;
+DROP TABLE emails;
+DROP DATABASE `a-b`;
+USE test;
+#
+# Bug#33053297 VIRTUAL INDEX CORRUPTED DURING CASCADE UPDATE ON CHILD TABLE
+#
+# Test-Case 1
+CREATE TABLE emails (
+id int unsigned NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (id)
+) ENGINE=InnoDB;
+CREATE TABLE email_stats (
+id bigint unsigned NOT NULL AUTO_INCREMENT,
+email_id int unsigned DEFAULT NULL,
+date_sent datetime NOT NULL,
+generated_sent_date date GENERATED ALWAYS AS
+(concat(year(date_sent), '-', lpad(month(date_sent), 2, '0'),
+'-', lpad(dayofmonth(date_sent), 2, '0'))),
+PRIMARY KEY (id),
+KEY IDX_ES1 (email_id),
+KEY mautic_generated_sent_date_email_id(generated_sent_date, email_id),
+FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+) ENGINE = InnoDB;
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_date
+1 1 2020-10-22 13:32:41 2020-10-22
+DELETE FROM emails;
+DELETE FROM email_stats;
+# Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+# Test-Case 2
+CREATE TABLE emails (
+id int unsigned NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (id)
+) ENGINE = InnoDB
+DEFAULT CHARSET = utf8mb4
+COLLATE = utf8mb4_unicode_ci
+ROW_FORMAT = DYNAMIC;
+CREATE TABLE email_stats (
+id bigint unsigned NOT NULL AUTO_INCREMENT,
+email_id int unsigned DEFAULT NULL,
+date_sent datetime NOT NULL,
+generated_sent_date date GENERATED ALWAYS AS
+(concat(year(date_sent), '-', lpad(month(date_sent), 2, '0'),
+'-', lpad(dayofmonth(date_sent), 2, '0'))),
+PRIMARY KEY (id),
+KEY IDX_ES1 (email_id),
+KEY mautic_generated_sent_date_email_id(generated_sent_date, email_id),
+FOREIGN KEY (email_id) REFERENCES emails (id)
+ON DELETE SET NULL
+ON UPDATE SET NULL
+) ENGINE = InnoDB;
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+VALUES (1, 1, '2020-10-22 13:32:41');
+UPDATE emails SET id = 2 where id = 1;
+SELECT id FROM email_stats WHERE generated_sent_date IS NULL;
+id
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_date
+1 NULL 2020-10-22 13:32:41 2020-10-22
+UPDATE email_stats
+SET email_id=2
+WHERE DATE(generated_sent_date) = '2020-10-22';
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_date
+1 2 2020-10-22 13:32:41 2020-10-22
+# Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+# Test-case 3
+CREATE TABLE emails (
+id int unsigned NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (id)
+) ENGINE = INNODB
+DEFAULT CHARSET = utf8mb4
+COLLATE = utf8mb4_unicode_ci
+ROW_FORMAT = DYNAMIC;
+CREATE TABLE email_stats (
+id bigint unsigned NOT NULL AUTO_INCREMENT,
+email_id int unsigned DEFAULT NULL,
+date_sent datetime NOT NULL,
+generated_sent_email varchar(20) GENERATED ALWAYS AS
+(CONCAT(YEAR(date_sent), '-', COALESCE(email_id, '$'))),
+PRIMARY KEY (id),
+KEY idx_es1 (email_id),
+KEY mautic_generated_sent_date_email(generated_sent_email, email_id),
+FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+) ENGINE = INNODB;
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 1 2020-10-22 13:32:41 2020-1
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+date_sent
+2020-10-22 13:32:41
+DELETE FROM emails;
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 NULL 2020-10-22 13:32:41 2020-$
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-$';
+date_sent
+2020-10-22 13:32:41
+# Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+# Test-case 4
+CREATE TABLE emails (
+id int unsigned NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (id)
+) ENGINE = INNODB;
+CREATE TABLE email_stats (
+id bigint unsigned NOT NULL AUTO_INCREMENT,
+email_id int unsigned DEFAULT NULL,
+date_sent datetime NOT NULL,
+generated_sent_email varchar(20) GENERATED ALWAYS AS
+(CONCAT(YEAR(date_sent), '-', COALESCE(email_id, '$'))),
+PRIMARY KEY (id),
+KEY idx_es1 (email_id),
+KEY mautic_generated_sent_date_email(generated_sent_email, email_id),
+FOREIGN KEY (email_id) REFERENCES emails (id) ON UPDATE SET NULL
+) ENGINE = INNODB;
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 1 2020-10-22 13:32:41 2020-1
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+date_sent
+2020-10-22 13:32:41
+UPDATE emails SET id = 2 WHERE id = 1;
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 NULL 2020-10-22 13:32:41 2020-$
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-$';
+date_sent
+2020-10-22 13:32:41
+DROP TABLE email_stats;
+DROP TABLE emails;
+CREATE TABLE emails (breaker int unsigned,
+KEY (breaker),
+id int unsigned NOT NULL AUTO_INCREMENT,
+PRIMARY KEY (id)
+) ENGINE=INNODB;
+CREATE TABLE email_stats (
+id bigint unsigned NOT NULL AUTO_INCREMENT,
+email_id int unsigned DEFAULT NULL,
+date_sent datetime NOT NULL,
+generated_sent_email varchar(20) GENERATED ALWAYS AS
+(CONCAT(YEAR(date_sent),
+'-',
+COALESCE(email_id, '$'))),
+PRIMARY KEY (id),
+KEY idx_es1 (email_id),
+KEY mautic_generated_sent_date_email (generated_sent_email, email_id),
+FOREIGN KEY fk_ea1 (email_id) REFERENCES emails (breaker)
+ON DELETE SET NULL
+) ENGINE=INNODB;
+show create table email_stats;
+Table Create Table
+email_stats CREATE TABLE `email_stats` (
+ `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+ `email_id` int(10) unsigned DEFAULT NULL,
+ `date_sent` datetime NOT NULL,
+ `generated_sent_email` varchar(20) GENERATED ALWAYS AS (concat(year(`date_sent`),'-',coalesce(`email_id`,'$'))) VIRTUAL,
+ PRIMARY KEY (`id`),
+ KEY `idx_es1` (`email_id`),
+ KEY `mautic_generated_sent_date_email` (`generated_sent_email`,`email_id`),
+ CONSTRAINT `fk_ea1` FOREIGN KEY (`email_id`) REFERENCES `emails` (`breaker`) ON DELETE SET NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+INSERT INTO emails VALUES (1,1);
+INSERT INTO email_stats(id, email_id, date_sent)
+VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 1 2020-10-22 13:32:41 2020-1
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+date_sent
+2020-10-22 13:32:41
+DELETE FROM emails;
+SELECT * FROM email_stats;
+id email_id date_sent generated_sent_email
+1 NULL 2020-10-22 13:32:41 2020-$
+SELECT date_sent
+FROM email_stats force index (mautic_generated_sent_date_email)
+WHERE generated_sent_email = '2020-$';
+date_sent
+2020-10-22 13:32:41
+SELECT date_sent
+FROM email_stats force index (idx_es1)
+WHERE generated_sent_email = '2020-$';
+date_sent
+2020-10-22 13:32:41
+DROP TABLE email_stats;
+DROP TABLE emails;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_fk_restart.result b/mysql-test/suite/gcol/r/innodb_virtual_fk_restart.result
new file mode 100644
index 00000000..c45579ae
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_fk_restart.result
@@ -0,0 +1,55 @@
+#
+# Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
+# WHEN A VIRTUAL INDEX EXISTS.
+# Add the VIRTUAL INDEX contains fk constraINT column
+# using INPLACE alter operatiON
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
+FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE) engine=innodb;
+CREATE TABLE u1(a INT, KEY(a)) ENGINE=InnoDB;
+CREATE TABLE u2(b INT, vb INT GENERATED ALWAYS AS(b) VIRTUAL, KEY(vb),
+FOREIGN KEY(b) REFERENCES u1(a)ON DELETE CASCADE)ENGINE=InnoDB;
+INSERT INTO u1 SET a=1;
+INSERT INTO u2 SET b=1;
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+# restart
+UPDATE t1 SET fld1= 2;
+DELETE FROM u1;
+SELECT * FROM u2;
+b vb
+DROP TABLE u2,u1;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 2
+alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM=INPLACE;
+UPDATE t1 SET fld1=3;
+SELECT fld3, fld1 FROM t2;
+fld3 fld1
+2 3
+DROP TABLE t2, t1;
+# TEMPORARY TABLE NAME and CHILD TABLE NAME are same
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
+CREATE TABLE t2(fld1 INT NOT NULL,
+fld2 INT AS (fld1) VIRTUAL,
+KEY(fld2),
+FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ON UPDATE CASCADE) engine=innodb;
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+# restart
+CREATE TEMPORARY TABLE t2 (fld1 INT NOT NULL)ENGINE=INNODB;
+UPDATE t1 SET fld1= 3 WHERE fld1= 2;
+connect con1,localhost,root,,test;
+SELECT fld2 FROM t2;
+fld2
+1
+3
+CHECK TABLE t2;
+Table Op Msg_type Msg_text
+test.t2 check status OK
+connection default;
+disconnect con1;
+DROP TABLE t2;
+DROP TABLE t2, t1;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_index.result b/mysql-test/suite/gcol/r/innodb_virtual_index.result
new file mode 100644
index 00000000..a26da4ae
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_index.result
@@ -0,0 +1,372 @@
+SET default_storage_engine= innodb;
+#
+# Bug 21922176 - PREBUILT->SEARCH_TUPLE CREATED WITHOUT INCLUDING
+# THE NUMBER OF VIRTUAL COLUMNS
+#
+CREATE TABLE t1 (a INT, a1 INT GENERATED ALWAYS AS (a) VIRTUAL, a2 INT
+GENERATED ALWAYS AS (a) VIRTUAL, a3 INT GENERATED ALWAYS AS (a) VIRTUAL, a4
+INT GENERATED ALWAYS AS (a) VIRTUAL, a5 INT GENERATED ALWAYS AS (a) VIRTUAL,
+a6 INT GENERATED ALWAYS AS (a) VIRTUAL, a7 INT GENERATED ALWAYS AS (a)
+VIRTUAL, a8 INT GENERATED ALWAYS AS (a) VIRTUAL, a9 INT GENERATED ALWAYS AS
+(a) VIRTUAL, INDEX(a1, a2, a3, a4, a5, a6, a7, a8, a9)) ;
+INSERT INTO t1(a) VALUES(10);
+SELECT * FROM t1 WHERE a1=10 AND a2 = 10 AND a3 =10 AND a4 = 10 AND a5=10 AND
+a6=10 AND a7=10 AND a8=10 AND a9=10;
+a a1 a2 a3 a4 a5 a6 a7 a8 a9
+10 10 10 10 10 10 10 10 10 10
+DROP TABLE t1;
+#
+# Bug 22572997 - GCOL:INNODB: FAILING ASSERTION: N < REC_OFFS_N_FIELDS(
+# OFFSETS)
+#
+SET @@SESSION.sql_mode=0;
+CREATE TABLE t1(
+c1 int(1)AUTO_INCREMENT,
+c2 int(1),
+c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+c5 date,
+c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
+c7 DATE,
+c8 time,
+c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+c12 CHAR(1),
+c13 CHAR(1)GENERATED ALWAYS AS (concat(c12,c12)) VIRTUAL,
+c14 CHAR(2)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
+PRIMARY KEY(c1),
+KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+CREATE TABLE t2(
+c1 int(1)AUTO_INCREMENT,
+c2 int(1),
+c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+c5 date,
+c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
+c6a date GENERATED ALWAYS AS((c6 + interval 30 day)) VIRTUAL,
+c7 DATE,
+c8 time,
+c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+c11a time GENERATED ALWAYS AS(addtime(c7,c10)) VIRTUAL,
+c12 CHAR(1),
+c13 CHAR(2)GENERATED ALWAYS AS (concat(RTRIM(c12),RTRIM(c12))) VIRTUAL,
+c14 CHAR(4)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
+PRIMARY KEY(c1),
+KEY c13(c13),
+KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t2(c1,c2,c5,c7,c8,c12)VALUES (0,0,0,0,0,'v');
+CREATE TABLE t3(
+c1 int(1)AUTO_INCREMENT,
+c2 int(1),
+c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+c5 date,
+c7 DATE,
+c8 time,
+c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+c12 CHAR(1),
+PRIMARY KEY(c1),
+KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t3(c1,c2,c5,c7,c8,c12)VALUES
+(0,0,0,0,0,'q'),(0,0,0,0,0,'g'),(0,0,0,0,0,'l'),(0,0,0,0,0,1),(0,0,0,0,0,'v'),
+(0,1,0,0,0,'c'),(0,0,0,0,0,'x');
+UPDATE
+t2 AS O1,t3 AS O2
+SET O1.c12=1
+WHERE O1.c14 NOT IN
+(
+SELECT
+DISTINCT I1.c14 AS y
+FROM t1 AS I1
+ORDER BY I1.c14);
+SET @@SESSION.sql_mode=default;
+InnoDB 0 transactions not purged
+DROP TABLE t1, t2, t3;
+#
+# Bug 22650296 - ASSERTION IN INNOBASE_BUILD_COL_MAP, ALTER
+#
+CREATE TABLE `ibstd_08` (
+`nc00577` tinyint(4) DEFAULT NULL,
+`nc07844` varchar(41) DEFAULT NULL,
+`gc01908` point NOT NULL,
+`nc04156` char(17) DEFAULT NULL,
+`nc09536` longblob NOT NULL,
+`nc09231` decimal(10,0) NOT NULL,
+`a` int(11) NOT NULL,
+`b` varchar(198) NOT NULL,
+`nc04560` mediumtext,
+`c` char(187) DEFAULT NULL,
+`vbidxcol` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+`gc00881` polygon NOT NULL,
+`nc05121` int(11) NOT NULL DEFAULT '85941481',
+KEY `a` (`a`),
+KEY `b` (`b`(3),`a`),
+KEY `c` (`c`(99),`b`(25)),
+KEY `b_2` (`b`(5),`c`(10),`a`),
+KEY `vbidxcol` (`vbidxcol`),
+KEY `a_2` (`a`,`vbidxcol`),
+KEY `vbidxcol_2` (`vbidxcol`),
+FULLTEXT KEY `ftsic` (`c`,`b`)
+) ENGINE=InnoDB;
+Warnings:
+Note 1831 Duplicate index `vbidxcol_2`. This is deprecated and will be disallowed in a future release
+ALTER TABLE ibstd_08 ADD COLUMN nc07006 BIGINT AUTO_INCREMENT NOT NULL , ADD KEY auto_nc07006(nc07006);
+DROP TABLE ibstd_08;
+#
+# Bug 22899305 - GCOLS: FAILING ASSERTION: !(COL->PRTYPE & 256)
+# AND SEGFAULT
+#
+set sql_mode="";
+create table t (a int) engine=innodb;
+create table s (
+b int generated always as (1) virtual,
+c int,
+d int generated always as (1) virtual,
+key (d)
+) engine=innodb;
+insert into t(a) values ((select d from s for update));
+insert into s(c) values ('');
+Warnings:
+Warning 1366 Incorrect integer value: '' for column `test`.`s`.`c` at row 1
+SET sql_mode = default;
+drop table if exists t,s;
+#
+# Bug 23014521 - GCOL:INNODB: FAILING ASSERTION: !IS_V
+#
+CREATE TABLE t1 (
+col1 int(11) NOT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL,
+col5 int(11) GENERATED ALWAYS AS ((col1 % col4)) VIRTUAL,
+col6 int(11) GENERATED ALWAYS AS ((col2 - col4)) VIRTUAL,
+col5x int(11) GENERATED ALWAYS AS ((col3 / col2)) VIRTUAL,
+col6b varchar(20) GENERATED ALWAYS AS (col2) VIRTUAL,
+col6x int(11) GENERATED ALWAYS AS ((col2 % col1)) VIRTUAL,
+col7 int(11) GENERATED ALWAYS AS ((col6x + col5x)) VIRTUAL,
+col8 int(11) GENERATED ALWAYS AS ((col5x / col5)) VIRTUAL,
+col7x int(11) GENERATED ALWAYS AS ((col5x + col5)) VIRTUAL,
+col8x int(11) GENERATED ALWAYS AS ((col5 / col5x)) VIRTUAL,
+col9 text,
+col2b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
+col8a int(11) GENERATED ALWAYS AS (col2) VIRTUAL,
+col4b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
+col1c int(11) GENERATED ALWAYS AS ((col2 * col1)) VIRTUAL,
+extra int(11) DEFAULT NULL,
+col5c int(11) GENERATED ALWAYS AS ((col1 / col1)) VIRTUAL,
+col6a bigint(20) GENERATED ALWAYS AS ((col3 / col1)) VIRTUAL,
+col1a varchar(20) GENERATED ALWAYS AS (col6) VIRTUAL,
+col6c int(11) GENERATED ALWAYS AS ((col2 % col2)) VIRTUAL,
+col7c bigint(20) GENERATED ALWAYS AS ((col2 / col1)) VIRTUAL,
+col2c int(11) GENERATED ALWAYS AS ((col5 % col5)) VIRTUAL,
+col1b int(11) GENERATED ALWAYS AS ((col1 / col2)) VIRTUAL,
+col3b bigint(20) GENERATED ALWAYS AS ((col6x % col6)) VIRTUAL,
+UNIQUE KEY idx7 (col1,col3,col2),
+UNIQUE KEY uidx (col9(10)),
+KEY idx15 (col9(10) DESC,col2 DESC),
+KEY idx10 (col9(10) DESC,col1 DESC),
+KEY idx11 (col6x DESC),
+KEY idx6 (col9(10) DESC,col7 DESC),
+KEY idx14 (col6 DESC)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
+VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+CREATE FULLTEXT INDEX idx ON t1(col9);
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
+VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
+DROP TABLE t1;
+CREATE TABLE t1 (
+col1 int(11) NOT NULL,
+col2 int(11) DEFAULT NULL,
+col3 int(11) NOT NULL,
+col4 int(11) DEFAULT NULL) engine=innodb;
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col1 % col2)
+VIRTUAL, ADD UNIQUE index idx (col1), algorithm=inplace;
+ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: INPLACE ADD or DROP of virtual columns cannot be combined with other ALTER TABLE actions. Try ALGORITHM=COPY
+DROP TABLE t1;
+#
+# Bug 27122803 - BACKPORT FIX FOR BUG 25899959 TO MYSQL-5.7
+#
+CREATE TABLE t1 (col1 int(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+ALTER TABLE t1 ADD col2 char(21) AS (col1 * col1), ADD INDEX n (col2);
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `col1` int(10) DEFAULT NULL,
+ `col2` char(21) GENERATED ALWAYS AS (`col1` * `col1`) VIRTUAL,
+ KEY `n` (`col2`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
+DROP TABLE t1;
+#
+# Bug #27968952 INNODB CRASH/CORRUPTION WITH TEXT PREFIX INDEXES
+#
+CREATE TABLE t1(
+a INT NOT NULL UNIQUE,
+b INT NOT NULL,
+c TEXT GENERATED ALWAYS AS (a <> b) VIRTUAL,
+d TEXT NOT NULL,
+UNIQUE KEY (c(1)), KEY(d(1))
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+SET @t = REPEAT('t',@@innodb_page_size);
+INSERT INTO t1 (a,b,d) VALUES (1,0,@t), (0,0,@t);
+UPDATE t1 SET b = a;
+ERROR 23000: Duplicate entry '0' for key 'c'
+REPLACE INTO t1 SET a = 0, b = 1, d = 'd';
+SELECT * FROM t1;
+a b c d
+0 1 1 d
+CHECK TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+DROP TABLE t1;
+CREATE TABLE t1(
+a VARCHAR(1000) GENERATED ALWAYS AS ('1') VIRTUAL,
+b VARCHAR(1000) NOT NULL,
+c VARCHAR(1000) GENERATED ALWAYS AS (b) STORED,
+KEY (b(1)),
+KEY (a(1))
+) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
+INSERT INTO t1(b) VALUES(REPEAT('b',1000));
+DELETE FROM t1;
+DROP TABLE t1;
+#
+# Bug #22990029 GCOLS: INCORRECT BEHAVIOR
+# AFTER DATA INSERTED WITH IGNORE KEYWORD
+#
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, vb DATE AS(b) VIRTUAL, KEY(vb))
+ENGINE=InnoDB;
+INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132);
+Warnings:
+Warning 1265 Data truncated for column 'vb' at row 1
+SELECT * FROM t1;
+a b vb
+1 20190132 0000-00-00
+BEGIN;
+DELETE FROM t1;
+INSERT INTO t1 (a,b) VALUES(1,20190123);
+SELECT * FROM t1;
+a b vb
+1 20190123 2019-01-23
+ROLLBACK;
+SELECT * FROM t1;
+a b vb
+1 20190132 0000-00-00
+CHECK TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+DROP TABLE t1;
+#
+# MDEV-25872 InnoDB: Assertion failure in row_merge_read_clustered_index
+# upon ALTER on table with indexed virtual columns
+#
+CREATE TABLE t1 (
+id BIGINT AUTO_INCREMENT PRIMARY KEY,
+a INT,
+va INT ZEROFILL AS (a) VIRTUAL,
+b TIMESTAMP,
+c CHAR(204),
+vc CHAR(8),
+KEY(vc,c(64),b,va)
+) ENGINE=InnoDB CHARACTER SET utf32;
+INSERT INTO t1 (id) SELECT NULL FROM seq_1_to_75;
+INSERT IGNORE INTO t1 (id, a) VALUES (NULL, -1);
+Warnings:
+Warning 1264 Out of range value for column 'va' at row 1
+ALTER TABLE t1 FORCE;
+ERROR 22003: Out of range value for column 'va' at row 0
+DROP TABLE t1;
+#
+# MDEV-24713 Assertion `dict_table_is_comp(index->table)' failed
+# in row_merge_buf_add()
+#
+CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(3),
+b CHAR(8) AS (a) VIRTUAL, KEY(b))
+ROW_FORMAT=REDUNDANT ENGINE=InnoDB
+CHARACTER SET utf8;
+INSERT INTO t1 (id,a) VALUES (1,'foo');
+OPTIMIZE TABLE t1;
+Table Op Msg_type Msg_text
+test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
+test.t1 optimize status OK
+DROP TABLE t1;
+#
+# MDEV-20154 Assertion `len <= col->len || ((col->mtype) == 5
+# || (col->mtype) == 14)' failed in row_merge_buf_add
+#
+CREATE TABLE t1 (
+a VARCHAR(2500),
+b VARCHAR(2499) AS (a) VIRTUAL
+) ENGINE=InnoDB;
+INSERT INTO t1 (a) VALUES ('foo');
+ALTER TABLE t1 MODIFY a VARCHAR(2600), ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD KEY (b), ALGORITHM=INPLACE;
+# Cleanup
+DROP TABLE t1;
+# End of 10.2 tests
+#
+# MDEV-29299 SELECT from table with vcol index reports warning
+#
+CREATE TABLE t(fld1 INT NOT NULL,
+fld2 INT AS (100/fld1) VIRTUAL,
+KEY(fld1), KEY(fld2));
+CREATE TABLE t_odd(id int);
+INSERT INTO t(fld1) VALUES(1), (2);
+connect stop_purge,localhost,root;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+INSERT INTO t_odd VALUES(10000);
+connection default;
+UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2;
+UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3;
+UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4;
+Warnings:
+Warning 1365 Division by 0
+SELECT fld2 FROM t FORCE INDEX(fld2);
+fld2
+NULL
+100
+SELECT fld2 FROM t FORCE INDEX(fld1);
+fld2
+100
+NULL
+Warnings:
+Warning 1365 Division by 0
+disconnect stop_purge;
+DROP TABLE t, t_odd;
+#
+# MDEV-29753 An error is wrongly reported during INSERT with vcol index
+# See also Bug #22990029
+#
+CREATE TABLE t(pk INT PRIMARY KEY,
+fld1 INT NOT NULL,
+fld2 INT AS (100/fld1) VIRTUAL,
+KEY(fld1), KEY(fld2));
+INSERT IGNORE t(pk, fld1) VALUES(1, 0);
+Warnings:
+Warning 1365 Division by 0
+SELECT * FROM t;
+pk fld1 fld2
+1 0 NULL
+Warnings:
+Warning 1365 Division by 0
+BEGIN;
+DELETE FROM t;
+Warnings:
+Warning 1365 Division by 0
+Warning 1365 Division by 0
+Warning 1365 Division by 0
+INSERT INTO t (pk, fld1) VALUES(1,1);
+SELECT * FROM t;
+pk fld1 fld2
+1 1 100
+# Cleanup
+ROLLBACK;
+DROP TABLE t;
+# End of 10.3 tests
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_purge.result b/mysql-test/suite/gcol/r/innodb_virtual_purge.result
new file mode 100644
index 00000000..7951bd0e
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_purge.result
@@ -0,0 +1,173 @@
+#
+# Bug#21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION
+# ON INDEXED VIRTUAL COLUMNS
+#
+CREATE TABLE t1 (a INT, b INT,
+a1 INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX(a1)
+) ENGINE=InnoDB;
+INSERT INTO t1 (a,b) VALUES(1,1);
+connect con1,localhost,root,,;
+CREATE TABLE t0 (a INT) ENGINE=InnoDB;
+BEGIN;
+SELECT * FROM t0;
+a
+connection default;
+UPDATE t1 SET a=0;
+ALTER TABLE t1 DROP COLUMN a1, ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD COLUMN b1 INT GENERATED ALWAYS AS (b) VIRTUAL, ADD
+INDEX(b1),
+ALGORITHM=INPLACE;
+connection con1;
+COMMIT;
+UPDATE t1 SET a=1;
+connection default;
+InnoDB 0 transactions not purged
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+SELECT b1 FROM t1;
+b1
+1
+ALTER TABLE t1
+ADD COLUMN a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
+ADD COLUMN a2 INT GENERATED ALWAYS AS (a + b) VIRTUAL,
+ADD COLUMN a3 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
+ADD COLUMN a4 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
+ADD INDEX(a1), ADD INDEX(a2), ADD INDEX(a3), ALGORITHM=INPLACE;
+CREATE TABLE t2 (
+a BLOB,
+b BLOB,
+c BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+h VARCHAR(10) DEFAULT NULL
+) ENGINE=InnoDB;
+INSERT INTO t2 VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, 'kk');
+INSERT INTO t2 VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+CREATE INDEX idx ON t2(c(100));
+INSERT INTO t1 (a, b) VALUES(1,1);
+connection con1;
+BEGIN;
+SELECT * FROM t0;
+a
+connection default;
+UPDATE t1 SET a=0;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+UPDATE t1 SET b=0;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t1 DROP COLUMN a3, ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET a=2;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t1 DROP COLUMN a2, ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET b=3;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t1 ADD COLUMN b2 INT GENERATED ALWAYS AS (b) VIRTUAL,
+ADD INDEX(b2), ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET b=9;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t1 ADD COLUMN b3 INT GENERATED ALWAYS AS (a) VIRTUAL,
+ADD INDEX(b3), ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET b=10;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t2 DROP COLUMN c;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t2 SET a = REPEAT('s', 6000) WHERE a like 'aaa%';
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+ALTER TABLE t2 ADD COLUMN x1 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ADD COLUMN x2 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ADD INDEX(x1(100), x2(120)), ADD INDEX (x1(20));
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET a=5;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+UPDATE t2 SET a = REPEAT('m', 16000) WHERE a like 'sss%';
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+ALTER TABLE t1 DROP COLUMN b2, ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET a=6;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+ALTER TABLE t2 DROP COLUMN x1, DROP COLUMN x2, ALGORITHM=INPLACE;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t2 SET a = REPEAT('x', 1000) WHERE a like 'mmm%';
+affected rows: 1
+info: Rows matched: 1 Changed: 1 Warnings: 0
+ALTER TABLE t1 DROP INDEX b3;
+affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+UPDATE t1 SET a=100;
+affected rows: 2
+info: Rows matched: 2 Changed: 2 Warnings: 0
+connection con1;
+COMMIT;
+disconnect con1;
+connection default;
+InnoDB 0 transactions not purged
+CHECK TABLE t1 EXTENDED;
+Table Op Msg_type Msg_text
+test.t1 check status OK
+SELECT b1 FROM t1;
+b1
+10
+10
+SELECT * FROM t1;
+a b b1 a1 a4 b3
+100 10 10 100 90 100
+100 10 10 100 90 100
+CHECK TABLE t2 EXTENDED;
+Table Op Msg_type Msg_text
+test.t2 check status OK
+DROP TABLE t2, t1, t0;
+CREATE TABLE t1 (a VARCHAR(30), b INT, a2 VARCHAR(30) GENERATED ALWAYS AS (a) VIRTUAL);
+CREATE INDEX idx ON t1(a2(10), b, a2(20));
+ERROR 42S21: Duplicate column name 'a2'
+DROP TABLE t1;
+#
+# MDEV-17540 Server crashes in row_purge after TRUNCATE TABLE
+#
+CREATE TABLE t1 (a BIT(14)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+(b'01110110101011'),(b'01100111111000'),(b'00001011110100'),
+(b'01110110111010'),(b'10001010101011'),(b'01100111001111');
+CREATE TABLE t2 (
+pk INT DEFAULT 1,
+b YEAR,
+c BIT(14),
+d YEAR AS (b),
+e BIT(14) AS (c),
+UNIQUE(pk),
+KEY(e)
+) ENGINE=InnoDB;
+DROP TABLE t1, t2;
+#
+# MDEV-30024 InnoDB: tried to purge non-delete-marked record
+# of an index on a virtual column prefix
+#
+CREATE TABLE t(a BINARY(8), b CHAR(8) AS (a) VIRTUAL, KEY(b(4)))
+CHARACTER SET utf8 ENGINE=InnoDB;
+INSERT INTO t (a) VALUES (''),('');
+UPDATE t SET a = 'x';
+UPDATE t SET a = '';
+SET GLOBAL innodb_max_purge_lag_wait=0;
+CHECK TABLE t EXTENDED;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t;
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_rebuild.result b/mysql-test/suite/gcol/r/innodb_virtual_rebuild.result
new file mode 100644
index 00000000..35f37034
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_rebuild.result
@@ -0,0 +1,98 @@
+CREATE TABLE t1 (j SERIAL, i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t2 (j SERIAL, i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT;
+CREATE TABLE t3 (i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t4 (i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT;
+INSERT INTO t4 SET i=1;
+ALTER TABLE t4 ADD INDEX(v), LOCK=NONE;
+ALTER TABLE t4 ADD COLUMN k INT, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t4 DROP k, LOCK=NONE;
+ERROR 42000: Can't DROP COLUMN `k`; check that it exists
+ALTER TABLE t4 DROP INDEX v, LOCK=NONE;
+INSERT INTO t3 SET i=1;
+ALTER TABLE t3 ADD INDEX(v), LOCK=NONE;
+ALTER TABLE t3 ADD COLUMN k INT, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t3 DROP k, LOCK=NONE;
+ERROR 42000: Can't DROP COLUMN `k`; check that it exists
+ALTER TABLE t3 DROP INDEX v, LOCK=NONE;
+INSERT INTO t2 SET i=1;
+ALTER TABLE t2 ADD INDEX(v), LOCK=NONE;
+ALTER TABLE t2 ADD COLUMN k INT, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t2 DROP k, LOCK=NONE;
+ERROR 42000: Can't DROP COLUMN `k`; check that it exists
+ALTER TABLE t2 DROP INDEX v, LOCK=NONE;
+INSERT INTO t1 SET i=1;
+ALTER TABLE t1 ADD INDEX(v), LOCK=NONE;
+ALTER TABLE t1 ADD COLUMN k INT, LOCK=NONE;
+ERROR 0A000: LOCK=NONE is not supported. Reason: online rebuild with indexed virtual columns. Try LOCK=SHARED
+ALTER TABLE t1 DROP k, LOCK=NONE;
+ERROR 42000: Can't DROP COLUMN `k`; check that it exists
+ALTER TABLE t1 DROP INDEX v, LOCK=NONE;
+connect ddl,localhost,root,,test;
+connection default;
+connection ddl;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL copied WAIT_FOR dml';
+ALTER TABLE t4 FORCE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+UPDATE t4 SET i = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+connection ddl;
+connection default;
+SELECT * FROM t4;
+i v
+1 1
+DROP TABLE t4;
+connection ddl;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL copied WAIT_FOR dml';
+ALTER TABLE t3 FORCE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+UPDATE t3 SET i = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+connection ddl;
+connection default;
+SELECT * FROM t3;
+i v
+1 1
+DROP TABLE t3;
+connection ddl;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL copied WAIT_FOR dml';
+ALTER TABLE t2 FORCE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+UPDATE t2 SET i = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+connection ddl;
+connection default;
+SELECT * FROM t2;
+j i v
+1 1 1
+DROP TABLE t2;
+connection ddl;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL copied WAIT_FOR dml';
+ALTER TABLE t1 FORCE;
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+UPDATE t1 SET i = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+connection ddl;
+connection default;
+SELECT * FROM t1;
+j i v
+1 1 1
+DROP TABLE t1;
+disconnect ddl;
+SET DEBUG_SYNC = 'RESET';
diff --git a/mysql-test/suite/gcol/r/innodb_virtual_stats.result b/mysql-test/suite/gcol/r/innodb_virtual_stats.result
new file mode 100644
index 00000000..74a04808
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_virtual_stats.result
@@ -0,0 +1,87 @@
+CREATE TABLE t (
+a INT,
+b INT,
+c INT GENERATED ALWAYS AS(a+b),
+d INT GENERATED ALWAYS AS(a+b+b),
+KEY idxa (a),
+KEY vidxcd (c, d)
+) ENGINE=INNODB STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
+INSERT INTO t (a,b) VALUES (1, 2);
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+idxa n_diff_pfx01 a
+idxa n_diff_pfx02 a,DB_ROW_ID
+idxa n_leaf_pages Number of leaf pages in the index
+idxa size Number of pages in the index
+vidxcd n_diff_pfx01 c
+vidxcd n_diff_pfx02 c,d
+vidxcd n_diff_pfx03 c,d,DB_ROW_ID
+vidxcd n_leaf_pages Number of leaf pages in the index
+vidxcd size Number of pages in the index
+ALTER TABLE t ADD COLUMN e INT GENERATED ALWAYS AS(a+a+b), ADD INDEX idxb (b), ALGORITHM=INPLACE;
+select count(*) from t;
+count(*)
+1
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+idxa n_diff_pfx01 a
+idxa n_diff_pfx02 a,DB_ROW_ID
+idxa n_leaf_pages Number of leaf pages in the index
+idxa size Number of pages in the index
+vidxcd n_diff_pfx01 c
+vidxcd n_diff_pfx02 c,d
+vidxcd n_diff_pfx03 c,d,DB_ROW_ID
+vidxcd n_leaf_pages Number of leaf pages in the index
+vidxcd size Number of pages in the index
+ALTER TABLE t DROP COLUMN c, DROP INDEX idxa, ALGORITHM=INPLACE;
+select count(*) from t;
+count(*)
+1
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+ALTER TABLE t ADD INDEX vidxe (e), ALGORITHM=INPLACE;
+select count(*) from t;
+count(*)
+1
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+ALTER TABLE t ADD COLUMN f INT GENERATED ALWAYS AS(a + a), ADD INDEX vidxf (f), ALGORITHM=INPLACE;
+select count(*) from t;
+count(*)
+1
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+ALTER TABLE t DROP INDEX vidxcd;
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+index_name stat_name stat_description
+GEN_CLUST_INDEX n_diff_pfx01 DB_ROW_ID
+GEN_CLUST_INDEX n_leaf_pages Number of leaf pages in the index
+GEN_CLUST_INDEX size Number of pages in the index
+DROP TABLE t;
diff --git a/mysql-test/suite/gcol/r/innodb_wl8114.result b/mysql-test/suite/gcol/r/innodb_wl8114.result
new file mode 100644
index 00000000..42e65101
--- /dev/null
+++ b/mysql-test/suite/gcol/r/innodb_wl8114.result
@@ -0,0 +1,52 @@
+CREATE TABLE t_8114 (a int) ENGINE = INNODB;
+ALTER TABLE t_8114 ADD b INT GENERATED ALWAYS AS (a) VIRTUAL;
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+NAME
+test/t_8114
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+NAME POS MTYPE PRTYPE LEN
+a 0 6 1027 4
+b 65537 6 9219 4
+INSERT INTO t_8114 VALUES (9, default);
+INSERT INTO t_8114 VALUES (3, default);
+INSERT INTO t_8114 VALUES (1, default);
+INSERT INTO t_8114 VALUES (5, default);
+SELECT * FROM t_8114;
+a b
+9 9
+3 3
+1 1
+5 5
+DROP TABLE t_8114;
+CREATE TABLE t_8114 (Column_1 CHAR(5) GENERATED ALWAYS AS (PI()+5), Column_2 CHAR(5)) engine=innodb;
+SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+NAME FLAG N_COLS
+test/t_8114 33 4
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+NAME POS MTYPE PRTYPE LEN
+Column_2 0 2 524542 5
+Column_1 65536 2 532734 5
+INSERT INTO t_8114 VALUES (default, "aa");
+INSERT INTO t_8114 VALUES (default, "bb");
+INSERT INTO t_8114 VALUES (default, "ee");
+INSERT INTO t_8114 VALUES (default, "pp");
+SELECT * FROM t_8114;
+Column_1 Column_2
+8.142 aa
+8.142 bb
+8.142 ee
+8.142 pp
+ALTER TABLE t_8114 DROP Column_1;
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+NAME
+test/t_8114
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+NAME POS MTYPE PRTYPE LEN
+Column_2 0 2 524542 5
+SELECT * FROM t_8114;
+Column_2
+aa
+bb
+ee
+pp
+DROP TABLE t_8114;
diff --git a/mysql-test/suite/gcol/r/main_alter_table.result b/mysql-test/suite/gcol/r/main_alter_table.result
new file mode 100644
index 00000000..77c0a382
--- /dev/null
+++ b/mysql-test/suite/gcol/r/main_alter_table.result
@@ -0,0 +1,52 @@
+#
+# Bug#22017616: ASSERTION FAILED: TABLE_SHARE->IS_MISSING_PRIMARY_KEY()
+# == M_PREBUILT->CLUST_IND
+#
+# Ensure that adding indexes with virtual columns are not promoted to
+# primary keys
+#
+# Base line with normal column - should be promoted
+CREATE TABLE t0(a INT NOT NULL) ENGINE=INNODB;
+ALTER TABLE t0 ADD UNIQUE INDEX (a);
+# Case a: Create table with virtual unique not null column
+CREATE TABLE t1(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL UNIQUE) ENGINE=INNODB;
+SELECT * FROM t1;
+a
+# Case b: Create table with index on virtual point column
+CREATE TABLE t2(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL, UNIQUE INDEX no_pk(a(1))) ENGINE=INNODB;
+SELECT * FROM t2;
+a
+# Case c: Add unique index on virtual point column
+CREATE TABLE t3(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL)
+ENGINE=INNODB;
+ALTER TABLE t3 ADD UNIQUE INDEX (a(1));
+SELECT * FROM t3;
+a
+# Case d: Add unique index on virtual blob column
+CREATE TABLE t4 (a BLOB, b BLOB GENERATED ALWAYS AS (a) VIRTUAL) ENGINE=INNODB;
+ALTER TABLE t4 ADD UNIQUE INDEX (b(1));
+SELECT * FROM t4;
+a b
+# Query I_S to verify that 'a' is promoted to pk only when it
+# isn't virtual
+SELECT T.NAME AS TABLE_NAME, I.NAME AS INDEX_NAME,
+CASE (I.TYPE & 3)
+WHEN 3 THEN "yes"
+ ELSE "no" END AS IS_PRIMARY_KEY,
+F.NAME AS FIELD_NAME, F.POS AS FIELD_POS FROM
+INFORMATION_SCHEMA.INNODB_SYS_TABLES AS T JOIN
+INFORMATION_SCHEMA.INNODB_SYS_INDEXES AS I JOIN
+INFORMATION_SCHEMA.INNODB_SYS_FIELDS AS F
+ON I.INDEX_ID = F.INDEX_ID AND I.TABLE_ID = T.TABLE_ID
+WHERE T.NAME LIKE 'test/t%';
+TABLE_NAME INDEX_NAME IS_PRIMARY_KEY FIELD_NAME FIELD_POS
+test/t0 a yes a 0
+test/t1 a no a 0
+test/t2 no_pk no a 0
+test/t3 a no a 0
+test/t4 b no b 0
+DROP TABLE t0;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE t4;
diff --git a/mysql-test/suite/gcol/r/main_mysqldump.result b/mysql-test/suite/gcol/r/main_mysqldump.result
new file mode 100644
index 00000000..78d99a0b
--- /dev/null
+++ b/mysql-test/suite/gcol/r/main_mysqldump.result
@@ -0,0 +1,49 @@
+CREATE DATABASE dump_generated;
+USE dump_generated;
+CREATE TABLE t1 (pk INTEGER, a INTEGER, b INTEGER, c VARCHAR(16),
+sum INTEGER GENERATED ALWAYS AS (a+b),
+sub VARCHAR(4) GENERATED ALWAYS AS (SUBSTRING(c, 1, 4)),
+key k1(sum),
+key k2(sub)
+) engine=innodb;
+INSERT INTO t1(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
+SELECT * FROM t1;
+pk a b c sum sub
+1 11 12 oneone 23 oneo
+2 21 22 twotwo 43 twot
+DELETE FROM t1;
+SELECT * FROM t1;
+pk a b c sum sub
+1 11 12 oneone 23 oneo
+2 21 22 twotwo 43 twot
+DELETE FROM t1;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t1;
+SELECT * FROM t1;
+pk a b c sum sub
+1 11 12 oneone 23 oneo
+2 21 22 twotwo 43 twot
+DROP TABLE t1;
+# A table with regular columns after generated
+CREATE TABLE t2 (pk INTEGER, a INTEGER, b INTEGER,
+sum INTEGER GENERATED ALWAYS AS (a+b),
+c VARCHAR(16),
+key k1(sum)
+) engine=innodb;
+INSERT INTO t2(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
+SELECT * FROM t2;
+pk a b sum c
+1 11 12 23 oneone
+2 21 22 43 twotwo
+DELETE FROM t2;
+SELECT * FROM t2;
+pk a b sum c
+1 11 12 23 oneone
+2 21 22 43 twotwo
+DELETE FROM t2;
+LOAD DATA INFILE 'MYSQLTEST_VARDIR/tmp/t2.txt' INTO TABLE t2;
+SELECT * FROM t2;
+pk a b sum c
+1 11 12 23 oneone
+2 21 22 43 twotwo
+DROP TABLE t2;
+DROP DATABASE dump_generated;
diff --git a/mysql-test/suite/gcol/r/rpl_gcol.result b/mysql-test/suite/gcol/r/rpl_gcol.result
new file mode 100644
index 00000000..bcf072ab
--- /dev/null
+++ b/mysql-test/suite/gcol/r/rpl_gcol.result
@@ -0,0 +1,33 @@
+SET @@session.default_storage_engine = 'InnoDB';
+include/master-slave.inc
+[connection master]
+connection master;
+create table t1 (a int, b int generated always as (a+1) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) GENERATED ALWAYS AS (`a` + 1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+a b
+1 2
+2 3
+connection slave;
+select * from t1;
+a b
+1 2
+2 3
+connection master;
+drop table t1;
+connection slave;
+DROP VIEW IF EXISTS v1,v2;
+DROP TABLE IF EXISTS t1,t2,t3;
+DROP PROCEDURE IF EXISTS p1;
+DROP FUNCTION IF EXISTS f1;
+DROP TRIGGER IF EXISTS trg1;
+DROP TRIGGER IF EXISTS trg2;
+set sql_warnings = 0;
+include/rpl_end.inc
diff --git a/mysql-test/suite/gcol/r/virtual_index_drop.result b/mysql-test/suite/gcol/r/virtual_index_drop.result
new file mode 100644
index 00000000..484b177a
--- /dev/null
+++ b/mysql-test/suite/gcol/r/virtual_index_drop.result
@@ -0,0 +1,72 @@
+#
+# MDEV-24971 InnoDB access freed virtual column
+# after rollback of secondary index
+#
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=EXCLUSIVE;
+ERROR 23000: Duplicate entry '3' for key 'f2'
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1` + 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=SHARED;
+ERROR 23000: Duplicate entry '3' for key 'f2'
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1` + 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3);
+connect con1,localhost,root,,,;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+SELECT * FROM t1;
+f1 f2
+1 1
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+connection con1;
+rollback;
+connection default;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+ALTER TABLE t1 ADD INDEX(f2);
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+connection con1;
+rollback;
+connection default;
+disconnect con1;
+DROP TABLE t1;
+CREATE TABLE t1(f1 CHAR(100), f2 CHAR(100) as (f1) VIRTUAL)ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN f3 CHAR(100) AS (f2) VIRTUAL, ADD INDEX(f3(10), f1, f3(12));
+ERROR 42S21: Duplicate column name 'f3'
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
diff --git a/mysql-test/suite/gcol/t/gcol_archive.test b/mysql-test/suite/gcol/t/gcol_archive.test
new file mode 100644
index 00000000..6dce34e1
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_archive.test
@@ -0,0 +1,44 @@
+################################################################################
+# t/gcol_archive.test #
+# #
+# Purpose: #
+# ARCHIVE branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_archive.inc
+SET @@session.default_storage_engine = 'archive';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+--source suite/gcol/inc/gcol_unsupported_storage_engines.inc
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_blackhole.test b/mysql-test/suite/gcol/t/gcol_blackhole.test
new file mode 100644
index 00000000..bf0d3fb3
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_blackhole.test
@@ -0,0 +1,44 @@
+################################################################################
+# t/gcol_blackhole.test #
+# #
+# Purpose: #
+# BLACKHOLE branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_blackhole.inc
+SET @@session.default_storage_engine = 'blackhole';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+--source suite/gcol/inc/gcol_unsupported_storage_engines.inc
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_innodb.test b/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_innodb.test
new file mode 100644
index 00000000..a1024b33
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_innodb.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_supported_sql_funcs.test #
+# #
+# Purpose: #
+# Test SQL functions not allowed for generated columns #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+let $skip_full_text_check = 1;
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_blocked_sql_funcs_main.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_myisam.test b/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_myisam.test
new file mode 100644
index 00000000..0f967ee8
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_blocked_sql_funcs_myisam.test
@@ -0,0 +1,44 @@
+################################################################################
+# t/gcol_supported_sql_funcs.test #
+# #
+# Purpose: #
+# Test SQL functions not allowed for generated columns #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_blocked_sql_funcs_main.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_bug20746926.test b/mysql-test/suite/gcol/t/gcol_bug20746926.test
new file mode 100644
index 00000000..8028823f
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_bug20746926.test
@@ -0,0 +1,28 @@
+--echo #Bug #20746926: GENERATED COLUMNS: INVALID READ OF THD WHEN WARNINGS
+--echo #
+--echo # Testing cmp_item_datetime
+connect(con1,localhost,root,,);
+--disable_warnings
+set sql_mode='';
+--enable_warnings
+create table t1 (
+a date not null,
+b mediumtext generated always as ((a not in (a,a))) virtual,
+c timestamp generated always as ((a not in (b,b))) stored
+);
+insert t1(a) values(7777777777);
+show warnings;
+disconnect con1;
+--source include/wait_until_disconnected.inc
+
+connect(con2,localhost,root,,);
+--disable_warnings
+set sql_mode='';
+--enable_warnings
+insert t1(a) values(6666666666);
+show warnings;
+
+drop table t1;
+disconnect con2;
+--source include/wait_until_disconnected.inc
+connection default;
diff --git a/mysql-test/suite/gcol/t/gcol_bugfixes.test b/mysql-test/suite/gcol/t/gcol_bugfixes.test
new file mode 100644
index 00000000..4c1b00a8
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_bugfixes.test
@@ -0,0 +1,726 @@
+################################################################################
+# t/gcol_bugfixes.test #
+# #
+# Purpose: #
+# Bug fixes that only need one storage engine #
+# #
+################################################################################
+
+--source include/have_innodb.inc
+--echo # Bug#21230709: Alter table statement fails with division by zero
+
+CREATE TABLE t1 (
+ col1 INTEGER NOT NULL,
+ col2 INTEGER NOT NULL,
+ col3 INTEGER NOT NULL,
+ gcol1 INTEGER GENERATED ALWAYS AS (col3 + col3) VIRTUAL,
+ col4 INTEGER DEFAULT NULL,
+ col5 INTEGER DEFAULT NULL,
+ col6 INTEGER DEFAULT NULL,
+ col7 INTEGER DEFAULT NULL,
+ col8 INTEGER DEFAULT NULL,
+ col9 INTEGER DEFAULT NULL,
+ col10 INTEGER DEFAULT NULL,
+ col11 INTEGER DEFAULT NULL,
+ col12 INTEGER DEFAULT NULL,
+ col13 INTEGER DEFAULT NULL,
+ col14 INTEGER DEFAULT NULL,
+ col15 INTEGER DEFAULT NULL,
+ col16 INTEGER DEFAULT NULL,
+ col17 INTEGER DEFAULT NULL,
+ col18 INTEGER DEFAULT NULL,
+ col19 INTEGER DEFAULT NULL,
+ col20 INTEGER DEFAULT NULL,
+ col21 INTEGER DEFAULT NULL,
+ col22 INTEGER DEFAULT NULL,
+ col23 INTEGER DEFAULT NULL,
+ col24 INTEGER DEFAULT NULL,
+ col25 INTEGER DEFAULT NULL,
+ col26 INTEGER DEFAULT NULL,
+ col27 INTEGER DEFAULT NULL,
+ col28 INTEGER DEFAULT NULL,
+ col29 INTEGER DEFAULT NULL,
+ col30 INTEGER DEFAULT NULL,
+ col31 INTEGER DEFAULT NULL,
+ col32 INTEGER DEFAULT NULL,
+ col33 INTEGER DEFAULT NULL,
+ gcol2 INTEGER GENERATED ALWAYS AS (col2 + col2) VIRTUAL,
+ gcol3 INTEGER GENERATED ALWAYS AS (gcol2 / gcol2) VIRTUAL,
+ PRIMARY KEY (col1),
+ KEY idx1 (gcol1)
+) engine=innodb;
+
+INSERT INTO t1 (col1, col2, col3)
+ VALUES (0,1,2), (1,2,3), (2,3,4), (3,4,5), (4,5,6);
+
+# This is likely needed to ensure we allocate a new record buffer that
+# contains zero in the mis-used field
+FLUSH TABLE t1;
+
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug 21340801 WL8149:ASSERTION `IS_VIRTUAL_GCOL()' FAILED
+--echo #
+
+CREATE TABLE t1 (
+ c_blob BLOB,
+ c_blob_key BLOB GENERATED ALWAYS AS (REPEAT(c_blob,15)) STORED,
+ KEY (c_blob_key(200))
+);
+
+INSERT INTO t1 (c_blob) VALUES ('xceks');
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21345972 WL8149:JOIN_CACHE::FILTER_VIRTUAL_GCOL_BASE_COLS(): ASSERTION `FALSE' FAILED.
+--echo #
+
+CREATE TABLE c (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_date_nokey DATE,
+ gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+ col_datetime_nokey DATETIME,
+ col_time_nokey TIME,
+ gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ col_varchar_nokey VARCHAR(1),
+ gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk),
+ UNIQUE KEY (gcol_int_key),
+ UNIQUE KEY (gcol_varchar_key),
+ UNIQUE KEY (gcol_date_key),
+ KEY (gcol_time_key),
+ KEY (gcol_datetime_key),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+ KEY (gcol_int_key, col_int_nokey),
+ KEY(gcol_int_key,gcol_date_key),
+ KEY(gcol_int_key, gcol_time_key),
+ KEY(gcol_int_key, gcol_datetime_key),
+ UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+ UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) ENGINE=INNODB;
+
+INSERT IGNORE INTO c ( col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+VALUES (7, '2004-04-09', '14:03:03.042673', '2001-11-28 00:50:27.051028', 'c'),
+ (1, '2006-05-13', '01:46:09.016386', '2007-10-09 19:53:04.008332', NULL);
+
+CREATE TABLE bb (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_date_nokey DATE,
+ gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+ col_datetime_nokey DATETIME,
+ col_time_nokey TIME,
+ gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ col_varchar_nokey VARCHAR(1),
+ gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk),
+ UNIQUE KEY (gcol_int_key),
+ UNIQUE KEY (gcol_varchar_key),
+ UNIQUE KEY (gcol_date_key),
+ KEY (gcol_time_key),
+ KEY (gcol_datetime_key),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+ KEY (gcol_int_key, col_int_nokey),
+ KEY(gcol_int_key,gcol_date_key),
+ KEY(gcol_int_key, gcol_time_key),
+ KEY(gcol_int_key, gcol_datetime_key),
+ UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+ UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) AUTO_INCREMENT=10 ENGINE=INNODB;
+
+INSERT IGNORE INTO bb ( col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+ VALUES (0, '2003-08-04', '01:48:05.048577', '2006-11-03 00:00:00', 'p'),
+ (2, '2007-11-06', '00:00:00', '2009-11-26 19:28:11.005115', 'n');
+
+CREATE TABLE cc (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ gcol_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_date_nokey DATE,
+ gcol_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+ col_datetime_nokey DATETIME,
+ col_time_nokey TIME,
+ gcol_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ gcol_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ col_varchar_nokey VARCHAR(1),
+ gcol_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk),
+ UNIQUE KEY (gcol_int_key),
+ UNIQUE KEY (gcol_varchar_key),
+ UNIQUE KEY (gcol_date_key),
+ KEY (gcol_time_key),
+ KEY (gcol_datetime_key),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key),
+ KEY (gcol_int_key, col_int_nokey),
+ KEY(gcol_int_key,gcol_date_key),
+ KEY(gcol_int_key, gcol_time_key),
+ KEY(gcol_int_key, gcol_datetime_key),
+ UNIQUE KEY(gcol_date_key,gcol_time_key,gcol_datetime_key),
+ UNIQUE KEY (gcol_varchar_key, col_varchar_nokey),
+ UNIQUE KEY (gcol_int_key, gcol_varchar_key, gcol_date_key, gcol_time_key, gcol_datetime_key)
+) AUTO_INCREMENT=10 ENGINE=INNODB;
+
+INSERT IGNORE INTO cc (col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey)
+ VALUES (172, '2009-04-23', '00:00:00', '2000-12-07 10:17:40.013275', 'h'),
+ (NULL, '2002-10-06', '00:50:49.017545', NULL, 'm');
+
+let $query=
+SELECT
+gp1 . gcol_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . gcol_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . gcol_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . gcol_int_key = p2 . pk )
+)
+AND gp1 . col_varchar_nokey = 'b'
+HAVING g1 > 6;
+
+eval EXPLAIN $query;
+eval $query;
+DROP TABLE bb, c, cc;
+
+--echo # Bug#21284646: Assertion !(table || table->read_set || bitmap_is_set())
+
+CREATE TABLE c (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_date_nokey DATE NOT NULL,
+ col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL,
+ col_datetime_nokey DATETIME NOT NULL,
+ col_time_nokey TIME NOT NULL,
+ col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL,
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk,col_int_nokey),
+ UNIQUE KEY (col_int_key),
+ UNIQUE KEY (col_varchar_key),
+ UNIQUE KEY (col_date_key),
+ KEY (col_time_key),
+ KEY (col_datetime_key),
+ UNIQUE KEY (col_int_key, col_varchar_key),
+ KEY (col_int_key, col_int_nokey),
+ KEY(col_int_key,col_date_key),
+ KEY(col_int_key, col_time_key),
+ KEY(col_int_key, col_datetime_key),
+ UNIQUE KEY (col_date_key,col_time_key,col_datetime_key),
+ UNIQUE KEY (col_varchar_key, col_varchar_nokey),
+ UNIQUE KEY (col_int_key, col_varchar_key, col_date_key, col_time_key, col_datetime_key)
+) ENGINE=INNODB;
+
+INSERT INTO c (col_int_nokey, col_date_nokey, col_time_nokey, col_datetime_nokey, col_varchar_nokey) VALUES
+(1, '2009-12-01', '00:21:38.058143', '2007-05-28 00:00:00', 'c'),
+(8, '2004-12-17', '04:08:02.046897', '2009-07-25 09:21:20.064099', 'm'),
+(9, '2000-03-14', '16:25:11.040240', '2002-01-16 00:00:00', 'd'),
+(6, '2006-05-25', '19:47:59.011283', '2001-02-15 03:08:38.035426', 'y'),
+(2, '2002-10-13', '00:00:00', '1900-01-01 00:00:00', 's'),
+(4, '1900-01-01', '15:57:25.019666', '2005-08-15 00:00:00', 'r');
+
+ANALYZE TABLE c;
+let $query=
+SELECT COUNT(DISTINCT col_varchar_key) AS x
+FROM c
+WHERE col_varchar_key IN ('rr', 'rr') OR
+ col_int_nokey <> 9 AND
+ pk >= 8
+HAVING x > '2000-02-06'
+ORDER BY col_time_nokey, pk;
+
+eval explain $query;
+eval $query;
+
+DROP TABLE c;
+
+--echo # Bug#21341044: Conditional jump at sort_param::make_sort_key
+
+CREATE TABLE t1 (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER,
+ col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_blob_nokey BLOB,
+ col_blob_key BLOB GENERATED ALWAYS AS (REPEAT(col_blob_nokey,15)) VIRTUAL,
+ col_longblob_nokey LONGBLOB,
+ col_longtext_nokey LONGTEXT,
+ col_longblob_key LONGBLOB GENERATED ALWAYS AS (REPEAT(col_longblob_nokey, 20)) VIRTUAL,
+ col_longtext_key LONGTEXT GENERATED ALWAYS AS (REPEAT(col_longblob_nokey, 18)) VIRTUAL,
+ col_text_nokey TEXT,
+ col_text_key TEXT GENERATED ALWAYS AS (REPEAT(col_text_nokey, 30)) VIRTUAL,
+ PRIMARY KEY (pk),
+ KEY (col_int_key),
+ KEY (col_text_key(50)),
+ KEY (col_blob_key(200)),
+ KEY (col_longtext_key(200)),
+ KEY (col_longblob_key(200)),
+ KEY (col_int_key, col_text_key(100)),
+ KEY (col_int_key, col_longtext_key(100)),
+ KEY (col_int_key, col_blob_key(100)),
+ KEY (col_int_key, col_longblob_key(100)),
+ KEY (col_longtext_key(10), col_longblob_key(100)),
+ KEY (col_int_key, col_text_key(10), col_blob_key(100), col_longtext_key(50), col_longblob_key(50))
+) engine=innodb;
+
+INSERT INTO t1 (col_int_nokey,col_blob_nokey,col_longtext_nokey,col_longblob_nokey,col_text_nokey)
+VALUES
+(0, 'ijcszxw', 'ijcszxw', 'ijcszxw', 'ijcszxw'),
+(5, 'jcszxwb', 'jcszxwb', 'jcszxwb', 'jcszxwb'),
+(4, 'cszxwbjjvv', 'cszxwbjjvv', 'cszxwbjjvv', 'cszxwbjjvv'),
+(3, 'szxw', 'szxw', 'szxw', 'szxw'),
+(7, 'zxwb', 'zxwb', 'zxwb', 'zxwb'),
+(42, 'xwbjjvvky', 'xwbjjvvky', 'xwbjjvvky', 'xwbjjvvky'),
+(142, 'wbjj', 'wbjj', 'wbjj', 'wbjj'),
+(5, 'bjjv', 'bjjv', 'bjjv', 'bjjv'),
+(0, 'jjvvkymalu', 'jjvvkymalu', 'jjvvkymalu', 'jjvvkymalu'),
+(3, 'j', 'j', 'j', 'j');
+SELECT alias1.pk AS field1
+FROM t1 AS alias1 LEFT OUTER JOIN t1 AS alias2
+ ON alias1.col_int_key = alias2.col_int_key
+WHERE alias2.col_int_key BETWEEN 8 AND (8 + 1 ) OR
+ alias2.col_int_key BETWEEN 8 AND (8 + 5 ) AND
+ alias2.col_int_key != 20 OR
+ alias2.col_int_key IN (8, 5, 8) AND
+ alias2.col_int_key >= 0 AND
+ alias2.col_int_key <= ( 8 + 75 ) AND
+ alias1.pk IS NOT NULL
+ORDER BY field1;
+
+DROP TABLE t1;
+--echo # bug#21487651: gcols: memory leak after failed alter table
+CREATE TABLE t(a int);
+ALTER TABLE t ADD COLUMN b int GENERATED ALWAYS AS (
+date_sub(a,interval a month)) VIRTUAL;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+ALTER TABLE t ADD COLUMN c int GENERATED ALWAYS AS (sum(a));
+DROP TABLE t;
+
+--echo #
+--echo # Bug#21628840: CRASH/MEMORY CORRUPTION ADDING INDEXES TO VIRTUAL COLUMN
+--echo # (II)
+--echo #
+CREATE TABLE t1( a INT ) ENGINE = INNODB;
+INSERT INTO t1( a ) VALUES ( 1 ), ( 2 ), ( 3 ), ( 4 ), ( 5 );
+
+ALTER TABLE t1 ADD COLUMN b INT GENERATED ALWAYS AS (a - 1) STORED;
+ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS (b + 1) VIRTUAL;
+
+--echo # Used to cause valgrind warning.
+ALTER TABLE t1 ADD INDEX( c );
+
+ANALYZE TABLE t1;
+
+--echo # Make sure the index is correct. That's kinda important.
+EXPLAIN
+SELECT c FROM t1;
+SELECT c FROM t1;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21797776 ASSERTION `BIT < MAP->N_BITS' FAILED.
+--echo #
+
+CREATE TABLE C (
+col_int_1 INT,
+col_int_2 INT GENERATED ALWAYS AS (col_int_1 + col_int_1) STORED,
+col_int_3 INT GENERATED ALWAYS AS (col_int_2 + col_int_1) VIRTUAL
+);
+
+CREATE ALGORITHM=TEMPTABLE VIEW v1 AS
+ SELECT
+ col_int_2 AS field1, col_int_2 AS field2,
+ col_int_3 AS field3, col_int_3 AS field4
+ FROM C;
+
+SELECT * FROM v1;
+
+DROP TABLE C;
+DROP VIEW v1;
+
+--echo #
+--echo # Bug#21613615 GCOLS: ASSERTION FAILED: !TABLE || (!TABLE->READ_SET || BITMAP_IS_SET
+--echo #
+
+CREATE TABLE t (a INT);
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL,
+KEY(c,b(1)));
+INSERT INTO v (a,c) VALUES (1,1);
+
+let $query=
+SELECT 1 FROM t WHERE ( SELECT 1 FROM t ) >=ANY( SELECT c FROM v );
+eval EXPLAIN $query;
+eval $query;
+
+# A similar one:
+let $query=
+SELECT (SELECT MAX(c) FROM v);
+eval EXPLAIN $query;
+eval $query;
+
+DROP TABLE t, v;
+
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL, KEY(c,b(1)));
+INSERT INTO v (a,c) VALUES (1,1);
+SELECT MAX(c), COUNT(b) FROM v;
+DROP TABLE v;
+
+# Using PK suffix of secondary index
+CREATE TABLE v (
+a INT PRIMARY KEY,
+b INT, KEY(b));
+INSERT INTO v (a,b) VALUES (1,1);
+SELECT MAX(a) FROM v WHERE b=1;
+DROP TABLE v;
+
+--echo #
+--echo # Bug#21824519: ASSERTION IN DROP TRIGGER WHEN TABLE HAS
+--echo # VIRTUAL GENERATED COLUMN
+--echo #
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL);
+CREATE TRIGGER tr BEFORE INSERT ON t FOR EACH ROW BEGIN END;
+INSERT INTO t (a) VALUES (1);
+SELECT * FROM t;
+# DROP TRIGGER used to hit a DBUG_ASSERT.
+DROP TRIGGER tr;
+SELECT * FROM t;
+CREATE FUNCTION f() RETURNS INT RETURN (SELECT COUNT(*) FROM t);
+# And this function call hit the same DBUG_ASSERT.
+SELECT f();
+DROP FUNCTION f;
+SELECT * FROM t;
+DROP TABLE t;
+
+--echo #
+--echo # Bug#21833760 CALC_DAYNR: ASSERTION `DELSUM+(INT) Y/4-TEMP >= 0' FAILED.
+--echo #
+
+CREATE TABLE C(
+c1 INT AUTO_INCREMENT,
+c8 DATETIME,
+c9 TIME,
+c11 TIME GENERATED ALWAYS AS(ADDTIME(c8,c9)) VIRTUAL,
+c13 TIME GENERATED ALWAYS AS(ADDTIME(c8,c11)) VIRTUAL,
+PRIMARY KEY(c1),
+UNIQUE KEY(c13)
+);
+
+INSERT INTO C (c8,c9) VALUES('1970-01-01',0),('1970-01-01',1);
+
+CREATE VIEW view_C AS SELECT * FROM C;
+
+SELECT /*+ NO_BNL(t1) */ t1.c13 FROM C AS t2 STRAIGHT_JOIN C AS t1 FORCE INDEX(c13);
+SELECT DISTINCT t1.c13 FROM C AS t1, view_C AS t2;
+
+DROP TABLE C;
+DROP VIEW view_C;
+
+--echo #
+--echo # Bug#21810529: CRASH IN ITEM_FUNC::WALK WHEN CODE JUMPS TO GARBAGE
+--echo # LOCATION
+--echo #
+CREATE TABLE t (a TIME,b INT GENERATED ALWAYS AS (a=1) VIRTUAL);
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t CHANGE COLUMN q w INT;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t CHANGE COLUMN q w INT;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t CHANGE COLUMN q w INT;
+--error ER_BAD_FIELD_ERROR
+ALTER TABLE t CHANGE COLUMN q w INT;
+DROP TABLE t;
+
+--echo #
+--echo # Bug#21940542 TOO MUCH SPAM: INNODB: COMPUTE VIRTUAL COLUMN VALUES FAILED
+--echo #
+
+CREATE TABLE t(b BLOB);
+--error ER_OPERAND_COLUMNS
+ALTER TABLE t ADD COLUMN c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL;
+DROP TABLE t;
+--error ER_OPERAND_COLUMNS
+CREATE TABLE t(b BLOB, c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL);
+
+--echo #
+--echo # Bug#21929967 GCOLS: GCOL VALUE CHANGES WHEN SESSION CHANGES SQL_MODE
+--echo #
+
+CREATE TABLE t1(a CHAR(1), b CHAR(1), c CHAR(2) AS (a || b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES('1','1');
+SELECT * FROM t1;
+SET SQL_MODE=PIPES_AS_CONCAT;
+SELECT * FROM t1;
+FLUSH TABLES;
+SELECT * FROM t1;
+DROP TABLE t1;
+# The other way around:
+CREATE TABLE t1(a CHAR(1), b CHAR(1), c CHAR(2) AS (a || b));
+SHOW CREATE TABLE t1;
+INSERT INTO t1 (a,b) VALUES('1','1');
+SELECT * FROM t1;
+SET SQL_MODE=DEFAULT;
+SELECT * FROM t1;
+FLUSH TABLES;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo # Bug#22018999: gcols: assertion failed: !error
+
+SET @save_old_sql_mode= @@sql_mode;
+SET sql_mode="";
+
+CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
+DROP TABLE t;
+
+CREATE TABLE t (a INTEGER) engine=innodb;
+
+ALTER TABLE t ADD b INTEGER AS (SUBSTR('','a',1));
+
+DROP TABLE t;
+
+set sql_mode= @save_old_sql_mode;
+
+--echo # Bug#21875520 Problems with virtual column indexes
+
+CREATE TABLE t(
+ a TIMESTAMP,
+ b BLOB,
+ c TIMESTAMP GENERATED ALWAYS AS (GREATEST(a, '2000-01-01 00:00:00')) VIRTUAL,
+ UNIQUE KEY(c)
+);
+INSERT INTO t(b) VALUES ('');
+UPDATE t SET a='2001-01-01 00:00:00';
+SELECT c FROM t;
+SELECT c, a FROM t;
+UPDATE t SET b='xyz';
+DO (SELECT @c1:= c FROM t);
+DO (SELECT (@c2:= c) - a FROM t);
+SELECT @c2 - @c1;
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug#22133710 GCOLS: READ UNCOMMITTED: ASSERT !TABLE || (!TABLE->WRITE_SET || BITMAP_IS_SET(TA
+--echo #
+
+CREATE TABLE t (
+ a INT,
+ b INT GENERATED ALWAYS AS (1) VIRTUAL,
+ c INT GENERATED ALWAYS AS (1) VIRTUAL,
+ d INT GENERATED ALWAYS AS (1) VIRTUAL,
+ KEY (b,d)
+) ENGINE=INNODB;
+INSERT INTO t VALUES();
+SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
+SELECT 1 FROM t WHERE c GROUP BY b;
+COMMIT;
+DROP TABLE t;
+
+--echo #
+--echo # Bug #25793677 INNODB: FAILING ASSERTION: CLUST_TEMPL_FOR_SEC || LEN ....
+--echo #
+
+CREATE TABLE v (
+a INT,
+c INT,
+b CHAR(2) GENERATED ALWAYS AS (a IN (1)) VIRTUAL,
+KEY(c,b(1))) charset utf8mb4;
+INSERT INTO v (a,c) VALUES (1,1);
+SELECT (SELECT MAX(c) FROM v);
+DROP TABLE v;
+
+--echo #
+--echo # MDEV-9255 Add generation_expression to information_schema.columns.
+--echo #
+
+CREATE TABLE gcol_t1 (
+ sidea DOUBLE,
+ sideb DOUBLE,
+ sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb))
+);
+
+SELECT table_schema,table_name,column_name,extra,is_generated,generation_expression
+FROM information_schema.columns WHERE table_name='gcol_t1';
+
+DROP TABLE gcol_t1;
+
+--echo #
+--echo # MDEV-16039 Crash when selecting virtual columns
+--echo # generated using functions with DAYNAME()
+--echo #
+
+CREATE TABLE t1 (
+ suppliersenttoday INT NOT NULL,
+ suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05')))
+) COLLATE utf8_bin;
+
+INSERT INTO t1 (suppliersenttoday) VALUES (0);
+INSERT INTO t1 (suppliersenttoday) VALUES (0);
+SELECT * FROM t1;
+
+PREPARE STMT FROM 'INSERT INTO t1 (suppliersenttoday) VALUES (1)';
+
+CREATE OR REPLACE TABLE t1 (
+ suppliersenttoday INT NOT NULL,
+ suppliercaptoday CHAR(10) AS (CONCAT('',DAYNAME('2020-02-05')))
+) COLLATE utf8_bin;
+
+EXECUTE STMT;
+EXECUTE STMT;
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+--echo # (duplicate) MDEV-20380 Server crash during update
+CREATE TABLE gafld (
+ nuigafld INTEGER NOT NULL,
+ ucrgafld VARCHAR(30) COLLATE UTF8_BIN NOT NULL
+ DEFAULT SUBSTRING_INDEX(USER(),'@',1)
+);
+EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10;
+EXPLAIN UPDATE gafld SET nuigafld = 0 WHERE nuigafld = 10;
+DROP TABLE gafld;
+
+--echo # (duplicate) MDEV-17653 replace into generated columns is unstable
+--echo # Some columns are snipped from the MDEV test
+CREATE TABLE t (
+ c0 TIMESTAMP NOT NULL DEFAULT current_timestamp()
+ ON UPDATE current_timestamp(),
+ c1 DECIMAL(27,25) GENERATED ALWAYS AS (DAYOFMONTH('2020-02-05')),
+ c4 TIME NOT NULL,
+ c8 SMALLINT(6) GENERATED ALWAYS AS
+ (CONCAT_WS(CONVERT(C1 USING CP932),
+ '900') <> (c4 = 1)),
+ PRIMARY KEY (c4)
+) DEFAULT CHARSET=latin1;
+
+REPLACE INTO t SET c0 = '2018-06-03 10:31:43', c4 = '02:58:55';
+REPLACE INTO t SET c0 = '2018-06-03 10:31:44', c4 = '02:58:55';
+REPLACE INTO t SET c0 = '2018-06-03 10:31:45', c4 = '02:58:55';
+
+DROP TABLE t;
+
+--echo # (duplicate) MDEV-17986 crash when I insert on a table
+CREATE OR REPLACE TABLE t2 (
+ number BIGINT(20) NOT NULL,
+ lrn BIGINT(20) NOT NULL DEFAULT 0,
+ source VARCHAR(15) NOT NULL
+ DEFAULT (REVERSE(SUBSTRING_INDEX(REVERSE(user()), '@', 1))),
+ PRIMARY KEY (number)
+);
+
+REPLACE t2(number) VALUES('1');
+REPLACE t2(number) VALUES('1');
+
+DROP TABLE t2;
+
+--echo # MDEV-24583 SELECT aborts after failed REPLACE into table with vcol
+
+CREATE TABLE t1 (pk INT, a VARCHAR(3), v VARCHAR(3) AS (CONCAT('x-',a)),
+ PRIMARY KEY(pk)) ENGINE=MyISAM;
+CREATE VIEW v1 AS SELECT * FROM t1;
+INSERT INTO t1 (pk, a) VALUES (1,'foo');
+SET sql_mode=CONCAT(@@sql_mode,',STRICT_ALL_TABLES');
+--error 0,ER_DATA_TOO_LONG
+REPLACE INTO t1 (pk,a) VALUES (1,'qux');
+SELECT * FROM v1;
+
+# Cleanup
+DROP VIEW v1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ pk INT,
+ a VARCHAR(1),
+ v VARCHAR(1) AS (CONCAT('virt-',a)) VIRTUAL,
+ PRIMARY KEY (pk)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (pk,a) VALUES
+(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e'),(6,'f');
+
+ --error ER_DATA_TOO_LONG
+REPLACE INTO t1 (pk) VALUES (1);
+SELECT * FROM t1 ORDER BY a;
+
+SET SQL_MODE=DEFAULT;
+DROP TABLE t1;
+
+--echo # (duplicate) MDEV-24656
+--echo # [FATAL] InnoDB: Data field type 0, len 0, ASAN heap-buffer-overflow
+--echo # upon LOAD DATA with virtual columns
+
+CREATE TABLE t1 (id INT PRIMARY KEY, a VARCHAR(2333),
+ va VARCHAR(171) AS (a)) ENGINE=InnoDB;
+INSERT INTO t1 (id,a) VALUES (1,REPEAT('x',200));
+--disable_ps2_protocol
+SELECT id, va INTO OUTFILE 'load_t1' FROM t1;
+--enable_ps2_protocol
+--error ER_DATA_TOO_LONG
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id,va);
+SELECT * FROM t1;
+LOAD DATA INFILE 'load_t1' IGNORE INTO TABLE t1 (id,va);
+
+DROP TABLE t1;
+--let $datadir= `select @@datadir`
+--remove_file $datadir/test/load_t1
+
+CREATE TABLE t1 (id BIGINT PRIMARY KEY, a VARCHAR(2333),
+ va VARCHAR(171) AS (a)) ENGINE=InnoDB;
+INSERT INTO t1 (id,a) VALUES (1,REPEAT('x',200));
+--disable_ps2_protocol
+SELECT id, va INTO OUTFILE 'load_t1' FROM t1;
+--enable_ps2_protocol
+--error ER_DATA_TOO_LONG
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id,va);
+SELECT * FROM t1;
+LOAD DATA INFILE 'load_t1' IGNORE INTO TABLE t1 (id,va);
+
+# Cleanup
+DROP TABLE t1;
+--let $datadir= `select @@datadir`
+--remove_file $datadir/test/load_t1
+
+
+--echo # (duplicate) MDEV-24665
+--echo # ASAN errors, assertion failures, corrupt values after failed
+--echo # LOAD DATA into table with virtual/stored column
+
+CREATE TABLE t1 (id INT PRIMARY KEY,
+ ts TIMESTAMP DEFAULT '1971-01-01 00:00:00',
+ c VARBINARY(8) DEFAULT '', vc VARCHAR(3) AS (c) STORED);
+INSERT IGNORE INTO t1 (id,c) VALUES (1,'foobar');
+--disable_ps2_protocol
+SELECT id, ts, vc INTO OUTFILE 'load_t1' FROM t1;
+--enable_ps2_protocol
+--error 0,ER_DATA_TOO_LONG
+LOAD DATA INFILE 'load_t1' REPLACE INTO TABLE t1 (id, ts, vc);
+INSERT IGNORE INTO t1 (id) VALUES (2);
+
+# Cleanup
+DROP TABLE t1;
+--let $datadir= `select @@datadir`
+--remove_file $datadir/test/load_t1
+
+
diff --git a/mysql-test/suite/gcol/t/gcol_column_def_options_innodb.test b/mysql-test/suite/gcol/t/gcol_column_def_options_innodb.test
new file mode 100644
index 00000000..68931cd0
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_column_def_options_innodb.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_column_def_options_innodb.test #
+# #
+# Purpose: #
+# Testing different optional parameters of generated columns. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_column_def_options.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_column_def_options_myisam.test b/mysql-test/suite/gcol/t/gcol_column_def_options_myisam.test
new file mode 100644
index 00000000..6f04ecf3
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_column_def_options_myisam.test
@@ -0,0 +1,46 @@
+################################################################################
+# t/gcol_column_def_options_myisam.test #
+# #
+# Purpose: #
+# Testing different optional parameters of generated columns. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_column_def_options.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_handler_innodb.test b/mysql-test/suite/gcol/t/gcol_handler_innodb.test
new file mode 100644
index 00000000..50f72135
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_handler_innodb.test
@@ -0,0 +1,46 @@
+################################################################################
+# t/gcol_handler_innodb.test #
+# #
+# Purpose: #
+# Testing HANDLER.
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_handler.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_handler_myisam.test b/mysql-test/suite/gcol/t/gcol_handler_myisam.test
new file mode 100644
index 00000000..21923547
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_handler_myisam.test
@@ -0,0 +1,45 @@
+################################################################################
+# t/gcol_handler_myisam.test #
+# #
+# Purpose: #
+# Testing HANDLER.
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_handler.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_ins_upd_innodb.test b/mysql-test/suite/gcol/t/gcol_ins_upd_innodb.test
new file mode 100644
index 00000000..15a0db29
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_ins_upd_innodb.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_ins_upd_innodb.test #
+# #
+# Purpose: #
+# Testing DDL operations such as INSERT, UPDATE, REPLACE and DELETE. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_ins_upd.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_ins_upd_myisam.test b/mysql-test/suite/gcol/t/gcol_ins_upd_myisam.test
new file mode 100644
index 00000000..d54a6ae6
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_ins_upd_myisam.test
@@ -0,0 +1,46 @@
+################################################################################
+# t/gcol_ins_upd_myisam.test #
+# #
+# Purpose: #
+# Testing DDL operations such as INSERT, UPDATE, REPLACE and DELETE. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_ins_upd.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_keys_innodb.test b/mysql-test/suite/gcol/t/gcol_keys_innodb.test
new file mode 100644
index 00000000..7f7c4503
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_keys_innodb.test
@@ -0,0 +1,89 @@
+################################################################################
+# t/gcol_keys_innodb.test #
+# #
+# Purpose: #
+# Testing keys, indexes defined upon generated columns. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $skip_spatial_index_check = 1;
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_keys.inc
+
+if ($support_virtual_index) {
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+--echo #
+--echo # BUG#21365158 WL8149:ASSERTION `!TABLE || (!TABLE->WRITE_SET
+--echo #
+CREATE TABLE t1 (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_varchar_nokey VARCHAR(1),
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk)
+);
+
+INSERT INTO t1 ( col_int_nokey, col_varchar_nokey)
+VALUES (4, 'b'),(9, 'o'),(4, 'k'),(5, 'a'),(5, 'f'),
+(9, 't'),(3, 'c'),(8, 'c'),(0, 'r'),(98, 'k');
+
+CREATE TABLE t2 (
+ pk INTEGER AUTO_INCREMENT,
+ col_int_nokey INTEGER NOT NULL,
+ col_varchar_nokey VARCHAR(1) NOT NULL,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+ (CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL,
+ PRIMARY KEY (pk),
+ UNIQUE KEY (col_varchar_key)
+);
+
+INSERT INTO t2 ( col_int_nokey, col_varchar_nokey)
+VALUES (1, 'c'),(8, 'm'),(9, 'd'), (6, 'y'),(1, 't'),
+(2, 's'),(4, 'r');
+
+SELECT
+ CONCAT( t2.col_varchar_nokey , t2.col_varchar_nokey ) AS f2,
+ t1.col_varchar_key AS f5
+FROM
+ t2 LEFT JOIN t1 ON t2.col_int_nokey > t1.col_int_nokey
+ORDER BY f2, f5;
+DROP TABLE t1,t2;
+
+--echo #
+
+}
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_keys_myisam.test b/mysql-test/suite/gcol/t/gcol_keys_myisam.test
new file mode 100644
index 00000000..9cd89107
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_keys_myisam.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_keys_myisam.test #
+# #
+# Purpose: #
+# Testing keys, indexes defined upon generated columns. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+let $skip_foreign_key_check=1;
+--source suite/gcol/inc/gcol_keys.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_memory.test b/mysql-test/suite/gcol/t/gcol_memory.test
new file mode 100644
index 00000000..a7d9235d
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_memory.test
@@ -0,0 +1,43 @@
+################################################################################
+# t/gcol_memory.test #
+# #
+# Purpose: #
+# MEMORY branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-02 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+SET @@session.default_storage_engine = 'memory';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+--source suite/gcol/inc/gcol_unsupported_storage_engines.inc
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_merge.test b/mysql-test/suite/gcol/t/gcol_merge.test
new file mode 100644
index 00000000..8e3ba476
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_merge.test
@@ -0,0 +1,52 @@
+################################################################################
+# t/gcol_merge.test #
+# #
+# Purpose: #
+# MERGE branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-03 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+--disable_warnings
+drop table if exists t1, t2, t3;
+--enable_warnings
+
+create table t1 (a int, b int generated always as (a % 10) virtual);
+create table t2 (a int, b int generated always as (a % 10) virtual);
+insert into t1 values (1,default);
+insert into t2 values (2,default);
+--error ER_UNSUPPORTED_ENGINE_FOR_GENERATED_COLUMNS
+create table t3 (a int, b int generated always as (a % 10) virtual) engine=MERGE UNION=(t1,t2);
+drop table t1,t2;
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_non_stored_columns_innodb.test b/mysql-test/suite/gcol/t/gcol_non_stored_columns_innodb.test
new file mode 100644
index 00000000..ed0d255b
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_non_stored_columns_innodb.test
@@ -0,0 +1,48 @@
+################################################################################
+# t/gcol_non_stored_columns_innodb.test #
+# #
+# Purpose: #
+# Ensure that MySQL behaviour is consistent irrelevant of #
+# - the place of a non-stored column among other columns, #
+# - the total number of non-stored fields. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_non_stored_columns.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_non_stored_columns_myisam.test b/mysql-test/suite/gcol/t/gcol_non_stored_columns_myisam.test
new file mode 100644
index 00000000..9784071e
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_non_stored_columns_myisam.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_non_stored_columns_myisam.test #
+# #
+# Purpose: #
+# Ensure that MySQL behaviour is consistent irrelevant of #
+# - the place of a non-stored column among other columns, #
+# - the total number of non-stored fields. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_non_stored_columns.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_partition_innodb.test b/mysql-test/suite/gcol/t/gcol_partition_innodb.test
new file mode 100644
index 00000000..a8765970
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_partition_innodb.test
@@ -0,0 +1,63 @@
+################################################################################
+# t/gcol_partition_innodb.test #
+# #
+# Purpose: #
+# Testing partitioning tables with generated columns. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_partition.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+--echo #
+--echo # MDEV-16980 Wrongly set tablename len while opening the
+--echo # table for purge thread
+--echo #
+
+CREATE TABLE t1(pk SERIAL, d DATE, vd DATE AS (d) VIRTUAL,
+ PRIMARY KEY(pk), KEY (vd))ENGINE=InnoDB
+ PARTITION BY HASH(pk) PARTITIONS 2;
+
+INSERT IGNORE INTO t1 (d) VALUES ('2015-04-14');
+SET sql_mode= '';
+REPLACE INTO t1 SELECT * FROM t1;
+
+# Cleanup
+DROP TABLE t1;
+
+--source suite/innodb/include/wait_all_purged.inc
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_partition_myisam.test b/mysql-test/suite/gcol/t/gcol_partition_myisam.test
new file mode 100644
index 00000000..0a0cd9f9
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_partition_myisam.test
@@ -0,0 +1,45 @@
+################################################################################
+# t/gcol_partition_myisam.test #
+# #
+# Purpose: #
+# Testing partitioning tables with generated columns. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_partition.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_purge.test b/mysql-test/suite/gcol/t/gcol_purge.test
new file mode 100644
index 00000000..cfe20c4a
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_purge.test
@@ -0,0 +1,33 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+SET @save_dbug=@@GLOBAL.debug_dbug;
+CREATE TABLE t1(f1 INT NOT NULL, f2 int not null,
+ f3 int generated always as (f2 * 2) VIRTUAL,
+ primary key(f1), INDEX (f3))ENGINE=InnoDB;
+connect(con1,localhost,root,,,);
+--source ../innodb/include/wait_all_purged.inc
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+INSERT INTO t1(f1, f2) VALUES(1,2);
+DELETE from t1 where f1 = 1;
+
+connect(con2,localhost,root,,,);
+begin;
+INSERT INTO t1 (f1, f2) VALUES(1,2);
+
+set global debug_dbug="+d,ib_purge_virtual_index_callback";
+connection con1;
+COMMIT;
+
+SET GLOBAL innodb_max_purge_lag_wait=1;
+
+connection con2;
+commit;
+
+disconnect con1;
+disconnect con2;
+connection default;
+SET GLOBAL debug_dbug=@save_dbug;
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/t/gcol_rejected_innodb.test b/mysql-test/suite/gcol/t/gcol_rejected_innodb.test
new file mode 100644
index 00000000..1780fdf8
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_rejected_innodb.test
@@ -0,0 +1,41 @@
+################################################################################
+# t/gcol_handler_innodb.test #
+# #
+# Purpose: #
+# Testing rejected generated column additions.
+# #
+# InnoDB branch #
+# #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT INNODB SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+# @todo This test is broken for all VIRTUAL columns
+#--source suite/gcol/inc/gcol_rejected.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_rollback.test b/mysql-test/suite/gcol/t/gcol_rollback.test
new file mode 100644
index 00000000..888e6be8
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_rollback.test
@@ -0,0 +1,136 @@
+--source include/have_debug.inc
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/not_embedded.inc
+
+# Save the initial number of concurrent sessions.
+--source include/count_sessions.inc
+
+# Make sure there are no unexpected open tables from previous tests
+--disable_query_log
+FLUSH TABLES;
+--enable_query_log
+
+CREATE TABLE t (
+ a INTEGER,
+ b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+ INDEX (b(57))
+)ENGINE=INNODB;
+
+INSERT INTO t (a) VALUES (9);
+BEGIN;
+SAVEPOINT a;
+UPDATE t set a = 12;
+DELETE FROM t where a = 12;
+ROLLBACK TO SAVEPOINT a;
+COMMIT;
+
+CHECK TABLE t;
+
+SELECT * FROM t;
+
+BEGIN;
+INSERT INTO t (a) VALUES (10);
+--let $shutdown_timeout= 0
+--source include/restart_mysqld.inc
+SELECT * FROM t;
+DROP TABLE t;
+
+CREATE TABLE t (
+ a INTEGER,
+ b BLOB GENERATED ALWAYS AS (a) VIRTUAL,
+ c INTEGER
+)ENGINE=INNODB;
+
+INSERT INTO t (a,c) VALUES (9, 10);
+SELECT * FROM t;
+
+connect (con1,localhost,root,,);
+connection con1;
+
+# This DEBUG_SYNC should not kick in yet, because the duplicate key will be
+# detected before we get a chance to apply the online log.
+
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+--send
+ALTER TABLE t ADD KEY(b(57)), ALGORITHM=INPLACE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t (a,c) VALUES (10, 12);
+SELECT * FROM t;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+
+connection con1;
+reap;
+disconnect con1;
+connection default;
+
+SELECT * FROM t;
+DROP TABLE t;
+
+# drop virtual column and alter index
+CREATE TABLE t (
+ a INT,
+ b INT,
+ c INT GENERATED ALWAYS AS(a+b),
+ d INT GENERATED ALWAYS AS(a+b+b),
+ KEY(c, d)
+)ENGINE=INNODB;
+
+INSERT INTO t (a,b) VALUES (9, 10);
+SELECT * FROM t;
+
+connect (con1,localhost,root,,);
+connection con1;
+
+# This DEBUG_SYNC should not kick in yet, because the duplicate key will be
+# detected before we get a chance to apply the online log.
+
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+--send
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR created';
+BEGIN;
+INSERT INTO t (a,b) VALUES (10, 12);
+SELECT * FROM t;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml_done';
+
+connection con1;
+reap;
+connection default;
+
+SELECT * FROM t;
+
+DROP TABLE t;
+SET DEBUG_SYNC = 'RESET';
+
+--echo #
+--echo # MDEV-30597 Assertion `flag == 1' failed in
+--echo # row_build_index_entry_low
+--echo #
+CREATE TABLE t1 (
+col1 INT PRIMARY KEY, col_text TEXT,
+col_text_g TEXT GENERATED ALWAYS AS (SUBSTR(col_text,1,499))
+) ENGINE = InnoDB ROW_FORMAT = Compact;
+connection con1;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+INSERT INTO t1 (col1) VALUES (1) ;
+DELETE FROM t1 WHERE col1 = 1;
+ALTER TABLE t1 ADD UNIQUE INDEX (col_text_g(9));
+BEGIN;
+INSERT INTO t1 (col1) VALUES (1);
+ROLLBACK;
+disconnect con1;
+DROP TABLE t1;
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
+
+--echo # End of 10.4 tests
diff --git a/mysql-test/suite/gcol/t/gcol_select_innodb.test b/mysql-test/suite/gcol/t/gcol_select_innodb.test
new file mode 100644
index 00000000..18c17041
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_select_innodb.test
@@ -0,0 +1,53 @@
+################################################################################
+# t/gcol_select_innodb.test #
+# #
+# Purpose: #
+# Testing different SELECTs. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-18 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+eval SET optimizer_switch='derived_merge=off';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 0;
+--source suite/gcol/inc/gcol_select.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+eval SET optimizer_switch='derived_merge=default';
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_select_myisam.test b/mysql-test/suite/gcol/t/gcol_select_myisam.test
new file mode 100644
index 00000000..e078efba
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_select_myisam.test
@@ -0,0 +1,52 @@
+################################################################################
+# t/gcol_select.test #
+# #
+# Purpose: #
+# Testing different SELECTs. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-18 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+eval SET optimizer_switch='derived_merge=off';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+let $support_virtual_index= 1;
+--source suite/gcol/inc/gcol_select.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+eval SET optimizer_switch='derived_merge=default';
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_innodb.test b/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_innodb.test
new file mode 100644
index 00000000..2e910936
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_innodb.test
@@ -0,0 +1,45 @@
+################################################################################
+# t/gcol_supported_sql_funcs.test #
+# #
+# Purpose: #
+# Test SQL functions allowed for generated columns #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_supported_sql_funcs_main.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_myisam.test b/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_myisam.test
new file mode 100644
index 00000000..a9dee4c7
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_myisam.test
@@ -0,0 +1,44 @@
+################################################################################
+# t/gcol_supported_sql_funcs.test #
+# #
+# Purpose: #
+# Test SQL functions allowed for generated columns #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-08-31 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_supported_sql_funcs_main.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_trigger_sp_innodb.test b/mysql-test/suite/gcol/t/gcol_trigger_sp_innodb.test
new file mode 100644
index 00000000..4478cbe2
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_trigger_sp_innodb.test
@@ -0,0 +1,47 @@
+################################################################################
+# t/gcol_trigger_sp_innodb.test #
+# #
+# Purpose: #
+# Testing triggers, stored procedures and functions #
+# defined on tables with generated columns. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_trigger_sp.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_trigger_sp_myisam.test b/mysql-test/suite/gcol/t/gcol_trigger_sp_myisam.test
new file mode 100644
index 00000000..1a39d921
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_trigger_sp_myisam.test
@@ -0,0 +1,46 @@
+################################################################################
+# t/gcol_trigger_sp_myisam.test #
+# #
+# Purpose: #
+# Testing triggers, stored procedures and functions #
+# defined on tables with generated columns. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_trigger_sp.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_update.test b/mysql-test/suite/gcol/t/gcol_update.test
new file mode 100644
index 00000000..2076632f
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_update.test
@@ -0,0 +1,62 @@
+--source include/have_innodb.inc
+
+connect (purge_control,localhost,root);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+
+# Index on virtual column
+
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+ vchar char(2) as (substr(f3,2,2)) virtual,
+ primary key(f1, f3(5)), index(vchar))engine=innodb;
+
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+
+connection purge_control;
+COMMIT;
+--source ../../innodb/include/wait_all_purged.inc
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+
+drop table t1;
+
+# Index on virtual column and blob
+
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+ vchar char(2) as (substr(f3,2,2)) virtual,
+ primary key(f1, f3(5)), index(vchar, f3(2)))engine=innodb;
+
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+
+connection purge_control;
+COMMIT;
+--source ../../innodb/include/wait_all_purged.inc
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+drop table t1;
+
+# Index on virtual column of blob type
+
+create table t1(f1 int not null, f2 blob not null, f3 blob not null,
+ vchar blob as (f3) virtual,
+ primary key(f1, f3(5)), index(vchar(3)))engine=innodb;
+
+insert into t1(f1,f2,f3) values(1, repeat('a',8000), repeat('b', 9000));
+
+update t1 set f1=5 where f1=1;
+delete from t1 where f1=5;
+
+connection purge_control;
+COMMIT;
+--source ../../innodb/include/wait_all_purged.inc
+disconnect purge_control;
+
+connection default;
+drop table t1;
diff --git a/mysql-test/suite/gcol/t/gcol_view_innodb.test b/mysql-test/suite/gcol/t/gcol_view_innodb.test
new file mode 100644
index 00000000..06ded123
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_view_innodb.test
@@ -0,0 +1,46 @@
+################################################################################
+# t/gcol_view_innodb.test #
+# #
+# Purpose: #
+# Testing views defined on tables with generated columns. #
+# #
+# InnoDB branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+eval SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_view.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/gcol_view_myisam.test b/mysql-test/suite/gcol/t/gcol_view_myisam.test
new file mode 100644
index 00000000..3779f0bb
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_view_myisam.test
@@ -0,0 +1,45 @@
+################################################################################
+# t/gcol_view_myisam.test #
+# #
+# Purpose: #
+# Testing views defined on tables with generated columns. #
+# #
+# MyISAM branch #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+eval SET @@session.default_storage_engine = 'MyISAM';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source suite/gcol/inc/gcol_view.inc
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
diff --git a/mysql-test/suite/gcol/t/innodb_partition.test b/mysql-test/suite/gcol/t/innodb_partition.test
new file mode 100644
index 00000000..268a8c7c
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_partition.test
@@ -0,0 +1,30 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+--echo #
+--echo # Bug#22444530 - GCOLS + PARTITIONED TABLE, CRASH IN
+--echo #
+set sql_mode='';
+create table t (
+ a int not null,
+ b int generated always as (1) virtual,
+ c int generated always as (1) virtual,
+ key (c)
+) engine=innodb partition by key (a) partitions 2;
+insert into t(a) values(1);
+select b from t group by c;
+
+drop table t;
+
+# Make column b a BLOB
+create table t (
+ a int not null,
+ b blob generated always as ("a") virtual,
+ c int generated always as (1) virtual,
+ key (c)
+) engine=innodb partition by key (a) partitions 2;
+insert into t(a) values(1);
+select b from t group by c;
+
+drop table t;
+
diff --git a/mysql-test/suite/gcol/t/innodb_prefix_index_check.test b/mysql-test/suite/gcol/t/innodb_prefix_index_check.test
new file mode 100644
index 00000000..4923ead9
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_prefix_index_check.test
@@ -0,0 +1,22 @@
+--source include/have_innodb.inc
+
+--echo #Bug #22445211 GCOLS: SIMPLE DML, FAILING ASSERTION:
+--echo #!CURSOR->INDEX->IS_COMMITTED()
+
+--echo #Create and alter table examples for virtual column for full
+--echo #column index followed by prefix index.
+
+CREATE TABLE t1(
+f1 INT DEFAULT NULL,
+f2 CHAR(2) GENERATED ALWAYS AS ('11') VIRTUAL,
+f3 INT,
+UNIQUE KEY(f1),
+UNIQUE KEY(f3,f1),
+KEY(f2,f1),
+key(f1,f2(1))
+)ENGINE=INNODB;
+
+REPLACE INTO t1(f3) VALUES (1),(1);
+
+DROP TABLE t1;
+
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_basic.test b/mysql-test/suite/gcol/t/innodb_virtual_basic.test
new file mode 100644
index 00000000..32598758
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_basic.test
@@ -0,0 +1,1446 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+--source include/big_test.inc
+
+call mtr.add_suppression("\\[Warning\\] InnoDB: Compute virtual");
+
+set default_storage_engine=innodb;
+
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c CHAR(10), d CHAR(20), e CHAR(10) GENERATED ALWAYS AS (c), g INT);
+INSERT INTO t VALUES(10, DEFAULT, "aa", "bb", DEFAULT, 20);
+INSERT INTO t VALUES(11, DEFAULT, "jj", "kk", DEFAULT, 21);
+
+CREATE INDEX idx ON t(e) algorithm=inplace;
+INSERT INTO t VALUES(12, DEFAULT, 'mm', "nn", DEFAULT, 22);
+
+SELECT e FROM t;
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+CREATE INDEX idx ON t(c);
+SELECT c FROM t;
+
+UPDATE t SET a = 10 WHERE a = 11;
+SELECT c FROM t;
+
+SELECT * FROM t;
+
+DELETE FROM t WHERE a = 18;
+
+SELECT c FROM t;
+
+START TRANSACTION;
+
+INSERT INTO t VALUES (128, 22, DEFAULT, "xx");
+INSERT INTO t VALUES (1290, 212, DEFAULT, "xmx");
+ROLLBACK;
+
+SELECT c FROM t;
+SELECT * FROM t;
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+
+SELECT c FROM t;
+SELECT m FROM t;
+SELECT p FROM t;
+SELECT * FROM t;
+
+update t set a = 13 where a =11;
+
+delete from t where a =13;
+
+DROP INDEX idx1 ON t;
+DROP INDEX idx2 ON t;
+DROP TABLE t;
+
+/* Test large BLOB data */
+CREATE TABLE `t` (
+ `a` BLOB,
+ `b` BLOB,
+ `c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ `h` VARCHAR(10) DEFAULT NULL
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk");
+
+CREATE INDEX idx ON t(c(100));
+
+SELECT length(c) FROM t;
+
+START TRANSACTION;
+
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+
+ROLLBACK;
+
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+
+START TRANSACTION;
+
+UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
+
+ROLLBACK;
+
+# This SELECT did not give correct answer, even though InnoDB return
+# all qualified rows
+SELECT COUNT(*) FROM t WHERE c like "aaa%";
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c);
+
+START TRANSACTION;
+
+UPDATE t SET a = 100 WHERE a = 11;
+
+UPDATE t SET a =22 WHERE a = 18;
+
+UPDATE t SET a = 33 WHERE a = 22;
+
+SELECT c FROM t;
+
+ROLLBACK;
+
+SELECT c FROM t;
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c);
+SELECT c FROM t;
+
+connect(con1,localhost,root,,test);
+START TRANSACTION;
+SELECT c FROM t;
+
+connection default;
+UPDATE t SET a = 19 WHERE a = 11;
+
+# this should report the same value as previous one (14, 19, 29).
+connection con1;
+SELECT c FROM t;
+
+ROLLBACK;
+
+SELECT c FROM t;
+
+connection default;
+disconnect con1;
+
+DROP TABLE t;
+
+# CREATE a more complex TABLE
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + x), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, RTRIM(y))), x INT, y CHAR(20), z INT, INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+
+INSERT INTO t VALUES(1, 2, DEFAULT, "hhh", 3, DEFAULT, "nnn", DEFAULT, 4, "yyy", 5);
+
+INSERT INTO t VALUES(2, 3, DEFAULT, "hhha", 4, DEFAULT, "nnna", DEFAULT, 5, "yyya", 6);
+
+INSERT INTO t VALUES(12, 13, DEFAULT, "hhhb", 14, DEFAULT, "nnnb", DEFAULT, 15, "yyyb", 16);
+
+# CREATE an INDEX ON multiple virtual COLUMN
+CREATE INDEX idx6 ON t(p, c);
+
+SELECT p, c FROM t;
+
+START TRANSACTION;
+INSERT INTO t VALUES(32, 33, DEFAULT, "hhhb", 34, DEFAULT, "nnnb", DEFAULT, 35, "yyyb", 36);
+ROLLBACK;
+
+UPDATE t SET a = 100 WHERE a = 1;
+
+START TRANSACTION;
+UPDATE t SET a = 1 WHERE a = 100;
+ROLLBACK;
+
+DROP TABLE t;
+
+CREATE TABLE t1(a INT);
+ALTER TABLE t1 add COLUMN (b INT generated always as (a+1) virtual, c INT as(5) virtual);
+ALTER TABLE t1 add COLUMN (d INT generated always as (a+1) virtual, e INT as(5) virtual);
+
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+
+#--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t1 add COLUMN (f INT generated always as (a+1) virtual, g INT as(5) virtual), DROP COLUMN e;
+
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+
+DROP TABLE t1;
+
+CREATE TABLE t1(a INT);
+INSERT INTO t1 VALUES(1);
+
+ALTER TABLE t1 add COLUMN (f INT generated always as (a+1) virtual, g INT );
+
+# Inplace ADD/DROP virtual COLUMNs can only go with their own for
+# inplace algorithm, not to combine with other operations, except create index
+ALTER TABLE t1 add COLUMN (h INT generated always as (a+1) virtual), add INDEX idx (h), algorithm=inplace;
+
+--enable_info
+ALTER TABLE t1 add COLUMN (h1 INT generated always as (a+1) virtual), add INDEX idx1 (h1);
+--disable_info
+
+ALTER TABLE t1 DROP COLUMN h1, DROP INDEX idx;
+
+DROP TABLE t1;
+
+# Virtual COLUMN cannot be INDEXed
+CREATE TABLE t1(a INT);
+CREATE INDEX idx ON t1(a);
+CREATE TABLE t3(a INT, b INT , INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a));
+--error ER_CANT_CREATE_TABLE
+CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a));
+CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b));
+DROP TABLE t3;
+DROP TABLE t2;
+DROP TABLE t1;
+
+CREATE TABLE t1(a INT);
+ALTER TABLE t1 add COLUMN (b INT generated always as (a+1) virtual, c INT as(5) virtual);
+
+ALTER TABLE t1 change b x INT generated always as (a+1) virtual;
+
+SELECT pos, base_pos FROM informatiON_schema.innodb_sys_virtual;
+
+DROP TABLE t1;
+
+# We do not support Fulltext or Spatial INDEX ON Virtual Columns
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+CREATE TABLE t (a TEXT, b TEXT GENERATED ALWAYS AS (a), fulltext INDEX idx (b));
+CREATE TABLE t (a TEXT, b TEXT GENERATED ALWAYS AS (a));
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+ALTER TABLE t ADD FULLTEXT INDEX (b);
+DROP TABLE t;
+
+--error ER_SPATIAL_CANT_HAVE_NULL
+CREATE TABLE t (a geometry not null, b geometry GENERATED ALWAYS AS (a), spatial INDEX idx (b));
+CREATE TABLE t (a geometry not null, b geometry GENERATED ALWAYS AS (a));
+--error ER_SPATIAL_CANT_HAVE_NULL
+ALTER TABLE t ADD SPATIAL INDEX (b);
+DROP TABLE t;
+
+#test DEFAULT value
+CREATE TABLE t (a INT DEFAULT 1, b INT DEFAULT 2, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+CREATE INDEX idx ON t(c);
+INSERT INTO t(h)VALUES ('mm');
+SELECT c FROM t;
+
+CREATE unique INDEX idx1 ON t(c);
+
+--error ER_DUP_ENTRY
+INSERT INTO t(h)VALUES ('mm');
+
+DROP TABLE t;
+
+CREATE TABLE `t1` ( `a` INT(11) DEFAULT NULL, `b` INT(11) DEFAULT NULL, `c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL, `x` INT(11) NOT NULL, `h` VARCHAR(10) DEFAULT NULL, PRIMARY KEY (`x`), KEY `idx` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t1 VALUES (1, 2, DEFAULT, 3, 'mm');
+INSERT INTO t1 VALUES (11, 22, DEFAULT, 23, 'mm');
+
+connect(con1,localhost,root,,test);
+UPDATE t1 SET x = 4 WHERE x =3;
+DROP TABLE t1;
+
+CREATE TABLE `t1` ( `a` INT(11) DEFAULT NULL, `b` INT(11) DEFAULT NULL, `c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL, `x` INT(11) NOT NULL, `h` VARCHAR(10) DEFAULT NULL, KEY `idx` (`c`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t1 VALUES (1, 2, DEFAULT, 3, 'mm');
+INSERT INTO t1 VALUES (11, 22, DEFAULT, 23, 'mm');
+
+START TRANSACTION;
+SELECT * FROM t1;
+
+connection con1;
+START TRANSACTION;
+UPDATE t1 SET x = 15 WHERE x = 3;
+
+UPDATE t1 SET b = 10 WHERE b=2;
+ROLLBACK;
+
+connection default;
+SELECT c FROM t1;
+
+disconnect con1;
+
+DROP TABLE t1;
+
+CREATE TABLE `t` (
+ `a` INT(11) DEFAULT NULL,
+ `b` INT(11) DEFAULT NULL,
+ `c` INT(11) GENERATED ALWAYS AS (a+b) VIRTUAL,
+ `d` INT(11) GENERATED ALWAYS AS (a) VIRTUAL,
+ `h` INT(11) NOT NULL,
+ PRIMARY KEY (`h`),
+ KEY `idx` (`c`)
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (11, 3, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (18, 1, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (28, 1, DEFAULT, DEFAULT, 3);
+INSERT INTO t VALUES (null, null, DEFAULT, DEFAULT, 4);
+
+delimiter |;
+CREATE PROCEDURE UPDATE_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 2000) DO
+ UPDATE t SET a = 100 + i WHERE h = 1;
+ SET i = i + 1;
+ END WHILE;
+END|
+
+CREATE PROCEDURE DELETE_insert_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 2000) DO
+ UPDATE t SET a = 100 + i WHERE h = 1;
+ SET i = i + 1;
+ END WHILE;
+END|
+delimiter ;|
+
+CALL UPDATE_t();
+SELECT c FROM t;
+
+CALL DELETE_insert_t();
+SELECT c FROM t;
+
+DROP INDEX idx ON t;
+CALL UPDATE_t();
+SELECT c FROM t;
+
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+
+DROP TABLE t;
+
+--echo # Bug#20767937: WL8149:ASSERTION FAILED IN ROW_UPD_SEC_INDEX_ENTRY
+CREATE TABLE b (
+col_INT_nokey INTEGER NOT NULL,
+col_INT_key INTEGER GENERATED ALWAYS AS (col_INT_nokey) VIRTUAL,
+col_date_nokey DATE,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,
+ INTerval 30 day)) VIRTUAL,
+
+col_datetime_nokey DATETIME NOT NULL,
+col_time_nokey TIME NOT NULL,
+
+col_datetime_key DATETIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey,
+ col_time_nokey)),
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey,
+ col_time_nokey)),
+
+col_VARCHAR_nokey VARCHAR(1) NOT NULL,
+col_VARCHAR_key VARCHAR(2) GENERATED ALWAYS AS(CONCAT(col_VARCHAR_nokey,
+ col_VARCHAR_nokey)),
+
+KEY (col_INT_key),
+KEY (col_VARCHAR_key),
+KEY (col_date_key),
+KEY (col_time_key),
+KEY (col_datetime_key),
+KEY (col_INT_key, col_VARCHAR_key),
+KEY (col_INT_key, col_VARCHAR_key, col_date_key,
+col_time_key, col_datetime_key)
+);
+INSERT INTO b (
+ col_INT_nokey,
+ col_date_nokey,
+ col_time_nokey,
+ col_datetime_nokey,
+ col_VARCHAR_nokey
+) VALUES
+(0, NULL, '21:22:34.025509', '2002-02-13 17:30:06.013935', 'j'),
+(8, '2004-09-18', '10:50:38.059966', '2008-09-27
+00:34:58.026613', 'v');
+
+EXPLAIN SELECT col_INT_key FROM b;
+SELECT col_INT_key FROM b;
+SELECT col_INT_nokey, col_INT_key FROM b;
+DELETE FROM b;
+
+DROP TABLE b;
+
+let $row_format=COMPACT;
+--source inc/innodb_v_large_col.inc
+
+CREATE TABLE `t` (
+ `a` BLOB,
+ `b` BLOB,
+ `c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ `d` BLOB GENERATED ALWAYS AS (b) VIRTUAL,
+ `e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` INT(11) NOT NULL,
+ PRIMARY KEY (`h`)
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, DEFAULT, DEFAULT, 1);
+INSERT INTO t VALUES (REPEAT('a', 32000), REPEAT('b', 11000), DEFAULT, DEFAULT, DEFAULT, 2);
+INSERT INTO t VALUES (REPEAT('m', 18000), REPEAT('n', 46000), DEFAULT, DEFAULT, DEFAULT, 3);
+
+CREATE INDEX idx ON t(c(100), d(20));
+
+UPDATE t SET a = NULL WHERE h=1;
+
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 2000) WHERE h = 1;
+
+UPDATE t SET a = REPEAT(CAST(1 AS CHAR), 1000) WHERE h = 1;
+
+delimiter |;
+
+CREATE PROCEDURE UPDATE_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 200) DO
+ UPDATE t SET a = REPEAT(CAST(i AS CHAR), 2000) WHERE h = 1;
+ SET i = i + 1;
+ END WHILE;
+END|
+
+CREATE PROCEDURE DELETE_insert_t()
+begin
+ DECLARE i INT DEFAULT 1;
+ WHILE (i <= 200) DO
+ DELETE FROM t WHERE h = 1;
+ INSERT INTO t VALUES (REPEAT(CAST(i AS CHAR), 2000) , REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 1);
+ SET i = i + 1;
+ END WHILE;
+END|
+delimiter ;|
+
+CALL UPDATE_t();
+CALL DELETE_insert_t();
+
+UPDATE t SET a = NULL WHERE h=1;
+
+DROP PROCEDURE DELETE_insert_t;
+DROP PROCEDURE UPDATE_t;
+DROP TABLE t;
+
+CREATE TABLE `t` (
+ `m1` INT(11) DEFAULT NULL,
+ `m2` INT(11) DEFAULT NULL,
+ `m3` INT(11) GENERATED ALWAYS AS (m1 + m2) VIRTUAL,
+ `m4` INT(11) DEFAULT NULL,
+ `m5` CHAR(10) DEFAULT NULL,
+ `m6` CHAR(12) GENERATED ALWAYS AS (m5) VIRTUAL,
+ `a` VARCHAR(10000) DEFAULT NULL,
+ `b` VARCHAR(3000) DEFAULT NULL,
+ `c` VARCHAR(14000) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ `d` VARCHAR(5000) GENERATED ALWAYS AS (b) VIRTUAL,
+ `e` INT(11) GENERATED ALWAYS AS (10) VIRTUAL,
+ `h` INT(11) NOT NULL,
+ PRIMARY KEY (`h`),
+ KEY `m3` (`m3`),
+ KEY `c` (`c`(100)),
+ KEY `e` (`e`,`d`(20))
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (1, 2, DEFAULT, 3, "aaa", DEFAULT, REPEAT('g', 10000), REPEAT('x', 2800), DEFAULT, DEFAULT, DEFAULT, 1);
+
+INSERT INTO t VALUES (11, 21, DEFAULT, 31, "bbb", DEFAULT, REPEAT('a', 9000), REPEAT('b', 2000), DEFAULT, DEFAULT, DEFAULT, 2);
+
+INSERT INTO t VALUES (21, 31, DEFAULT, 41, "zzz", DEFAULT, REPEAT('m', 8000), REPEAT('n', 3000), DEFAULT, DEFAULT, DEFAULT, 3);
+
+ALTER TABLE t DROP COLUMN c;
+
+DELETE FROM t;
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+CREATE INDEX idx ON t(a, c);
+SELECT a, c FROM t;
+
+START TRANSACTION;
+
+UPDATE t SET a = 13 where a = 11;
+
+ROLLBACK;
+DELETE FROM t;
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), m int);
+
+INSERT INTO t VALUES (11, 3, DEFAULT, "a", 1);
+INSERT INTO t VALUES (18, 1, DEFAULT, "b", 2);
+INSERT INTO t VALUES (28, 1, DEFAULT, "c", 3 );
+INSERT INTO t VALUES (null, null, DEFAULT, "d", 4);
+
+CREATE INDEX idx ON t(a, c, h);
+SELECT a, c FROM t;
+
+START TRANSACTION;
+UPDATE t SET m =10 WHERE m = 1;
+UPDATE t SET h = "e" WHERE h="a";
+ROLLBACK;
+SELECT a, c, h FROM t;
+
+DROP TABLE t;
+
+# bug#21065137 - WL8149:FAILING ASSERTION: NAME_OFS < FULL_LEN
+CREATE TABLE `t1` (
+ `col1` int(11) NOT NULL,
+ `col2` int(11) NOT NULL,
+ `col3` int(11) NOT NULL,
+ `col4` int(11) DEFAULT NULL,
+ `col5` int(11) GENERATED ALWAYS AS (col2 % col3) VIRTUAL,
+ `col7` int(11) GENERATED ALWAYS AS (col5 * col5) VIRTUAL,
+ `col8` int(11) GENERATED ALWAYS AS (col5 % col5) VIRTUAL,
+ `col9` text,
+ `extra` int(11) DEFAULT NULL,
+ UNIQUE KEY `uidx` (`col5`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+ALTER TABLE t1 CHANGE COLUMN extra col6 INT;
+
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# No spatial and FTS index on virtual columns
+--error ER_SPATIAL_CANT_HAVE_NULL
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c point, d point GENERATED ALWAYS AS (c), spatial index idx (d));
+
+--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
+CREATE TABLE t (a INT, b INT GENERATED ALWAYS AS (a), c CHAR(10), d char(20) GENERATED ALWAYS AS (c), fulltext index idx (d));
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+
+alter table t add x int, add xx int generated ALWAYS AS(x);
+
+DROP TABLE t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10), j INT, m INT GENERATED ALWAYS AS(b + j), n VARCHAR(10), p VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), INDEX idx1(c), INDEX idx2 (m), INDEX idx3(p));
+
+INSERT INTO t VALUES(11, 22, DEFAULT, "AAA", 8, DEFAULT, "XXX", DEFAULT);
+INSERT INTO t VALUES(1, 2, DEFAULT, "uuu", 9, DEFAULT, "uu", DEFAULT);
+INSERT INTO t VALUES(3, 4, DEFAULT, "uooo", 1, DEFAULT, "umm", DEFAULT);
+
+ALTER TABLE t DROP COLUMN c, algorithm=inplace;
+ALTER TABLE t DROP COLUMN p, ADD COLUMN s VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), algorithm=inplace;
+
+# This should fail
+#ALTER TABLE t ADD x INT, DROP COLUMN m, algorithm=inplace;
+SELECT s FROM t;
+
+ALTER TABLE t ADD x VARCHAR(20) GENERATED ALWAYS AS(CONCAT(n, h)), ADD INDEX idx (x), algorithm=inplace;
+DROP TABLE t;
+
+CREATE TABLE `t1` (
+ `col1` int(11) DEFAULT NULL,
+ `col2` int(11) DEFAULT NULL,
+ `col3` int(11) DEFAULT NULL,
+ `col4` int(11) DEFAULT NULL,
+ `col5` int(11) GENERATED ALWAYS AS (col4 * col2) VIRTUAL,
+ `col6` int(11) GENERATED ALWAYS AS (col2 % col4) VIRTUAL,
+ `col7` int(11) GENERATED ALWAYS AS (col5 / col6) VIRTUAL,
+ `col8` int(11) GENERATED ALWAYS AS (col5 + col5) VIRTUAL,
+ `col9` text,
+ `extra` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+ALTER TABLE t1 DROP COLUMN col7;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ col1 INTEGER NOT NULL,
+ gv_col INTEGER GENERATED ALWAYS AS (col1) VIRTUAL,
+ txt1 TEXT,
+ FULLTEXT INDEX fi(txt1)
+);
+
+select * from t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ col1 INTEGER NOT NULL,
+ col2 INTEGER NOT NULL,
+ col3 INTEGER DEFAULT NULL,
+ col4 INTEGER DEFAULT NULL,
+ col5 INTEGER DEFAULT NULL,
+ col6 INTEGER DEFAULT NULL,
+ col7 INTEGER DEFAULT NULL,
+ col8 INTEGER DEFAULT NULL,
+ col9 INTEGER DEFAULT NULL,
+ col10 INTEGER DEFAULT NULL,
+ col11 INTEGER DEFAULT NULL,
+ col12 INTEGER DEFAULT NULL,
+ col13 INTEGER DEFAULT NULL,
+ col14 INTEGER DEFAULT NULL,
+ col15 INTEGER DEFAULT NULL,
+ col16 INTEGER DEFAULT NULL,
+ col17 INTEGER DEFAULT NULL,
+ col18 INTEGER DEFAULT NULL,
+ col19 INTEGER DEFAULT NULL,
+ col20 INTEGER DEFAULT NULL,
+ col21 INTEGER DEFAULT NULL,
+ col22 INTEGER DEFAULT NULL,
+ col23 INTEGER DEFAULT NULL,
+ col24 INTEGER DEFAULT NULL,
+ col25 INTEGER DEFAULT NULL,
+ col26 INTEGER DEFAULT NULL,
+ col27 INTEGER DEFAULT NULL,
+ col28 INTEGER DEFAULT NULL,
+ col29 INTEGER DEFAULT NULL,
+ col30 INTEGER DEFAULT NULL,
+ col31 INTEGER DEFAULT NULL,
+ col32 INTEGER DEFAULT NULL,
+ col33 INTEGER DEFAULT NULL,
+ gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
+ KEY idx1 (gcol1)
+);
+
+INSERT INTO t1 (col1, col2)
+ VALUES (0,1), (1,2), (2,3), (3,4), (4,5);
+
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+
+ALTER TABLE t1 ADD COLUMN extra INTEGER;
+
+SELECT gcol1 FROM t1 FORCE INDEX(idx1);
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ id INT NOT NULL,
+ store_id INT NOT NULL,
+ x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+ PARTITION p0 VALUES LESS THAN (6),
+ PARTITION p1 VALUES LESS THAN (11),
+ PARTITION p2 VALUES LESS THAN (16),
+ PARTITION p3 VALUES LESS THAN (21)
+);
+
+INSERT INTO t1 VALUES(1, 2, default);
+INSERT INTO t1 VALUES(3, 4, default);
+
+INSERT INTO t1 VALUES(3, 12, default);
+INSERT INTO t1 VALUES(4, 18, default);
+
+CREATE INDEX idx ON t1(x);
+
+SELECT x FROM t1;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ id INT NOT NULL,
+ store_id INT NOT NULL,
+ x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (x) (
+ PARTITION p0 VALUES LESS THAN (6),
+ PARTITION p1 VALUES LESS THAN (11),
+ PARTITION p2 VALUES LESS THAN (16),
+ PARTITION p3 VALUES LESS THAN (21)
+);
+
+insert into t1 values(1, 2, default);
+insert into t1 values(3, 4, default);
+
+insert into t1 values(3, 12, default);
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+insert into t1 values(4, 18, default);
+
+CREATE INDEX idx ON t1(x);
+SELECT x FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a+1) ,c int) PARTITION BY RANGE (b) (
+PARTITION p0 VALUES LESS THAN (6),
+PARTITION p1 VALUES LESS THAN (11),
+PARTITION p2 VALUES LESS THAN (16),
+PARTITION p3 VALUES LESS THAN (21) );
+
+INSERT INTO t1 VALUES (10,DEFAULT,2);
+INSERT INTO t1 VALUES (19,DEFAULT,8);
+
+CREATE INDEX idx ON t1 (b);
+
+INSERT INTO t1 VALUES (5,DEFAULT,9);
+
+SELECT * FROM t1;
+
+ALTER TABLE t1 REMOVE PARTITIONING;
+
+DROP TABLE t1;
+
+CREATE TABLE `t#P#1` (a INT, bt INT GENERATED ALWAYS AS (a+1) ,c int)
+PARTITION BY RANGE (bt)
+subpartition by hash (bt)
+ (
+ PARTITION p0 VALUES LESS THAN (6) (
+ SUBPARTITION s0,
+ SUBPARTITION s1),
+ PARTITION p1 VALUES LESS THAN (11) (
+ SUBPARTITION s2,
+ SUBPARTITION s3),
+ PARTITION p2 VALUES LESS THAN (16) (
+ SUBPARTITION s4,
+ SUBPARTITION s5),
+ PARTITION p3 VALUES LESS THAN (21) (
+ SUBPARTITION s6,
+ SUBPARTITION s7)
+ );
+insert into `t#P#1` values (10,DEFAULT,2);
+insert into `t#P#1` values (19,DEFAULT,8);
+create index idx on `t#P#1` (bt);
+insert into `t#P#1` values (5,DEFAULT,9);
+select * from `t#P#1`;
+alter table `t#P#1` remove partitioning;
+drop table `t#P#1`;
+
+let $row_format=DYNAMIC;
+--source inc/innodb_v_large_col.inc
+
+let $row_format=REDUNDANT;
+--source inc/innodb_v_large_col.inc
+
+let $row_format=COMPRESSED;
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+--source inc/innodb_v_large_col.inc
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+# Make sure FTS_DOC_ID for FULLTEXT index set with correct column id with
+# virtual columns
+CREATE TABLE t(a TEXT CHARSET UTF8)ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN b BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+ALTER TABLE t ADD FULLTEXT INDEX (a) ;
+ALTER TABLE t ADD INDEX (b(1)) ;
+
+DROP TABLE t;
+
+CREATE TABLE t(a TEXT CHARSET UTF8, FULLTEXT INDEX(a))ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN b BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+ALTER TABLE t ADD INDEX (b(1)) ;
+DROP TABLE t;
+
+# Virtual column cannot be used as DOC ID column for FULLTEXT index
+CREATE TABLE t(a TEXT CHARSET UTF8)ENGINE=INNODB;
+ALTER TABLE t ADD COLUMN FTS_DOC_ID BLOB GENERATED ALWAYS AS (a) VIRTUAL ;
+--error ER_INNODB_FT_WRONG_DOCID_COLUMN
+ALTER TABLE t ADD FULLTEXT INDEX (a) ;
+DROP TABLE t;
+
+# Test uses ICP on column h and d
+create table t (a int,b int,c int,d int,e int,
+f int generated always as (a+b) virtual,
+g int,h blob,i int,unique key (d,h(25))) engine=innodb;
+
+select h from t where d is null;
+drop table t;
+
+# Test Add virtual column of MySQL long true type
+create table t(a blob not null) engine=innodb;
+alter table t add column b int;
+alter table t add column c varbinary (1000) generated always as (a) virtual;
+alter table t add unique index (c(39));
+replace into t set a = 'a',b =1;
+replace into t set a = 'a',b =1;
+drop table t;
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t ADD COLUMN xs INT GENERATED ALWAYS AS(a+b), ADD COLUMN mm INT
+GENERATED ALWAYS AS(a+b) STORED, ALGORITHM = INPLACE;
+
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ALGORITHM = INPLACE;
+
+ALTER TABLE t DROP COLUMN x, ALGORITHM = INPLACE;
+
+ALTER TABLE t ADD COLUMN x1 INT GENERATED ALWAYS AS(a+b), DROP COLUMN c,
+ALGORITHM = INPLACE;
+
+DROP TABLE t;
+
+if (0) {
+# Some test on virtual/stored column numbering for spatial indexing
+CREATE TABLE `t` (
+ `a` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `b` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `c` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `d` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e` POINT GENERATED ALWAYS AS (1) STORED
+) ENGINE=INNODB;
+ALTER TABLE t ADD SPATIAL INDEX (`e`);
+DROP TABLE t;
+CREATE TABLE `t` (
+ `a` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `b` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `c` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `d` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e` POINT GENERATED ALWAYS AS (1) STORED,
+ SPATIAL INDEX (`e`)
+) ENGINE=INNODB;
+DROP TABLE t;
+CREATE TABLE `t` (
+ `a` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `b` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `c` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `d` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e2` POINT GENERATED ALWAYS AS (1) STORED,
+ `e` POINT GENERATED ALWAYS AS (1) STORED
+) ENGINE=INNODB;
+ALTER TABLE t ADD SPATIAL INDEX (`e`);
+DROP TABLE t;
+CREATE TABLE `t` (
+ `a` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `b` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `c` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `d` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e2` POINT GENERATED ALWAYS AS (1) STORED,
+ `d2` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e` POINT GENERATED ALWAYS AS (1) STORED
+) ENGINE=INNODB;
+ALTER TABLE t ADD SPATIAL INDEX (`e`);
+DROP TABLE t;
+CREATE TABLE `t` (
+ `a` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `b` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `c` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `d` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e2` POINT GENERATED ALWAYS AS (1) STORED,
+ `d2` INT GENERATED ALWAYS AS (1) VIRTUAL,
+ `e` int
+) ENGINE=INNODB;
+ALTER TABLE t ADD INDEX (`e`);
+DROP TABLE t;
+}
+
+CREATE TABLE t (a INT GENERATED ALWAYS AS(1) VIRTUAL,KEY(a)) ENGINE=INNODB;
+INSERT INTO t VALUES(default);
+SELECT a FROM t FOR UPDATE;
+DROP TABLE t;
+
+# Test add virtual column and add index at the same time
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+--enable_info
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x);
+--disable_info
+
+SELECT x FROM t;
+
+DROP TABLE t;
+
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t1 VALUES (11, 3, DEFAULT, 'mm');
+
+INSERT INTO t1 VALUES (18, 1, DEFAULT, 'mm');
+
+INSERT INTO t1 VALUES (28, 1, DEFAULT, 'mm');
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD INDEX idx12 (c) , FORCE, LOCK=NONE;
+ALTER TABLE t1 ADD INDEX idx12 (c), LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP COLUMN h, ADD INDEX idx (c) , FORCE, LOCK=NONE;
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 DROP COLUMN h, ADD INDEX idx (c), LOCK=NONE;
+
+DROP TABLE t1 ;
+
+# Check ALTER TABLE CHANGE VIRTUAL COLUMN TYPE and ORDER
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), d INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t1 VALUES (11, 3, DEFAULT, DEFAULT, 'mm');
+
+INSERT INTO t1 VALUES (18, 1, DEFAULT, DEFAULT, 'mm');
+
+INSERT INTO t1 VALUES (28, 1, DEFAULT, DEFAULT, 'mm');
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 CHANGE d d INT GENERATED ALWAYS AS(a+b) FIRST, ALGORITHM = INPLACE;
+
+# Change column type is not allow for inplace also
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t1 CHANGE d d VARCHAR(10) GENERATED ALWAYS AS(h), ALGORITHM = INPLACE;
+
+ALTER TABLE t1 CHANGE d d INT GENERATED ALWAYS AS(a+b) FIRST;
+
+SHOW CREATE TABLE t1;
+
+DROP TABLE t1;
+
+# Test foreign key which could be a base column of indexed virtual column
+CREATE TABLE parent (id INT PRIMARY KEY) ENGINE=INNODB;
+
+CREATE TABLE child (
+ id INT,
+ parent_id INT,
+ x int(11) GENERATED ALWAYS AS (parent_id+1),
+ INDEX par_ind (parent_id),
+ FOREIGN KEY (parent_id)
+ REFERENCES parent(id)
+ ON DELETE CASCADE
+) ENGINE=INNODB;
+
+ALTER TABLE child ADD INDEX `i1` (x);
+
+# If foreign constrain does not have cascade clause, or with "no action" clause
+# the index can still be created
+CREATE TABLE child_1 (
+ id INT,
+ parent_id INT,
+ x int(11) GENERATED ALWAYS AS (parent_id+1),
+ INDEX par_ind (parent_id),
+ FOREIGN KEY (parent_id)
+ REFERENCES parent(id)
+) ENGINE=INNODB;
+
+# This should be successful
+ALTER TABLE child_1 ADD INDEX `i1` (x);
+
+DROP TABLE child_1;
+
+DROP TABLE child;
+
+CREATE TABLE child (
+ id INT,
+ parent_id INT,
+ x int(11) GENERATED ALWAYS AS (parent_id+1),
+ INDEX par_ind (parent_id),
+ INDEX i1 (x),
+
+ FOREIGN KEY (parent_id)
+ REFERENCES parent(id)
+ ON DELETE CASCADE
+) ENGINE=INNODB;
+
+DROP TABLE child;
+
+CREATE TABLE child (
+ id INT,
+ parent_id INT,
+ x int(11) GENERATED ALWAYS AS (parent_id+1),
+ INDEX par_ind (parent_id),
+ INDEX `i1` (x)
+) ENGINE=INNODB;
+
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE;
+
+# Check inplace option
+SET foreign_key_checks = 0;
+
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE CASCADE;
+
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON DELETE SET NULL;
+
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id)
+ON UPDATE CASCADE;
+
+# this should be successful
+ALTER TABLE child ADD FOREIGN KEY (parent_id)
+REFERENCES parent(id);
+
+SET foreign_key_checks = 1;
+
+DROP TABLE child;
+
+DROP TABLE parent;
+
+# Test for Bug 21890816 - ASSERT UPDATE->OLD_VROW, VIRTUAL COLUMNS
+CREATE TABLE `ibstd_16` (
+ `a` int(11) DEFAULT NULL,
+ `d` int(11) DEFAULT NULL,
+ `b` varchar(198) DEFAULT NULL,
+ `c` char(179) DEFAULT NULL,
+ `vadcol` int(11) GENERATED ALWAYS AS (a+length(d)) STORED,
+ `vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+ UNIQUE KEY `b` (`b`(10),`d`),
+ KEY `d` (`d`),
+ KEY `a` (`a`),
+ KEY `c` (`c`(99),`b`(33)),
+ KEY `b_2` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `a_2` (`a`,`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=INNODB;
+
+# Block when FK constraint on base column of stored column.
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+CREATE TABLE `ibstd_16_fk` (
+ `a` int(11) DEFAULT NULL,
+ `d` int(11) DEFAULT NULL,
+ `b` varchar(198) DEFAULT NULL,
+ `c` char(179) DEFAULT NULL,
+ `vadcol` int(11) GENERATED ALWAYS AS (a+length(d)) STORED,
+ `vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+ UNIQUE KEY `b` (`b`(10),`a`,`d`),
+ KEY `d` (`d`),
+ KEY `a` (`a`),
+ KEY `c` (`c`(99),`b`(33)),
+ KEY `b_2` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `a_2` (`a`,`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`,`d`),
+ CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL
+) ENGINE=InnoDB;
+
+# Take out "KEY `a_2` (`a`,`vbidxcol`)", this should then be successful
+CREATE TABLE `ibstd_16_fk` (
+ `a` int(11) DEFAULT NULL,
+ `d` int(11) DEFAULT NULL,
+ `b` varchar(198) DEFAULT NULL,
+ `c` char(179) DEFAULT NULL,
+ `vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+ UNIQUE KEY `b` (`b`(10),`a`,`d`),
+ KEY `d` (`d`),
+ KEY `a` (`a`),
+ KEY `c` (`c`(99),`b`(33)),
+ KEY `b_2` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`,`d`),
+ CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL
+) ENGINE=InnoDB;
+
+ALTER TABLE ibstd_16_fk ADD INDEX `a_2` (`a`,`vbidxcol`);
+
+# Now try to add a table with virtual index, and then add constraint
+DROP TABLE ibstd_16_fk;
+
+# Create a table without constraint
+CREATE TABLE `ibstd_16_fk` (
+ `a` int(11) DEFAULT NULL,
+ `d` int(11) DEFAULT NULL,
+ `b` varchar(198) DEFAULT NULL,
+ `c` char(179) DEFAULT NULL,
+ `vbcol` char(2) GENERATED ALWAYS AS (substr(b,2,2)) VIRTUAL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL,
+ UNIQUE KEY `b` (`b`(10),`a`,`d`),
+ KEY `d` (`d`),
+ KEY `a` (`a`),
+ KEY `c` (`c`(99),`b`(33)),
+ KEY `b_2` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `a_2` (`a`,`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=InnoDB;
+
+ALTER TABLE `ibstd_16_fk` ADD CONSTRAINT `fk_16` FOREIGN KEY (`a`) REFERENCES `ibstd_16` (`a`) ON DELETE SET NULL;
+
+# DROP the index
+DROP INDEX a_2 ON ibstd_16_fk;
+
+INSERT INTO ibstd_16 VALUES (1, 2, "aaa", "bbb", default, default, default);
+INSERT INTO ibstd_16_fk VALUES(1, 3, "mmm", "SSS", default, default);
+
+# Cascading delete/update on column non-related to virtual column or virtual
+# index will be fine
+DELETE FROM ibstd_16 WHERE a = 1;
+
+DROP TABLE ibstd_16_fk;
+DROP TABLE ibstd_16;
+
+# Bug 21941320 - GCOLS: FAILING ASSERTION: N_IDX > 0
+create table t(a int) engine=innodb;
+insert into t set a=1;
+alter table t add column c int generated always as (1) virtual;
+insert into t set a=2;
+
+# Following will cause create index fail, we need to make sure the column
+# ord_part is reset
+--error ER_DUP_ENTRY
+alter table t add unique index(c);
+insert into t set a=1;
+drop table t;
+
+# Bug 21875974 - VCOL : READ OF FREED MEMORY IN DTUPLE_GET_N_FIELDS
+# CAUSE CRASH
+
+create table t (
+ x int,
+ a int generated always as (x) virtual,
+ b int generated always as (1) stored,
+ c int not null,
+ unique (b),
+ unique (a,b)
+) engine=innodb;
+
+insert into t(x, c) values(1, 3);
+
+# This will exercise row_vers_impl_x_locked_low() for virtual columns
+replace into t(x, c) values(1, 0);
+
+drop table t;
+
+# Bug22123674 VCOL:INNODB: FAILING ASSERTION: !UT_STRCMP(NAME,
+# FIELD->FIELD_NAME)
+
+CREATE TABLE t(
+c7c CHAR(1)GENERATED ALWAYS AS (c3) VIRTUAL,
+c1 int(1),
+c2 int(1),
+c3 int(1),
+c4 int(1),
+c5 int(1)GENERATED ALWAYS AS ((c2 - c4)) VIRTUAL,
+UNIQUE KEY c5_9(c5)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t CHANGE COLUMN c5 c5 INT(1) GENERATED ALWAYS AS(c2 -
+c4)VIRTUAL AFTER c3,ALGORITHM=INPLACE;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED
+ALTER TABLE t CHANGE COLUMN c7c c7c INT(1) GENERATED ALWAYS AS(c3)
+VIRTUAL AFTER c5,ALGORITHM=INPLACE;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t DROP COLUMN c7c,ADD COLUMN c5c INT GENERATED ALWAYS AS(c4/
+c3)VIRTUAL AFTER c3,ALGORITHM=INPLACE;
+
+DROP TABLE t;
+
+# Bug22111464 VCOL:INNODB: FAILING ASSERTION: I < TABLE->N_DEF
+
+CREATE TABLE `t` (
+ `col1` int(11) DEFAULT NULL,
+ `col2` int(11) DEFAULT NULL,
+ `col4` int(11) DEFAULT NULL,
+ `col5` int(11) GENERATED ALWAYS AS ((`col2` % `col4`)) VIRTUAL,
+ `col6` int(11) GENERATED ALWAYS AS ((`col2` - `col2`)) VIRTUAL,
+ `col5x` int(11) GENERATED ALWAYS AS ((`col1` / `col1`)) VIRTUAL,
+ `col6x` int(11) GENERATED ALWAYS AS ((`col2` / `col4`)) VIRTUAL,
+ `col7x` int(11) GENERATED ALWAYS AS ((`col6` % `col6x`)) VIRTUAL,
+ `col8x` int(11) GENERATED ALWAYS AS ((`col6` / `col6`)) VIRTUAL,
+ `col9` text,
+ `col7c` int(11) GENERATED ALWAYS AS ((`col6x` % `col6x`)) VIRTUAL,
+ `col1b` varchar(20) GENERATED ALWAYS AS (`col1`) VIRTUAL,
+ `col3` int(11) DEFAULT NULL,
+ `col7` int(11) DEFAULT NULL,
+ `col5c` int(11) GENERATED ALWAYS AS ((`col5x` * `col6`)) VIRTUAL,
+ `col6c` varchar(20) GENERATED ALWAYS AS (`col5x`) VIRTUAL,
+ `col3b` bigint(20) GENERATED ALWAYS AS ((`col6x` * `col6`)) VIRTUAL,
+ `col1a` varchar(20) GENERATED ALWAYS AS (`col1`) VIRTUAL,
+ `col8` int(11) DEFAULT NULL,
+ UNIQUE KEY `col5` (`col5`),
+ UNIQUE KEY `col6x` (`col6x`),
+ UNIQUE KEY `col5_2` (`col5`),
+ KEY `idx2` (`col9`(10)),
+ KEY `idx4` (`col2`),
+ KEY `idx8` (`col9`(10),`col5`),
+ KEY `idx9` (`col6`),
+ KEY `idx6` (`col6`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+ALTER TABLE t CHANGE COLUMN col3b col8a BIGINT GENERATED ALWAYS AS
+(col6x * col6) VIRTUAL, ADD UNIQUE KEY uidx ( col8a );
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug 22141031 - GCOLS: PURGED THREAD DIES: TRIED TO PURGE
+--echo # NON-DELETE-MARKED RECORD IN INDEX
+--echo #
+create table t (
+ a int,b int,c text,d int,e int,f int,g int,
+ h text generated always as ('1') virtual,
+ i int,j int,k int,l int,m int,
+ primary key (c(1)),unique key (c(1)),
+ key (i),key (h(1))
+) engine=innodb default charset latin1;
+
+replace into t(c) values ('');
+replace into t(c) values ('');
+alter table t drop column d ;
+
+drop table t;
+
+--echo #
+--echo # Bug 22139917 - ASSERTION: DICT_TABLE_GET_NTH_COL(USER_TABLE, NTH_COL)
+--echo # ->LEN < NEW_LEN
+--echo #
+
+create table t (
+ a int generated always as (1) virtual,
+ b varbinary(1),
+ c varbinary(1) generated always as (b) virtual
+) engine=innodb;
+alter table t change column b b varbinary(2), algorithm=inplace;
+alter table t change column c c varbinary(2) generated always as (b) virtual, algorithm=inplace;
+
+drop table t;
+
+# Bug22202788 GCOL:ASSERTION:0 IN ROW_SEL_GET_CLUST_REC_FOR_MYSQL AT
+# ROW0SEL.CC
+SET @@SESSION.sql_mode=0;
+
+CREATE TABLE t(
+ c1 INT AUTO_INCREMENT,
+ c2 INT,
+ c3 INT GENERATED ALWAYS AS(c2 + c2)VIRTUAL,
+ c3k INT GENERATED ALWAYS AS(c2 + c3)VIRTUAL,
+ c4 DATE,
+ c5 DATE GENERATED ALWAYS AS(DATE_ADD(c4,interval 30 day)) VIRTUAL,
+ c5k DATE GENERATED ALWAYS AS(DATE_ADD(c4,interval 30 day)) VIRTUAL,
+ c5time_gckey DATE,
+ c6 TIME,
+ c5time DATE GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c6)) VIRTUAL,
+ c7 TIME GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c6)) VIRTUAL,
+ c5timek DATE GENERATED ALWAYS AS(ADDTIME(c5time_gckey,c7)) VIRTUAL,
+ c7k TIME GENERATED ALWAYS AS(ADDTIME(c5time,c6)) VIRTUAL,
+ c8 CHAR(10),
+ c9 CHAR(20)GENERATED ALWAYS AS (CONCAT(RTRIM(c8),RTRIM(c8))) VIRTUAL,
+ c9k CHAR(15)GENERATED ALWAYS AS (CONCAT(RTRIM(c8),0)) VIRTUAL,
+ PRIMARY KEY(c1),
+ KEY(c3),
+ KEY(c9(10)),
+ UNIQUE KEY(c9k),
+ UNIQUE KEY(c3k,c9k(5),c5k,c7k,c5timek,c3,c9(5),c5,c7,c5time)
+)ENGINE=INNODB;
+
+--error ER_DUP_ENTRY
+INSERT INTO
+t(c2,c4,c6,c5time_gckey,c8)VALUES(1,0,0,0,0),(0,0,0,0,'ityzg'),(0,0,1,0,'tyzgk
+t'),(0,1,0,1,'yzgktb'),(0,0,0,0,'zgktb'),(0,0,0,0,'gktbkj'),(0,0,0,0,0),(0,0,1
+,0,1),(0,0,0,0,1),(0,0,0,0,'tbkjrkm'),(0,0,0,0,'bkjr'),(0,0,0,0,0),(0,0,0,0,0)
+,(0,0,0,0,'rk'),(0,0,0,0,'kmqmknbtoe'),(1,0,0,0,'mqmknbt'),(0,1,0,0,'qmknb'),(
+0,0,0,0,'mkn'),(0,0,0,0,'knbtoervql'),(0,0,1,0,1),(0,0,0,0,'nbtoerv'),(0,0,0,0
+,'btoerv'),(0,0,1,0,'toer'),(1,0,0,0,0),(0,0,0,0,'ervq'),(0,0,0,0,'rvqlzsvasu'
+),(0,0,0,0,'vqlzs'),(0,0,0,0,0),(0,1,0,0,'lzsvasu'),(0,0,0,0,'zsvasurq');
+
+SELECT
+DISTINCT * FROM t
+FORCE KEY(PRIMARY,c3k,c3,c9k,c9)
+WHERE
+(c9 IS NULL AND (c9=0))
+OR(
+(c9k NOT IN ('ixfq','xfq','New Mexico','fq')OR c9 IS NULL)
+)
+OR(c9 BETWEEN 'hwstqua' AND 'wstquadcji' OR (c9k=0))
+AND(c3 IS NULL OR c3 IN (0,0,0));
+
+drop table t;
+
+#
+# BUG#22082762 RE-ENABLE SUPPORT FOR ADDING VIRTUAL INDEX WHILE DROPPING VIRTUAL COLUMN
+#
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), d INT
+GENERATED ALWAYS AS(a+b+b), e INT GENERATED ALWAYS AS(a), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, DEFAULT, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, DEFAULT, DEFAULT, 'mm');
+CREATE INDEX idx ON t(c, d);
+CREATE INDEX idx1 ON t(c);
+CREATE INDEX idx2 ON t(e, c, d);
+
+# This will drop column c, drop index idx1 on column c, and build index
+# idx and idx2, so they become idx(d) and idx2(e, d) respectively.
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+
+SELECT d FROM t;
+
+SHOW CREATE TABLE t;
+
+# Drop a column, adding a new column and also adding a index on this new column
+# is not allowed for INPLACE algorithm
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t DROP COLUMN d, ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE;
+
+# Add an index on existing column along with dropping a column is allowed
+ALTER TABLE t DROP COLUMN d, ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (e), ALGORITHM=INPLACE, LOCK=NONE;
+SHOW CREATE TABLE t;
+
+# Add an index on existing column along with adding a virtual column and droping a virtual index
+ALTER TABLE t ADD INDEX idx4(c, e), ADD COLUMN x VARCHAR(10) GENERATED ALWAYS AS(h), DROP INDEX idx, ALGORITHM=INPLACE, LOCK=NONE;
+SHOW CREATE TABLE t;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD COLUMN j INT, ALGORITHM=INPLACE;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t ADD INDEX (x), ADD COLUMN j INT, ALGORITHM=INPLACE, LOCK=NONE;
+ALTER TABLE t ADD INDEX (x), ADD COLUMN j INT, ALGORITHM=INPLACE;
+SHOW CREATE TABLE t;
+
+# Online add an index on newly added virtual column is not allowed.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD INDEX (i), ALGORITHM=INPLACE, LOCK=NONE;
+
+ALTER TABLE t ADD COLUMN i INT GENERATED ALWAYS AS(a+a+b), ADD INDEX (i), ALGORITHM=INPLACE, LOCK=SHARED;
+SHOW CREATE TABLE t;
+
+SELECT i FROM t;
+
+SELECT * FROM t;
+
+DROP TABLE t;
+
+#
+# BUG#22469459 WRONG VALUES IN ADDED INDEX WHILE DROPPING VIRTUAL COLUMN
+#
+
+# Drop column with existing index on it.
+CREATE TABLE t (
+ a INT,
+ b INT,
+ c INT GENERATED ALWAYS AS(a+b),
+ d INT GENERATED ALWAYS AS(a+b+b),
+ KEY vidx (c, d)
+)ENGINE=INNODB;
+
+INSERT INTO t (a,b) VALUES (0, 0), (1, NULL), (NULL, 2), (NULL, NULL);
+
+SELECT c, d FROM t;
+
+SELECT * FROM t;
+
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+
+SELECT d FROM t;
+
+SELECT * FROM t;
+
+DROP TABLE t;
+
+# Drop column with a new index.
+CREATE TABLE t (
+ a INT,
+ b INT,
+ c INT GENERATED ALWAYS AS(a+b),
+ d INT GENERATED ALWAYS AS(a+b+b)
+)ENGINE=INNODB;
+
+INSERT INTO t (a,b) VALUES (0, 0), (1, NULL), (NULL, 2), (NULL, NULL);
+
+SELECT * FROM t;
+
+ALTER TABLE t DROP COLUMN c, ADD INDEX vidx(d), ALGORITHM=INPLACE;
+
+SELECT d FROM t;
+
+SELECT * FROM t WHERE d > 0;
+
+SELECT * FROM t;
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug #22162200 MEMORY LEAK IN HA_INNOPART_SHARE
+--echo # ::SET_V_TEMPL PARTITIONED ON VIRTUAL COLUMN
+--echo #
+create table t (
+ c tinyint,
+ d longblob generated always as (c) virtual
+) engine=innodb partition by key (c) partitions 2;
+
+select d in(select d from t)from t group by d;
+drop table t;
+
+--echo #
+--echo # BUG#23052231 - ASSERTION FAILURE: ROW0MERGE.CC:2100:ADD_AUTOINC
+--echo # < DICT_TABLE_GET_N_USER_COLS
+--echo #
+CREATE TABLE `t` (
+ `a` int(11) NOT NULL,
+ `d` int(11) NOT NULL,
+ `b` varchar(198) NOT NULL,
+ `c` char(177) DEFAULT NULL,
+ `vadcol` int(11) GENERATED ALWAYS AS ((`a` + length(`d`))) STORED,
+ `vbcol` char(2) GENERATED ALWAYS AS (substr(`b`,2,2)) VIRTUAL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+ PRIMARY KEY (`b`(10),`a`,`d`),
+ KEY `d` (`d`),
+ KEY `a` (`a`),
+ KEY `c_renamed` (`c`(99),`b`(35)),
+ KEY `b` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `a_2` (`a`,`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`,`d`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+INSERT INTO t values (11, 1, "11", "aa", default, default, default);
+
+ALTER TABLE t ADD COLUMN nc01128 BIGINT AUTO_INCREMENT NOT NULL, ADD KEY auto_nc01128(nc01128);
+
+DROP TABLE t;
+
+--echo #
+--echo #Bug #22965271 NEEDS REBUILD FOR COLUMN LENGTH CHANGE THAT IS
+--echo #PART OF VIRTUAL INDEX.
+--echo #
+
+CREATE TABLE t1(
+a VARCHAR(45) CHARACTER SET LATIN1,
+b VARCHAR(115) CHARACTER SET UTF8 GENERATED ALWAYS AS ('f1') VIRTUAL,
+UNIQUE KEY (b,a))ENGINE=INNODB;
+INSERT INTO t1(a) VALUES ('');
+ALTER TABLE t1 CHANGE COLUMN a a VARCHAR(85);
+SELECT * FROM t1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a INT GENERATED ALWAYS AS(1) VIRTUAL) ENGINE=InnoDB;
+ALTER TABLE t1 ADD b INT GENERATED ALWAYS AS (2) VIRTUAL;
+ALTER TABLE t1 ADD c INT;
+SELECT * FROM t1;
+INSERT INTO t1 SET c=3;
+SELECT * FROM t1;
+DROP TABLE t1;
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_blob.test b/mysql-test/suite/gcol/t/innodb_virtual_blob.test
new file mode 100644
index 00000000..e94d2c77
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_blob.test
@@ -0,0 +1,25 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug#22046353 ALTER: ASSERT PAGE_SIZE.EQUALS_TO(SPACE_PAGE_SIZE),
+--echo # BTR_COPY_BLOB_PREFIX
+--echo #
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+
+CREATE TABLE t1
+( f1 int primary key, f2 blob,
+ f3 blob generated always as (f2))
+ row_format=compressed, engine=innodb;
+insert into t1 (f1, f2) values (1, repeat('&', 50000));
+alter table t1 add index i1 (f3(200)) ;
+alter table t1 row_format=compact;
+
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+
+drop table t1;
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_debug.test b/mysql-test/suite/gcol/t/innodb_virtual_debug.test
new file mode 100644
index 00000000..cd2b8604
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_debug.test
@@ -0,0 +1,341 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_debug.inc
+--source include/count_sessions.inc
+
+set default_storage_engine=innodb;
+CREATE TABLE `t` (
+ `a` VARCHAR(100),
+ `b` VARCHAR(100),
+ `c` VARCHAR(200) GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ `h` VARCHAR(10) DEFAULT NULL,
+ `i` int
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 10), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
+
+CREATE INDEX idx ON t(c(100));
+
+SET session debug_dbug="+d,ib_alter_add_virtual_fail";
+--error ER_WRONG_KEY_COLUMN
+ALTER TABLE t ADD COLUMN x VARCHAR(200) GENERATED ALWAYS AS (a) VIRTUAL,
+ALGORITHM = INPLACE;
+--error ER_WRONG_KEY_COLUMN
+ALTER TABLE t DROP COLUMN c, ALGORITHM = INPLACE;
+SET session debug_dbug="";
+DROP TABLE t;
+
+#online test
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, "mx");
+
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+--send CREATE INDEX idx ON t(c)
+
+connect (con1,localhost,root,,);
+
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+update t set a=0 where a = 11;
+start transaction;
+update t set a=1 where a = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+reap;
+
+SELECT c FROM t;
+SHOW CREATE TABLE t;
+SELECT * FROM t;
+
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t FORCE, LOCK=NONE;
+if (0) {# MDEV-14341 TODO: re-enable this
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+--send ALTER TABLE t FORCE
+
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+start transaction;
+update t set a=1 where a = 0;
+rollback;
+start transaction;
+delete from t;
+insert into t values(1,null,default,null);
+rollback;
+start transaction;
+update t set b=b+1;
+rollback;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+reap;
+
+check table t;
+SELECT c FROM t;
+
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+--send ALTER TABLE t FORCE
+
+connection con1;
+
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+start transaction;
+DELETE FROM t WHERE a = 0;
+ROLLBACK;
+DELETE FROM t WHERE a = 0;
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+reap;
+
+SELECT c FROM t;
+}
+
+disconnect con1;
+DROP TABLE t;
+
+SET DEBUG_SYNC = 'RESET';
+
+
+# Test add virtual column and add index at the same time
+# introduce some error
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+CREATE INDEX idx_1 on t(c);
+
+SET @saved_dbug = @@SESSION.debug_dbug;
+SET debug_dbug = '+d,create_index_fail';
+
+--enable_info
+--error ER_DUP_ENTRY
+ALTER TABLE t ADD COLUMN x INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (x),
+ADD INDEX idcx (c,x);
+
+UPDATE t SET a=a+1;
+
+--error ER_DUP_ENTRY
+ALTER TABLE t ADD INDEX idc(c);
+SET debug_dbug = @saved_dbug;
+--disable_info
+
+UPDATE t SET b=b-1;
+
+SHOW CREATE TABLE t;
+
+SELECT c FROM t;
+
+DROP TABLE t;
+
+if (0) {# MDEV-14341 TODO: re-enable LOCK=NONE and these tests
+--echo #
+--echo # Bug#22018532 ASSERTION WHEN ONLINE REAPPLY REBUILD LOG ON
+--echo # MULTIPLE INDEXED VIRTUAL COLUMNS
+--echo #
+
+create table t (
+ a int as (1) virtual,
+ b int,
+ c int as (1) virtual,
+ unique(b),
+ unique(c),
+ key(a)
+) engine=innodb;
+
+insert ignore into t values();
+
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+--send optimize table t
+
+connect (con1,localhost,root,,);
+
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+insert ignore into t values();
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+--echo /* connection default */ optimize table t;
+reap;
+SELECT c FROM t;
+SHOW CREATE TABLE t;
+SELECT * FROM t;
+DROP TABLE t;
+
+# Do another test without duplicate error
+
+CREATE TABLE t (a INT, b INT, c INT GENERATED ALWAYS AS(a+b), h VARCHAR(10));
+
+INSERT INTO t VALUES (11, 3, DEFAULT, 'mm');
+INSERT INTO t VALUES (18, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (28, 1, DEFAULT, 'mm');
+INSERT INTO t VALUES (null, null, DEFAULT, 'mm');
+
+CREATE INDEX idx ON t(c);
+
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_rebuild WAIT_FOR go_ahead';
+--send optimize table t
+
+connection con1;
+SET DEBUG_SYNC = 'now WAIT_FOR start_rebuild';
+INSERT INTO t VALUES (48, 2, DEFAULT, 'xx');
+INSERT INTO t VALUES (68, 3, DEFAULT, 'sx');
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+--echo /* connection default */ optimize table t;
+reap;
+
+SELECT c FROM t;
+
+disconnect con1;
+
+DROP TABLE t;
+
+--echo #
+--echo # Bug#22951879 - ASSERTS RELATED TO ONLINE DDL AND GCOL
+--echo #
+
+# Create a table with 2 virtual column, one (vbidxcol) is indexed and
+# the other one (vbcol) is not
+create table ibstd_14 (a int not null, d int not null, b varchar(198) not null, c char(181), vadcol int as (a+length(d)) stored, vbcol char(2) as (substr(b,2,2)) virtual, vbidxcol char(3) as (substr(b,1,3)) virtual , index(d), index(a), index(vbidxcol), index(a,vbidxcol), index(vbidxcol,d), unique key (b(10), a, d), index(c(99), b(31)), index(b(5), c(10), a) , index(a,d)) engine=InnoDB stats_persistent=1 row_format=dynamic;
+
+# Do an alter table rebuild table and also create a new index on this
+# non-indexed virtual column
+SET DEBUG_SYNC = 'innodb_inplace_alter_table_enter SIGNAL start_create WAIT_FOR go_ahead';
+--send alter table ibstd_14 row_format=compressed key_block_size=4,add key kn3 (d,c,vbcol,b)
+
+# Do a concurrent insert, and make sure this newly indexed virtual column
+# is also logged
+connect (con1,localhost,root);
+SET DEBUG_SYNC = 'now WAIT_FOR start_create';
+insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6',repeat('oacolaarlruoacuroauurloraarucoooarcooauoolacalllaulrruarrrucruuooclacuoouccarrcoocloccorrrrarourcooalloocooccouruolaorlcaocualolc','1'),repeat('lolrrlalcocroraaulauclaaucolcorcuooaolruaooooluooooouaoorlarucorullalcrrloccououaooaorluorraclrcooouuolocoaolcocaaculruoocucoocoooauuolarcoraraocaoolulolarru','1'),default,default);
+
+insert into ibstd_14 (a,d,b,c, vbidxcol, vbcol) values ('118','6', 'aaaa', 'lll', default, default);
+
+# Also do an concurrent update, make sure this is performed
+update ibstd_14 set b='11111' where b='aaaa';
+
+SET DEBUG_SYNC = 'now SIGNAL go_ahead';
+
+connection default;
+reap;
+
+select * from ibstd_14;
+
+# This will use the newly added "kn3" index, to check materialized vbcol
+# after log reapply
+select d,c,vbcol,b from ibstd_14;
+
+# check the value is inserted into the index
+select vbcol from ibstd_14;
+
+drop table ibstd_14;
+
+--echo #
+--echo # Bug#22018745 CORRUPTION IN ONLINE TABLE REBUILD
+--echo # (ROW_FORMAT=REDUNDANT, INDEXED VIRTUAL COLUMN)
+--echo #
+
+CREATE TABLE t (
+ b char(5) PRIMARY KEY,
+ v char(3) GENERATED ALWAYS AS (substr(b,1,3)) VIRTUAL, KEY(v)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=REDUNDANT;
+
+connection con1;
+SET DEBUG_SYNC='row_log_table_apply1_before SIGNAL prepared WAIT_FOR apply';
+--send OPTIMIZE TABLE t
+connection default;
+
+SET DEBUG_SYNC='now WAIT_FOR prepared';
+INSERT INTO t SET b='fubar';
+BEGIN;
+DELETE FROM t;
+ROLLBACK;
+SET DEBUG_SYNC='now SIGNAL apply';
+
+connection con1;
+reap;
+
+connection default;
+CHECK TABLE t;
+SELECT * FROM t;
+DROP TABLE t;
+
+disconnect con1;
+}
+SET DEBUG_SYNC = 'RESET';
+
+
+--echo #
+--echo # Bug#28825718 - ASSERTION FAILURE: TRX0REC.CC:NNN:N_IDX > 0 WHILE DOING REPLACE/INSERT
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, c INT GENERATED ALWAYS AS(b+1) VIRTUAL) ENGINE=InnoDB;
+
+INSERT INTO t1(a, b) VALUES(1, 1);
+
+connect (con1,localhost,root,,);
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL s1 WAIT_FOR s2';
+SET lock_wait_timeout = 1;
+--send ALTER TABLE t1 ADD UNIQUE INDEX(c, b)
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR s1';
+SET DEBUG_SYNC = 'row_log_insert_handle SIGNAL s2 WAIT_FOR s3';
+--send INSERT INTO t1(a, b) VALUES(2, 2)
+
+connection con1;
+--error ER_LOCK_WAIT_TIMEOUT
+reap;
+SET DEBUG_SYNC = 'now SIGNAL s3';
+disconnect con1;
+connection default;
+reap;
+SET DEBUG_SYNC = 'RESET';
+ALTER TABLE t1 ADD KEY(b);
+INSERT INTO t1(a, b) VALUES(3, 3);
+SELECT * FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-28806 Assertion `flag == 1' failure in
+--echo # row_build_index_entry_low upon concurrent ALTER and UPDATE
+--echo #
+
+CREATE TABLE t1(a CHAR(8), b INT, c INT AS (b), KEY(a)) ENGINE=InnoDB;
+INSERT INTO t1(b) VALUES (1),(2);
+
+--connect (con1,localhost,root,,test)
+SET DEBUG_SYNC="alter_table_inplace_before_lock_upgrade SIGNAL dml_start WAIT_FOR dml_commit";
+send ALTER TABLE t1 ADD KEY ind (c);
+
+--connection default
+SET DEBUG_SYNC="now WAIT_FOR dml_start";
+UPDATE t1 SET a ='foo';
+SET DEBUG_SYNC="now SIGNAL dml_commit";
+
+# Cleanup
+--connection con1
+--reap
+CHECK TABLE t1;
+DROP TABLE t1;
+--disconnect con1
+connection default;
+SET DEBUG_SYNC=RESET;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt
new file mode 100644
index 00000000..a1207721
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.opt
@@ -0,0 +1 @@
+--innodb-purge-threads=1
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.test b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.test
new file mode 100644
index 00000000..09fba028
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_debug_purge.test
@@ -0,0 +1,268 @@
+--source include/have_innodb.inc
+--source include/have_debug_sync.inc
+--source include/have_debug.inc
+--source include/have_partition.inc
+
+set default_storage_engine=innodb;
+set @old_dbug=@@global.debug_dbug;
+# Ensure that the history list length will actually be decremented by purge.
+SET @saved_stats_persistent = @@GLOBAL.innodb_stats_persistent;
+SET GLOBAL innodb_stats_persistent = OFF;
+
+CREATE TABLE `t` (
+ `a` BLOB,
+ `b` BLOB,
+ `c` BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ `h` VARCHAR(10) DEFAULT NULL,
+ `i` int
+) ENGINE=InnoDB;
+
+INSERT INTO t VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, "mm", 2);
+
+CREATE INDEX idx ON t(c(100));
+
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t SET a = REPEAT('m', 16000) WHERE a like "aaa%";
+--source ../../innodb/include/wait_all_purged.inc
+SET global debug_dbug=@old_dbug;
+DROP TABLE t;
+
+CREATE TABLE t (
+ a TINYBLOB,
+ b TINYBLOB,
+ c TINYBLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ h VARCHAR(10) DEFAULT NULL,
+ i INT
+) ROW_FORMAT=COMPACT ENGINE=InnoDB;
+
+INSERT INTO t VALUES (REPEAT('g', 100), REPEAT('x', 100), DEFAULT, "kk", 1);
+INSERT INTO t VALUES (REPEAT('a', 100), REPEAT('b', 100), DEFAULT, "mm", 2);
+
+CREATE INDEX idx ON t(c(100));
+
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t SET a = REPEAT('m', 100) WHERE a like "aaa%";
+--source ../../innodb/include/wait_all_purged.inc
+SET global debug_dbug=@old_dbug;
+DROP TABLE t;
+
+
+CREATE TABLE t1 (
+ id INT NOT NULL,
+ store_id INT NOT NULL,
+ x INT GENERATED ALWAYS AS (id + store_id)
+)
+PARTITION BY RANGE (store_id) (
+ PARTITION p0 VALUES LESS THAN (6),
+ PARTITION p1 VALUES LESS THAN (11),
+ PARTITION p2 VALUES LESS THAN (16),
+ PARTITION p3 VALUES LESS THAN (21)
+);
+
+insert into t1 values(1, 2, default);
+insert into t1 values(3, 4, default);
+
+insert into t1 values(3, 12, default);
+insert into t1 values(4, 18, default);
+
+CREATE INDEX idx ON t1(x);
+
+SET global debug_dbug="d,ib_purge_virtual_index_callback";
+UPDATE t1 SET id = 10 WHERE id = 1;
+--source ../../innodb/include/wait_all_purged.inc
+SET global debug_dbug=@old_dbug;
+DROP TABLE t1;
+
+#
+# BUG#22082762 RE-ENABLE SUPPORT FOR ADDING VIRTUAL INDEX WHILE DROPPING VIRTUAL COLUMN
+#
+--source include/count_sessions.inc
+
+connect (con1,localhost,root,,);
+connection default;
+
+# Test adding virtual index on newly added virtual column
+CREATE TABLE t1 (a INT, b INT);
+
+INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3);
+
+connection con1;
+--echo # disable purge
+CREATE TABLE t0 (a INT) ENGINE=InnoDB;
+BEGIN; SELECT * FROM t0;
+
+connection default;
+DELETE FROM t1 WHERE a = 1;
+
+UPDATE t1 SET a = 4, b = 4 WHERE a = 3;
+
+INSERT INTO t1(a, b) VALUES (5, 5);
+
+SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+send ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
+
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
+
+--echo # enable purge
+COMMIT;
+
+--echo # wait for purge to process the deleted records.
+let $wait_all_purged = 1;
+--source ../../innodb/include/wait_all_purged.inc
+let $wait_all_purged = 0;
+
+SET DEBUG_SYNC= 'now SIGNAL purged';
+
+connection default;
+--echo /* connection default */ ALTER TABLE t1 ADD COLUMN c INT GENERATED ALWAYS AS(a+b), ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=SHARED;
+--reap
+SHOW CREATE TABLE t1;
+
+SELECT * FROM t1;
+
+DROP TABLE t1;
+
+# Test adding index on existing virtual column
+CREATE TABLE t1 (a INT, b INT, c INT GENERATED ALWAYS AS(a+b));
+
+INSERT INTO t1(a, b) VALUES (1, 1), (2, 2), (3, 3), (4, 4);
+
+connection con1;
+--echo # disable purge
+BEGIN; SELECT * FROM t0;
+
+connection default;
+DELETE FROM t1 WHERE a = 1;
+
+UPDATE t1 SET a = 2, b = 2 WHERE a = 5;
+
+INSERT INTO t1(a, b) VALUES (6, 6);
+
+SET DEBUG_SYNC= 'inplace_after_index_build SIGNAL uncommitted WAIT_FOR purged';
+send ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+
+connection con1;
+SET DEBUG_SYNC= 'now WAIT_FOR uncommitted';
+
+DELETE FROM t1 WHERE a = 3;
+
+UPDATE t1 SET a = 7, b = 7 WHERE a = 4;
+
+INSERT INTO t1(a, b) VALUES (8, 8);
+
+--echo # enable purge
+COMMIT;
+
+--echo # wait for purge to process the deleted/updated records.
+let $wait_all_purged=2;
+--source ../../innodb/include/wait_all_purged.inc
+let $wait_all_purged=0;
+
+SET DEBUG_SYNC= 'now SIGNAL purged';
+
+disconnect con1;
+
+connection default;
+--echo /* connection default */ ALTER TABLE t1 ADD INDEX idx (c), ALGORITHM=INPLACE, LOCK=NONE;
+--reap
+SHOW CREATE TABLE t1;
+
+SELECT * FROM t1;
+
+DROP TABLE t0, t1;
+
+#
+# test MDLs with purge
+#
+create table t (a blob, b blob, c blob as (concat(a,b)), h varchar(10), index (c(100)));
+insert t(a,b,h) values (repeat('g', 16000), repeat('x', 16000), "kk");
+insert t(a,b,h) values (repeat('a', 16000), repeat('b', 16000), "mm");
+set global debug_dbug="d,ib_purge_virtual_index_callback";
+connect(prevent_purge, localhost, root);
+start transaction with consistent snapshot;
+connection default;
+update t set a = repeat('m', 16000) where a like "aaa%";
+connect(lock_table, localhost, root);
+lock table t write;
+connection prevent_purge;
+commit;
+connection default;
+disconnect lock_table;
+--source ../../innodb/include/wait_all_purged.inc
+set global debug_dbug=@old_dbug;
+drop table t;
+
+--echo #
+--echo # MDEV-15165 InnoDB purge for index on virtual column
+--echo # is trying to access an incomplete record
+--echo #
+CREATE TABLE t1(
+ u INT PRIMARY KEY, b BLOB, ug INT GENERATED ALWAYS AS (u) VIRTUAL,
+ INDEX bug(b(100),ug)
+) ENGINE=InnoDB;
+INSERT INTO t1 (u,b) VALUES(1,REPEAT('a',16384));
+connection prevent_purge;
+start transaction with consistent snapshot;
+connection default;
+DELETE FROM t1;
+SET DEBUG_SYNC='blob_write_middle SIGNAL halfway WAIT_FOR purged';
+send INSERT INTO t1 (u,b) VALUES(1,REPEAT('a',16384));
+connection prevent_purge;
+SET DEBUG_SYNC='now WAIT_FOR halfway';
+COMMIT;
+--source ../../innodb/include/wait_all_purged.inc
+SET DEBUG_SYNC='now SIGNAL purged';
+
+connection default;
+reap;
+DROP TABLE t1;
+
+CREATE TABLE t1 (y YEAR, vy YEAR AS (y) VIRTUAL UNIQUE, pk INT PRIMARY KEY)
+ENGINE=InnoDB;
+
+INSERT INTO t1 (pk,y) VALUES (1,2022);
+CREATE TABLE t2(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
+
+SET GLOBAL debug_dbug = 'd,ib_purge_virtual_index_callback';
+
+BEGIN;
+INSERT INTO t2(f1) VALUES(1);
+connection prevent_purge;
+SET DEBUG_SYNC=RESET;
+start transaction with consistent snapshot;
+connection default;
+COMMIT;
+
+connect(truncate,localhost,root,,);
+REPLACE INTO t1(pk, y) SELECT pk,y FROM t1;
+send TRUNCATE TABLE t1;
+
+connection prevent_purge;
+COMMIT;
+SET DEBUG_SYNC='now SIGNAL purge_start';
+disconnect prevent_purge;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR purge_start';
+--source ../../innodb/include/wait_all_purged.inc
+SET GLOBAL debug_dbug=@old_dbug;
+
+connection truncate;
+reap;
+disconnect truncate;
+
+connection default;
+DROP TABLE t1, t2;
+
+--disable_ps2_protocol
+--enable_ps2_protocol
+--disable_ps2_protocol
+--enable_ps2_protocol
+--source include/wait_until_count_sessions.inc
+set debug_sync=reset;
+
+SET GLOBAL innodb_stats_persistent = @saved_stats_persistent;
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_fk.test b/mysql-test/suite/gcol/t/innodb_virtual_fk.test
new file mode 100644
index 00000000..0f0406b5
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_fk.test
@@ -0,0 +1,879 @@
+-- source include/have_innodb.inc
+
+set default_storage_engine=innodb;
+
+--echo #
+--echo # Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
+--echo # WHEN A VIRTUAL INDEX EXISTS.
+
+
+--echo # UPDATE CASCADE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # UPDATE SET NULL
+CREATE TABLE t1(fld1 INT NOT NULL, fld2 INT NOT NULL PRIMARY KEY,
+ KEY(fld1));
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE SET NULL);
+INSERT INTO t1 VALUES(1, 2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DELETE CASCADE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t1 VALUES(2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+INSERT INTO t2 VALUES(2, DEFAULT);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DELETE SET NULL
+CREATE TABLE t1(fld1 INT NOT NULL, fld2 INT NOT NULL PRIMARY KEY, KEY(fld1));
+CREATE TABLE t2(fld1 INT, fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE SET NULL);
+INSERT INTO t1 VALUES(1, 1);
+INSERT INTO t1 VALUES(2, 2);
+INSERT INTO t2 VALUES(1, DEFAULT);
+INSERT INTO t2 VALUES(2, DEFAULT);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # VIRTUAL INDEX CONTAINS FK CONSTRAINT COLUMN
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT, fld3 INT AS (fld2) VIRTUAL,
+ KEY(fld3, fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 3);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Multiple level of VIRTUAL columns.
+
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld3), KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT fld3 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Drop the VIRTUAL INDEX using alter copy ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL, KEY vk(fld2),
+ KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Drop the VIRTUAL INDEX using INPLACE alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY vk(fld2), KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Add the VIRTUAL INDEX using COPY alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Add the VIRTUAL INDEX using INPLACE alter ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1) VALUES(1);
+UPDATE t1 SET fld1= 2;
+SELECT fld2, fld1 FROM t2;
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM= INPLACE;
+UPDATE t1 SET fld1= 3;
+SELECT fld2, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Drop the VIRTUAL INDEX contains fk constraint column
+--echo # using alter copy ALGORITHM
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY vk(fld3, fld1),
+ KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+ALTER TABLE t2 DROP INDEX vk, ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Drop the VIRTUAL INDEX which contains fk constraint column
+--echo # using INPLACE alter operation
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY vk(fld3, fld1),
+ KEY(fld1), FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+alter TABLE t2 DROP INDEX vk, ALGORITHM= INPLACE;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Add the VIRTUAL INDEX contains fk constraint column
+--echo # using copy alter operatiON
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+UPDATE t1 SET fld1= 2;
+SELECT fld3, fld1 FROM t2;
+alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM= COPY;
+UPDATE t1 SET fld1= 3;
+SELECT fld3, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # Cascading UPDATEs and DELETEs for the multiple
+--echo # fk dependent TABLEs
+
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld1), KEY(fld2, fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld2, fld1),
+ FOREIGN KEY(fld1) REFERENCES t2(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2(fld1) VALUES(1), (2);
+INSERT INTO t3(fld1) VALUES(1), (2);
+UPDATE t1 SET fld1= 4 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t2;
+SELECT fld2, fld1 FROM t3;
+DROP TABLE t3, t2, t1;
+
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1), KEY(fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1),
+ FOREIGN KEY(fld1) REFERENCES t2(fld1) ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, 1, DEFAULT), (2, 2, default);
+INSERT INTO t3 VALUES(1, 1, DEFAULT), (2, 2, default);
+UPDATE t1 SET fld1= 4 WHERE fld1= 1;
+SELECT fld3, fld1 FROM t2;
+SELECT fld3, fld1 FROM t3;
+DROP TABLE t3, t2, t1;
+
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld1), KEY(fld2, fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON DELETE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld2, fld1), FOREIGN KEY(fld1) REFERENCES t2(fld1)
+ ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2(fld1) VALUES(1), (2);
+INSERT INTO t3(fld1) VALUES(1), (2);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t2;
+SELECT fld2, fld1 FROM t3;
+DROP TABLE t3, t2, t1;
+
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL,
+ KEY(fld3, fld1), KEY(fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON DELETE CASCADE);
+CREATE TABLE t3(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld3, fld1),
+ FOREIGN KEY(fld1) REFERENCES t2(fld1)
+ ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, 1, DEFAULT), (2, 2, default);
+INSERT INTO t3 VALUES(1, 1, DEFAULT), (2, 2, default);
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld3, fld1 FROM t2;
+SELECT fld3, fld1 FROM t3;
+DROP TABLE t3, t2, t1;
+
+--echo # RENAME TABLE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld2, fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON DELETE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+RENAME TABLE t2 to t3;
+DELETE FROM t1 WHERE fld1= 1;
+SELECT fld2, fld1 FROM t3;
+DROP TABLE t3, t1;
+
+--echo # FOREIGN_KEY_CHECKS disabled DURING INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX vk(fld2), ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 3 WHERE fld1= 2;
+SELECT fld2 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # GENERATED COLUMN COMPUTATION FAILS when SQL_MODE
+--echo # is set to ERROR_FOR_DIVISION_BY_ZERO
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (100/fld1) VIRTUAL,
+ KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+#--error ER_DIVISION_BY_ZERO
+UPDATE IGNORE t1 SET fld1= 0 WHERE fld1= 2;
+SELECT fld2 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # CHANGE SQL_MODE and try the ERROR_FOR_DIVISION_BY_ZERO
+SET sql_mode = STRICT_ALL_TABLES;
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (100/fld1) VIRTUAL,
+ KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+UPDATE t1 SET fld1= 0 WHERE fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+SET sql_mode = default;
+
+--echo # ADD FOREIGN CONSTRAINT USING COPY
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL, KEY(fld2));
+ALTER TABLE t2 ADD FOREIGN KEY (fld1)
+ REFERENCES t1(fld1) ON UPDATE CASCADE,
+ ALGORITHM=copy;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # ADD FOREIGN CONSTRAINT USING INPLACE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL, KEY(fld2));
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD FOREIGN KEY (fld1)
+ REFERENCES t1(fld1) ON UPDATE CASCADE,
+ ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP FOREIGN CONSTRAINT USING COPY
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ CONSTRAINT fidx FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP FOREIGN KEY fidx, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP FOREIGN CONSTRAINT USING INPLACE
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL, KEY(fld2),
+ CONSTRAINT fidx FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP FOREIGN KEY fidx, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # ADD VC INDEX and ADD FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 ADD INDEX(fld2), ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE, ALGORITHM=copy;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # ADD VC INDEX and ADD FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX(fld2), ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE, ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # ADD VC INDEX and DROP FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 ADD INDEX(fld2), DROP FOREIGN KEY fidx, ALGORITHM=copy;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # ADD VC INDEX and DROP FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 ADD INDEX(fld2), DROP FOREIGN KEY fidx, ALGORITHM=inplace;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP VC INDEX and ADD FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY idx(fld2));
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP INDEX idx, ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP VC INDEX and ADD FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY idx(fld2));
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP INDEX idx, ADD FOREIGN KEY (fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP VC INDEX and DROP FK IN SAME COPY ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY idx(fld2),
+ CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+ALTER TABLE t2 DROP KEY idx, DROP FOREIGN KEY fidx, ALGORITHM=COPY;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+--echo # DROP VC INDEX and DROP FK IN SAME INPLACE ALTER
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY);
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY idx(fld2),
+ CONSTRAINT fidx FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE);
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2 VALUES(1, DEFAULT);
+SET foreign_key_checks = 0;
+ALTER TABLE t2 DROP KEY idx, DROP FOREIGN KEY fidx, ALGORITHM=INPLACE;
+SET foreign_key_checks = 1;
+UPDATE t1 SET fld1= 2;
+SELECT fld2 FROM t2;
+SELECT * FROM t2;
+DROP TABLE t2, t1;
+
+# Foreign key constraint references to virtual index
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+ KEY (f1, f2), FOREIGN KEY(f1) REFERENCES t1(f1))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+EXPLAIN SELECT f1, f2 FROM t2;
+SELECT f1, f2 FROM t2;
+--error ER_NO_REFERENCED_ROW_2
+INSERT INTO t2(f1) VALUES(2);
+DROP TABLE t2, t1;
+
+# Update foreign key constraint references to virtual index
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+ KEY (f1, f2), FOREIGN KEY(f1) REFERENCES t1(f1)
+ ON UPDATE CASCADE)ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+EXPLAIN SELECT f1, f2 FROM t2;
+SELECT f1, f2 FROM t2;
+UPDATE t1 SET f1 = 2 WHERE f1 = 1;
+EXPLAIN SELECT f1, f2 FROM t2;
+SELECT f1, f2 FROM t2;
+DROP TABLE t2, t1;
+
+# Add foreign key constraint via inplace alter references to virtual index
+
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+ KEY (f1, f2))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+SET FOREIGN_KEY_CHECKS = 0;
+ALTER TABLE t2 ADD FOREIGN KEY (f1) REFERENCES t1(f1)
+ ON UPDATE CASCADE, ALGORITHM=INPLACE;
+SET FOREIGN_KEY_CHECKS = 1;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f2 FROM t2;
+SELECT f1, f2 FROM t2;
+DROP TABLE t2, t1;
+
+# Add foreign key constraint via copy alter references to virtual index
+
+CREATE TABLE t1 (f1 INT NOT NULL PRIMARY KEY)ENGINE=INNODB;
+CREATE TABLE t2 (f1 INT NOT NULL, f2 INT AS (f1) VIRTUAL,
+ KEY (f1, f2))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 ADD FOREIGN KEY (f1) REFERENCES t1(f1)
+ ON UPDATE CASCADE, ALGORITHM=COPY;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f2 FROM t2;
+SELECT f1, f2 FROM t2;
+DROP TABLE t2, t1;
+
+# Drop column via inplace alter which triggers to remove the FK index idx
+
+CREATE TABLE t1(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=INNODB;
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT AS (1) VIRTUAL,
+ f3 INT AS (2) VIRTUAL,
+ FOREIGN KEY idx (f1) REFERENCES t1(f1) ON UPDATE CASCADE,
+ KEY idx1 (f2, f1, f3))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 DROP COLUMN f2, ALGORITHM=INPLACE;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f3 FROM t2;
+SELECT f1, f3 FROM t2;
+DROP TABLE t2, t1;
+
+# Drop column via copy alter which triggers to remove the FK index idx
+
+CREATE TABLE t1(f1 INT NOT NULL, PRIMARY KEY(f1))ENGINE=INNODB;
+CREATE TABLE t2(f1 INT NOT NULL, f2 INT AS (1) VIRTUAL,
+ f3 INT AS (2) VIRTUAL,
+ FOREIGN KEY idx (f1) REFERENCES t1(f1) ON UPDATE CASCADE,
+ KEY idx1 (f2, f1, f3))ENGINE=INNODB;
+INSERT INTO t1 VALUES(1);
+INSERT INTO t2(f1) VALUES(1);
+ALTER TABLE t2 DROP COLUMN f2, ALGORITHM=COPY;
+UPDATE t1 SET f1 = 3;
+EXPLAIN SELECT f1, f3 FROM t2;
+SELECT f1, f3 FROM t2;
+DROP TABLE t2, t1;
+
+--echo #
+--echo # MDEV-15553 Assertion failed in dict_table_get_col_name
+--echo #
+CREATE TABLE t1 (
+ c1 TIMESTAMP,
+ c2 YEAR,
+ c3 TIME,
+ c4 CHAR(10),
+ v1 TIMESTAMP AS (c1) VIRTUAL,
+ v2 YEAR AS (c2) VIRTUAL,
+ v3 TIME AS (c3) VIRTUAL,
+ v4 CHAR(10) AS (c4) VIRTUAL
+) ENGINE=InnoDB;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+SET foreign_key_checks=0;
+--error ER_FK_NO_INDEX_CHILD
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+ALTER TABLE t1 ADD INDEX(v4);
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+SET foreign_key_checks=1;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 DROP FOREIGN KEY fk;
+--error ER_CANT_CREATE_TABLE
+ALTER TABLE t1 ADD CONSTRAINT fk FOREIGN KEY (v4) REFERENCES nosuch(col);
+SHOW CREATE TABLE t1;
+# Cleanup
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-20396 Server crashes after DELETE with SEL NULL Foreign key and a
+--echo # virtual column in index
+--echo #
+CREATE TABLE parent
+(
+ ID int unsigned NOT NULL,
+ PRIMARY KEY (ID)
+);
+
+CREATE TABLE child
+(
+ ID int unsigned NOT NULL,
+ ParentID int unsigned NULL,
+ Value int unsigned NOT NULL DEFAULT 0,
+ Flag int unsigned AS (Value) VIRTUAL,
+ PRIMARY KEY (ID),
+ KEY (ParentID, Flag),
+ FOREIGN KEY (ParentID) REFERENCES parent (ID) ON DELETE SET NULL
+ ON UPDATE CASCADE
+);
+
+INSERT INTO parent (ID) VALUES (100);
+INSERT INTO child (ID,ParentID,Value) VALUES (123123,100,1);
+DELETE FROM parent WHERE ID=100;
+select * from child;
+INSERT INTO parent (ID) VALUES (100);
+UPDATE child SET ParentID=100 WHERE ID=123123;
+
+# Cleanup
+DROP TABLE child, parent;
+--echo #
+--echo # MDEV-23387 dict_load_foreign() fails to load the table during alter
+--echo #
+SET FOREIGN_KEY_CHECKS=0;
+CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
+ f3 INT AS (f1) VIRTUAL,
+ INDEX(f1), INDEX(f2))ENGINE=InnoDB;
+ALTER TABLE t1 ADD CONSTRAINT r FOREIGN KEY(f2) REFERENCES t1(f1), LOCK=NONE;
+SHOW CREATE TABLE t1;
+ALTER TABLE t1 DROP INDEX f1;
+ALTER TABLE t1 DROP f3;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-24041 Generated column DELETE with FOREIGN KEY crash InnoDB
+--echo #
+SET FOREIGN_KEY_CHECKS=1;
+CREATE DATABASE `a-b`;
+USE `a-b`;
+CREATE TABLE emails (
+ id int,
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE email_stats (
+ id int,
+ email_id int,
+ date_sent char(4),
+ generated_email_id int as (email_id),
+ #generated_sent_date DATE GENERATED ALWAYS AS (date_sent),
+ PRIMARY KEY (id),
+ KEY mautic_generated_sent_date_email_id (generated_email_id),
+ FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+ ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+
+CREATE TABLE emails_metadata (
+ email_id int,
+ PRIMARY KEY (email_id),
+ CONSTRAINT FK FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE CASCADE
+ ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent) VALUES (1,1,'Jan');
+INSERT INTO emails_metadata VALUES (1);
+
+UPDATE emails SET id=2;
+DELETE FROM emails;
+
+DROP TABLE email_stats;
+DROP TABLE emails_metadata;
+DROP TABLE emails;
+DROP DATABASE `a-b`;
+USE test;
+
+--echo #
+--echo # Bug#33053297 VIRTUAL INDEX CORRUPTED DURING CASCADE UPDATE ON CHILD TABLE
+--echo #
+
+--echo # Test-Case 1
+CREATE TABLE emails (
+ id int unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE=InnoDB;
+
+CREATE TABLE email_stats (
+ id bigint unsigned NOT NULL AUTO_INCREMENT,
+ email_id int unsigned DEFAULT NULL,
+ date_sent datetime NOT NULL,
+ generated_sent_date date GENERATED ALWAYS AS
+ (concat(year(date_sent), '-', lpad(month(date_sent), 2, '0'),
+ '-', lpad(dayofmonth(date_sent), 2, '0'))),
+ PRIMARY KEY (id),
+ KEY IDX_ES1 (email_id),
+ KEY mautic_generated_sent_date_email_id(generated_sent_date, email_id),
+ FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+) ENGINE = InnoDB;
+
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+ VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+
+DELETE FROM emails;
+DELETE FROM email_stats;
+
+--echo # Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+
+--echo # Test-Case 2
+CREATE TABLE emails (
+ id int unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE = InnoDB
+ DEFAULT CHARSET = utf8mb4
+ COLLATE = utf8mb4_unicode_ci
+ ROW_FORMAT = DYNAMIC;
+
+CREATE TABLE email_stats (
+ id bigint unsigned NOT NULL AUTO_INCREMENT,
+ email_id int unsigned DEFAULT NULL,
+ date_sent datetime NOT NULL,
+ generated_sent_date date GENERATED ALWAYS AS
+ (concat(year(date_sent), '-', lpad(month(date_sent), 2, '0'),
+ '-', lpad(dayofmonth(date_sent), 2, '0'))),
+ PRIMARY KEY (id),
+ KEY IDX_ES1 (email_id),
+ KEY mautic_generated_sent_date_email_id(generated_sent_date, email_id),
+ FOREIGN KEY (email_id) REFERENCES emails (id)
+ ON DELETE SET NULL
+ ON UPDATE SET NULL
+) ENGINE = InnoDB;
+
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+ VALUES (1, 1, '2020-10-22 13:32:41');
+
+UPDATE emails SET id = 2 where id = 1;
+
+SELECT id FROM email_stats WHERE generated_sent_date IS NULL;
+SELECT * FROM email_stats;
+UPDATE email_stats
+ SET email_id=2
+ WHERE DATE(generated_sent_date) = '2020-10-22';
+SELECT * FROM email_stats;
+
+--echo # Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+
+--echo # Test-case 3
+CREATE TABLE emails (
+ id int unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE = INNODB
+ DEFAULT CHARSET = utf8mb4
+ COLLATE = utf8mb4_unicode_ci
+ ROW_FORMAT = DYNAMIC;
+CREATE TABLE email_stats (
+ id bigint unsigned NOT NULL AUTO_INCREMENT,
+ email_id int unsigned DEFAULT NULL,
+ date_sent datetime NOT NULL,
+ generated_sent_email varchar(20) GENERATED ALWAYS AS
+ (CONCAT(YEAR(date_sent), '-', COALESCE(email_id, '$'))),
+ PRIMARY KEY (id),
+ KEY idx_es1 (email_id),
+ KEY mautic_generated_sent_date_email(generated_sent_email, email_id),
+ FOREIGN KEY (email_id) REFERENCES emails (id) ON DELETE SET NULL
+) ENGINE = INNODB;
+
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+ VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+
+DELETE FROM emails;
+
+SELECT * FROM email_stats;
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-$';
+
+--echo # Clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+
+--echo # Test-case 4
+CREATE TABLE emails (
+ id int unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE = INNODB;
+
+CREATE TABLE email_stats (
+ id bigint unsigned NOT NULL AUTO_INCREMENT,
+ email_id int unsigned DEFAULT NULL,
+ date_sent datetime NOT NULL,
+ generated_sent_email varchar(20) GENERATED ALWAYS AS
+ (CONCAT(YEAR(date_sent), '-', COALESCE(email_id, '$'))),
+ PRIMARY KEY (id),
+ KEY idx_es1 (email_id),
+ KEY mautic_generated_sent_date_email(generated_sent_email, email_id),
+ FOREIGN KEY (email_id) REFERENCES emails (id) ON UPDATE SET NULL
+) ENGINE = INNODB;
+
+INSERT INTO emails VALUES (1);
+INSERT INTO email_stats (id, email_id, date_sent)
+ VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+
+UPDATE emails SET id = 2 WHERE id = 1;
+
+SELECT * FROM email_stats;
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-$';
+
+#clean up.
+DROP TABLE email_stats;
+DROP TABLE emails;
+
+CREATE TABLE emails (breaker int unsigned,
+ KEY (breaker),
+ id int unsigned NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (id)
+) ENGINE=INNODB;
+
+CREATE TABLE email_stats (
+ id bigint unsigned NOT NULL AUTO_INCREMENT,
+ email_id int unsigned DEFAULT NULL,
+ date_sent datetime NOT NULL,
+ generated_sent_email varchar(20) GENERATED ALWAYS AS
+ (CONCAT(YEAR(date_sent),
+ '-',
+ COALESCE(email_id, '$'))),
+ PRIMARY KEY (id),
+ KEY idx_es1 (email_id),
+ KEY mautic_generated_sent_date_email (generated_sent_email, email_id),
+ FOREIGN KEY fk_ea1 (email_id) REFERENCES emails (breaker)
+ ON DELETE SET NULL
+) ENGINE=INNODB;
+
+show create table email_stats;
+INSERT INTO emails VALUES (1,1);
+INSERT INTO email_stats(id, email_id, date_sent)
+ VALUES (1, 1, '2020-10-22 13:32:41');
+SELECT * FROM email_stats;
+SELECT date_sent FROM email_stats WHERE generated_sent_email = '2020-1';
+DELETE FROM emails;
+SELECT * FROM email_stats;
+SELECT date_sent
+ FROM email_stats force index (mautic_generated_sent_date_email)
+ WHERE generated_sent_email = '2020-$';
+SELECT date_sent
+ FROM email_stats force index (idx_es1)
+ WHERE generated_sent_email = '2020-$';
+
+DROP TABLE email_stats;
+DROP TABLE emails;
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_fk_restart.test b/mysql-test/suite/gcol/t/innodb_virtual_fk_restart.test
new file mode 100644
index 00000000..45d1c129
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_fk_restart.test
@@ -0,0 +1,51 @@
+-- source include/have_innodb.inc
+-- source include/not_embedded.inc
+
+--echo #
+--echo # Bug#22469130: FOREIGN KEY ON DELETE CASCADE NOT ALLOWED
+--echo # WHEN A VIRTUAL INDEX EXISTS.
+
+--echo # Add the VIRTUAL INDEX contains fk constraINT column
+--echo # using INPLACE alter operatiON
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
+CREATE TABLE t2(fld1 INT NOT NULL, fld2 INT NOT NULL,
+ fld3 INT AS (fld2) VIRTUAL, KEY(fld1),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1) ON UPDATE CASCADE) engine=innodb;
+CREATE TABLE u1(a INT, KEY(a)) ENGINE=InnoDB;
+CREATE TABLE u2(b INT, vb INT GENERATED ALWAYS AS(b) VIRTUAL, KEY(vb),
+ FOREIGN KEY(b) REFERENCES u1(a)ON DELETE CASCADE)ENGINE=InnoDB;
+
+INSERT INTO u1 SET a=1;
+INSERT INTO u2 SET b=1;
+INSERT INTO t1(fld1) VALUES(1);
+INSERT INTO t2(fld1, fld2) VALUES(1, 2);
+--source include/restart_mysqld.inc
+UPDATE t1 SET fld1= 2;
+DELETE FROM u1;
+SELECT * FROM u2;
+DROP TABLE u2,u1;
+SELECT fld3, fld1 FROM t2;
+alter TABLE t2 ADD INDEX vk(fld3, fld1), ALGORITHM=INPLACE;
+UPDATE t1 SET fld1=3;
+SELECT fld3, fld1 FROM t2;
+DROP TABLE t2, t1;
+
+--echo # TEMPORARY TABLE NAME and CHILD TABLE NAME are same
+CREATE TABLE t1(fld1 INT NOT NULL PRIMARY KEY) engine=innodb;
+CREATE TABLE t2(fld1 INT NOT NULL,
+ fld2 INT AS (fld1) VIRTUAL,
+ KEY(fld2),
+ FOREIGN KEY(fld1) REFERENCES t1(fld1)
+ ON UPDATE CASCADE) engine=innodb;
+INSERT INTO t1 VALUES(1), (2);
+INSERT INTO t2 VALUES(1, DEFAULT), (2, default);
+--source include/restart_mysqld.inc
+CREATE TEMPORARY TABLE t2 (fld1 INT NOT NULL)ENGINE=INNODB;
+UPDATE t1 SET fld1= 3 WHERE fld1= 2;
+--connect(con1,localhost,root,,test)
+SELECT fld2 FROM t2;
+CHECK TABLE t2;
+connection default;
+disconnect con1;
+DROP TABLE t2;
+DROP TABLE t2, t1;
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_index.opt b/mysql-test/suite/gcol/t/innodb_virtual_index.opt
new file mode 100644
index 00000000..c3f4a891
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_index.opt
@@ -0,0 +1 @@
+--innodb_sort_buffer_size=64k
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_index.test b/mysql-test/suite/gcol/t/innodb_virtual_index.test
new file mode 100644
index 00000000..83d9a6bd
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_index.test
@@ -0,0 +1,386 @@
+--source include/have_innodb.inc
+--source include/have_sequence.inc
+
+SET default_storage_engine= innodb;
+
+--echo #
+--echo # Bug 21922176 - PREBUILT->SEARCH_TUPLE CREATED WITHOUT INCLUDING
+--echo # THE NUMBER OF VIRTUAL COLUMNS
+--echo #
+
+CREATE TABLE t1 (a INT, a1 INT GENERATED ALWAYS AS (a) VIRTUAL, a2 INT
+GENERATED ALWAYS AS (a) VIRTUAL, a3 INT GENERATED ALWAYS AS (a) VIRTUAL, a4
+INT GENERATED ALWAYS AS (a) VIRTUAL, a5 INT GENERATED ALWAYS AS (a) VIRTUAL,
+a6 INT GENERATED ALWAYS AS (a) VIRTUAL, a7 INT GENERATED ALWAYS AS (a)
+VIRTUAL, a8 INT GENERATED ALWAYS AS (a) VIRTUAL, a9 INT GENERATED ALWAYS AS
+(a) VIRTUAL, INDEX(a1, a2, a3, a4, a5, a6, a7, a8, a9)) ;
+
+INSERT INTO t1(a) VALUES(10);
+
+SELECT * FROM t1 WHERE a1=10 AND a2 = 10 AND a3 =10 AND a4 = 10 AND a5=10 AND
+a6=10 AND a7=10 AND a8=10 AND a9=10;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug 22572997 - GCOL:INNODB: FAILING ASSERTION: N < REC_OFFS_N_FIELDS(
+--echo # OFFSETS)
+--echo #
+SET @@SESSION.sql_mode=0;
+
+CREATE TABLE t1(
+c1 int(1)AUTO_INCREMENT,
+ c2 int(1),
+ c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+ c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+ c5 date,
+ c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
+ c7 DATE,
+ c8 time,
+ c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+ c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+ c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+ c12 CHAR(1),
+ c13 CHAR(1)GENERATED ALWAYS AS (concat(c12,c12)) VIRTUAL,
+ c14 CHAR(2)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
+ PRIMARY KEY(c1),
+ KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+CREATE TABLE t2(
+ c1 int(1)AUTO_INCREMENT,
+ c2 int(1),
+ c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+ c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+ c5 date,
+ c6 date GENERATED ALWAYS AS((c5 + interval 30 day)) VIRTUAL,
+ c6a date GENERATED ALWAYS AS((c6 + interval 30 day)) VIRTUAL,
+ c7 DATE,
+ c8 time,
+ c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+ c10 time GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+ c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+ c11a time GENERATED ALWAYS AS(addtime(c7,c10)) VIRTUAL,
+ c12 CHAR(1),
+ c13 CHAR(2)GENERATED ALWAYS AS (concat(RTRIM(c12),RTRIM(c12))) VIRTUAL,
+ c14 CHAR(4)GENERATED ALWAYS AS (concat(c13,'x')) VIRTUAL,
+ PRIMARY KEY(c1),
+ KEY c13(c13),
+ KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t2(c1,c2,c5,c7,c8,c12)VALUES (0,0,0,0,0,'v');
+
+CREATE TABLE t3(
+ c1 int(1)AUTO_INCREMENT,
+ c2 int(1),
+ c3 int(1)GENERATED ALWAYS AS ((c2 + c2)) VIRTUAL,
+ c4 int(1)GENERATED ALWAYS AS ((c3 + c2)) VIRTUAL,
+ c5 date,
+ c7 DATE,
+ c8 time,
+ c9 DATE GENERATED ALWAYS AS(addtime(c7,c8)) VIRTUAL,
+ c11 DATE GENERATED ALWAYS AS(addtime(c9,c8)) VIRTUAL,
+ c12 CHAR(1),
+ PRIMARY KEY(c1),
+ KEY c4_6(c4,c11)
+)ENGINE=InnoDB DEFAULT CHARSET=latin1;
+INSERT INTO t3(c1,c2,c5,c7,c8,c12)VALUES
+(0,0,0,0,0,'q'),(0,0,0,0,0,'g'),(0,0,0,0,0,'l'),(0,0,0,0,0,1),(0,0,0,0,0,'v'),
+(0,1,0,0,0,'c'),(0,0,0,0,0,'x');
+
+UPDATE
+t2 AS O1,t3 AS O2
+SET O1.c12=1
+WHERE O1.c14 NOT IN
+(
+SELECT
+DISTINCT I1.c14 AS y
+FROM t1 AS I1
+ORDER BY I1.c14);
+
+SET @@SESSION.sql_mode=default;
+--source ../../innodb/include/wait_all_purged.inc
+
+DROP TABLE t1, t2, t3;
+
+--echo #
+--echo # Bug 22650296 - ASSERTION IN INNOBASE_BUILD_COL_MAP, ALTER
+--echo #
+CREATE TABLE `ibstd_08` (
+ `nc00577` tinyint(4) DEFAULT NULL,
+ `nc07844` varchar(41) DEFAULT NULL,
+ `gc01908` point NOT NULL,
+ `nc04156` char(17) DEFAULT NULL,
+ `nc09536` longblob NOT NULL,
+ `nc09231` decimal(10,0) NOT NULL,
+ `a` int(11) NOT NULL,
+ `b` varchar(198) NOT NULL,
+ `nc04560` mediumtext,
+ `c` char(187) DEFAULT NULL,
+ `vbidxcol` char(3) GENERATED ALWAYS AS (substr(`b`,1,3)) VIRTUAL,
+ `gc00881` polygon NOT NULL,
+ `nc05121` int(11) NOT NULL DEFAULT '85941481',
+ KEY `a` (`a`),
+ KEY `b` (`b`(3),`a`),
+ KEY `c` (`c`(99),`b`(25)),
+ KEY `b_2` (`b`(5),`c`(10),`a`),
+ KEY `vbidxcol` (`vbidxcol`),
+ KEY `a_2` (`a`,`vbidxcol`),
+ KEY `vbidxcol_2` (`vbidxcol`),
+ FULLTEXT KEY `ftsic` (`c`,`b`)
+) ENGINE=InnoDB;
+
+
+ALTER TABLE ibstd_08 ADD COLUMN nc07006 BIGINT AUTO_INCREMENT NOT NULL , ADD KEY auto_nc07006(nc07006);
+
+DROP TABLE ibstd_08;
+
+--echo #
+--echo # Bug 22899305 - GCOLS: FAILING ASSERTION: !(COL->PRTYPE & 256)
+--echo # AND SEGFAULT
+--echo #
+set sql_mode="";
+create table t (a int) engine=innodb;
+create table s (
+b int generated always as (1) virtual,
+c int,
+d int generated always as (1) virtual,
+key (d)
+) engine=innodb;
+
+insert into t(a) values ((select d from s for update));
+insert into s(c) values ('');
+
+SET sql_mode = default;
+drop table if exists t,s;
+
+--echo #
+--echo # Bug 23014521 - GCOL:INNODB: FAILING ASSERTION: !IS_V
+--echo #
+CREATE TABLE t1 (
+ col1 int(11) NOT NULL,
+ col2 int(11) DEFAULT NULL,
+ col3 int(11) NOT NULL,
+ col4 int(11) DEFAULT NULL,
+ col5 int(11) GENERATED ALWAYS AS ((col1 % col4)) VIRTUAL,
+ col6 int(11) GENERATED ALWAYS AS ((col2 - col4)) VIRTUAL,
+ col5x int(11) GENERATED ALWAYS AS ((col3 / col2)) VIRTUAL,
+ col6b varchar(20) GENERATED ALWAYS AS (col2) VIRTUAL,
+ col6x int(11) GENERATED ALWAYS AS ((col2 % col1)) VIRTUAL,
+ col7 int(11) GENERATED ALWAYS AS ((col6x + col5x)) VIRTUAL,
+ col8 int(11) GENERATED ALWAYS AS ((col5x / col5)) VIRTUAL,
+ col7x int(11) GENERATED ALWAYS AS ((col5x + col5)) VIRTUAL,
+ col8x int(11) GENERATED ALWAYS AS ((col5 / col5x)) VIRTUAL,
+ col9 text,
+ col2b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
+ col8a int(11) GENERATED ALWAYS AS (col2) VIRTUAL,
+ col4b varchar(20) GENERATED ALWAYS AS (col4) VIRTUAL,
+ col1c int(11) GENERATED ALWAYS AS ((col2 * col1)) VIRTUAL,
+ extra int(11) DEFAULT NULL,
+ col5c int(11) GENERATED ALWAYS AS ((col1 / col1)) VIRTUAL,
+ col6a bigint(20) GENERATED ALWAYS AS ((col3 / col1)) VIRTUAL,
+ col1a varchar(20) GENERATED ALWAYS AS (col6) VIRTUAL,
+ col6c int(11) GENERATED ALWAYS AS ((col2 % col2)) VIRTUAL,
+ col7c bigint(20) GENERATED ALWAYS AS ((col2 / col1)) VIRTUAL,
+ col2c int(11) GENERATED ALWAYS AS ((col5 % col5)) VIRTUAL,
+ col1b int(11) GENERATED ALWAYS AS ((col1 / col2)) VIRTUAL,
+ col3b bigint(20) GENERATED ALWAYS AS ((col6x % col6)) VIRTUAL,
+ UNIQUE KEY idx7 (col1,col3,col2),
+ UNIQUE KEY uidx (col9(10)),
+ KEY idx15 (col9(10) DESC,col2 DESC),
+ KEY idx10 (col9(10) DESC,col1 DESC),
+ KEY idx11 (col6x DESC),
+ KEY idx6 (col9(10) DESC,col7 DESC),
+ KEY idx14 (col6 DESC)
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+# Cannot add virtual column along with create FULLTEXT index with
+# adding a hidden FTS_DOC_ID column (which require a table rebuild)
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
+VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
+
+# This will add a hidden FTS_DOC_ID column
+CREATE FULLTEXT INDEX idx ON t1(col9);
+
+# Since there is no table rebuild needed, now the alter would be sucessful
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col5x % col6x)
+VIRTUAL, ADD FULLTEXT KEY ftidx ( col9 ), algorithm=inplace;
+
+DROP TABLE t1;
+
+CREATE TABLE t1 (
+ col1 int(11) NOT NULL,
+ col2 int(11) DEFAULT NULL,
+ col3 int(11) NOT NULL,
+ col4 int(11) DEFAULT NULL) engine=innodb;
+
+# This secondary key idx will be coverted to a new Primary Key, thus a table
+# rebuild. It is blocked since there is an adding of virtual columns
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+ALTER TABLE t1 ADD COLUMN col7a INT GENERATED ALWAYS AS (col1 % col2)
+VIRTUAL, ADD UNIQUE index idx (col1), algorithm=inplace;
+
+DROP TABLE t1;
+
+--echo #
+--echo # Bug 27122803 - BACKPORT FIX FOR BUG 25899959 TO MYSQL-5.7
+--echo #
+CREATE TABLE t1 (col1 int(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+ALTER TABLE t1 ADD col2 char(21) AS (col1 * col1), ADD INDEX n (col2);
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #27968952 INNODB CRASH/CORRUPTION WITH TEXT PREFIX INDEXES
+--echo #
+
+CREATE TABLE t1(
+ a INT NOT NULL UNIQUE,
+ b INT NOT NULL,
+ c TEXT GENERATED ALWAYS AS (a <> b) VIRTUAL,
+ d TEXT NOT NULL,
+ UNIQUE KEY (c(1)), KEY(d(1))
+) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
+SET @t = REPEAT('t',@@innodb_page_size);
+INSERT INTO t1 (a,b,d) VALUES (1,0,@t), (0,0,@t);
+--error ER_DUP_ENTRY
+UPDATE t1 SET b = a;
+REPLACE INTO t1 SET a = 0, b = 1, d = 'd';
+SELECT * FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--disable_query_log
+SET @save_innodb_read_only_compressed=@@GLOBAL.innodb_read_only_compressed;
+SET GLOBAL innodb_read_only_compressed=OFF;
+--enable_query_log
+CREATE TABLE t1(
+ a VARCHAR(1000) GENERATED ALWAYS AS ('1') VIRTUAL,
+ b VARCHAR(1000) NOT NULL,
+ c VARCHAR(1000) GENERATED ALWAYS AS (b) STORED,
+ KEY (b(1)),
+ KEY (a(1))
+) ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1;
+INSERT INTO t1(b) VALUES(REPEAT('b',1000));
+DELETE FROM t1;
+--disable_query_log
+SET GLOBAL innodb_read_only_compressed=@save_innodb_read_only_compressed;
+--enable_query_log
+DROP TABLE t1;
+
+--echo #
+--echo # Bug #22990029 GCOLS: INCORRECT BEHAVIOR
+--echo # AFTER DATA INSERTED WITH IGNORE KEYWORD
+--echo #
+
+CREATE TABLE t1(a INT PRIMARY KEY, b INT, vb DATE AS(b) VIRTUAL, KEY(vb))
+ENGINE=InnoDB;
+INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132);
+SELECT * FROM t1;
+BEGIN;
+DELETE FROM t1;
+INSERT INTO t1 (a,b) VALUES(1,20190123);
+SELECT * FROM t1;
+ROLLBACK;
+SELECT * FROM t1;
+CHECK TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-25872 InnoDB: Assertion failure in row_merge_read_clustered_index
+--echo # upon ALTER on table with indexed virtual columns
+--echo #
+
+CREATE TABLE t1 (
+ id BIGINT AUTO_INCREMENT PRIMARY KEY,
+ a INT,
+ va INT ZEROFILL AS (a) VIRTUAL,
+ b TIMESTAMP,
+ c CHAR(204),
+ vc CHAR(8),
+ KEY(vc,c(64),b,va)
+) ENGINE=InnoDB CHARACTER SET utf32;
+INSERT INTO t1 (id) SELECT NULL FROM seq_1_to_75;
+INSERT IGNORE INTO t1 (id, a) VALUES (NULL, -1);
+--error ER_WARN_DATA_OUT_OF_RANGE
+ALTER TABLE t1 FORCE;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-24713 Assertion `dict_table_is_comp(index->table)' failed
+--echo # in row_merge_buf_add()
+--echo #
+CREATE TABLE t1 (id INT PRIMARY KEY, a CHAR(3),
+ b CHAR(8) AS (a) VIRTUAL, KEY(b))
+ ROW_FORMAT=REDUNDANT ENGINE=InnoDB
+ CHARACTER SET utf8;
+INSERT INTO t1 (id,a) VALUES (1,'foo');
+OPTIMIZE TABLE t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-20154 Assertion `len <= col->len || ((col->mtype) == 5
+--echo # || (col->mtype) == 14)' failed in row_merge_buf_add
+--echo #
+
+CREATE TABLE t1 (
+ a VARCHAR(2500),
+ b VARCHAR(2499) AS (a) VIRTUAL
+) ENGINE=InnoDB;
+INSERT INTO t1 (a) VALUES ('foo');
+
+ALTER TABLE t1 MODIFY a VARCHAR(2600), ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD KEY (b), ALGORITHM=INPLACE;
+
+--echo # Cleanup
+DROP TABLE t1;
+
+--echo # End of 10.2 tests
+
+--echo #
+--echo # MDEV-29299 SELECT from table with vcol index reports warning
+--echo #
+
+CREATE TABLE t(fld1 INT NOT NULL,
+ fld2 INT AS (100/fld1) VIRTUAL,
+ KEY(fld1), KEY(fld2));
+CREATE TABLE t_odd(id int);
+INSERT INTO t(fld1) VALUES(1), (2);
+
+--connect stop_purge,localhost,root
+# This prevents purge for records in t
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+INSERT INTO t_odd VALUES(10000);
+
+--connection default
+UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2;
+UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3;
+UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4;
+SELECT fld2 FROM t FORCE INDEX(fld2);
+SELECT fld2 FROM t FORCE INDEX(fld1);
+
+--disconnect stop_purge
+DROP TABLE t, t_odd;
+
+--echo #
+--echo # MDEV-29753 An error is wrongly reported during INSERT with vcol index
+--echo # See also Bug #22990029
+--echo #
+
+CREATE TABLE t(pk INT PRIMARY KEY,
+ fld1 INT NOT NULL,
+ fld2 INT AS (100/fld1) VIRTUAL,
+ KEY(fld1), KEY(fld2));
+INSERT IGNORE t(pk, fld1) VALUES(1, 0);
+SELECT * FROM t;
+BEGIN;
+DELETE FROM t;
+INSERT INTO t (pk, fld1) VALUES(1,1);
+SELECT * FROM t;
+
+--echo # Cleanup
+ROLLBACK;
+DROP TABLE t;
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_purge.test b/mysql-test/suite/gcol/t/innodb_virtual_purge.test
new file mode 100644
index 00000000..99c7267c
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_purge.test
@@ -0,0 +1,185 @@
+--source include/have_innodb.inc
+--source include/count_sessions.inc
+
+--echo #
+--echo # Bug#21869656 UNDO LOG DOES NOT CONTAIN ENOUGH INFORMATION
+--echo # ON INDEXED VIRTUAL COLUMNS
+--echo #
+
+CREATE TABLE t1 (a INT, b INT,
+ a1 INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX(a1)
+) ENGINE=InnoDB;
+
+INSERT INTO t1 (a,b) VALUES(1,1);
+
+connect (con1,localhost,root,,);
+# disable purge
+CREATE TABLE t0 (a INT) ENGINE=InnoDB;
+BEGIN; SELECT * FROM t0;
+
+connection default;
+# write the problematic update_undo log record
+UPDATE t1 SET a=0;
+
+ALTER TABLE t1 DROP COLUMN a1, ALGORITHM=INPLACE;
+ALTER TABLE t1 ADD COLUMN b1 INT GENERATED ALWAYS AS (b) VIRTUAL, ADD
+INDEX(b1),
+ALGORITHM=INPLACE;
+
+connection con1;
+# enable purge
+COMMIT;
+UPDATE t1 SET a=1;
+
+connection default;
+--source ../../innodb/include/wait_all_purged.inc
+
+CHECK TABLE t1 EXTENDED;
+SELECT b1 FROM t1;
+
+
+# Create multi-virtual column, more ADD/DROP to test it
+ALTER TABLE t1
+ADD COLUMN a1 INT GENERATED ALWAYS AS (a) VIRTUAL,
+ADD COLUMN a2 INT GENERATED ALWAYS AS (a + b) VIRTUAL,
+ADD COLUMN a3 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
+ADD COLUMN a4 INT GENERATED ALWAYS AS (a - b) VIRTUAL,
+ADD INDEX(a1), ADD INDEX(a2), ADD INDEX(a3), ALGORITHM=INPLACE;
+
+CREATE TABLE t2 (
+ a BLOB,
+ b BLOB,
+ c BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ h VARCHAR(10) DEFAULT NULL
+) ENGINE=InnoDB;
+
+INSERT INTO t2 VALUES (REPEAT('g', 16000), REPEAT('x', 16000), DEFAULT, 'kk');
+
+INSERT INTO t2 VALUES (REPEAT('a', 16000), REPEAT('b', 16000), DEFAULT, 'mm');
+
+CREATE INDEX idx ON t2(c(100));
+
+INSERT INTO t1 (a, b) VALUES(1,1);
+
+connection con1;
+# disable purge
+BEGIN; SELECT * FROM t0;
+
+connection default;
+--enable_info
+
+# write the problematic update_undo log record
+UPDATE t1 SET a=0;
+UPDATE t1 SET b=0;
+
+ALTER TABLE t1 DROP COLUMN a3, ALGORITHM=INPLACE;
+
+UPDATE t1 SET a=2;
+ALTER TABLE t1 DROP COLUMN a2, ALGORITHM=INPLACE;
+UPDATE t1 SET b=3;
+
+ALTER TABLE t1 ADD COLUMN b2 INT GENERATED ALWAYS AS (b) VIRTUAL,
+ADD INDEX(b2), ALGORITHM=INPLACE;
+UPDATE t1 SET b=9;
+
+ALTER TABLE t1 ADD COLUMN b3 INT GENERATED ALWAYS AS (a) VIRTUAL,
+ADD INDEX(b3), ALGORITHM=INPLACE;
+
+UPDATE t1 SET b=10;
+
+ALTER TABLE t2 DROP COLUMN c;
+
+UPDATE t2 SET a = REPEAT('s', 6000) WHERE a like 'aaa%';
+
+ALTER TABLE t2 ADD COLUMN x1 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ADD COLUMN x2 BLOB GENERATED ALWAYS AS (CONCAT(a,b)) VIRTUAL,
+ADD INDEX(x1(100), x2(120)), ADD INDEX (x1(20));
+
+UPDATE t1 SET a=5;
+
+UPDATE t2 SET a = REPEAT('m', 16000) WHERE a like 'sss%';
+
+ALTER TABLE t1 DROP COLUMN b2, ALGORITHM=INPLACE;
+
+UPDATE t1 SET a=6;
+
+ALTER TABLE t2 DROP COLUMN x1, DROP COLUMN x2, ALGORITHM=INPLACE;
+
+UPDATE t2 SET a = REPEAT('x', 1000) WHERE a like 'mmm%';
+
+ALTER TABLE t1 DROP INDEX b3;
+UPDATE t1 SET a=100;
+--disable_info
+
+connection con1;
+# enable purge
+COMMIT;
+disconnect con1;
+
+connection default;
+--source ../../innodb/include/wait_all_purged.inc
+
+CHECK TABLE t1 EXTENDED;
+SELECT b1 FROM t1;
+
+SELECT * FROM t1;
+CHECK TABLE t2 EXTENDED;
+DROP TABLE t2, t1, t0;
+
+CREATE TABLE t1 (a VARCHAR(30), b INT, a2 VARCHAR(30) GENERATED ALWAYS AS (a) VIRTUAL);
+
+--error ER_DUP_FIELDNAME
+CREATE INDEX idx ON t1(a2(10), b, a2(20));
+
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-17540 Server crashes in row_purge after TRUNCATE TABLE
+--echo #
+
+# Note: this test case is nondeterministic and should depend on
+# MDEV-12288 to trigger the needed purge activity.
+# The test does not seem to repeat the bug on MariaDB 10.2.
+
+CREATE TABLE t1 (a BIT(14)) ENGINE=InnoDB;
+INSERT INTO t1 VALUES
+ (b'01110110101011'),(b'01100111111000'),(b'00001011110100'),
+ (b'01110110111010'),(b'10001010101011'),(b'01100111001111');
+
+CREATE TABLE t2 (
+ pk INT DEFAULT 1,
+ b YEAR,
+ c BIT(14),
+ d YEAR AS (b),
+ e BIT(14) AS (c),
+ UNIQUE(pk),
+ KEY(e)
+) ENGINE=InnoDB;
+
+# Run a few times in order to improve the chances of triggering the bug.
+--disable_query_log
+let $n=10;
+while ($n) {
+REPLACE INTO t2 (c) SELECT a FROM t1;
+TRUNCATE TABLE t2;
+dec $n;
+}
+--enable_query_log
+
+DROP TABLE t1, t2;
+
+--echo #
+--echo # MDEV-30024 InnoDB: tried to purge non-delete-marked record
+--echo # of an index on a virtual column prefix
+--echo #
+
+CREATE TABLE t(a BINARY(8), b CHAR(8) AS (a) VIRTUAL, KEY(b(4)))
+CHARACTER SET utf8 ENGINE=InnoDB;
+INSERT INTO t (a) VALUES (''),('');
+UPDATE t SET a = 'x';
+UPDATE t SET a = '';
+SET GLOBAL innodb_max_purge_lag_wait=0;
+CHECK TABLE t EXTENDED;
+DROP TABLE t;
+
+--source include/wait_until_count_sessions.inc
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_rebuild.test b/mysql-test/suite/gcol/t/innodb_virtual_rebuild.test
new file mode 100644
index 00000000..fe4f5e30
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_rebuild.test
@@ -0,0 +1,51 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+CREATE TABLE t1 (j SERIAL, i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t2 (j SERIAL, i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT;
+CREATE TABLE t3 (i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB;
+CREATE TABLE t4 (i INT, v INT AS (i) VIRTUAL) ENGINE=InnoDB
+ROW_FORMAT=REDUNDANT;
+
+let $n=4;
+while ($n)
+{
+eval INSERT INTO t$n SET i=1;
+eval ALTER TABLE t$n ADD INDEX(v), LOCK=NONE;
+# MDEV-17468 FIXME: Fix this, and remove the 2 --error below.
+--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
+eval ALTER TABLE t$n ADD COLUMN k INT, LOCK=NONE;
+--error ER_CANT_DROP_FIELD_OR_KEY
+eval ALTER TABLE t$n DROP k, LOCK=NONE;
+eval ALTER TABLE t$n DROP INDEX v, LOCK=NONE;
+dec $n;
+}
+
+connect (ddl,localhost,root,,test);
+connection default;
+
+let $n=4;
+while ($n)
+{
+connection ddl;
+SET DEBUG_SYNC = 'row_log_table_apply1_before SIGNAL copied WAIT_FOR dml';
+send_eval ALTER TABLE t$n FORCE;
+
+connection default;
+SET DEBUG_SYNC = 'now WAIT_FOR copied';
+BEGIN;
+eval UPDATE t$n SET i = 0;
+ROLLBACK;
+SET DEBUG_SYNC = 'now SIGNAL dml';
+
+connection ddl;
+reap;
+connection default;
+eval SELECT * FROM t$n;
+eval DROP TABLE t$n;
+dec $n;
+}
+disconnect ddl;
+SET DEBUG_SYNC = 'RESET';
diff --git a/mysql-test/suite/gcol/t/innodb_virtual_stats.test b/mysql-test/suite/gcol/t/innodb_virtual_stats.test
new file mode 100644
index 00000000..69c67af8
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_virtual_stats.test
@@ -0,0 +1,56 @@
+--source include/have_innodb.inc
+
+#
+# BUG#22469660 INNODB DOESN'T UPDATE INDEX STATS WHEN ADDING OR DROPPING VIRTUAL COLUMN
+#
+
+CREATE TABLE t (
+ a INT,
+ b INT,
+ c INT GENERATED ALWAYS AS(a+b),
+ d INT GENERATED ALWAYS AS(a+b+b),
+ KEY idxa (a),
+ KEY vidxcd (c, d)
+) ENGINE=INNODB STATS_PERSISTENT=1 STATS_AUTO_RECALC=1;
+
+INSERT INTO t (a,b) VALUES (1, 2);
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+ALTER TABLE t ADD COLUMN e INT GENERATED ALWAYS AS(a+a+b), ADD INDEX idxb (b), ALGORITHM=INPLACE;
+select count(*) from t;
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+ALTER TABLE t DROP COLUMN c, DROP INDEX idxa, ALGORITHM=INPLACE;
+select count(*) from t;
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+ALTER TABLE t ADD INDEX vidxe (e), ALGORITHM=INPLACE;
+select count(*) from t;
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+ALTER TABLE t ADD COLUMN f INT GENERATED ALWAYS AS(a + a), ADD INDEX vidxf (f), ALGORITHM=INPLACE;
+select count(*) from t;
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+ALTER TABLE t DROP INDEX vidxcd;
+
+SELECT index_name, stat_name, stat_description
+FROM mysql.innodb_index_stats
+WHERE database_name = 'test' AND table_name = 't';
+
+DROP TABLE t;
diff --git a/mysql-test/suite/gcol/t/innodb_wl8114.test b/mysql-test/suite/gcol/t/innodb_wl8114.test
new file mode 100644
index 00000000..bed83753
--- /dev/null
+++ b/mysql-test/suite/gcol/t/innodb_wl8114.test
@@ -0,0 +1,42 @@
+--source include/have_innodb.inc
+
+# Test alter table add column
+CREATE TABLE t_8114 (a int) ENGINE = INNODB;
+
+ALTER TABLE t_8114 ADD b INT GENERATED ALWAYS AS (a) VIRTUAL;
+
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+
+INSERT INTO t_8114 VALUES (9, default);
+INSERT INTO t_8114 VALUES (3, default);
+INSERT INTO t_8114 VALUES (1, default);
+INSERT INTO t_8114 VALUES (5, default);
+
+SELECT * FROM t_8114;
+
+DROP TABLE t_8114;
+
+CREATE TABLE t_8114 (Column_1 CHAR(5) GENERATED ALWAYS AS (PI()+5), Column_2 CHAR(5)) engine=innodb;
+
+SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+
+INSERT INTO t_8114 VALUES (default, "aa");
+INSERT INTO t_8114 VALUES (default, "bb");
+INSERT INTO t_8114 VALUES (default, "ee");
+INSERT INTO t_8114 VALUES (default, "pp");
+
+SELECT * FROM t_8114;
+
+ALTER TABLE t_8114 DROP Column_1;
+
+SELECT NAME FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114";
+
+SELECT NAME, POS, MTYPE, PRTYPE, LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS WHERE TABLE_ID IN (SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE "%t_8114");
+
+SELECT * FROM t_8114;
+
+DROP TABLE t_8114;
diff --git a/mysql-test/suite/gcol/t/main_alter_table.test b/mysql-test/suite/gcol/t/main_alter_table.test
new file mode 100644
index 00000000..2ce768a9
--- /dev/null
+++ b/mysql-test/suite/gcol/t/main_alter_table.test
@@ -0,0 +1,50 @@
+--source include/have_innodb.inc
+
+--echo #
+--echo # Bug#22017616: ASSERTION FAILED: TABLE_SHARE->IS_MISSING_PRIMARY_KEY()
+--echo # == M_PREBUILT->CLUST_IND
+--echo #
+--echo # Ensure that adding indexes with virtual columns are not promoted to
+--echo # primary keys
+--echo #
+--echo # Base line with normal column - should be promoted
+CREATE TABLE t0(a INT NOT NULL) ENGINE=INNODB;
+ALTER TABLE t0 ADD UNIQUE INDEX (a);
+
+--echo # Case a: Create table with virtual unique not null column
+CREATE TABLE t1(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL UNIQUE) ENGINE=INNODB;
+SELECT * FROM t1;
+
+--echo # Case b: Create table with index on virtual point column
+CREATE TABLE t2(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL, UNIQUE INDEX no_pk(a(1))) ENGINE=INNODB;
+SELECT * FROM t2;
+
+--echo # Case c: Add unique index on virtual point column
+CREATE TABLE t3(a POINT GENERATED ALWAYS AS (POINT(1,1)) VIRTUAL)
+ENGINE=INNODB;
+ALTER TABLE t3 ADD UNIQUE INDEX (a(1));
+SELECT * FROM t3;
+
+--echo # Case d: Add unique index on virtual blob column
+CREATE TABLE t4 (a BLOB, b BLOB GENERATED ALWAYS AS (a) VIRTUAL) ENGINE=INNODB;
+ALTER TABLE t4 ADD UNIQUE INDEX (b(1));
+SELECT * FROM t4;
+
+--echo # Query I_S to verify that 'a' is promoted to pk only when it
+--echo # isn't virtual
+SELECT T.NAME AS TABLE_NAME, I.NAME AS INDEX_NAME,
+ CASE (I.TYPE & 3)
+ WHEN 3 THEN "yes"
+ ELSE "no" END AS IS_PRIMARY_KEY,
+ F.NAME AS FIELD_NAME, F.POS AS FIELD_POS FROM
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES AS T JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_INDEXES AS I JOIN
+ INFORMATION_SCHEMA.INNODB_SYS_FIELDS AS F
+ ON I.INDEX_ID = F.INDEX_ID AND I.TABLE_ID = T.TABLE_ID
+ WHERE T.NAME LIKE 'test/t%';
+
+DROP TABLE t0;
+DROP TABLE t1;
+DROP TABLE t2;
+DROP TABLE t3;
+DROP TABLE t4;
diff --git a/mysql-test/suite/gcol/t/main_mysqldump.test b/mysql-test/suite/gcol/t/main_mysqldump.test
new file mode 100644
index 00000000..c2b4efd0
--- /dev/null
+++ b/mysql-test/suite/gcol/t/main_mysqldump.test
@@ -0,0 +1,44 @@
+--source include/have_innodb.inc
+--source include/not_embedded.inc
+
+CREATE DATABASE dump_generated;
+USE dump_generated;
+CREATE TABLE t1 (pk INTEGER, a INTEGER, b INTEGER, c VARCHAR(16),
+ sum INTEGER GENERATED ALWAYS AS (a+b),
+ sub VARCHAR(4) GENERATED ALWAYS AS (SUBSTRING(c, 1, 4)),
+ key k1(sum),
+ key k2(sub)
+) engine=innodb;
+INSERT INTO t1(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
+SELECT * FROM t1;
+--exec $MYSQL_DUMP dump_generated t1 > $MYSQLTEST_VARDIR/tmp/t1.sql
+DELETE FROM t1;
+--exec $MYSQL dump_generated < $MYSQLTEST_VARDIR/tmp/t1.sql
+SELECT * FROM t1;
+--exec $MYSQL_DUMP dump_generated t1 --tab=$MYSQLTEST_VARDIR/tmp/
+DELETE FROM t1;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t1.txt' INTO TABLE t1
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo # A table with regular columns after generated
+CREATE TABLE t2 (pk INTEGER, a INTEGER, b INTEGER,
+ sum INTEGER GENERATED ALWAYS AS (a+b),
+ c VARCHAR(16),
+ key k1(sum)
+) engine=innodb;
+INSERT INTO t2(pk, a, b, c) VALUES (1, 11, 12, 'oneone'), (2, 21, 22, 'twotwo');
+SELECT * FROM t2;
+--exec $MYSQL_DUMP dump_generated t2 > $MYSQLTEST_VARDIR/tmp/t2.sql
+DELETE FROM t2;
+--exec $MYSQL dump_generated < $MYSQLTEST_VARDIR/tmp/t2.sql
+SELECT * FROM t2;
+--exec $MYSQL_DUMP dump_generated t2 --tab=$MYSQLTEST_VARDIR/tmp/
+DELETE FROM t2;
+--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
+--eval LOAD DATA INFILE '$MYSQLTEST_VARDIR/tmp/t2.txt' INTO TABLE t2
+SELECT * FROM t2;
+DROP TABLE t2;
+
+DROP DATABASE dump_generated;
diff --git a/mysql-test/suite/gcol/t/rpl_gcol.test b/mysql-test/suite/gcol/t/rpl_gcol.test
new file mode 100644
index 00000000..6193d944
--- /dev/null
+++ b/mysql-test/suite/gcol/t/rpl_gcol.test
@@ -0,0 +1,65 @@
+################################################################################
+# t/gcol_rpl.test #
+# #
+# Purpose: #
+# Test replication of tables with generated columns. #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-04 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+#
+# NOTE: PLEASE DO NOT ADD NOT MYISAM SPECIFIC TESTCASES HERE !
+# TESTCASES WHICH MUST BE APPLIED TO ALL STORAGE ENGINES MUST BE ADDED IN
+# THE SOURCED FILES ONLY.
+#
+
+#------------------------------------------------------------------------------#
+# General not engine specific settings and requirements
+
+#------------------------------------------------------------------------------#
+# Engine specific settings and requirements
+
+##### Storage engine to be tested
+# Set the session storage engine
+--source include/have_innodb.inc
+SET @@session.default_storage_engine = 'InnoDB';
+
+##### Workarounds for known open engine specific bugs
+# none
+
+#------------------------------------------------------------------------------#
+# Execute the tests to be applied to all storage engines
+--source include/master-slave.inc
+
+connection master;
+create table t1 (a int, b int generated always as (a+1) virtual);
+show create table t1;
+insert into t1 values (1,default);
+insert into t1 values (2,default);
+select * from t1;
+save_master_pos;
+
+connection slave;
+sync_with_master;
+select * from t1;
+
+connection master;
+drop table t1;
+save_master_pos;
+
+connection slave;
+sync_with_master;
+
+#------------------------------------------------------------------------------#
+# Execute storage engine specific tests
+
+
+#------------------------------------------------------------------------------#
+# Cleanup
+--source suite/gcol/inc/gcol_cleanup.inc
+--source include/rpl_end.inc
diff --git a/mysql-test/suite/gcol/t/virtual_index_drop.test b/mysql-test/suite/gcol/t/virtual_index_drop.test
new file mode 100644
index 00000000..0fe4986f
--- /dev/null
+++ b/mysql-test/suite/gcol/t/virtual_index_drop.test
@@ -0,0 +1,74 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+--source include/have_debug_sync.inc
+
+--echo #
+--echo # MDEV-24971 InnoDB access freed virtual column
+--echo # after rollback of secondary index
+--echo #
+
+# Exclusive lock must not defer the index removal
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=EXCLUSIVE;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# If Shared lock and table doesn't have any other open handle
+# then InnoDB must not defer the index removal
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=SHARED;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# InnoDB should store the newly dropped virtual column into
+# new_vcol_info in index when rollback of alter happens
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+SEND ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3);
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+SELECT * FROM t1;
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+--error ER_DUP_ENTRY
+reap;
+connection con1;
+rollback;
+connection default;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+send ALTER TABLE t1 ADD INDEX(f2);
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+--error ER_DUP_ENTRY
+reap;
+connection con1;
+rollback;
+connection default;
+disconnect con1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 CHAR(100), f2 CHAR(100) as (f1) VIRTUAL)ENGINE=InnoDB;
+--error ER_DUP_FIELDNAME
+ALTER TABLE t1 ADD COLUMN f3 CHAR(100) AS (f2) VIRTUAL, ADD INDEX(f3(10), f1, f3(12));
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;