diff options
author | Sergei Golubchik <serg@mariadb.org> | 2022-11-27 00:03:04 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2022-12-02 16:19:13 +0100 |
commit | 37bfe32c6d4a65ea7b8297817e01954d6212c863 (patch) | |
tree | 12df8926b405b350e5c72b470216f2aedad03d3b | |
parent | ae53f684d3d02c1ef342891087fa0326b601c2fd (diff) | |
download | mariadb-git-37bfe32c6d4a65ea7b8297817e01954d6212c863.tar.gz |
try harder to reject not strictly deterministic vcols in indexes/stored
detect non-determinism in vcol of vcol, like:
create table t1 (a int, b real as (rand()), c real as (b) stored);
-rw-r--r-- | mysql-test/suite/vcol/r/not_supported.result | 13 | ||||
-rw-r--r-- | mysql-test/suite/vcol/t/not_supported.test | 15 | ||||
-rw-r--r-- | sql/item.h | 11 | ||||
-rw-r--r-- | sql/table.cc | 9 |
4 files changed, 42 insertions, 6 deletions
diff --git a/mysql-test/suite/vcol/r/not_supported.result b/mysql-test/suite/vcol/r/not_supported.result index d8703f755da..37ce4865dcc 100644 --- a/mysql-test/suite/vcol/r/not_supported.result +++ b/mysql-test/suite/vcol/r/not_supported.result @@ -42,3 +42,16 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp # # End of 10.2 tests # +create table t1 (a int, b real as (rand()), c real as (b) stored); +ERROR HY000: Function or expression 'b' cannot be used in the GENERATED ALWAYS AS clause of `c` +create table t1 (a int, b real as (rand()), c real as (b) unique); +ERROR HY000: Function or expression 'b' cannot be used in the GENERATED ALWAYS AS clause of `c` +create table t1 (a int auto_increment primary key, +b int as (a+1), c int as (b+1) stored); +ERROR HY000: Function or expression 'b' cannot be used in the GENERATED ALWAYS AS clause of `c` +create table t1 (a int auto_increment primary key, +b int as (a+1), c int as (b+1) unique); +ERROR HY000: Function or expression 'b' cannot be used in the GENERATED ALWAYS AS clause of `c` +# +# End of 10.3 tests +# diff --git a/mysql-test/suite/vcol/t/not_supported.test b/mysql-test/suite/vcol/t/not_supported.test index 2b5baf4ff4b..d58b207a7eb 100644 --- a/mysql-test/suite/vcol/t/not_supported.test +++ b/mysql-test/suite/vcol/t/not_supported.test @@ -49,3 +49,18 @@ create table t1 (a int, b serial as (a+1)); --echo # --echo # End of 10.2 tests --echo # + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int, b real as (rand()), c real as (b) stored); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int, b real as (rand()), c real as (b) unique); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int auto_increment primary key, + b int as (a+1), c int as (b+1) stored); +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +create table t1 (a int auto_increment primary key, + b int as (a+1), c int as (b+1) unique); + +--echo # +--echo # End of 10.3 tests +--echo # diff --git a/sql/item.h b/sql/item.h index 07fbe848bb7..ec87a3fb812 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3184,12 +3184,13 @@ public: bool check_vcol_func_processor(void *arg) { context= 0; + uint res= VCOL_FIELD_REF; if (field && (field->unireg_check == Field::NEXT_NUMBER)) - { - // Auto increment fields are unsupported - return mark_unsupported_function(field_name.str, arg, VCOL_FIELD_REF | VCOL_AUTO_INC); - } - return mark_unsupported_function(field_name.str, arg, VCOL_FIELD_REF); + res|= VCOL_AUTO_INC; + if (field && field->vcol_info && + field->vcol_info->flags & (VCOL_NOT_STRICTLY_DETERMINISTIC | VCOL_AUTO_INC)) + res|= VCOL_NON_DETERMINISTIC; + return mark_unsupported_function(field_name.str, arg, res); } bool set_fields_as_dependent_processor(void *arg) { diff --git a/sql/table.cc b/sql/table.cc index b2d8c4676e6..ec49241dd7a 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3172,11 +3172,18 @@ bool Virtual_column_info::fix_and_check_expr(THD *thd, TABLE *table) pointer at that time */ myf warn= table->s->frm_version < FRM_VER_EXPRESSSIONS ? ME_JUST_WARNING : 0; - my_error(ER_VIRTUAL_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(warn), + my_error(ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(warn), "AUTO_INCREMENT", get_vcol_type_name(), res.name); if (!warn) DBUG_RETURN(1); } + else if (vcol_type != VCOL_GENERATED_VIRTUAL && vcol_type != VCOL_DEFAULT && + res.errors & VCOL_NOT_STRICTLY_DETERMINISTIC) + { + my_error(ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED, MYF(0), + res.name, get_vcol_type_name(), name.str); + DBUG_RETURN(1); + } flags= res.errors; if (!table->s->tmp_table && need_refix()) |