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

     1  
     2  -- test sys tenement non-system database, create cluster table.
     3  drop database if exists test_db1;
     4  create database test_db1;
     5  use test_db1;
     6  drop table if exists t1;
     7  create cluster table t1(a int, b int);
     8  drop database test_db1;
     9  
    10  
    11  -- test sys tenement system database, create cluster table.(only mo_catalog support)
    12  use mo_task;
    13  drop table if exists t2;
    14  create cluster table t2(a int, b int);
    15  
    16  use information_schema;
    17  drop table if exists t3;
    18  create cluster table t3(a int, b int);
    19  desc t3;
    20  drop table t3;
    21  
    22  use mysql;
    23  drop table if exists t4;
    24  create cluster table t4(a int, b int);
    25  desc t4;
    26  drop table t4;
    27  
    28  use system_metrics;
    29  drop table if exists t5;
    30  create cluster table t5(a int, b int);
    31  desc t5;
    32  drop table t5;
    33  
    34  use system;
    35  drop table if exists t6;
    36  create cluster table t6(a int, b int);
    37  desc t6;
    38  drop table t6;
    39  
    40  use mo_catalog;
    41  drop table if exists t7;
    42  create cluster table t7(a int, b int);
    43  desc t7;
    44  drop table t7;
    45  
    46  -- test system tenant inserts data into the cluster table
    47  use mo_catalog;
    48  drop table if exists cluster_table_1;
    49  create cluster table cluster_table_1(a int, b int);
    50  
    51  drop table if exists statement_cu;
    52  
    53  CREATE CLUSTER TABLE `statement_cu` (
    54  `statement_id` VARCHAR(36) NOT NULL,
    55  `account` VARCHAR(300) NOT NULL,
    56  `response_at` DATETIME DEFAULT NULL,
    57  `cu` DECIMAL(23,3) NOT NULL,
    58  PRIMARY KEY (`statement_id`,`account_id`)
    59  );
    60  
    61  
    62  drop account if exists test_account1;
    63  create account test_account1 admin_name = 'test_user' identified by '111';
    64  
    65  drop account if exists test_account2;
    66  create account test_account2 admin_name = 'test_user' identified by '111';
    67  
    68  insert into cluster_table_1 values(0,0,0),(1,1,0);
    69  insert into cluster_table_1 values(0,0,1),(1,1,1);
    70  insert into cluster_table_1 values(0,0,2),(1,1,2) on duplicate key update b=b;
    71  update cluster_table_1 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
    72  update cluster_table_1 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
    73  select a,b from cluster_table_1;
    74  
    75  -- @session:id=2&user=test_account1:test_user&password=111
    76  use mo_catalog;
    77  select * from cluster_table_1;
    78  SELECT attname AS name, mo_show_visible_bin(atttyp,3) AS data_type, replace(mo_table_col_max(att_database,att_relname,attname),'\\0', '') AS `maximum`,  mo_table_col_min(att_database,att_relname,attname) as minimum from mo_catalog.mo_columns where att_database='mo_catalog' and att_relname='statement_cu' and attname NOT IN  ('__mo_rowid', '__mo_cpkey_col', '__mo_fake_pk_col') ORDER BY attnum;
    79  -- @session
    80  
    81  -- @session:id=3&user=test_account2:test_user&password=111
    82  use mo_catalog;
    83  select * from cluster_table_1;
    84  SELECT attname AS name, mo_show_visible_bin(atttyp,3) AS data_type, replace(mo_table_col_max(att_database,att_relname,attname),'\\0', '') AS `maximum`,  mo_table_col_min(att_database,att_relname,attname) as minimum from mo_catalog.mo_columns where att_database='mo_catalog' and att_relname='statement_cu' and attname NOT IN  ('__mo_rowid', '__mo_cpkey_col', '__mo_fake_pk_col') ORDER BY attnum;
    85  -- @session
    86  
    87  insert into cluster_table_1 values(200,200, 0);
    88  insert into cluster_table_1 values(100,100, 0);
    89  insert into cluster_table_1 values(50,50, 0);
    90  select a,b from cluster_table_1;
    91  
    92  -- @session:id=2&user=test_account1:test_user&password=111
    93  use mo_catalog;
    94  select * from cluster_table_1;
    95  -- @session
    96  
    97  -- @session:id=3&user=test_account2:test_user&password=111
    98  use mo_catalog;
    99  select * from cluster_table_1;
   100  -- @session
   101  
   102  drop table cluster_table_1;
   103  
   104  
   105  -- test system tenant load data into the cluster table
   106  drop table if exists cluster_table_2;
   107  create cluster table cluster_table_2(
   108  col1 int,
   109  col2 float,
   110  col3 decimal,
   111  col4 date,
   112  col5 bool,
   113  col6 json,
   114  col7 blob,
   115  col8 text,
   116  col9 varchar
   117  );
   118  
   119  load data infile '$resources/load_data/cluster_table.csv' into table cluster_table_2 fields terminated by ',';
   120  update cluster_table_2 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   121  update cluster_table_2 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   122  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_2;
   123  
   124  -- @session:id=2&user=test_account1:test_user&password=111
   125  use mo_catalog;
   126  select * from cluster_table_2;
   127  -- @session
   128  
   129  -- @session:id=3&user=test_account2:test_user&password=111
   130  use mo_catalog;
   131  select * from cluster_table_2;
   132  -- @session
   133  
   134  drop table cluster_table_2;
   135  
   136  
   137  -- test system tenement, operation cluster table (update,delete,truncate)
   138  drop table if exists cluster_table_3;
   139  create cluster table cluster_table_3(
   140  col1 int,
   141  col2 float,
   142  col3 decimal,
   143  col4 date,
   144  col5 bool,
   145  col6 json,
   146  col7 blob,
   147  col8 text,
   148  col9 varchar
   149  );
   150  
   151  insert into cluster_table_3 values (1,1.09,1.345,"2022-10-02",0,'{"a":1}',"你好","text","varchar", 0);
   152  insert into cluster_table_3 values (1,1.09,1.345,"2022-10-02",0,'{"a":1}',"你好","text","varchar", 1);
   153  insert into cluster_table_3 values (1,1.09,1.345,"2022-10-02",0,'{"a":1}',"你好","text","varchar", 2);
   154  insert into cluster_table_3 values (2,10.9,13.45,"2022-10-02",1,'{"b":2}',"nihao","文本","字符", 0);
   155  insert into cluster_table_3 values (2,10.9,13.45,"2022-10-02",1,'{"b":2}',"nihao","文本","字符", 1);
   156  insert into cluster_table_3 values (2,10.9,13.45,"2022-10-02",1,'{"b":2}',"nihao","文本","字符", 2);
   157  update cluster_table_3 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   158  update cluster_table_3 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   159  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   160  
   161  update cluster_table_3 set col1=100 where account_id=0 and col1=1;
   162  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   163  
   164  -- @session:id=2&user=test_account1:test_user&password=111
   165  use mo_catalog;
   166  select * from cluster_table_3;
   167  -- @session
   168  
   169  -- @session:id=3&user=test_account2:test_user&password=111
   170  use mo_catalog;
   171  select * from cluster_table_3;
   172  -- @session
   173  
   174  update cluster_table_3 set col1=100 where account_id=(select account_id from mo_account where account_name="test_account1") and col1=1;
   175  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   176  
   177  -- @session:id=2&user=test_account1:test_user&password=111
   178  use mo_catalog;
   179  select * from cluster_table_3;
   180  -- @session
   181  
   182  -- @session:id=3&user=test_account2:test_user&password=111
   183  use mo_catalog;
   184  select * from cluster_table_3;
   185  -- @session
   186  
   187  update cluster_table_3 set col1=100 where account_id=(select account_id from mo_account where account_name="test_account2") and col1=1;
   188  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   189  
   190  -- @session:id=2&user=test_account1:test_user&password=111
   191  use mo_catalog;
   192  select * from cluster_table_3;
   193  -- @session
   194  
   195  -- @session:id=3&user=test_account2:test_user&password=111
   196  use mo_catalog;
   197  select * from cluster_table_3;
   198  -- @session
   199  
   200  
   201  delete from cluster_table_3 where account_id=0;
   202  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   203  
   204  -- @session:id=2&user=test_account1:test_user&password=111
   205  use mo_catalog;
   206  select * from cluster_table_3;
   207  -- @session
   208  
   209  -- @session:id=3&user=test_account2:test_user&password=111
   210  use mo_catalog;
   211  select * from cluster_table_3;
   212  -- @session
   213  
   214  
   215  delete from cluster_table_3 where account_id=(select account_id from mo_account where account_name="test_account1");
   216  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   217  
   218  -- @session:id=2&user=test_account1:test_user&password=111
   219  use mo_catalog;
   220  select * from cluster_table_3;
   221  -- @session
   222  
   223  -- @session:id=3&user=test_account2:test_user&password=111
   224  use mo_catalog;
   225  select * from cluster_table_3;
   226  -- @session
   227  
   228  
   229  delete from cluster_table_3 where account_id=(select account_id from mo_account where account_name="test_account2");
   230  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   231  
   232  -- @session:id=2&user=test_account1:test_user&password=111
   233  use mo_catalog;
   234  select * from cluster_table_3;
   235  -- @session
   236  
   237  -- @session:id=3&user=test_account2:test_user&password=111
   238  use mo_catalog;
   239  select * from cluster_table_3;
   240  -- @session
   241  
   242  
   243  truncate table cluster_table_3;
   244  select col1,col2,col3,col4,col5,col6,col7,col8,col9 from cluster_table_3;
   245  
   246  -- @session:id=2&user=test_account1:test_user&password=111
   247  use mo_catalog;
   248  select * from cluster_table_3;
   249  -- @session
   250  
   251  -- @session:id=3&user=test_account2:test_user&password=111
   252  use mo_catalog;
   253  select * from cluster_table_3;
   254  -- @session
   255  
   256  drop table cluster_table_3;
   257  
   258  
   259  -- test create cluster table include account_id columns
   260  create cluster table cluster_table_xx(account_id int);
   261  
   262  -- test common tenement operation(desc table,show create table,drop table)
   263  drop table if exists cluster_table_4;
   264  create cluster table cluster_table_4(
   265  col1 int,
   266  col2 varchar
   267  );
   268  
   269  insert into cluster_table_4 values (1,'a',0),(2,'b',0);
   270  insert into cluster_table_4 values (1,'a',1),(2,'b',1);
   271  insert into cluster_table_4 values (1,'a',2),(2,'b',2);
   272  update cluster_table_4 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   273  update cluster_table_4 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   274  select col1,col2 from cluster_table_4;
   275  
   276  -- @session:id=2&user=test_account1:test_user&password=111
   277  use mo_catalog;
   278  desc cluster_table_4;
   279  show create table cluster_table_4;
   280  drop table cluster_table_4;
   281  -- @session
   282  
   283  -- test common tenement operation table include (insert,update,delete,truncate)
   284  -- @session:id=2&user=test_account1:test_user&password=111
   285  use mo_catalog;
   286  insert into cluster_table_4 values (3, 'c');
   287  update cluster_table_4 set col1=10 where col2='a';
   288  delete from cluster_table_4 where col1=2;
   289  truncate table cluster_table_4;
   290  -- @session
   291  
   292  drop table cluster_table_4;
   293  
   294  
   295  -- test cluster table relevance query(join,union)
   296  drop table if exists cluster_table_5;
   297  create cluster table cluster_table_5(
   298  col1 int,
   299  col2 varchar
   300  );
   301  
   302  insert into cluster_table_5  values (1,'a',0),(2,'b',0),(3,'c',0),(4,'d',0),(5,'f',0),(6,'g',0);
   303  insert into cluster_table_5  values (1,'a',1),(2,'b',1),(3,'c',1),(4,'d',1),(5,'f',1),(6,'g',1);
   304  insert into cluster_table_5  values (1,'a',2),(2,'b',2),(3,'c',2),(4,'d',2),(5,'f',2),(6,'g',2);
   305  update cluster_table_5 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   306  update cluster_table_5 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   307  drop table if exists cluster_table_6;
   308  create cluster table cluster_table_6(
   309  a int,
   310  b varchar
   311  );
   312  
   313  insert into cluster_table_6 values (100,'a',0),(200,'a',0),(300,'a',0);
   314  insert into cluster_table_6 values (100,'a',1),(200,'a',1),(300,'a',1);
   315  insert into cluster_table_6 values (100,'a',2),(200,'a',2),(300,'a',2);
   316  update cluster_table_6 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   317  update cluster_table_6 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   318  
   319  select a1.col1,a1.col2,a2.a,a2.b from cluster_table_5 a1 left join cluster_table_6 a2 on a1.col2=a2.b;
   320  select a1.col1,a1.col2,a2.a,a2.b from cluster_table_5 a1 right join cluster_table_6 a2 on a1.col2=a2.b;
   321  select a1.col1,a1.col2,a2.a,a2.b from cluster_table_5 a1 inner join cluster_table_6 a2 on a1.col2=a2.b;
   322  
   323  select col1,col2 from cluster_table_5 union select a,b from cluster_table_6;
   324  select col1,col2 from cluster_table_5 union all select a,b from cluster_table_6;
   325  
   326  select col1,col2 from cluster_table_5 intersect select a,b from cluster_table_6;
   327  
   328  SELECT col1,col2 FROM cluster_table_5 MINUS SELECT a,b FROM cluster_table_6;
   329  SELECT a,b FROM cluster_table_6 MINUS SELECT col1,col2 FROM cluster_table_5;
   330  
   331  
   332  -- @session:id=2&user=test_account1:test_user&password=111
   333  use mo_catalog;
   334  select * from cluster_table_5  left join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   335  select * from cluster_table_5  right join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   336  select * from cluster_table_5  inner join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   337  
   338  select * from cluster_table_5 union select * from cluster_table_6;
   339  select * from cluster_table_5 union all select * from cluster_table_6;
   340  
   341  select * from cluster_table_5 intersect select * from cluster_table_6;
   342  
   343  SELECT * FROM cluster_table_5 MINUS SELECT * FROM cluster_table_6;
   344  SELECT * FROM cluster_table_6 MINUS SELECT * FROM cluster_table_5;
   345  -- @session
   346  
   347  
   348  -- @session:id=3&user=test_account2:test_user&password=111
   349  use mo_catalog;
   350  select * from cluster_table_5  left join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   351  select * from cluster_table_5  right join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   352  select * from cluster_table_5  inner join cluster_table_6 on cluster_table_5.col2=cluster_table_6.b;
   353  
   354  select * from cluster_table_5 union select * from cluster_table_6;
   355  select * from cluster_table_5 union all select * from cluster_table_6;
   356  
   357  select * from cluster_table_5 intersect select * from cluster_table_6;
   358  
   359  SELECT * FROM cluster_table_5 MINUS SELECT * FROM cluster_table_6;
   360  SELECT * FROM cluster_table_6 MINUS SELECT * FROM cluster_table_5;
   361  -- @session
   362  
   363  
   364  drop table cluster_table_5;
   365  drop table cluster_table_6;
   366  
   367  
   368  -- test when delete a tenant, the data of the tenant in the cluster table is deleted
   369  drop table if exists cluster_table_7;
   370  create cluster table cluster_table_7(
   371  col1 int,
   372  col2 varchar
   373  );
   374  
   375  insert into cluster_table_7 values (1,'a',0),(2,'b',0);
   376  insert into cluster_table_7 values (1,'a',1),(2,'b',1);
   377  insert into cluster_table_7 values (1,'a',2),(2,'b',2);
   378  update cluster_table_7 set account_id=(select account_id from mo_account where account_name="test_account1") where account_id=1;
   379  update cluster_table_7 set account_id=(select account_id from mo_account where account_name="test_account2") where account_id=2;
   380  select col1,col2 from cluster_table_7;
   381  
   382  drop account test_account1;
   383  select col1,col2 from cluster_table_7;
   384  
   385  drop account test_account2;
   386  select col1,col2 from cluster_table_7;
   387  
   388  drop table cluster_table_7;
   389  
   390  use mo_catalog;
   391  CREATE CLUSTER TABLE mo_instance (id varchar(128) NOT NULL,name VARCHAR(255) NOT NULL,account_name varchar(128) NOT NULL,provider longtext NOT NULL,provider_id longtext,region longtext NOT NULL,plan_type longtext NOT NULL,version longtext,status longtext,quota longtext,network_policy longtext,created_by longtext,created_at datetime(3) NULL,PRIMARY KEY (id, account_id),UNIQUE INDEX uniq_acc (account_name));
   392  create account acc_idx ADMIN_NAME 'root' IDENTIFIED BY '123456';
   393  drop account acc_idx;
   394  drop table mo_instance;
   395  drop table if exists statement_cu;