Commit 37bfe32c authored by Sergei Golubchik's avatar Sergei Golubchik

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);
parent ae53f684
...@@ -42,3 +42,16 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp ...@@ -42,3 +42,16 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
# #
# End of 10.2 tests # 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
#
...@@ -49,3 +49,18 @@ create table t1 (a int, b serial as (a+1)); ...@@ -49,3 +49,18 @@ create table t1 (a int, b serial as (a+1));
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --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 #
...@@ -3184,12 +3184,13 @@ class Item_field :public Item_ident, ...@@ -3184,12 +3184,13 @@ class Item_field :public Item_ident,
bool check_vcol_func_processor(void *arg) bool check_vcol_func_processor(void *arg)
{ {
context= 0; context= 0;
uint res= VCOL_FIELD_REF;
if (field && (field->unireg_check == Field::NEXT_NUMBER)) if (field && (field->unireg_check == Field::NEXT_NUMBER))
{ res|= VCOL_AUTO_INC;
// Auto increment fields are unsupported if (field && field->vcol_info &&
return mark_unsupported_function(field_name.str, arg, VCOL_FIELD_REF | VCOL_AUTO_INC); field->vcol_info->flags & (VCOL_NOT_STRICTLY_DETERMINISTIC | VCOL_AUTO_INC))
} res|= VCOL_NON_DETERMINISTIC;
return mark_unsupported_function(field_name.str, arg, VCOL_FIELD_REF); return mark_unsupported_function(field_name.str, arg, res);
} }
bool set_fields_as_dependent_processor(void *arg) bool set_fields_as_dependent_processor(void *arg)
{ {
......
...@@ -3172,11 +3172,18 @@ bool Virtual_column_info::fix_and_check_expr(THD *thd, TABLE *table) ...@@ -3172,11 +3172,18 @@ bool Virtual_column_info::fix_and_check_expr(THD *thd, TABLE *table)
pointer at that time pointer at that time
*/ */
myf warn= table->s->frm_version < FRM_VER_EXPRESSSIONS ? ME_JUST_WARNING : 0; 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); "AUTO_INCREMENT", get_vcol_type_name(), res.name);
if (!warn) if (!warn)
DBUG_RETURN(1); 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; flags= res.errors;
if (!table->s->tmp_table && need_refix()) if (!table->s->tmp_table && need_refix())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment