summaryrefslogtreecommitdiff
path: root/mysql-test/suite/gcol
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2016-11-07 16:48:50 +0100
committerSergei Golubchik <serg@mariadb.org>2016-12-12 20:27:36 +0100
commita418c9920047d5222a0d065343347312127b780f (patch)
treee50f4f15396655ec81dc04b461ec5ffb52ce2410 /mysql-test/suite/gcol
parent4136968ca0910c1e4fc0191a659fbdc113fbf709 (diff)
downloadmariadb-git-a418c9920047d5222a0d065343347312127b780f.tar.gz
gcol mysql-test suite from 5.7
update tests and results, fix bugs
Diffstat (limited to 'mysql-test/suite/gcol')
-rw-r--r--mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc249
-rw-r--r--mysql-test/suite/gcol/inc/gcol_cleanup.inc24
-rw-r--r--mysql-test/suite/gcol/inc/gcol_column_def_options.inc585
-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.inc609
-rw-r--r--mysql-test/suite/gcol/inc/gcol_keys.inc766
-rw-r--r--mysql-test/suite/gcol/inc/gcol_non_stored_columns.inc155
-rw-r--r--mysql-test/suite/gcol/inc/gcol_partition.inc155
-rw-r--r--mysql-test/suite/gcol/inc/gcol_select.inc1163
-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.inc1245
-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.inc223
-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.result179
-rw-r--r--mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result181
-rw-r--r--mysql-test/suite/gcol/r/gcol_bug20746926.result32
-rw-r--r--mysql-test/suite/gcol/r/gcol_bugfixes.result628
-rw-r--r--mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result582
-rw-r--r--mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result582
-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.result602
-rw-r--r--mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result524
-rw-r--r--mysql-test/suite/gcol/r/gcol_keys_innodb.result421
-rw-r--r--mysql-test/suite/gcol/r/gcol_keys_myisam.result421
-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.result95
-rw-r--r--mysql-test/suite/gcol/r/gcol_partition_myisam.result95
-rw-r--r--mysql-test/suite/gcol/r/gcol_rejected_innodb.result8
-rw-r--r--mysql-test/suite/gcol/r/gcol_rollback.result75
-rw-r--r--mysql-test/suite/gcol/r/gcol_select_innodb.result976
-rw-r--r--mysql-test/suite/gcol/r/gcol_select_myisam.result978
-rw-r--r--mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result3000
-rw-r--r--mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result3000
-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.result30
-rw-r--r--mysql-test/suite/gcol/r/gcol_view_innodb.result280
-rw-r--r--mysql-test/suite/gcol/r/gcol_view_myisam.result280
-rw-r--r--mysql-test/suite/gcol/r/rpl_gcol.result33
-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.test601
-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.test47
-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.test46
-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.test46
-rw-r--r--mysql-test/suite/gcol/t/gcol_partition_myisam.test45
-rw-r--r--mysql-test/suite/gcol/t/gcol_rejected_innodb.test41
-rw-r--r--mysql-test/suite/gcol/t/gcol_rollback.test108
-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.test56
-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/rpl_gcol.test65
83 files changed, 21604 insertions, 0 deletions
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 00000000000..b1774490958
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_blocked_sql_funcs_main.inc
@@ -0,0 +1,249 @@
+################################################################################
+# 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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (last_insert_id()) virtual);
+
+--echo # MASTER_POS_WAIT()
+-- error ER_VIRTUAL_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_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32) generated always as (name_const('test',1)) virtual);
+
+--echo # RELEASE_LOCK()
+-- error ER_VIRTUAL_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_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (row_count()) virtual);
+
+--echo # SLEEP()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (sleep(a)) virtual);
+
+--echo # VALUES()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(1024), b varchar(1024) generated always as (values(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_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int generated always as (p1()) virtual);
+-- error ER_VIRTUAL_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_VIRTUAL_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_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (avg(a)) virtual);
+
+--echo # BIT_AND()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_and(a)) virtual);
+
+--echo # BIT_OR()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_or(a)) virtual);
+
+--echo # BIT_XOR()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (bit_xor(a)) virtual);
+
+--echo # COUNT(DISTINCT)
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (count(distinct a)) virtual);
+
+--echo # COUNT()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (count(a)) virtual);
+
+--echo # GROUP_CONCAT()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a varchar(32), b int generated always as (group_concat(a,'')) virtual);
+
+--echo # MAX()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (max(a)) virtual);
+
+--echo # MIN()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (min(a)) virtual);
+
+--echo # STD()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (std(a)) virtual);
+
+--echo # STDDEV_POP()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev_pop(a)) virtual);
+
+--echo # STDDEV_SAMP()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev_samp(a)) virtual);
+
+--echo # STDDEV()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (stddev(a)) virtual);
+
+--echo # SUM()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (sum(a)) virtual);
+
+--echo # VAR_POP()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (var_pop(a)) virtual);
+
+--echo # VAR_SAMP()
+-- error ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED
+create table t1 (a int, b int generated always as (var_samp(a)) virtual);
+
+--echo # VARIANCE()
+-- error ER_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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;
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 00000000000..39f7ff7fcea
--- /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 00000000000..935a20503bf
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_column_def_options.inc
@@ -0,0 +1,585 @@
+################################################################################
+# 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 1064
+create table t1 (a int, b int generated always as (a+1) virtual default 0);
+create table t1 (a int);
+--error 1064
+alter table t1 add column b int generated always as (a+1) virtual default 0;
+drop table t1;
+
+--echo # AUTO_INCREMENT
+--error 1064
+create table t1 (a int, b int generated always as (a+1) virtual AUTO_INCREMENT);
+create table t1 (a int);
+--error 1064
+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);
+create table t1 (a int, b int generated always as (a % 2) stored references t2(a));
+show create table t1;
+drop table t1;
+create table t1 (a int, b int generated always as (a % 2) virtual);
+--error 1064
+alter table t1 modify b int generated always as (a % 2) stored references t2(a);
+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_EXITS
+alter table t1 add constraint foreign key fk(d) references t2(a);
+if ($support_virtual_foreign)
+{
+--replace_regex /`#sql-.*`/`#sql-temporary`/
+--error ER_CANT_CREATE_TABLE
+alter table t1 add constraint foreign key fk(b) references t2(a);
+}
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN
+alter table t1 add constraint foreign key fk(c) references t2(a) on delete set null;
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN
+alter table t1 add constraint foreign key fk(c) references t2(a) on update set null;
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_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_EXPRESSION_REFERS_TO_UNINIT_FIELD
+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);
+
+--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_VIRTUAL_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_VIRTUAL_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 #
+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;
+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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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;
+}
+
+--error ER_PARSE_ERROR
+CREATE TABLE t1 (c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar"));
+CREATE TABLE t1 (i INT);
+--error ER_PARSE_ERROR
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+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)
+{
+
+#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_VIRTUAL_COLUMN
+ALTER TABLE t1 MODIFY COLUMN vgc1 INTEGER AS (col2 * col3) STORED;
+
+# Change stored generated column to become virtual
+--error ER_UNSUPPORTED_ACTION_ON_VIRTUAL_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
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 00000000000..5ef433097d9
--- /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 00000000000..9ac6d5916ca
--- /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 00000000000..951cf5ff0e5
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc
@@ -0,0 +1,609 @@
+################################################################################
+# 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 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 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 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 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;
+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
+
+CREATE TABLE t (
+a BLOB GENERATED ALWAYS AS ('') VIRTUAL,
+b TIMESTAMP(4) GENERATED ALWAYS AS ('') VIRTUAL,
+KEY (a(183),b)
+);
+
+INSERT 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 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;
+
+}
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 00000000000..aaba019ec4c
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_keys.inc
@@ -0,0 +1,766 @@
+################################################################################
+# 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;
+}
+
+--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 1687
+ 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 1687
+ alter table t1 add spatial index (b);
+ drop table t1;
+}
+
+--echo # FOREIGN KEY
+
+--echo # Rejected FK options.
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_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_VIRTUAL_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_VIRTUAL_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_VIRTUAL_COLUMN
+alter table t1 add foreign key (b) references t2(a) on update set null;
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN
+alter table t1 add foreign key (b) references t2(a) on update cascade;
+--error ER_WRONG_FK_OPTION_FOR_VIRTUAL_COLUMN
+alter table t1 add foreign key (b) references t2(a) on delete set null;
+drop table t1;
+
+if($support_virtual_index)
+{
+--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);
+--replace_regex /`#sql-.*`/`#sql-temporary`/
+--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 10 x 11 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), algorithm=inplace;
+DESC t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#21346132: WL8149:INNODB: FAILING ASSERTION:
+--echo # PRIMARY_KEY_NO == -1 || PRIMARY_KEY_NO == 0
+--echo #
+CREATE TABLE t1 (
+ col_int_nokey int(11) NOT NULL,
+ col_int_key int(11) GENERATED ALWAYS AS (col_int_nokey),
+ col_varchar_nokey varchar(1) NOT NULL,
+ col_varchar_key varchar(2) GENERATED ALWAYS AS (col_varchar_nokey),
+ UNIQUE KEY col_int_key (col_int_key),
+ UNIQUE KEY col_varchar_key (col_varchar_key),
+ UNIQUE KEY col_int_key_2 (col_int_key,col_varchar_key),
+ UNIQUE KEY col_varchar_key_2 (col_varchar_key,col_varchar_nokey),
+ KEY col_int_key_3 (col_int_key,col_int_nokey)
+);
+
+ALTER TABLE t1 DROP COLUMN col_varchar_key;
+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 ...
+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");
+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;
+
+--echo #
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 00000000000..bc82512aa21
--- /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_VIRTUAL_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_VIRTUAL_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 00000000000..df199e86c68
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_partition.inc
@@ -0,0 +1,155 @@
+################################################################################
+# 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;
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 00000000000..efaffd5168d
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_select.inc
@@ -0,0 +1,1163 @@
+################################################################################
+# inc/gcol_select.inc #
+# #
+# Purpose: #
+# Testing different SELECTs. #
+# #
+# #
+#------------------------------------------------------------------------------#
+# Original Author: Andrey Zhakov #
+# Original Date: 2008-09-18 #
+# Change Author: #
+# Change Date: #
+# Change: #
+################################################################################
+
+# 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);
+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 10 # 11 #
+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 10 # 11 #
+EXPLAIN SELECT pk FROM cc WHERE col_int_key > 3;
+SELECT pk FROM cc WHERE col_int_key > 3;
+--replace_column 10 # 11 #
+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 10 #
+--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 10 #
+--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 10 #
+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;
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 00000000000..88f2f7c4da1
--- /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 00000000000..88268ddd6c4
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_supported_sql_funcs_main.inc
@@ -0,0 +1,1245 @@
+################################################################################
+# 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: #
+################################################################################
+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 # DES_ENCRYPT(), DES_DECRYPT()
+--source include/have_ssl_crypto_functs.inc
+let $cols = a varchar(1024), b varchar(1024) generated always as (des_encrypt(des_decrypt(a,'adf'),'adf')) virtual;
+let $values1 = 'MySQL',default;
+--disable_warnings
+eval create table t1 ($cols);
+show create table t1;
+--enable_warnings
+eval insert into t1 values ($values1);
+select * from t1;
+drop table t1;
+
+--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 00000000000..b6ba5280216
--- /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 00000000000..c6aed0253f6
--- /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_VIRTUAL_COLUMNS
+create table t1 (a int, b int generated always as (a+1) virtual);
+create table t1 (a int);
+--error ER_UNSUPPORTED_ENGINE_FOR_VIRTUAL_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 00000000000..51cb9b5d725
--- /dev/null
+++ b/mysql-test/suite/gcol/inc/gcol_view.inc
@@ -0,0 +1,223 @@
+################################################################################
+# 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 10 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 10 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 10 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 10 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 10 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 10 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 10 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;
+
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 00000000000..9c8de3987f0
--- /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 00000000000..0d8072943b7
--- /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 computed 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 computed 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 00000000000..2d448566114
--- /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 computed 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 computed 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 00000000000..27270654e9b
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_innodb.result
@@ -0,0 +1,179 @@
+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 (values(a)) virtual);
+ERROR HY000: Function or expression 'values()' 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 'std()' 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;
+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 00000000000..24fd3b988c2
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_blocked_sql_funcs_myisam.result
@@ -0,0 +1,181 @@
+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 (values(a)) virtual);
+ERROR HY000: Function or expression 'values()' 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 'std()' 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;
+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 00000000000..74fe76b3f1a
--- /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 Incorrect datetime value: '0'
+show warnings;
+Level Code Message
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 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 Incorrect datetime value: '0'
+show warnings;
+Level Code Message
+Warning 1265 Data truncated for column 'a' at row 1
+Warning 1292 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 00000000000..3ee376bd146
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_bugfixes.result
@@ -0,0 +1,628 @@
+# 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 /*! NULL */,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+col_date_nokey DATE /*! NULL */,
+col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+PRIMARY KEY (pk),
+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 /*! 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:
+Warning 1048 Column 'col_varchar_key' cannot be null
+CREATE TABLE bb (
+pk INTEGER AUTO_INCREMENT,
+col_int_nokey INTEGER /*! NULL */,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+col_date_nokey DATE /*! NULL */,
+col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+PRIMARY KEY (pk),
+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)
+) 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 /*! NULL */,
+col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+col_date_nokey DATE /*! NULL */,
+col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+col_datetime_nokey DATETIME /*! NULL */,
+col_time_nokey TIME /*! NULL */,
+col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+col_varchar_nokey VARCHAR(1) /*! NULL */,
+col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+PRIMARY KEY (pk),
+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)
+) 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:
+Warning 1048 Column 'col_int_key' cannot be null
+Warning 1048 Column 'col_datetime_key' cannot be null
+Warning 1048 Column 'col_time_key' cannot be null
+EXPLAIN SELECT
+gp1 . col_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . col_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . col_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . col_int_key = p2 . pk )
+)
+AND gp1 . col_varchar_nokey = 'b'
+HAVING g1 > 6;
+id select_type table partitions type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE gp1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where
+1 SIMPLE p1 NULL const col_varchar_key,col_varchar_key_2 col_varchar_key 4 const 1 100.00 NULL
+1 SIMPLE p2 NULL eq_ref PRIMARY PRIMARY 4 test.p1.col_int_key 1 100.00 Using index; FirstMatch(gp1)
+1 SIMPLE gp2 NULL index NULL col_datetime_key 5 NULL 2 100.00 Using where; Using index; Using join buffer (Block Nested Loop)
+Warnings:
+Warning 1292 Incorrect datetime value: '6' for column 'col_datetime_key' at row 1
+Note 1003 /* select#1 */ select `test`.`gp1`.`col_datetime_key` AS `g1` from `test`.`cc` `gp1` semi join (`test`.`bb` `p1` left join `test`.`bb` `p2` on((`test`.`p1`.`col_int_key` = `test`.`p2`.`pk`))) left join `test`.`c` `gp2` on((`test`.`gp2`.`col_datetime_key` <> `test`.`gp1`.`col_time_nokey`)) where ((`test`.`gp1`.`col_varchar_nokey` = 'b') and ('b' = `test`.`p1`.`col_varchar_key`)) having (`g1` > 6)
+SELECT
+gp1 . col_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . col_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . col_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . col_int_key = p2 . pk )
+)
+AND gp1 . col_varchar_nokey = 'b'
+HAVING g1 > 6;
+g1
+Warnings:
+Warning 1292 Incorrect datetime value: '6' for column 'col_datetime_key' at row 1
+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 not null,
+col_date_nokey DATE NOT NULL,
+col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+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 not null,
+col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL 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 not null,
+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;
+Table Op Msg_type Msg_text
+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 partitions type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE c NULL index_merge PRIMARY,col_varchar_key,col_int_key_2,col_varchar_key_2,col_int_key_7 col_varchar_key,PRIMARY 4,4 NULL 2 100.00 Using sort_union(col_varchar_key,PRIMARY); Using where
+Warnings:
+Note 1003 /* select#1 */ select count(distinct `test`.`c`.`col_varchar_key`) AS `x` from `test`.`c` where ((`test`.`c`.`col_varchar_key` in ('rr','rr')) or ((`test`.`c`.`col_int_nokey` <> 9) and (`test`.`c`.`pk` >= 8))) having (`x` > '2000-02-06')
+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 DOUBLE 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 /*! NULL */,
+col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+col_blob_nokey BLOB /*! NULL */,
+col_blob_key BLOB GENERATED ALWAYS AS (REPEAT(col_blob_nokey,15)) VIRTUAL,
+col_longblob_nokey LONGBLOB /*! NULL */,
+col_longtext_nokey LONGTEXT /*! NULL */,
+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 /*! NULL */,
+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: Invalid use of group function
+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 OK
+# Make sure the index is correct. That's kinda important.
+EXPLAIN
+SELECT c FROM t1;
+id select_type table partitions type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 NULL index NULL c 5 NULL 5 100.00 Using index
+Warnings:
+Note 1003 /* select#1 */ select `test`.`t1`.`c` AS `c` from `test`.`t1`
+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 partitions type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
+3 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+2 SUBQUERY t NULL ALL NULL NULL NULL NULL 1 100.00 NULL
+Warnings:
+Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t` where 0
+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 partitions type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
+Warnings:
+Note 1003 /* select#1 */ select (/* select#2 */ select max(`test`.`v`.`c`) from `test`.`v`) AS `(SELECT MAX(c) FROM v)`
+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);
+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:01
+00:00:00
+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 #21808680: JSON + GENERATED COLUMN CORRUPTS TABLE CACHE
+# MEMORY, CRASHES
+#
+CREATE TABLE t (a INT, b JSON, c TEXT GENERATED ALWAYS AS (REPEAT(a=b, 2)));
+INSERT INTO t (a, b) VALUES (1, '2'), (3, '3');
+SELECT * FROM t;
+a b c
+1 2 00
+3 3 11
+DROP TABLE t;
+#
+# 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 HY000: Expression of generated column 'c' contains a disallowed function.
+DROP TABLE t;
+CREATE TABLE t(b BLOB, c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL);
+ERROR HY000: Expression of generated column 'c' contains a disallowed function.
+#
+# 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` or `b`)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+INSERT INTO t1 (a,b) VALUES('1','1');
+SELECT * FROM t1;
+a b c
+1 1 1
+SET SQL_MODE=PIPES_AS_CONCAT;
+Warnings:
+Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
+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=InnoDB DEFAULT CHARSET=latin1
+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="";
+Warnings:
+Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
+CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
+ERROR 22007: Truncated incorrect INTEGER value: 'a'
+CREATE TABLE t (a INTEGER) engine=innodb;
+ALTER TABLE t ADD b INTEGER AS (SUBSTR('','a',1));
+ERROR 22007: Truncated incorrect INTEGER value: 'a'
+DROP TABLE t;
+set sql_mode= @save_old_sql_mode;
+Warnings:
+Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
+# 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;
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 00000000000..e750bf01d7d
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_column_def_options_innodb.result
@@ -0,0 +1,582 @@
+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: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+alter table t1 add column (d int, e int generated always as (a+1) virtual);
+affected rows: 0
+info: Records: 0 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) 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) 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) 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
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t2;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) PERSISTENT
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL PERSISTENT
+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));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) PERSISTENT
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 computed 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 computed 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 computed 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) AS (a % 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) PERSISTENT
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL PERSISTENT
+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) AS (a % 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (5 * 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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 refering 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 refering 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 01000: Expression for field `col_int_nokey` is refering to uninitialized field `pk`
+# 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#20769299: INCORRECT KEY ERROR WHEN TRYING TO CREATE INDEX ON
+# VIRTUAL GC FOR MYISAM
+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));
+ERROR HY000: Key/Index cannot be defined on a non-stored computed column
+# 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 refering 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) AS (a + 1) VIRTUAL,
+ `c` varchar(12) AS ("aaaabb") PERSISTENT,
+ `d` blob AS (c) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a + 1) VIRTUAL,
+ `c` varchar(12) AS ("aaaabb") PERSISTENT,
+ `d` blob AS (c) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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
+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
+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
+#
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5 AS c2;
+Warnings:
+Warning 1906 The value specified for computed column 'c2' in table 't1' ignored
+CREATE TABLE t2 (a int);
+INSERT INTO t2 values(1);
+DROP TABLE t1;
+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 computed column 'c2' in table 't1' 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#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"));
+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 ("foo bar"))' at line 1
+CREATE TABLE t1 (i INT);
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+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 ("foo bar")' at line 1
+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: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t ADD d int, ADD f char(10) AS ('aaa');
+affected rows: 0
+info: Records: 0 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: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t CHANGE b b int(11) after c;
+affected rows: 0
+info: Records: 0 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
+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 sgc1 (sgc1);
+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 110 0
+2 20 200 NULL 220 0
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+0
+0
+ALTER TABLE t1 DROP INDEX sgc1;
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD UNIQUE INDEX sgc1 (sgc1);
+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 computed columns
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR HY000: This is not yet supported for computed 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#22680839: DEFAULT IS NOT DETERMINISTIC AND SHOULD NOT BE
+# ALLOWED IN GENERATED COLUMNS
+#
+# 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: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 MODIFY COLUMN a INT DEFAULT 8;
+affected rows: 0
+info: Records: 0 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: 0
+info: Records: 0 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;
+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 00000000000..dff8208591d
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_column_def_options_myisam.result
@@ -0,0 +1,582 @@
+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) 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) 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) 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
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) VIRTUAL COMMENT 'my comment'
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t2;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) PERSISTENT
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL PERSISTENT
+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));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) PERSISTENT
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 computed 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 computed 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 computed 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) AS (a % 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (a % 2) PERSISTENT
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL PERSISTENT
+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) AS (a % 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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) AS (5 * 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES NULL VIRTUAL
+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 refering 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 refering 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 01000: Expression for field `col_int_nokey` is refering to uninitialized field `pk`
+# 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#20769299: INCORRECT KEY ERROR WHEN TRYING TO CREATE INDEX ON
+# VIRTUAL GC FOR MYISAM
+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));
+ERROR HY000: Key/Index cannot be defined on a non-stored computed column
+# 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 refering 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) AS (a + 1) VIRTUAL,
+ `c` varchar(12) AS ("aaaabb") PERSISTENT,
+ `d` blob AS (c) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a + 1) VIRTUAL,
+ `c` varchar(12) AS ("aaaabb") PERSISTENT,
+ `d` blob AS (c) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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
+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
+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
+#
+CREATE TABLE t1 (c1 INT, c2 INT AS (c1 * 2)) SELECT 1 AS c1, 5 AS c2;
+Warnings:
+Warning 1906 The value specified for computed column 'c2' in table 't1' ignored
+CREATE TABLE t2 (a int);
+INSERT INTO t2 values(1);
+DROP TABLE t1;
+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 computed column 'c2' in table 't1' 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#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"));
+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 ("foo bar"))' at line 1
+CREATE TABLE t1 (i INT);
+ALTER TABLE t1 ADD COLUMN c CHAR(10) CHARACTER SET utf8 COLLATE utf8_bin GENERATED ALWAYS AS ("foo bar");
+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 ("foo bar")' at line 1
+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
+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 sgc1 (sgc1);
+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 110 0
+2 20 200 NULL 220 0
+SELECT sgc1 FROM t1 order by sgc1;
+sgc1
+0
+0
+ALTER TABLE t1 DROP INDEX sgc1;
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 - col3) STORED;
+ALTER TABLE t1 ADD UNIQUE INDEX sgc1 (sgc1);
+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 computed columns
+ALTER TABLE t1 MODIFY COLUMN sgc1 INTEGER AS (col2 / col3) VIRTUAL;
+ERROR HY000: This is not yet supported for computed 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#22680839: DEFAULT IS NOT DETERMINISTIC AND SHOULD NOT BE
+# ALLOWED IN GENERATED COLUMNS
+#
+# 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: 0
+info: Records: 0 Duplicates: 0 Warnings: 0
+ALTER TABLE t1 MODIFY COLUMN a INT DEFAULT 8;
+affected rows: 0
+info: Records: 0 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;
+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 00000000000..20708586d51
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_csv.result
@@ -0,0 +1,14 @@
+SET @@session.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 00000000000..2eb558e6b69
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_falcon.result
@@ -0,0 +1,14 @@
+SET @@session.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 00000000000..6de4c2ae61d
--- /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 00000000000..3b03fd37cc0
--- /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 00000000000..924b8b8d7d9
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result
@@ -0,0 +1,602 @@
+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 into t1 values (1,2,3);
+Warnings:
+Warning 1906 The value specified for computed column 'b' in table 't1' ignored
+Warning 1906 The value specified for computed column 'c' in table 't1' 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 into t1 (a,b) values (1,3), (2,4);
+Warnings:
+Warning 1906 The value specified for computed column 'b' in table 't1' ignored
+Warning 1906 The value specified for computed column 'b' in table 't1' 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 t1 set c=3 where a=2;
+Warnings:
+Warning 1906 The value specified for computed column 'c' in table 't1' 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 t1 set c=3 where b=-2;
+Warnings:
+Warning 1906 The value specified for computed column 'c' in table 't1' 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#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;
+# 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;
+#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;
+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 00000000000..a7db5508384
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_ins_upd_myisam.result
@@ -0,0 +1,524 @@
+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 into t1 values (1,2,3);
+Warnings:
+Warning 1906 The value specified for computed column 'b' in table 't1' ignored
+Warning 1906 The value specified for computed column 'c' in table 't1' 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 into t1 (a,b) values (1,3), (2,4);
+Warnings:
+Warning 1906 The value specified for computed column 'b' in table 't1' ignored
+Warning 1906 The value specified for computed column 'b' in table 't1' 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 t1 set c=3 where a=2;
+Warnings:
+Warning 1906 The value specified for computed column 'c' in table 't1' 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 t1 set c=3 where b=-2;
+Warnings:
+Warning 1906 The value specified for computed column 'c' in table 't1' 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#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;
+# 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;
+#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;
+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 00000000000..ff3e7970f29
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_keys_innodb.result
@@ -0,0 +1,421 @@
+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) stored unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a*2) PERSISTENT,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL PERSISTENT
+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) AS (a*2) PERSISTENT,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL PERSISTENT
+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) stored, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a*2) PERSISTENT,
+ KEY `b` (`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL PERSISTENT
+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) AS (a*2) PERSISTENT,
+ KEY `a` (`a`,`b`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES MUL NULL
+b int(11) YES NULL PERSISTENT
+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 computed 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 computed 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 computed 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 computed 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 computed 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 computed 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;
+
+# 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 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 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 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#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 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 OK
+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;
+#
+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 00000000000..f6a4ffe6c60
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_keys_myisam.result
@@ -0,0 +1,421 @@
+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) stored unique);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a*2) PERSISTENT,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL PERSISTENT
+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) AS (a*2) PERSISTENT,
+ UNIQUE KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES UNI NULL PERSISTENT
+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) stored, index (b));
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a*2) PERSISTENT,
+ KEY `b` (`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES NULL
+b int(11) YES MUL NULL PERSISTENT
+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) AS (a*2) PERSISTENT,
+ KEY `a` (`a`,`b`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+describe t1;
+Field Type Null Key Default Extra
+a int(11) YES MUL NULL
+b int(11) YES NULL PERSISTENT
+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 computed 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 computed 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 computed 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 computed 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 computed 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 computed 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;
+
+# 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 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 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 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#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 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 OK
+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;
+#
+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 00000000000..7ede64807f0
--- /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 computed 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 computed 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 00000000000..5a9f3ad8770
--- /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 computed 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 00000000000..4c1c2a446e9
--- /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 00000000000..aed3fbc8e0b
--- /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 computed columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) PERSISTENT
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 computed columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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
+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
+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) AS (dayofyear(b)) VIRTUAL,
+ `b` datetime DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (dayofyear(b)) PERSISTENT,
+ `b` datetime DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (week(b,1)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 00000000000..2ebe751009c
--- /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 computed columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) PERSISTENT
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 computed columns
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) AS (a % 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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
+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
+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) AS (dayofyear(b)) VIRTUAL,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (dayofyear(b)) PERSISTENT,
+ `b` datetime DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (week(b,1)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 00000000000..9a0e676e76f
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_partition_innodb.result
@@ -0,0 +1,95 @@
+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;
+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 00000000000..81324da6fcd
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_partition_myisam.result
@@ -0,0 +1,95 @@
+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;
+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_rejected_innodb.result b/mysql-test/suite/gcol/r/gcol_rejected_innodb.result
new file mode 100644
index 00000000000..b8d0db567ca
--- /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 00000000000..006c8408a84
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_rollback.result
@@ -0,0 +1,75 @@
+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);
+# Kill and 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
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+ALTER TABLE t ADD KEY(b(57)), ALGORITHM=INPLACE;
+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';
+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
+SET DEBUG_SYNC = 'row_log_apply_after SIGNAL created WAIT_FOR dml_done';
+ALTER TABLE t DROP COLUMN c, ALGORITHM=INPLACE;
+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';
+SELECT * FROM t;
+a b d
+9 10 29
+DROP TABLE t;
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 00000000000..e815cfcbe8e
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_select_innodb.result
@@ -0,0 +1,976 @@
+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);
+analyze table t1,t2,t3;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+test.t2 analyze status OK
+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 t3 index c c 5 NULL 3 Using index
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+# 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 index c c 5 NULL 3 Using where; Using index
+1 PRIMARY t1 ALL c NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+# 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 (scanning)
+###
+### 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 3 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 3 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 3 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 3 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 DOUBLE value: 'c'
+Warning 1292 Truncated incorrect DOUBLE value: 't'
+Warning 1292 Truncated incorrect DOUBLE value: 'm'
+Warning 1292 Truncated incorrect DOUBLE 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;
+Warnings:
+Warning 1264 Out of range value for column 'c' at row 1
+ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL;
+Warnings:
+Warning 1264 Out of range value for column 'c' at row 1
+SELECT * FROM t1;
+a c
+2147483647 127
+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;
+Warnings:
+Warning 1264 Out of range value for column 'f' at row 1
+ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=EXCLUSIVE;
+Warnings:
+Warning 1264 Out of range value for column 'f' at row 1
+Warning 1264 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
+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 OK
+test.t2 analyze status OK
+test.t3 analyze status OK
+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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 00000000000..5a2af800a91
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_select_myisam.result
@@ -0,0 +1,978 @@
+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);
+analyze table t1,t2,t3;
+Table Op Msg_type Msg_text
+test.t1 analyze status OK
+test.t2 analyze status OK
+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 2 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 t3 index c c 5 NULL 3 Using index
+1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join)
+# 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 index c c 5 NULL 3 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 (scanning)
+###
+### 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 1 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 3 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 1 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 1 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 3 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 1 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 3 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 1 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 3 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 1 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;
+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 DOUBLE value: 'c'
+Warning 1292 Truncated incorrect DOUBLE value: 't'
+Warning 1292 Truncated incorrect DOUBLE value: 'm'
+Warning 1292 Truncated incorrect DOUBLE 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;
+Warnings:
+Warning 1264 Out of range value for column 'b' at row 1
+ALTER TABLE t1 DROP COLUMN b;
+ALTER TABLE t1 ADD COLUMN c SMALLINT AS (a) VIRTUAL;
+Warnings:
+Warning 1264 Out of range value for column 'c' at row 1
+ALTER TABLE t1 DROP COLUMN c;
+ALTER TABLE t1 ADD COLUMN d SMALLINT AS (a) VIRTUAL;
+Warnings:
+Warning 1264 Out of range value for column 'd' at row 1
+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;
+Warnings:
+Warning 1264 Out of range value for column 'c' at row 1
+ALTER TABLE t1 MODIFY c TINYINT AS(a) VIRTUAL;
+Warnings:
+Warning 1264 Out of range value for column 'c' at row 1
+SELECT * FROM t1;
+a c
+2147483647 127
+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;
+Warnings:
+Warning 1264 Out of range value for column 'f' at row 1
+ALTER TABLE t1 ADD COLUMN g SMALLINT AS (a) VIRTUAL, ALGORITHM=COPY, LOCK=EXCLUSIVE;
+Warnings:
+Warning 1264 Out of range value for column 'f' at row 1
+Warning 1264 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 DOUBLE 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 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 19 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 OK
+test.t2 analyze status OK
+test.t3 analyze status OK
+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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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 <subquery2> ALL distinct_key NULL NULL NULL 3
+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 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_supported_sql_funcs_innodb.result b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result
new file mode 100644
index 00000000000..72021909e0f
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_innodb.result
@@ -0,0 +1,3000 @@
+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) AS (abs(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(acos(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(asin(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(atan(a,b),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(atan(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(atan2(a,b),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ceil(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (conv(a,b,c)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(cos(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(cot(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (crc32(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(degrees(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (a/2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(exp(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (floor(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(ln(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+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 AS (format(log(a,b),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (2,65536,default);
+insert into t1 values (10,100,default);
+insert into t1 values (1,100,default);
+select * from t1;
+a b c
+1 100 NULL
+10 100 2
+2 65536 16
+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 AS (format(log(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+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 AS (format(log2(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (65536,default);
+insert into t1 values (-100,default);
+select * from t1;
+a b
+-100 NULL
+65536 16
+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 AS (format(log10(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (100,default);
+insert into t1 values (-100,default);
+select * from t1;
+a b
+-100 NULL
+100 2
+2 0.30103
+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 AS (a-1) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (mod(a,10)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a % 10) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (oct(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(PI()*a*a,6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a+1) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (pow(a,2)) VIRTUAL,
+ `c` int(11) AS (power(a,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(radians(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (round(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (round(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (sign(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(sin(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(sqrt(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (format(tan(a),6)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (a*3) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (truncate(a,4)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (-a) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ascii(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (bin(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (bit_length(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (char_length(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (char(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (character_length(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (concat_ws(',',a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (concat(a,',',b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (elt(c,a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (export_set(a,'1','0','',10)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (field('aa',a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (find_in_set(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (format(a,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (hex(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (hex(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (insert(a,length(a),length(b),b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (instr(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (lcase(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (left(a,5)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (length(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a like 'H%o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (locate('bar',a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (lower(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (lpad(a,4,' ')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ltrim(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (make_set(c,a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (mid(a,1,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a not like 'H%o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a not regexp 'H.+o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (octet_length(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ord(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (position('bar' in a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (quote(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a regexp 'H.+o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (repeat(a,3)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (replace(a,'aa','bb')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (reverse(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (right(a,4)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a rlike 'H.+o') VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (rpad(a,4,'??')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (rtrim(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (soundex(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a sounds like b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (concat(a,space(5))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (strcmp(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (substr(a,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (substring_index(a,'.',2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (substring(a from 2 for 2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (trim(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ucase(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (unhex(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (upper(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (weight_string(a as char(4))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (case a when NULL then 'asd' when 'b' then 'B' else a end) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (if(a=1,a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ifnull(a,'DEFAULT')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (nullif(a,'DEFAULT')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a>0 && a<2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a between 0 and 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (binary a) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a & 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (~a) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a | 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a ^ 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a div 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a <=> b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a=b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a >= b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a > b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a is not null) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a is null) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a << 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a <= b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a < b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a not between 0 and 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a <> b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a != b) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a>5 || a<3) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a >> 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (a xor 5) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (adddate(a,interval 1 month)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (addtime(a,'02:00:00')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (convert_tz(a,'MET','UTC')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (date_add(a,interval 1 month)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (date_format(a,'%W %M %D')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (date_sub(a,interval 1 month)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (date(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (datediff(a,'2000-01-01')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (day(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (dayname(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (dayofmonth(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (dayofweek(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (dayofyear(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (extract(year from a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (from_days(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (from_unixtime(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (date_format(a,get_format(DATE,'EUR'))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (hour(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (last_day(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values ('2003-02-05',default);
+insert into t1 values ('2003-02-32',default);
+Warnings:
+Warning 1265 Data truncated for column 'a' at row 1
+select * from t1;
+a b
+0000-00-00 00:00:00 NULL
+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 AS (makedate(a,1)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (maketime(a,1,3)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (microsecond(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (minute(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (month(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (monthname(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (period_add(a,2)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (period_diff(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (quarter(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (sec_to_time(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (second(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (str_to_date(a,'%m/%d/%Y')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (subdate(a,interval 1 month)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (subtime(a,'02:00:00')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (time_format(a,'%r')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (time_to_sec(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (time(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (timediff(a,b)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (timestamp(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (timestampadd(minute,1,a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `c` bigint(20) AS (timestampdiff(MONTH, a, a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (to_days(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (week(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (weekday(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (weekofyear(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (year(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (yearweek(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (cast(a as unsigned)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 AS (convert(a,unsigned)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ExtractValue(a,'/b')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (aes_encrypt(aes_decrypt(a,'adf'),'adf')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (bit_count(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (charset(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (coercibility(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (collation(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (uncompress(compress(a))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (decode(encode(a,'abc'),'abc')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (ifnull(a,default(a))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values ('any value',default);
+select * from t1;
+a b
+any value any value
+drop table t1;
+set sql_warnings = 0;
+# DES_ENCRYPT(), DES_DECRYPT()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (des_encrypt(des_decrypt(a,'adf'),'adf')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) AS (des_encrypt(des_decrypt(a,'adf'),'adf')) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL ÿw2¥ð
+èõÁ
+drop table t1;
+# 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) AS (inet_ntoa(inet_aton(a))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (md5(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (password(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (sha1(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (sha(a)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (sha2(a,224)) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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) AS (uncompressed_length(compress(repeat(a,30)))) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+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 00000000000..add3a6a3fe0
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_supported_sql_funcs_myisam.result
@@ -0,0 +1,3000 @@
+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) AS (abs(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(acos(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(asin(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(atan(a,b),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(atan(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(atan2(a,b),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ceil(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (conv(a,b,c)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(cos(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(cot(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (crc32(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(degrees(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (a/2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(exp(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (floor(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(ln(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+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 AS (format(log(a,b),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values (2,65536,default);
+insert into t1 values (10,100,default);
+insert into t1 values (1,100,default);
+select * from t1;
+a b c
+1 100 NULL
+10 100 2
+2 65536 16
+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 AS (format(log(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (-2,default);
+select * from t1;
+a b
+-2 NULL
+2 0.693147
+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 AS (format(log2(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values (65536,default);
+insert into t1 values (-100,default);
+select * from t1;
+a b
+-100 NULL
+65536 16
+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 AS (format(log10(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values (2,default);
+insert into t1 values (100,default);
+insert into t1 values (-100,default);
+select * from t1;
+a b
+-100 NULL
+100 2
+2 0.30103
+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 AS (a-1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (mod(a,10)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a % 10) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (oct(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(PI()*a*a,6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a+1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (pow(a,2)) VIRTUAL,
+ `c` int(11) AS (power(a,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(radians(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (round(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (round(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (sign(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(sin(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(sqrt(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (format(tan(a),6)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (a*3) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (truncate(a,4)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (-a) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ascii(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (bin(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (bit_length(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (char_length(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (char(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (character_length(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (concat_ws(',',a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (concat(a,',',b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (elt(c,a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (export_set(a,'1','0','',10)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (field('aa',a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (find_in_set(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (format(a,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (hex(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (hex(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (insert(a,length(a),length(b),b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (instr(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (lcase(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (left(a,5)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (length(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a like 'H%o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (locate('bar',a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (lower(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (lpad(a,4,' ')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ltrim(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (make_set(c,a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (mid(a,1,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a not like 'H%o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a not regexp 'H.+o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (octet_length(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ord(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (position('bar' in a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (quote(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a regexp 'H.+o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (repeat(a,3)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (replace(a,'aa','bb')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (reverse(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (right(a,4)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a rlike 'H.+o') VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (rpad(a,4,'??')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (rtrim(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (soundex(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a sounds like b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (concat(a,space(5))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (strcmp(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (substr(a,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (substring_index(a,'.',2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (substring(a from 2 for 2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (trim(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ucase(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (unhex(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (upper(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (weight_string(a as char(4))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (case a when NULL then 'asd' when 'b' then 'B' else a end) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (if(a=1,a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ifnull(a,'DEFAULT')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (nullif(a,'DEFAULT')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a>0 && a<2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a between 0 and 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (binary a) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a & 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (~a) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a | 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a ^ 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a div 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a <=> b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a=b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a >= b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a > b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a is not null) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a is null) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a << 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a <= b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a < b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a not between 0 and 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a <> b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a != b) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a>5 || a<3) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a >> 2) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (a xor 5) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (adddate(a,interval 1 month)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (addtime(a,'02:00:00')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (convert_tz(a,'MET','UTC')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (date_add(a,interval 1 month)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (date_format(a,'%W %M %D')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (date_sub(a,interval 1 month)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (date(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (datediff(a,'2000-01-01')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (day(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (dayname(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (dayofmonth(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (dayofweek(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (dayofyear(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (extract(year from a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (from_days(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (from_unixtime(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (date_format(a,get_format(DATE,'EUR'))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (hour(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (last_day(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values ('2003-02-05',default);
+insert into t1 values ('2003-02-32',default);
+Warnings:
+Warning 1265 Data truncated for column 'a' at row 1
+select * from t1;
+a b
+0000-00-00 00:00:00 NULL
+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 AS (makedate(a,1)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (maketime(a,1,3)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (microsecond(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (minute(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (month(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (monthname(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (period_add(a,2)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (period_diff(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (quarter(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (sec_to_time(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (second(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (str_to_date(a,'%m/%d/%Y')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (subdate(a,interval 1 month)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (subtime(a,'02:00:00')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (time_format(a,'%r')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (time_to_sec(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (time(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (timediff(a,b)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (timestamp(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (timestampadd(minute,1,a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `c` bigint(20) AS (timestampdiff(MONTH, a, a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (to_days(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (week(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (weekday(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (weekofyear(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (year(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (yearweek(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (cast(a as unsigned)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 AS (convert(a,unsigned)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ExtractValue(a,'/b')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (aes_encrypt(aes_decrypt(a,'adf'),'adf')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (bit_count(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (charset(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (coercibility(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (collation(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (uncompress(compress(a))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (decode(encode(a,'abc'),'abc')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (ifnull(a,default(a))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values ('any value',default);
+select * from t1;
+a b
+any value any value
+drop table t1;
+set sql_warnings = 0;
+# DES_ENCRYPT(), DES_DECRYPT()
+create table t1 (a varchar(1024), b varchar(1024) generated always as (des_encrypt(des_decrypt(a,'adf'),'adf')) virtual);
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` varchar(1024) DEFAULT NULL,
+ `b` varchar(1024) AS (des_encrypt(des_decrypt(a,'adf'),'adf')) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+insert into t1 values ('MySQL',default);
+select * from t1;
+a b
+MySQL ÿw2¥ð
+èõÁ
+drop table t1;
+# 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) AS (inet_ntoa(inet_aton(a))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (md5(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (password(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (sha1(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (sha(a)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (sha2(a,224)) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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) AS (uncompressed_length(compress(repeat(a,30)))) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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 00000000000..60dce012b78
--- /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 00000000000..a5e3bda2a0e
--- /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 00000000000..380d1c1efef
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_update.result
@@ -0,0 +1,30 @@
+set global innodb_purge_stop_now = 1;
+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;
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+set global innodb_purge_stop_now = 1;
+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;
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+set global innodb_purge_stop_now = 1;
+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;
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+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 00000000000..ec82c792493
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_view_innodb.result
@@ -0,0 +1,280 @@
+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 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 5 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 5 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 5 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 5 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 6 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 6 X
+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 6 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 6 X
+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 2 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 4 X
+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 2 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 4 X
+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;
+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 00000000000..13cb74ebcb5
--- /dev/null
+++ b/mysql-test/suite/gcol/r/gcol_view_myisam.result
@@ -0,0 +1,280 @@
+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 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 5 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 5 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 5 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 5 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 6 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 6 X
+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 6 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 6 X
+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 2 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 4 X
+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 2 X
+2 DERIVED t1 ALL NULL NULL NULL NULL 4 X
+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;
+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/rpl_gcol.result b/mysql-test/suite/gcol/r/rpl_gcol.result
new file mode 100644
index 00000000000..245ce3ba2e5
--- /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) AS (a+1) VIRTUAL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+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/t/gcol_archive.test b/mysql-test/suite/gcol/t/gcol_archive.test
new file mode 100644
index 00000000000..6dce34e1d6e
--- /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 00000000000..bf0d3fb3022
--- /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 00000000000..a1024b33ad6
--- /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 00000000000..0f967ee85d0
--- /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 00000000000..8028823f9a7
--- /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 00000000000..8c084d0b54a
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_bugfixes.test
@@ -0,0 +1,601 @@
+################################################################################
+# 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 /*! NULL */,
+ col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+
+ col_date_nokey DATE /*! NULL */,
+ col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+
+ col_datetime_nokey DATETIME /*! NULL */,
+ col_time_nokey TIME /*! NULL */,
+
+ col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+ col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+
+ col_varchar_nokey VARCHAR(1) /*! NULL */,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+
+ PRIMARY KEY (pk),
+ 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 /*! 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 /*! NULL */,
+ col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+
+ col_date_nokey DATE /*! NULL */,
+ col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+
+ col_datetime_nokey DATETIME /*! NULL */,
+ col_time_nokey TIME /*! NULL */,
+
+ col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+ col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+
+ col_varchar_nokey VARCHAR(1) /*! NULL */,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+
+ PRIMARY KEY (pk),
+ 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)
+ ) 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 /*! NULL */,
+ col_int_key INTEGER GENERATED ALWAYS AS
+(col_int_nokey + col_int_nokey) VIRTUAL not null,
+
+ col_date_nokey DATE /*! NULL */,
+ col_date_key DATE GENERATED ALWAYS AS
+(DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+
+ col_datetime_nokey DATETIME /*! NULL */,
+ col_time_nokey TIME /*! NULL */,
+
+ col_datetime_key DATETIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+ col_time_key TIME GENERATED ALWAYS AS
+(ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL not null,
+
+ col_varchar_nokey VARCHAR(1) /*! NULL */,
+ col_varchar_key VARCHAR(2) GENERATED ALWAYS AS
+(CONCAT(col_varchar_nokey, col_varchar_nokey)) VIRTUAL not null,
+
+ PRIMARY KEY (pk),
+ 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)
+ ) 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 . col_datetime_key AS g1
+FROM cc AS gp1 LEFT JOIN c AS gp2 ON ( gp2 . col_datetime_key <> gp1 .
+col_time_nokey )
+WHERE
+gp1 . col_varchar_nokey IN
+(
+SELECT
+DISTINCT p1 . col_varchar_key AS p1
+FROM bb AS p1 LEFT JOIN bb AS p2
+ON ( p1 . col_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 not null,
+ col_date_nokey DATE NOT NULL,
+ col_date_key DATE GENERATED ALWAYS AS (DATE_ADD(col_date_nokey,interval 30 day)) VIRTUAL not null,
+ 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 not null,
+ col_time_key TIME GENERATED ALWAYS AS (ADDTIME(col_datetime_nokey, col_time_nokey)) VIRTUAL 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 not null,
+ 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 /*! NULL */,
+ col_int_key INTEGER GENERATED ALWAYS AS (col_int_nokey + col_int_nokey) VIRTUAL,
+ col_blob_nokey BLOB /*! NULL */,
+ col_blob_key BLOB GENERATED ALWAYS AS (REPEAT(col_blob_nokey,15)) VIRTUAL,
+ col_longblob_nokey LONGBLOB /*! NULL */,
+ col_longtext_nokey LONGTEXT /*! NULL */,
+ 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 /*! NULL */,
+ 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 1111
+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 #21808680: JSON + GENERATED COLUMN CORRUPTS TABLE CACHE
+--echo # MEMORY, CRASHES
+--echo #
+CREATE TABLE t (a INT, b JSON, c TEXT GENERATED ALWAYS AS (REPEAT(a=b, 2)));
+INSERT INTO t (a, b) VALUES (1, '2'), (3, '3');
+# The next statement used to crash.
+SELECT * FROM t;
+DROP TABLE t;
+
+--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_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+ALTER TABLE t ADD COLUMN c INT GENERATED ALWAYS AS ((1,1)) VIRTUAL;
+DROP TABLE t;
+--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
+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="";
+
+--error ER_TRUNCATED_WRONG_VALUE
+CREATE TABLE t (a INTEGER AS (SUBSTR('','a',1))) engine=innodb;
+
+CREATE TABLE t (a INTEGER) engine=innodb;
+
+--error ER_TRUNCATED_WRONG_VALUE
+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;
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 00000000000..285974d1ccc
--- /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= 0;
+--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 00000000000..4f91b0021bc
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_column_def_options_myisam.test
@@ -0,0 +1,47 @@
+################################################################################
+# 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= 0;
+let $support_virtual_foreign= 0;
+--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 00000000000..50f72135497
--- /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 00000000000..219235478a7
--- /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 00000000000..23d97a797e0
--- /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= 0;
+--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 00000000000..168321caab9
--- /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= 0;
+--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 00000000000..3fe1ee4ff61
--- /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= 0;
+--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 00000000000..bbe27b90c7e
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_keys_myisam.test
@@ -0,0 +1,46 @@
+################################################################################
+# 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= 0;
+--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 00000000000..a7d9235da02
--- /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 00000000000..fd90da42328
--- /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_VIRTUAL_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 00000000000..ed0d255bfd8
--- /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 00000000000..9784071e126
--- /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 00000000000..06e6ccc1ba4
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_partition_innodb.test
@@ -0,0 +1,46 @@
+################################################################################
+# 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
+
+#------------------------------------------------------------------------------#
+# 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 00000000000..0a0cd9f9e86
--- /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_rejected_innodb.test b/mysql-test/suite/gcol/t/gcol_rejected_innodb.test
new file mode 100644
index 00000000000..1780fdf8c19
--- /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 00000000000..5109012b2e2
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_rollback.test
@@ -0,0 +1,108 @@
+--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
+
+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);
+--source include/kill_and_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;
+disconnect con1;
+connection default;
+
+SELECT * FROM t;
+
+DROP TABLE t;
+
+# Wait till all disconnects are completed
+--source include/wait_until_count_sessions.inc
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 00000000000..18c170413a0
--- /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 00000000000..bb2b46a4fa3
--- /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= 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_supported_sql_funcs_innodb.test b/mysql-test/suite/gcol/t/gcol_supported_sql_funcs_innodb.test
new file mode 100644
index 00000000000..2e91093681c
--- /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 00000000000..a9dee4c76b0
--- /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 00000000000..4478cbe23fe
--- /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 00000000000..1a39d921c11
--- /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 00000000000..0a7265bebac
--- /dev/null
+++ b/mysql-test/suite/gcol/t/gcol_update.test
@@ -0,0 +1,56 @@
+--source include/have_debug.inc
+--source include/have_innodb.inc
+# The embedded server does not support restarting.
+--source include/not_embedded.inc
+
+set global innodb_purge_stop_now = 1;
+
+# 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;
+
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+set global innodb_purge_stop_now = 1;
+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;
+
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+set global innodb_purge_stop_now = 1;
+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;
+
+set global innodb_purge_run_now=1;
+set global innodb_fast_shutdown=0;
+--source include/restart_mysqld.inc
+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 00000000000..06ded123776
--- /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 00000000000..3779f0bb045
--- /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/rpl_gcol.test b/mysql-test/suite/gcol/t/rpl_gcol.test
new file mode 100644
index 00000000000..6193d944101
--- /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