Commit eaa87eb8 authored by Sergei Golubchik's avatar Sergei Golubchik

allow random_bytes() in virtual columns

parent ffc08863
...@@ -257,9 +257,13 @@ drop table t1; ...@@ -257,9 +257,13 @@ drop table t1;
--echo # --echo #
create table t1 (a int); create table t1 (a int);
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED insert t1 values (1);
alter table t1 add column b binary(32) generated always as (random_bytes(a)); alter table t1 add column b binary(32) generated always as (random_bytes(a));
alter table t1 add column b binary(32) default (random_bytes(a)); select a,length(b) from t1;
--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
alter table t1 add index (b);
alter table t1 add column c binary(32) default (random_bytes(a));
select a,length(b),length(c) from t1;
drop table t1; drop table t1;
--echo # --echo #
......
...@@ -177,9 +177,17 @@ drop table t1; ...@@ -177,9 +177,17 @@ drop table t1;
# MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column # MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column
# #
create table t1 (a int); create table t1 (a int);
insert t1 values (1);
alter table t1 add column b binary(32) generated always as (random_bytes(a)); alter table t1 add column b binary(32) generated always as (random_bytes(a));
select a,length(b) from t1;
a length(b)
1 32
alter table t1 add index (b);
ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b`
alter table t1 add column b binary(32) default (random_bytes(a)); alter table t1 add column c binary(32) default (random_bytes(a));
select a,length(b),length(c) from t1;
a length(b) length(c)
1 32 32
drop table t1; drop table t1;
# #
# #
......
...@@ -179,9 +179,17 @@ drop table t1; ...@@ -179,9 +179,17 @@ drop table t1;
# MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column # MDEV-29029 Index corruption and/or assertion failure upon using RANDOM_BYTES for indexed virtual column
# #
create table t1 (a int); create table t1 (a int);
insert t1 values (1);
alter table t1 add column b binary(32) generated always as (random_bytes(a)); alter table t1 add column b binary(32) generated always as (random_bytes(a));
select a,length(b) from t1;
a length(b)
1 32
alter table t1 add index (b);
ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'random_bytes()' cannot be used in the GENERATED ALWAYS AS clause of `b`
alter table t1 add column b binary(32) default (random_bytes(a)); alter table t1 add column c binary(32) default (random_bytes(a));
select a,length(b),length(c) from t1;
a length(b) length(c)
1 32 32
drop table t1; drop table t1;
# #
# #
......
...@@ -423,8 +423,7 @@ class Item_func_random_bytes : public Item_str_func ...@@ -423,8 +423,7 @@ class Item_func_random_bytes : public Item_str_func
} }
bool check_vcol_func_processor(void *arg) override bool check_vcol_func_processor(void *arg) override
{ {
return mark_unsupported_function(func_name(), "()", arg, return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC);
VCOL_NON_DETERMINISTIC | VCOL_NEXTVAL);
} }
Item *get_copy(THD *thd) override Item *get_copy(THD *thd) override
{ {
......
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