github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/ddl/create_table_as_select.sql (about)

     1  create database test;
     2  use test;
     3  
     4  create table t1(a int default 123, b char(5));
     5  desc t1;
     6  INSERT INTO t1 values (1, '1');
     7  INSERT INTO t1 values (2, '2');
     8  INSERT INTO t1 values (0x7fffffff, 'max');
     9  select * from t1;
    10  
    11  CREATE table t2 (c float) as select b, a from t1;
    12  desc t2;
    13  select * from t2;
    14  
    15  CREATE table if not exists t2 (d float) as select b, a from t1;
    16  desc t2;
    17  
    18  CREATE table t3 (a bigint unsigned not null auto_increment primary key, c float) as select a, b from t1;
    19  desc t3;
    20  select * from t3;
    21  
    22  CREATE table t4 (a tinyint) as select * from t1;
    23  
    24  CREATE table t5 (a char(10)) as select * from t1;
    25  desc t5;
    26  select * from t5;
    27  
    28  insert into t1 values (1, '1_1');
    29  select * from t1;
    30  CREATE table t6 (a int unique) as select * from t1;
    31  drop table t6;
    32  
    33  CREATE table t6 as select max(a) from t1;
    34  desc t6;
    35  select * from t6;
    36  
    37  CREATE table t7 as select * from (select * from t1) as t;
    38  desc t7;
    39  select * from t7;
    40  
    41  CREATE table t8 as select a as alias_a, 1 from t1;
    42  desc t8;
    43  select * from t8;
    44  
    45  CREATE table t9 (index (a)) as select * from t1;
    46  desc t9;
    47  select * from t9;
    48  
    49  drop table t1;
    50  drop table t2;
    51  drop table t3;
    52  drop table t5;
    53  drop table t6;
    54  drop table t7;
    55  drop table t8;
    56  drop table t9;
    57  
    58  -- the columns of the original table cover all data types
    59  drop table if exists table01;
    60  create table table01(a int default 123, b char(5));
    61  desc table01;
    62  insert into table01 values (1, '1');
    63  insert into table01 values (2, '2');
    64  insert into table01 values (0x7fffffff, 'max');
    65  select * from table01;
    66  
    67  drop table if exists table02;
    68  create table table02 (c float) as select b, a from table01;
    69  desc table02;
    70  select * from table02;
    71  
    72  drop table if exists table02;
    73  create table table02 (d float) as select b, a from table01;
    74  desc table02;
    75  select * from table02;
    76  drop table table01;
    77  drop table table02;
    78  
    79  drop table if exists table03;
    80  create table table03(col1 int, col2 char, col3 varchar(10), col4 text, col5 tinyint unsigned, col6 bigint, col7 decimal, col8 float, col9 double);
    81  insert into table03 values (1, 'a', 'database', 'cover all data types', 12, 372743927942, 3232.000, -1489.1231, 72392342);
    82  insert into table03 values (2, 'b', 'table', 'database management system', 1, 324214, 0.0001, 32932.000, -321342.0);
    83  insert into table03 values (null, null, null, null, null, null, null, null, null);
    84  select * from table03;
    85  
    86  drop table if exists table04;
    87  create table table04 as select * from table03;
    88  -- @bvt:issue#14792
    89  show create table table04;
    90  -- @bvt:issue
    91  select * from table04;
    92  
    93  drop table if exists table05;
    94  create table table05 as select col1, col3, col5, col7 from table03;
    95  show create table table05;
    96  select * from table05;
    97  
    98  drop table if exists table06;
    99  create table table06(col10 binary) as select col2, col4, col6, col8, col9 from table03;
   100  -- @bvt:issue#14792
   101  show create table table06;
   102  -- @bvt:issue
   103  desc table06;
   104  select * from table06;
   105  
   106  drop table table03;
   107  drop table table04;
   108  drop table table05;
   109  drop table table06;
   110  
   111  drop table if exists t1;
   112  create table t1(a int default 123, b char(5));
   113  desc t1;
   114  INSERT INTO t1 values (1, '1');
   115  INSERT INTO t1 values (2, '2');
   116  INSERT INTO t1 values (0x7fffffff, 'max');
   117  select * from t1;
   118  
   119  create table t2 (c float) as select b, a from t1;
   120  desc t2;
   121  select * from t2;
   122  -- @bvt:issue#14775
   123  CREATE table if not exists t2 (d float) as select b, a from t1;
   124  -- @bvt:issue
   125  select * from t2;
   126  drop table t1;
   127  drop table t2;
   128  
   129  drop table if exists table07;
   130  create table table07(col1 date, col2 datetime, col3 timestamp, col4 blob, col5 json);
   131  insert into table07 values ('2020-10-11', '2023-11-11 10:00:01', '1997-01-13 12:12:12.000', 'abcdef', '{"x": 17, "x": "red"}');
   132  insert into table07 values ('1919-12-01', '1990-10-10 01:01:01', '2001-12-12 01:01:01.000', 'xxxx', '{"t1": "a"}');
   133  insert into table07 values (null, null, null, null, null);
   134  select * from table07;
   135  
   136  drop table if exists table08;
   137  create table table08(col6 int, col7 bigint, col8 char) as select * from table07;
   138  -- @bvt:issue#14792
   139  show create table table08;
   140  -- @bvt:issue
   141  select * from table08;
   142  drop table table08;
   143  
   144  drop table if exists table09;
   145  create table table09 as select col1, col2, col4 as newCol4 from table07;
   146  -- @bvt:issue#14792
   147  show create table table09;
   148  -- @bvt:issue
   149  select * from table09;
   150  drop table table09;
   151  
   152  -- column duplication
   153  drop table if exists table12;
   154  create table table12 (col1 date) as select * from table07;
   155  -- @bvt:issue#14792
   156  show create table table12;
   157  -- @bvt:issue
   158  select * from table12;
   159  drop table table12;
   160  drop table table07;
   161  
   162  -- create table as select distinct
   163  drop table if exists distinct01;
   164  create table distinct01 (
   165      id int,
   166      first_name varchar(50),
   167      last_name varchar(50),
   168      course varchar(100)
   169  );
   170  
   171  insert into distinct01 (id, first_name, last_name, course)  values
   172  (1, 'John', 'Doe', 'Computer Science'),
   173  (2, 'Jane', 'Smith', 'Mathematics'),
   174  (3, 'Alice', 'Johnson', 'Computer Science'),
   175  (4, 'Bob', 'Brown', 'Physics'),
   176  (5, 'Charlie', 'Doe', 'Computer Science'),
   177  (5, 'Charlie', 'Doe', 'Computer Science');
   178  
   179  drop table if exists unique_courses;
   180  create table unique_courses as select distinct course from distinct01;
   181  show create table unique_courses;
   182  select * from unique_courses;
   183  
   184  drop table if exists unique_courses;
   185  create table unique_courses as select distinct * from distinct01;
   186  show create table unique_courses;
   187  select * from unique_courses;
   188  drop table unique_courses;
   189  
   190  -- columns that can be casted to each other (float -> double, double -> float)
   191  drop table if exists cast01;
   192  create table cast01 (col1 float, col2 double);
   193  insert into cast01 values (2617481243.2114, 372534.4353);
   194  insert into cast01 values (-3628742.3223252, 0);
   195  insert into cast01 values (null, null);
   196  select * from cast01;
   197  
   198  drop table if exists cast02;
   199  create table cast02(col1 double, col2 float) select * from cast01;
   200  show create table cast02;
   201  select * from cast02;
   202  drop table cast01;
   203  drop table cast02;
   204  
   205  -- columns that can be casted to each other (value -> char)
   206  drop table if exists cast03;
   207  create table cast03 (col1 int, col2 float, col3 double);
   208  insert into cast03 values (321424, 213412.23142, -100.313);
   209  insert into cast03 values (-1241, 2314321, 0);
   210  insert into cast03 values (0, 0, 0);
   211  select * from cast03;
   212  
   213  drop table if exists cast04;
   214  create table cast04(col1 char(10), col2 char(10), col3 char(10)) as select * from cast03;
   215  -- @bvt:issue#14475
   216  select * from cast04;
   217  -- @bvt:issue
   218  drop table cast03;
   219  drop table cast04;
   220  
   221  -- columns that can be casted to each other (character type in numeric format -> numeric type)
   222  drop table if exists cast05;
   223  create table cast05 (col1 char, col2 varchar(10));
   224  insert into cast05 values ('9', '-32824');
   225  insert into cast05 values ('0', '32422');
   226  insert into cast05 values (null, null);
   227  select * from cast05;
   228  
   229  drop table if exists cast06;
   230  create table cast06(col1 int, col2 bigint) as select * from cast05;
   231  select * from cast06;
   232  show create table cast06;
   233  drop table cast05;
   234  drop table cast06;
   235  
   236  -- columns that can be casted to each other (time -> int)
   237  drop table if exists time01;
   238  create table time01 (col1 date, col2 datetime, col3 timestamp, col4 time);
   239  insert into time01 values ('2020-01-01', '2020-12-12 00:00:01', '1997-01-01 10:10:10.000', '12:12:12');
   240  insert into time01 values ('1996-12-11', '1989-12-09 00:01:01', '2000-05-06 01:01:01.000', '00:01:01');
   241  insert into time01 values (null, null, null, null);
   242  select * from time01;
   243  
   244  drop table if exists time02;
   245  create table time02 (col1 int, col2 int, col4 int) as select * from time01;
   246  show create table time02;
   247  select * from time02;
   248  drop table time02;
   249  
   250  -- columns that can be casted to each other (time -> decimal)
   251  drop table if exists time03;
   252  create table time03 (col2 decimal(38, 0), col4 decimal) as select col2, col3, col4 from time01;
   253  show create table time03;
   254  select * from time03;
   255  drop table time03;
   256  
   257  -- the columns of a table have constraints
   258  drop table if exists table01;
   259  create table table01 (col1 int primary key , col2 char default 'c', col3 decimal not null);
   260  insert into table01 values (1, 'a', 3728.424);
   261  insert into table01 values (3131, 'b', -32832.43);
   262  insert into table01 values (-1, '' , 0);
   263  select * from table01;
   264  
   265  drop table if exists table02;
   266  create table table02 as select * from table01;
   267  show create table table02;
   268  desc table02;
   269  select * from table02;
   270  drop table table01;
   271  drop table table02;
   272  
   273  drop table if exists table04;
   274  drop table if exists table03;
   275  create table table03 (a int primary key, b varchar(5) unique key);
   276  create table table04 (a int ,b varchar(5), c int, foreign key(c) references table03(a));
   277  insert into table03 values (101,'abc'),(102,'def');
   278  insert into table04 values (1,'zs1',101),(2,'zs2',102);
   279  
   280  drop table if exists table05;
   281  create table table05 as select * from table04;
   282  show create table table05;
   283  select * from table05;
   284  drop table if exists table06;
   285  create table table06 (d char not null default 'a') as select a from table03;
   286  -- @bvt:issue#14792
   287  show create table table06;
   288  -- @bvt:issue
   289  select * from table06;
   290  drop table table04;
   291  drop table table03;
   292  drop table table05;
   293  drop table table06;
   294  
   295  -- ctas combines with aggr functions
   296  drop table if exists math01;
   297  create table math01 (col1 int default 0, col2 decimal, col3 float, col4 double not null);
   298  insert into math01 values (1, 7382.4324, 432453.3243, -2930.321323);
   299  insert into math01 values (-100, 3283.32324, 328932.0, -9392032);
   300  insert into math01 values (22813, -241, 932342.4324, -0.1);
   301  insert into math01 values (null, null, null, 10);
   302  
   303  drop table if exists agg01;
   304  -- @bvt:issue#14792
   305  create table agg01 as select avg(col1) as avgCol, sum(col2) as sumcol, count(col3) as countCol, max(col4) as maxCol, min(col4) as minCol from math01;
   306  show create table agg01;
   307  select * from agg01;
   308  drop table agg01;
   309  -- @bvt:issue
   310  
   311  drop table if exists bit01;
   312  create table bit01 (col1 char(1), col2 int);
   313  insert into bit01 values ('a',111),('a',110),('a',100),('a',000),('b',001),('b',011);
   314  select * from bit01;
   315  
   316  drop table if exists bit02;
   317  create table bit02 as select bit_and(col2), bit_or(col2), bit_xor(col2), stddev_pop(col2) from bit01;
   318  -- @bvt:issue#14792
   319  desc bit02;
   320  show create table bit02;
   321  -- @bvt:issue
   322  select count(*) from bit02;
   323  select * from bit02;
   324  drop table bit02;
   325  drop table bit01;
   326  
   327  -- ctas combines with math functions
   328  drop table if exists math01;
   329  create table math01 (col1 int, col2 decimal, col3 bigint, col4 double, col5 float);
   330  insert into math01 values (1, 10.50, 1234567890, 123.45, 678.90),
   331                              (2, 20.75, 9876543210, 234.56, 789.01),
   332                              (3, 30.10, 1122334455, 345.67, 890.12),
   333                              (4, 40.25, 2233445566, 456.78, 901.23),
   334                              (5, 50.40, -3344556677, 567.89, 101.24),
   335                              (6, 60.55, -4455667788, 678.90, 112.35),
   336                              (7, 70.70, 5566778899, 789.01, 123.46),
   337                              (8, 80.85, -6677889900, 890.12, 134.57),
   338                              (9, 90.00, 7788990011, 901.23, 145.68),
   339                              (10, 100.00, 8899001122, 101.24, 156.79);
   340  drop table if exists math02;
   341  create table math02 as select abs(col3), sin(col1), cos(col2), tan(col1), round(col4) from math01;
   342  select * from math02;
   343  drop table if exists math03;
   344  create table math03 as select cot(col1), atan(col1), sinh(col1), floor(col5) from math01;
   345  select * from math02;
   346  drop table if exists math04;
   347  create table math04 as select ceil(col4), power(col5, 2), pi() * col1, log(col2), ln(col2), exp(col1) from math01;
   348  select * from math04;
   349  
   350  drop table math01;
   351  drop table math02;
   352  drop table math03;
   353  drop table math04;
   354  
   355  -- ctas combines with string functions
   356  drop table if exists string01;
   357  create table string01 (col1 varchar(40), col2 char, col3 text default null);
   358  insert into string01 values ('  database system', '2', '云原生数据库');
   359  insert into string01 values (' string function ', '1', '字符串函数');
   360  insert into string01 values ('test create table as select', '0', null);
   361  
   362  drop table if exists string02;
   363  create table string02 as select concat_ws(',', col1, 'abcde') from string01;
   364  -- @bvt:issue#14792
   365  show create table string02;
   366  -- @bvt:issue
   367  select * from string02;
   368  drop table string02;
   369  
   370  drop table if exists string03;
   371  create table string03 as select find_in_set(col2, col1) from string01;
   372  -- @bvt:issue#14792
   373  show create table string03;
   374  -- @bvt:issue
   375  select * from string03;
   376  drop table string03;
   377  
   378  drop table if exists string04;
   379  create table string04 as select oct(col2), empty(col3), length(col1) from string01;
   380  -- @bvt:issue#14792
   381  show create table string04;
   382  -- @bvt:issue
   383  select * from string04;
   384  drop table string04;
   385  
   386  drop table if exists string05;
   387  create table string05 as select trim(col1), ltrim(col1), rtrim(col1) from string01;
   388  show create table string05;
   389  select * from string05;
   390  drop table string05;
   391  
   392  drop table if exists string06;
   393  create table string06 as select lpad(col1, 5, '-'), rpad(col1, 1, '-') from string01;
   394  -- @bvt:issue#14792
   395  show create table string06;
   396  -- @bvt:issue
   397  select * from string06;
   398  drop table string06;
   399  
   400  drop table if exists string07;
   401  create table string07 as select startswith(col1, ' '), endswith(col1, ' ') from string01;
   402  show create table string07;
   403  select * from string07;
   404  drop table string07;
   405  
   406  drop table if exists string08;
   407  create table string08 as select hex(col2) from string01;
   408  show create table string08;
   409  select * from string08;
   410  drop table string08;
   411  
   412  drop table if exists string09;
   413  create table string09 as select substring(col1, 3, 4), reverse(col2) from string01;
   414  show create table string09;
   415  select * from string09;
   416  drop table string09;
   417  
   418  drop table if exists string10;
   419  create table string10 (col1 bigint);
   420  insert into string10 values (2319318313), (null);
   421  drop table if exists string11;
   422  create table string11 as select bin(col1) from string10;
   423  show create table string11;
   424  select * from string11;
   425  drop table string10;
   426  drop table string11;
   427  
   428  drop table if exists string12;
   429  drop table string12;
   430  create table string12 (col1 varchar(100) not null, col2 date not null);
   431  insert into string12 values ('   Deepak Sharma', '2014-12-01'  ), ('   Ankana Jana', '2018-08-17'),('  Shreya Ghosh', '2020-09-10');
   432  select * from string12;
   433  drop table if exists string13;
   434  create table string13 as select * from string12 where col1 = space(5);
   435  show create table string13;
   436  select * from string13;
   437  drop table string12;
   438  drop table string13;
   439  drop table string01;
   440  
   441  -- ctas combines with time functions
   442  drop table if exists time01;
   443  create table time01(col1 date, col2 datetime, col3 timestamp, col4 time);
   444  insert into time01 values ('2020-10-11', '2023-11-11 10:00:01', '1997-01-13 12:12:12.000', '12:12:12');
   445  insert into time01 values ('1919-12-01', '1990-10-10 01:01:01', '2001-12-12 01:01:01.000', '10:59:59');
   446  insert into time01 values (null, null, null, null);
   447  select * from time01;
   448  
   449  drop table if exists time02;
   450  create table time02 as select date_format(col2, '%W %M %Y') from time01;
   451  -- @bvt:issue#14792
   452  show create table time02;
   453  desc time02;
   454  -- @bvt:issue
   455  select * from time02;
   456  drop table time02;
   457  
   458  drop table if exists time03;
   459  create table time03 as select date(col1), date(col2), year(col1), day(col1), weekday(col1), dayofyear(col1) as dya from time01;
   460  -- @bvt:issue#14792
   461  desc time03;
   462  show create table time03;
   463  -- @bvt:issue
   464  select * from time03;
   465  drop table time03;
   466  
   467  drop table if exists time04;
   468  create table time04 as select date_add(col2, interval 45 day), date_sub(col2, interval 5 day) from time01;
   469  show create table time04;
   470  select * from time04;
   471  drop table time04;
   472  
   473  -- @bvt:issue#14804
   474  drop table if exists time05;
   475  create table time05 as select unix_timestamp(col1) from time01;
   476  show create table time05;
   477  select * from time05;
   478  drop table time05;
   479  -- @bvt:issue
   480  
   481  drop table if exists time06;
   482  create table time06 as select datediff('2007-12-31 23:59:59', col1) as timedifferent from time01;
   483  -- @bvt:issue#14792
   484  show create table time06;
   485  -- @bvt:issue
   486  select * from time06;
   487  drop table time06;
   488  
   489  drop table if exists time07;
   490  create table time07 as select timediff("22:22:22", col4) as timedifferent from time01;
   491  show create table time07;
   492  select * from time07;
   493  drop table time07;
   494  
   495  drop table if exists test01;
   496  create table test01 as select col1 from time01 order by col1 nulls first;
   497  select * from test01;
   498  drop table test01;
   499  
   500  drop table if exists test02;
   501  create table test02 as select * from time01 order by col2 desc nulls first;
   502  select * from test02;
   503  drop table test02;
   504  
   505  drop table if exists test03;
   506  create table test03 as select * from time01 order by col2 desc nulls last;
   507  select * from test03;
   508  drop table test03;
   509  
   510  drop table if exists test04;
   511  create table test04 as select col1 from time01 order by col1 nulls first;
   512  select * from test04;
   513  drop table test04;
   514  
   515  insert into time01 values ('2014-10-11', '2021-11-11 10:00:01', '1989-01-13 12:12:12.000', '12:11:12');
   516  insert into time01 values ('2014-12-11', '2021-01-11 10:00:02', '1981-02-13 12:12:12.000', '14:12:12');
   517  insert into time01 values ('2015-10-11', '2021-11-11 10:00:03', '1982-01-13 12:12:12.000', '15:12:12');
   518  insert into time01 values ('2016-10-11', '2021-11-11 10:00:04', '1983-01-13 12:12:12.000', '16:12:12');
   519  insert into time01 values ('2017-10-11', '2021-11-11 10:00:05', '1984-01-13 12:12:12.000', '17:12:12');
   520  insert into time01 values ('2018-10-11', '2021-11-11 10:00:06', '1985-01-13 12:12:12.000', '18:12:12');
   521  insert into time01 values ('2019-10-11', '2021-11-11 10:00:07', '1986-01-13 12:12:12.000', '19:12:12');
   522  insert into time01 values ('2010-10-11', '2021-11-11 10:00:08', '1987-01-13 12:12:12.000', '20:12:12');
   523  insert into time01 values ('2033-10-11', '2021-11-11 10:00:09', '1988-01-13 12:12:12.000', '21:12:12');
   524  insert into time01 values ('2014-10-12', '2021-11-11 10:00:20', '1989-02-13 12:12:12.000', '22:12:12');
   525  
   526  drop table if exists new_table;
   527  create table new_table as
   528  select *
   529  from time01
   530  order by col1
   531  limit 5
   532  offset 10;
   533  select * from new_table;
   534  drop table new_table;
   535  
   536  drop table if exists new_table01;
   537  create table new_table01 as
   538  select col2, col3
   539  from time01
   540  order by col1 desc
   541  limit 100
   542  offset 10;
   543  select * from new_table01;
   544  drop table new_table01;
   545  drop table time01;
   546  
   547  -- cras combines with group by ... having, order by
   548  drop table if exists orders;
   549  create table orders (order_id int primary key , customer_id int, order_date date, total_amount decimal);
   550  insert into orders values (1, 101, '2023-01-01', 100.00),
   551                            (2, 101, '2023-01-05', 150.00),
   552                            (3, 102, '2023-01-02', 200.00),
   553                            (4, 103, '2023-01-03', 50.00),
   554                            (5, 101, '2023-01-04', 75.00),
   555                            (6, 104, '2023-01-06', 300.00),
   556                            (7, 104, '2023-01-07', 200.00),
   557                            (8, 105, '2023-01-08', 100.00);
   558  select * from orders;
   559  
   560  drop table if exists customer_totals;
   561  create table customer_totals as select customer_id, count(order_id) as total_orders, sum(total_amount) as total_amount from orders group by customer_id having count(order_id) > 1 and sum(total_amount) > 150.0;
   562  -- @bvt:issue#14792
   563  show create table customer_totals;
   564  -- @bvt:issue
   565  select * from customer_totals;
   566  
   567  drop table if exists max_totals;
   568  create table max_totals as select customer_id, total_orders from customer_totals order by total_orders desc limit 1;
   569  -- @bvt:issue#14792
   570  desc max_totals;
   571  -- @bvt:issue
   572  select * from max_totals;
   573  
   574  drop table if exists max_customer;
   575  create table max_customer as select customer_id, total_amount from customer_totals order by total_amount asc limit 1;
   576  show create table max_customer;
   577  select * from max_customer;
   578  
   579  drop table orders;
   580  drop table customer_totals;
   581  drop table max_totals;
   582  drop table max_customer;
   583  
   584  -- cras combines with filter
   585  drop table if exists original_table;
   586  create table original_table (id int primary key, name varchar(50), age int, salary decimal, hire_date date);
   587  insert into original_table (id, name, age, salary, hire_date) values (1, 'Alice', 30, 5000.00, '2020-01-01'),
   588                                                                       (2, 'Bob', 35, 6000.00, '2021-05-15'),
   589                                                                       (3, 'Charlie', 28, 4500.00, '2022-02-20'),
   590                                                                       (4, 'David', 40, 7000.00, '2021-10-01'),
   591                                                                       (5, 'Eve', 25, 4000.00, '2020-07-15');
   592  
   593  drop table if exists selected_employees;
   594  -- @bvt:issue#14775
   595  create table selected_employees as select * from original_table where
   596  salary >= 5500.00
   597  and salary < 7000.00
   598  and age > 29
   599  and hire_date >= '2021-01-01'
   600  and name not like 'A%'
   601  and id not in (1, 3)
   602  and salary between 5000.00 and 6500.00;
   603  show create table selected_employees;
   604  select * from selected_employees;
   605  drop table selected_employees;
   606  -- @bvt:issue
   607  drop table original_table;
   608  
   609  -- after ctas, create view
   610  drop table if exists view01;
   611  drop table if exists view02;
   612  drop view if exists v1;
   613  create table view01 (a int, b int);
   614  insert into view01 values (1,2),(3,4);
   615  create table view02 select * from view01;
   616  create view v1 as select * from view02;
   617  select * from v1;
   618  drop view v1;
   619  drop table view01;
   620  drop table view02;
   621  
   622  -- update/insert/delete/truncate/alter
   623  drop table if exists table01;
   624  create table table01 (
   625      id int auto_increment primary key,
   626      col1 varchar(255) not null ,
   627      col2 int,
   628      col3 decimal(10, 2),
   629      col4 date,
   630      col5 boolean,
   631      col6 enum('apple', 'banana', 'orange'),
   632      col7 text,
   633      col8 timestamp,
   634      col9 blob,
   635      col10 char,
   636      unique index(col8, col10)
   637  );
   638  insert into table01 (col1, col2, col3, col4, col5, col6, col7, col8, col9, col10) values
   639  ('Value2', 456, 78.90, '2023-10-24', false, 'banana', 'Another text', '2022-01-01 01:01:01.000', 'More binary data', 'D'),
   640  ('Value3', 789, 12.34, '2023-10-25', true, 'orange', 'Yet another text', '1979-01-01 01:01:01.123', 'Even more binary data', 'E');
   641  create table test.table02 as select * from table01;
   642  show create table table02;
   643  select * from table02;
   644  insert into table02 values (12, 'Value1', 123, 45.67, '2023-10-23', TRUE, 'apple', 'This is a text', '2019-01-01 01:01:01.000', 'Some binary data', 'C');
   645  select * from table02;
   646  update table02 set col1 = 'newvalue' where col2 = 456;
   647  delete from table02 where col10 = 'D';
   648  select * from table02;
   649  alter table table02 add column newcolumn int after col3, drop column col4;
   650  show create table table02;
   651  alter table table02 modify column newcolumn bigint;
   652  desc table02;
   653  select * from table02;
   654  truncate table02;
   655  select * from table02;
   656  drop table table02;
   657  drop table table01;
   658  
   659  -- cras combines with join
   660  drop table if exists students;
   661  create table students (student_id int primary key , student_name varchar(20), student_age int);
   662  insert into students values (1, 'Alice', 20);
   663  insert into students values (2, 'Bob', 22);
   664  insert into students values (3, 'Charlie', 21);
   665  insert into students values (4, 'Dave', 23);
   666  
   667  drop table if exists courses;
   668  create table courses (course_id int, course_name varchar(10));
   669  insert into courses values (101, 'Math'), (102, 'English'), (103, 'History'), (104, 'Science');
   670  
   671  drop table if exists enrollments;
   672  create table enrollments (student_id int, course_id int);
   673  insert into enrollments values (1, 101), (1, 103), (2, 102), (3, 101), (3, 102), (3, 103), (4, 104);
   674  
   675  drop table if exists c_enrollments;
   676  create table student_course_enrollments as
   677  select
   678      s.student_id,
   679      s.student_name,
   680      s.student_age,
   681      c.course_name
   682  from
   683      students s
   684  left join
   685      enrollments e ON s.student_id = e.student_id
   686  left join
   687      courses c ON e.course_id = c.course_id;
   688  select * from student_course_enrollments;
   689  -- @bvt:issue#14792
   690  show create table student_course_enrollments;
   691  -- @bvt:issue
   692  
   693  drop table if exists student_course_enrollments_inner;
   694  create table student_course_enrollments_inner AS
   695  select
   696      s.student_id,
   697      s.student_name,
   698      s.student_age,
   699      c.course_name
   700  from
   701      students s
   702  inner join
   703      enrollments e on s.student_id = e.student_id
   704  inner join
   705      courses c on e.course_id = c.course_id;
   706  -- @bvt:issue#14792
   707  show create table student_course_enrollments_inner;
   708  -- @bvt:issue
   709  select * from student_course_enrollments;
   710  
   711  drop table if exists student_course_enrollments_right;
   712  create table test.student_course_enrollments_right AS
   713  select
   714      s.student_id,
   715      s.student_name,
   716      s.student_age,
   717      c.course_name
   718  from
   719      students s
   720  right join
   721      enrollments e on s.student_id = e.student_id
   722  right join
   723      courses c on e.course_id = c.course_id;
   724  -- @bvt:issue#14792
   725  show create table student_course_enrollments_right;
   726  -- @bvt:issue
   727  select * from student_course_enrollments_right;
   728  
   729  drop table if exists student_course_enrollments_full;
   730  create table student_course_enrollments_full AS
   731  select
   732      s.student_id,
   733      s.student_name,
   734      s.student_age,
   735      c.course_name
   736  from
   737      students s
   738  right join
   739      enrollments e on s.student_id = e.student_id
   740  right join
   741      courses c on e.course_id = c.course_id;
   742  -- @bvt:issue#14792
   743  show create table student_course_enrollments_full;
   744  -- @bvt:issue
   745  select * from student_course_enrollments_full;
   746  
   747  drop table if exists outerjoin01;
   748  create table outerjoin01 (col1 int, col2 char(3));
   749  insert into outerjoin01 values(10,'aaa'), (10,null), (10,'bbb'), (20,'zzz');
   750  drop table if exists outerjoin02;
   751  create table outerjoin02(a1 char(3), a2 int, a3 real);
   752  insert into outerjoin02 values('AAA', 10, 0.5);
   753  insert into outerjoin02 values('BBB', 20, 1.0);
   754  
   755  drop table if exists oj01;
   756  create table oj01 as select outerjoin01.col1, outerjoin01.col2, outerjoin02.a2 from outerjoin01 left outer join outerjoin02 on outerjoin01.col1=10 limit 3;
   757  show create table oj01;
   758  select * from oj01;
   759  
   760  drop table if exists oj02;
   761  create table oj02 as select outerjoin01.col1, outerjoin01.col2, outerjoin02.a2 from outerjoin01 natural join outerjoin02 order by col1 desc;
   762  show create table oj02;
   763  select * from oj02;
   764  drop table oj01;
   765  drop table oj02;
   766  drop table outerjoin01;
   767  drop table outerjoin02;
   768  drop table student_course_enrollments;
   769  drop table student_course_enrollments_full;
   770  drop table student_course_enrollments_inner;
   771  drop table student_course_enrollments_right;
   772  
   773  -- subquery
   774  drop table if exists employees;
   775  create table employees (col1 int, col2 bigint);
   776  insert into employees values (1, 50000), (2, 60000), (3, 55000), (4, 70000);
   777  drop table if exists sal;
   778  create table sal as
   779  select
   780      col1,
   781      col2,
   782      col2 * 0.1 as bonus
   783  from
   784      employees;
   785  select * from sal;
   786  
   787  drop table if exists sal;
   788  create table test.sal as
   789  select
   790      col1,
   791      col2,
   792      (select col2 * 0.1 from employees e2 where e2.col1 = e1.col1) as bonus
   793  from
   794      employees e1;
   795  select * from sal;
   796  
   797  drop table if exists sal;
   798  create table sal as
   799      select
   800          col1,
   801          col2,
   802          (select col2 from employees where col2 = 60000)
   803      from employees;
   804  select * from sal;
   805  drop table employees;
   806  drop table sal;
   807  
   808  -- derived tables have column restrictions
   809  drop table if exists test01;
   810  create table test01 (col1 int, col2 decimal, col3 varchar(50));
   811  insert into test01 values (1, 3242434.423, '3224332r32r');
   812  insert into test01 values (2, 39304.3424, '343234343213124');
   813  insert into test01 values (3, 372.324, '00');
   814  
   815  drop table if exists test02;
   816  create table test02 (col1 int primary key ) as select col1 from test01;
   817  show create table test02;
   818  desc test02;
   819  insert into test02 values (2);
   820  
   821  drop table if exists test03;
   822  create table test03 (col2 decimal unique key) as select col2 from test01;
   823  show create table test03;
   824  desc test03;
   825  insert into test03 values (372.324);
   826  
   827  drop table if exists test04;
   828  create table test04 (col1 int, col2 varchar(50), key(col1, col2)) as select col1, col3 from test01;
   829  show create table test04;
   830  select * from test04;
   831  
   832  drop table if exists test05;
   833  create table test05 (col1 int, col2 decimal, primary key (col1, col2)) as select col1, col2 from test01;
   834  show create table test05;
   835  select * from test05;
   836  -- @pattern
   837  insert into test05 values (2, 39304.3424);
   838  
   839  alter table test01 rename column col1 to newCol;
   840  show create table test01;
   841  
   842  drop table if exists test06;
   843  create table test06 (col1 int not null default 100) as select col1 from test01;
   844  create table test06 (col1 int not null default 100) as select newcol from test01;
   845  -- @bvt:issue#14792
   846  show create table test06;
   847  -- @bvt:issue
   848  select * from test06;
   849  
   850  drop table test01;
   851  drop table test02;
   852  drop table test03;
   853  drop table test04;
   854  drop table test05;
   855  drop table test06;
   856  
   857  -- ctas in prepare statement
   858  drop table if exists prepare01;
   859  create table prepare01(col1 int primary key , col2 char);
   860  insert into prepare01 values (1,'a'),(2,'b'),(3,'c');
   861  show create table prepare01;
   862  show columns from prepare01;
   863  drop table if exists prepare02;
   864  prepare s1 from 'create table prepare02 as select * from prepare01';
   865  execute s1;
   866  show create table prepare02;
   867  select * from prepare02;
   868  drop table if exists prepare03;
   869  prepare s2 from 'create table prepare03(col1 int, col2 char, col3 char) as select col1, col2 from prepare01';
   870  execute s2;
   871  select * from prepare03;
   872  show create table prepare03;
   873  drop table prepare01;
   874  drop table prepare02;
   875  drop table prepare03;
   876  
   877  -- cras temporary table
   878  drop table if exists orders;
   879  create table orders (order_id int primary key , customer_id int, order_date date, total_amount decimal);
   880  insert into orders values (1, 101, '2023-01-01', 100.00),
   881                            (2, 101, '2023-01-05', 150.00),
   882                            (3, 102, '2023-01-02', 200.00),
   883                            (4, 103, '2023-01-03', 50.00),
   884                            (5, 101, '2023-01-04', 75.00),
   885                            (6, 104, '2023-01-06', 300.00),
   886                            (7, 104, '2023-01-07', 200.00),
   887                            (8, 105, '2023-01-08', 100.00);
   888  select * from orders;
   889  
   890  drop table if exists customer_totals;
   891  create temporary table customer_totals as select customer_id, count(order_id) as total_orders, sum(total_amount) as total_amount from orders group by customer_id having count(order_id) > 1 and sum(total_amount) > 150.0;
   892  -- @bvt:issue#14792
   893  show create table customer_totals;
   894  -- @bvt:issue
   895  select * from customer_totals;
   896  
   897  drop table if exists max_totals;
   898  create temporary table max_totals as select customer_id, total_orders from customer_totals order by total_orders desc limit 1;
   899  -- @bvt:issue#14792
   900  desc max_totals;
   901  -- @bvt:issue
   902  select * from max_totals;
   903  
   904  drop table if exists max_customer;
   905  create temporary table max_customer as select customer_id, total_amount from customer_totals order by total_amount asc limit 1;
   906  show create table max_customer;
   907  select * from max_customer;
   908  
   909  drop table orders;
   910  drop table customer_totals;
   911  drop table max_totals;
   912  drop table max_customer;
   913  
   914  -- abnormal test, column is not exists in origin table
   915  drop table if exists table10;
   916  drop table if exists table11;
   917  create table table10 as select col100 from table07;
   918  create table table11 (col20 decimal, col30 char, col40 varchar) as select col100 from table07;
   919  drop table table07;
   920  drop table table08;
   921  drop table table09;
   922  drop table table12;
   923  
   924  -- abnormal test: null column to not null column
   925  drop table if exists abnormal01;
   926  create table abnormal01 (col1 int default null );
   927  insert into abnormal01 values (1), (null);
   928  drop table if exists abnormal02;
   929  create table test.abnormal02 (col1 int not null) as select col1 from abnormal01;
   930  drop table abnormal01;
   931  
   932  -- abnormal test: normal column to pk column
   933  drop table if exists abnormal03;
   934  create table abnormal03 (col1 int, col2 bigint);
   935  insert into abnormal03 values (1, 8324824234);
   936  insert into abnormal03 values (1, 8324824234);
   937  select * from abnormal03;
   938  drop table if exists abnormal04;
   939  drop table if exists abnormal05;
   940  create table abnormal04 (col1 int primary key ) as select col1 from abnormal03;
   941  create table abnormal05 (col2 bigint unique key) as select col2 from abnormal03;
   942  drop table abnormal03;
   943  
   944  -- abnormal test: data out of range
   945  drop table if exists abnormal06;
   946  create table abnormal06 (col1 bigint, col2 decimal);
   947  insert into abnormal06 values (271928310313092, 32984832.3214214);
   948  drop table if exists abnormal07;
   949  create table abnormal07 (col1 int) as select col1 from abnormal06;
   950  drop table abnormal06;
   951  
   952  -- abnormal test: count of column is not the same
   953  drop table if exists abnormal07;
   954  create table abnormal07 (col1 int, col2 bigint, col3 decimal, col4 char);
   955  insert into abnormal07 values (1, 2, 3, 'a');
   956  insert into abnormal07 values (1, 2, 3, 'b');
   957  insert into abnormal07 values (1, 2, 3, 'c');
   958  insert into abnormal07 values (1, 2, 3, 'd');
   959  insert into abnormal07 values (null, null, null, null);
   960  
   961  drop table if exists abnormal08;
   962  create table abnormal08 as select col1, col2, col3, col4, col5 from abnormal07;
   963  create table abnormal07 as select * from abnormal07;
   964  drop table abnormal07;
   965  
   966  -- the inserted data violates the constraints of the new table
   967  drop table if exists abnormal09;
   968  create table abnormal09 (col1 int, col2 decimal);
   969  insert into abnormal09 values (1, 2);
   970  insert into abnormal09 values (1, 2);
   971  drop table if exists abnormal10;
   972  create table abnormal10(col1 int primary key) as select col1 from abnormal09;
   973  create table abnormal10(col2 decimal unique key) as select col2 from abnormal09;
   974  drop table abnormal09;
   975  
   976  -- perform CTAS operations on the metadata table
   977  drop table if exists abnormal10;
   978  create table abnormal10 as select * from mo_catalog.mo_columns;
   979  
   980  -- combines with window function
   981  drop table if exists time_window01;
   982  create table time_window01 (ts timestamp primary key , col2 int);
   983  insert into time_window01 values ('2021-01-12 00:00:00.000', 12);
   984  insert into time_window01 values ('2020-01-12 12:00:12.000', 24);
   985  insert into time_window01 values ('2023-01-12 00:00:00.000', 34);
   986  insert into time_window01 values ('2024-01-12 12:00:12.000', 20);
   987  select * from time_window01;
   988  drop table if exists time_window02;
   989  create table time_window02 as select _wstart, _wend, max(col2), min(col2) from time_window01 where ts > '2020-01-11 12:00:12.000' and ts < '2021-01-13 00:00:00.000' interval(ts, 100, day) fill(prev);
   990  select * from time_window02;
   991  drop table time_window01;
   992  drop table time_window02;
   993  
   994  drop table if exists time_window03;
   995  create table time_window03 (ts timestamp primary key , col2 bool);
   996  insert into time_window03 values ('2023-10-26 10:00:00.000', false);
   997  insert into time_window03 values ('2023-10-26 10:10:00.000', true);
   998  insert into time_window03 values ('2023-10-26 10:20:00.000', null);
   999  insert into time_window03 values ('2023-10-26 10:30:00.000', true);
  1000  select * from time_window03;
  1001  drop table if exists time_window04;
  1002  create table time_window04 as select _wstart, _wend, max(col2), min(col2) from time_window03 where ts > '2020-01-11 12:00:12.000' and ts < '2024-01-13 00:00:00.000' interval(ts, 10, second) fill(prev);
  1003  select * from time_window04;
  1004  select * from time_window03;
  1005  drop table time_window03;
  1006  drop table time_window04;
  1007  
  1008  drop table if exists test.window01;
  1009  create table window01 (user_id integer not null, date date);
  1010  insert into window01 values (1, '2002-06-09');
  1011  insert into window01 values (2, '2002-06-09');
  1012  insert into window01 values (1, '2002-06-09');
  1013  insert into window01 values (3, '2002-06-09');
  1014  insert into window01 values (4, '2002-06-09');
  1015  insert into window01 values (4, '2002-06-09');
  1016  insert into window01 values (5, '2002-06-09');
  1017  drop table if exists window02;
  1018  create table window02 as select rank() over () r from window01;
  1019  select * from window02;
  1020  drop table if exists window03;
  1021  create table window03 as select dense_rank() over () r from window01;
  1022  select * from window03;
  1023  drop table window01;
  1024  drop table window02;
  1025  drop table window03;
  1026  
  1027  drop table if exists row01;
  1028  create table row01(i int,j int);
  1029  insert into row01 values(1,1);
  1030  insert into row01 values(1,4);
  1031  insert into row01 values(1,2);
  1032  insert into row01 values(1,4);
  1033  drop table if exists row02;
  1034  create table row02 as select i, j, sum(i+j) over (order by j rows between 2 preceding and 1 preceding) foo from row01 order by foo desc;
  1035  select * from row02;
  1036  drop table if exists row03;
  1037  create table row03 as select i, j, sum(i+j) over (order by j rows between 2 following and 1 following) foo from row01 order by foo desc;
  1038  select * from row03;
  1039  drop table row01;
  1040  drop table row02;
  1041  drop table row03;
  1042  
  1043  drop table if exists dense_rank01;
  1044  create table dense_rank01 (id integer, sex char(1));
  1045  insert into dense_rank01 values (1, 'm');
  1046  insert into dense_rank01 values (2, 'f');
  1047  insert into dense_rank01 values (3, 'f');
  1048  insert into dense_rank01 values (4, 'f');
  1049  insert into dense_rank01 values (5, 'm');
  1050  drop table if exists dense_rank02;
  1051  create table dense_rank02 as select sex, id, rank() over (partition by sex order by id desc) from dense_rank01;
  1052  select * from dense_rank02;
  1053  drop table if exists dense_rank03;
  1054  create table dense_rank03 as select sex, id, dense_rank() over (partition by sex order by id desc) from dense_rank01;
  1055  select * from dense_rank03;
  1056  drop table dense_rank01;
  1057  drop table dense_rank02;
  1058  drop table dense_rank03;
  1059  
  1060  -- combine with pub-sub table
  1061  drop table if exists test01;
  1062  create table test01(
  1063  col1 tinyint,
  1064  col2 smallint,
  1065  col3 int,
  1066  col4 bigint,
  1067  col5 tinyint unsigned,
  1068  col6 smallint unsigned,
  1069  col7 int unsigned,
  1070  col8 bigint unsigned,
  1071  col9 float,
  1072  col10 double
  1073  );
  1074  
  1075  insert into test01 values (1,2,3,4,5,6,7,8,10.2131,3824.34324);
  1076  insert into test01 values (2,3,4,5,6,7,8,9,2131.3242343,-3824.34324);
  1077  show create table test01;
  1078  create publication publication01 database test;
  1079  -- @ignore:2,3
  1080  show publications;
  1081  drop table if exists test02;
  1082  create table test02 as select * from test01;
  1083  select * from test02;
  1084  
  1085  drop publication publication01;
  1086  drop table test01;
  1087  
  1088  drop account if exists acc0;
  1089  create account acc0 admin_name 'root' identified by '111';
  1090  drop table if exists sys_tbl_1;
  1091  create table sys_tbl_1(a int primary key, b decimal, c char, d varchar(20) );
  1092  insert into sys_tbl_1 values(1,2,'a','database'),(2,3,'b','test publication'),(3, 4, 'c','324243243');
  1093  create publication sys_pub_1 database test;
  1094  select * from sys_tbl_1;
  1095  -- @ignore:2,3
  1096  show publications;
  1097  select pub_name, database_name, account_list from mo_catalog.mo_pubs;
  1098  -- @session:id=2&user=acc0:root&password=111
  1099  create database sub1 from sys publication sys_pub_1;
  1100  show databases;
  1101  use sub1;
  1102  drop table if exists test;
  1103  create table test as select * from sys_tbl_1;
  1104  -- @session
  1105  
  1106  -- @session:id=3&user=acc0:root&password=111
  1107  drop database sub1;
  1108  -- @session
  1109  drop account acc0;
  1110  drop publication sys_pub_1;
  1111  
  1112  -- alias
  1113  show variables like 'lower_case_table_names';
  1114  set @@global.lower_case_table_names = 0;
  1115  -- @session:id=24&user=sys:dump&password=111
  1116  use test;
  1117  drop table if exists alias01;
  1118  create table alias01 (col1 int, col2 decimal);
  1119  insert into alias01 values (1,2);
  1120  insert into alias01 values (2,3);
  1121  drop table if exists alias02;
  1122  create table alias02 (NewCol int) as select * from alias01;
  1123  show create table alias02;
  1124  select * from alias02;
  1125  drop table alias01;
  1126  -- @session
  1127  drop database test;
  1128  
  1129  -- privilege
  1130  drop database if exists db1;
  1131  create database db1;
  1132  use db1;
  1133  drop role if exists role_r1;
  1134  drop user if exists role_u1;
  1135  create role role_r1;
  1136  create user role_u1 identified by '111' default role role_r1;
  1137  drop table if exists t1;
  1138  create table t1(col1 int);
  1139  insert into t1 values(1);
  1140  insert into t1 values(2);
  1141  grant create database, drop database on account * to role_r1;
  1142  grant show databases on account * to role_r1;
  1143  grant connect on account * to role_r1;
  1144  grant create table, drop table on database *.* to role_r1;
  1145  grant show tables on database * to role_r1;
  1146  -- @session:id=4&user=sys:role_u1:role_r1&password=111
  1147  use db1;
  1148  drop table if exists t2;
  1149  create table t2 as select * from t1;
  1150  -- @session
  1151  grant select on table * to role_r1;
  1152  grant insert on table * to role_r1;
  1153  -- @session:id=5&user=sys:role_u1:role_r1&password=111
  1154  use db1;
  1155  drop table if exists t2;
  1156  create table t2 as select * from t1;
  1157  select * from t2;
  1158  -- @session
  1159  drop table t1;
  1160  drop table t2;
  1161  drop database db1;
  1162  
  1163  drop database if exists db2;
  1164  create database db2;
  1165  use db2;
  1166  drop role if exists role_r1;
  1167  drop role if exists role_r2;
  1168  drop user if exists role_u1;
  1169  drop user if exists role_u2;
  1170  create role role_r1;
  1171  create user role_u1 identified by '111' default role role_r1;
  1172  create role role_r2;
  1173  create user role_u2 identified by '111' default role role_r2;
  1174  drop table if exists t1;
  1175  create table t1(col1 int);
  1176  insert into t1 values(1);
  1177  insert into t1 values(2);
  1178  grant create database, drop database on account * to role_r1;
  1179  grant show databases on account * to role_r1;
  1180  grant connect on account * to role_r1;
  1181  grant create table, drop table on database *.* to role_r1;
  1182  grant show tables on database * to role_r1;
  1183  grant select on table * to role_r1;
  1184  grant insert on table * to role_r1;
  1185  -- @session:id=6&user=sys:role_u1:role_r1&password=111
  1186  use db2;
  1187  drop table if exists t2;
  1188  create table t2 as select * from t1;
  1189  -- @session
  1190  -- @session:id=7&user=sys:role_u2:role_r2&password=111
  1191  use db2;
  1192  drop table if exists t3;
  1193  create table t3 as select * from t2;
  1194  select * from t3;
  1195  -- @session
  1196  grant create database, drop database on account * to role_r2;
  1197  grant show databases on account * to role_r2;
  1198  grant connect on account * to role_r2;
  1199  grant create table, drop table on database *.* to role_r2;
  1200  grant show tables on database * to role_r2;
  1201  grant select on table * to role_r2;
  1202  grant insert on table * to role_r2;
  1203  -- @session:id=8&user=sys:role_u2:role_r2&password=111
  1204  use db2;
  1205  drop table if exists t3;
  1206  create table t3 as select * from t2;
  1207  select * from t3;
  1208  -- @session
  1209  drop table t1;
  1210  drop table t2;
  1211  drop table t3;
  1212  drop role role_r1;
  1213  drop role role_r2;
  1214  drop user role_u1;
  1215  drop user role_u2;
  1216  drop database db2;
  1217  
  1218  -- privilege
  1219  drop role if exists role_r1;
  1220  drop user if exists role_u1;
  1221  create role role_r1;
  1222  create user role_u1 identified by '111' default role role_r1;
  1223  grant show databases on account * to role_r1;
  1224  grant connect on account * to role_r1;
  1225  grant show tables on database * to role_r1;
  1226  grant create database, drop database on account * to role_r1;
  1227  -- @session:id=9&user=sys:role_u1:role_r1&password=111
  1228  drop database if exists db3;
  1229  create database db3;
  1230  drop database if exists db4;
  1231  create database db4;
  1232  -- @session
  1233  use db3;
  1234  grant create table, drop table on database db3 to role_r1;
  1235  grant create table, drop table on database db4 to role_r1;
  1236  grant select on table * to role_r1;
  1237  grant insert on table * to role_r1;
  1238  use db4;
  1239  grant select on table * to role_r1;
  1240  grant insert on table * to role_r1;
  1241  -- @session:id=9&user=sys:role_u1:role_r1&password=111
  1242  use db3;
  1243  drop table if exists t1;
  1244  create table t1(col1 int);
  1245  insert into t1 values(1);
  1246  insert into t1 values(2);
  1247  drop database if exists db4;
  1248  create database db4;
  1249  use db4;
  1250  drop table if exists t2;
  1251  create table t2 as select * from db3.t1;
  1252  use db3;
  1253  drop table t1;
  1254  -- @session
  1255  use db4;
  1256  select * from t2;
  1257  drop table t2;
  1258  drop role role_r1;
  1259  drop user role_u1;
  1260  drop database db3;
  1261  drop database db4;
  1262  
  1263  -- privilege
  1264  drop database if exists db;
  1265  create database db;
  1266  use db;
  1267  drop role if exists role_r1;
  1268  drop role if exists role_r2;
  1269  drop user if exists role_u1;
  1270  drop user if exists role_u2;
  1271  create role role_r1;
  1272  create user role_u1 identified by '111' default role role_r1;
  1273  create role role_r2;
  1274  create user role_u2 identified by '111' default role role_r2;
  1275  grant create database, drop database on account * to role_r1;
  1276  grant show databases on account * to role_r1;
  1277  grant connect on account * to role_r1;
  1278  grant create table, drop table on database *.* to role_r1;
  1279  grant show tables on database * to role_r1;
  1280  grant select on table * to role_r1;
  1281  grant insert on table * to role_r1;
  1282  -- @session:id=20&user=sys:role_u1:role_r1&password=111
  1283  drop database if exists db5;
  1284  create database db5;
  1285  use db5;
  1286  drop table if exists t1;
  1287  create table t1 (col1 int);
  1288  insert into t1 values (1);
  1289  insert into t1 values (2);
  1290  -- @session
  1291  grant role_r1 to role_r2;
  1292  -- @session:id=22&user=sys:role_u2:role_r2&password=111
  1293  drop database if exists db6;
  1294  create database db6;
  1295  use db6;
  1296  create table t2 as select * from db5.t1;
  1297  -- @session
  1298  select * from db6.t2;
  1299  drop role role_r1;
  1300  drop role role_r2;
  1301  drop user role_u1;
  1302  drop user role_u2;
  1303  drop database db;
  1304  drop database db5;
  1305  drop database db6;
  1306  
  1307  -- privilege
  1308  drop database if exists db7;
  1309  create database db7;
  1310  use db7;
  1311  drop role if exists role_r1;
  1312  drop user if exists role_u1;
  1313  create role role_r1;
  1314  create user role_u1 identified by '111' default role role_r1;
  1315  drop table if exists t1;
  1316  create table t1(col1 int);
  1317  insert into t1 values(1);
  1318  insert into t1 values(2);
  1319  grant create database, drop database on account * to role_r1;
  1320  grant show databases on account * to role_r1;
  1321  grant connect on account * to role_r1;
  1322  grant create table, drop table on database *.* to role_r1;
  1323  grant show tables on database * to role_r1;
  1324  -- @session:id=23&user=sys:role_u1:role_r1&password=111
  1325  create table t2 as select * from t1;
  1326  -- @session
  1327  grant select on table * to role_r1;
  1328  grant insert on table * to role_r1;
  1329  -- @session:id=24&user=sys:role_u1:role_r1&password=111
  1330  drop table if exists t2;
  1331  create table t2 as select * from t1;
  1332  select * from t2;
  1333  -- @session
  1334  drop table t1;
  1335  drop table t2;
  1336  drop role role_r1;
  1337  drop user role_u1;
  1338  drop database db7;
  1339  set @@global.lower_case_table_names = 1;