radondb / radon

RadonDB is an open source, cloud-native MySQL database for building global, scalable cloud services

Home Page:https://radondb.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[bug] some bugs found when doing DDL integration test

hustjieke opened this issue · comments

  1. When create table with unkown database, we get wrong msg
mysql> create table not_existing_database.test (a int);
ERROR 1046 (3D000): No database selected

in mysql we get:

mysql> create table not_existing_database.test (a int);
ERROR 1049 (42000): Unknown database 'not_existing_database'

The err msg during create is in sql/table.cc, line 4167:

	if (file= mysql_file_create(...)) {
	......
	4164   else                                                                                                             
	4165   { 
	4166     if (my_errno() == ENOENT)
	4167       my_error(ER_BAD_DB_ERROR,MYF(0),db);                                                                         
	4168     else
	4169       my_error(ER_CANT_CREATE_TABLE,MYF(0),table,my_errno());                                                      
	4170   }
4171   	return (file);
4172 } /* create_frm */
  1. Wrong handling on table/DB name with char space ' ' or '/', in mysql, both of them will be converted by func strconvert() in sql/strfunc.cc.
    see: https://github.com/mysql/mysql-server/blob/5.7/sql/strfunc.cc#L274

    1. in mysql, if last char is space in tbl/db name, mysql will return an error, otherwise char space
      will be converted to @0020f by func check_table_name() in sql/table.cc.
      see: https://github.com/mysql/mysql-server/blob/5.7/sql/table.cc#L4284
    2. char / will be converted to @002f by func strconvert(), e.g.:a/a will first converted to a@002fa and then write to disk.
      see: https://github.com/mysql/mysql-server/blob/5.7/sql/sql_table.cc#L518

In radon, we support both, this is not a correct way. As we did't have a function like strconver(), we don't support them currently(Ohter special characters like ?, - also have the same problem, we should find a better way to solve this problem).

  1. When create table fail during write to disk, the operation returned without clear cache in map.
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| tx             |
| a              |
+----------------+
2 rows in set (0.00 sec)

mysql> create table `a/a` (a int key);
ERROR 1105 (HY000): open bin/radon-meta/test/a/a.json: no such file or directory
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| a              |
| tx             |
| a/a            |
+----------------+
3 rows in set (0.01 sec)
  1. When create table with an error engine opt, radon did not return error msg. The code in proxy/ddl.go next is wrong.
 41     // Change the storage engine to InnoDB.                                                                         
 42     if !check {
 43         ddl.TableSpec.Options.Engine = "InnoDB"                                                                     
 44     } 

Now radon:

mysql> create table t(a int key) engine=ixx;
Query OK, 0 rows affected (2.60 sec)

Actually we should get:

mysql> create table t(a int) engine=ixx;
ERROR 1286 (42000): Unknown storage engine 'ixx'

In mysql, the error msg got from :
https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6181

For mysql support engine type(named: enum legacy_db_type)
see: https://github.com/mysql/mysql-server/blob/5.7/sql/handler.h#L397

  1. The len of db/table name should be limited.
    In mysql, the limit NAME_CHAR_LEN = 64,
    see check_table_name() in:
    https://github.com/mysql/mysql-server/blob/5.7/sql/table.cc#L4255
    and check_and_convert_db_name() in:
    https://github.com/mysql/mysql-server/blob/5.7/sql/table.cc#L4207
commented

Good catch.
ACK

Index definition has a lot of problem, include some bugs and some feature not supported, the code in sql.y should be refactored.

  1. The complete index supported in mysql doc.
create_definition: {
    col_name column_definition
  | {INDEX | KEY} [index_name] [index_type] (key_part,...)
      [index_option] ...
  | {FULLTEXT | SPATIAL} [INDEX | KEY] [index_name] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] PRIMARY KEY
      [index_type] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] UNIQUE [INDEX | KEY]
      [index_name] [index_type] (key_part,...)
      [index_option] ...
  | [CONSTRAINT [symbol]] FOREIGN KEY
      [index_name] (col_name,...)
      reference_definition
  | CHECK (expr)
}

Currently we do not support featrues like FOREIGN KEY and CHECK (expr), also we'll support index rtree which not describe in doc.
see: https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L7440

btree_or_rtree:
          BTREE_SYM { $$= HA_KEY_ALG_BTREE; }
        | RTREE_SYM { $$= HA_KEY_ALG_RTREE; }
        | HASH_SYM  { $$= HA_KEY_ALG_HASH; }
        ;

In the future, the TYPE will alse be supported just like USING.
See: https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L7405

key_using_alg:
          USING btree_or_rtree     { Lex->key_create_info.algorithm= $2; }
        | TYPE_SYM btree_or_rtree  { Lex->key_create_info.algorithm= $2; }
        ;

some features not suppored listed as next:
not support key in create:

mysql> create table t1 (a int not null, b int, primary key(a), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b), key (b));
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 62

not support index in create:

mysql> create table t1 (`primary` int, index(`primary`));
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 39

not support using in index_type:

mysql> CREATE TABLE t1(c1 VARCHAR(33), KEY USING BTREE (c1));
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 42 near 'using'
  1. not support set type:
mysql> create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, l datetime, m enum('a','b'), n set('a','b'), o char(10));
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 242 near 'set'
  1. not support start as column name:
mysql> CREATE TABLE t2(id varchar(15) NOT NULL, proc varchar(100) NOT NULL, runID varchar(16) NOT NULL, start datetime NOT NULL, PRIMARY KEY  (id,proc,runID,start));
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 103 near 'start'
  1. not support default [true | false]:
mysql> create table t1 (b bool not null default false);
ERROR 1149 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use, syntax error at position 47 near 'false'
commented

Good catch.
1 NOT-SUPPORT is in low priority, 2/3/4 we should support it.