1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-28 17:36:30 +03:00
Files
mariadb/mysql-test/suite/vcol/t/vcol_syntax.test
Aleksey Midenkov 42f8548ff6 MDEV-25091 CREATE TABLE: field references qualified by a wrong table name succeed
Before FRM is written walk vcol expressions through
check_table_name_processor() and check if field items match (db,
table_name) qualifier.

We cannot do this in check_vcol_func_processor() as there is already
no table name qualifiers in expressions of written and loaded FRM.
2021-04-23 15:20:35 +03:00

75 lines
2.3 KiB
Plaintext

#
# test syntax
#
--disable_warnings
drop table if exists t1;
--enable_warnings
set @OLD_SQL_MODE=@@SESSION.SQL_MODE;
create table t1 (a int, b int generated always as (a+1));
show create table t1;
drop table t1;
create table t1 (a int, b int as (a+1) virtual);
show create table t1;
drop table t1;
create table t1 (a int, b int generated always as (a+1) persistent);
show create table t1;
drop table t1;
set session sql_mode='ORACLE';
create table t1 (a int, b int as (a+1));
show create table t1;
drop table t1;
create table t1 (a int, b int generated always as (a+1) virtual);
show create table t1;
drop table t1;
create table t1 (a int, b int as (a+1) persistent);
show create table t1;
drop table t1;
set session sql_mode=@OLD_SQL_MODE;
--echo #
--echo # MDEV-25091 CREATE TABLE: field references qualified by a wrong table name succeed
--echo #
create table t2 (x int);
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int generated always as (t2.x));
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int check (y > t2.x));
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int default t2.x);
--error ER_BAD_FIELD_ERROR
create table t1 (x int, check (t2.x > 0));
create table t1 (x int);
--error ER_BAD_FIELD_ERROR
alter table t1 add column y int generated always as (t2.x);
--error ER_BAD_FIELD_ERROR
alter table t1 add column y int check (z > t2.x);
--error ER_BAD_FIELD_ERROR
alter table t1 add column y int default t2.x;
--error ER_BAD_FIELD_ERROR
alter table t1 add constraint check (t2.x > 0);
create or replace table t1 (x int, y int generated always as (t1.x));
create or replace table t1 (x int, y int check (y > t1.x));
create or replace table t1 (x int, y int default t1.x);
create or replace table t1 (x int, check (t1.x > 0));
create or replace table t1 (x int, y int generated always as (test.t1.x));
create or replace table t1 (x int, y int check (y > test.t1.x));
create or replace table t1 (x int, y int default test.t1.x);
create or replace table t1 (x int, check (test.t1.x > 0));
drop tables t1, t2;
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int generated always as (test2.t1.x));
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int check (y > test2.t1.x));
--error ER_BAD_FIELD_ERROR
create table t1 (x int, y int default test2.t1.x);
--error ER_BAD_FIELD_ERROR
create table t1 (x int, check (test2.t1.x > 0));