diff --git a/.bzrignore b/.bzrignore index 135d0a66fbf..3b65e8d24e4 100644 --- a/.bzrignore +++ b/.bzrignore @@ -3072,3 +3072,4 @@ libmysqld/sql_profile.cc *.exp comments maria-win.patch +storage/maria/maria_dump_log diff --git a/mysql-test/r/maria.result b/mysql-test/r/maria.result index d5fe9f1d237..724d623e07c 100644 --- a/mysql-test/r/maria.result +++ b/mysql-test/r/maria.result @@ -2071,6 +2071,37 @@ Maria_pagecache_read_requests # Maria_pagecache_reads # Maria_pagecache_write_requests # Maria_pagecache_writes # +create table t1 (b char(0)); +insert into t1 values(NULL),(""); +select length(b) from t1; +length(b) +NULL +0 +alter table t1 add column c char(0), add key (c); +insert into t1 values("",""),("",NULL); +select length(b),length(c) from t1; +length(b) length(c) +NULL NULL +0 NULL +0 0 +0 NULL +select length(b),length(c) from t1 where c is null; +length(b) length(c) +NULL NULL +0 NULL +0 NULL +select length(b),length(c) from t1 where c is not null; +length(b) length(c) +0 0 +select length(b),length(c) from t1 order by c; +length(b) length(c) +NULL NULL +0 NULL +0 NULL +0 0 +alter table t1 add column d char(0) not null, add key (d); +ERROR 42000: The used storage engine can't index column 'd' +drop table t1; set global maria_page_checksum=1; create table t1 (a int); show create table t1; diff --git a/mysql-test/t/maria.test b/mysql-test/t/maria.test index 5feefa20c09..91d2b2111b5 100644 --- a/mysql-test/t/maria.test +++ b/mysql-test/t/maria.test @@ -1315,6 +1315,23 @@ show variables like 'maria%'; --replace_column 2 # show status like 'maria%'; +# +# Test creating table with no field data and index on zero length columns +# + +create table t1 (b char(0)); +insert into t1 values(NULL),(""); +select length(b) from t1; +alter table t1 add column c char(0), add key (c); +insert into t1 values("",""),("",NULL); +select length(b),length(c) from t1; +select length(b),length(c) from t1 where c is null; +select length(b),length(c) from t1 where c is not null; +select length(b),length(c) from t1 order by c; +--error 1167 +alter table t1 add column d char(0) not null, add key (d); +drop table t1; + # # Show that page_checksum is remembered # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 839ea6b7245..c4897efd447 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2899,10 +2899,10 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, else if (!(file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS)) length=column->length; } - else if (length == 0) + else if (length == 0 && (sql_field->flags & NOT_NULL_FLAG)) { my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name); - DBUG_RETURN(TRUE); + DBUG_RETURN(TRUE); } if (length > file->max_key_part_length() && key->type != Key::FULLTEXT) { diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index ccff0bb23ae..a5ab813745b 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -85,7 +85,7 @@ int maria_create(const char *name, enum data_file_type datafile_type, ci=&tmp_create_info; } - if (keys + uniques > MARIA_MAX_KEY || columns == 0) + if (keys + uniques > MARIA_MAX_KEY) { DBUG_RETURN(my_errno=HA_WRONG_CREATE_OPTION); } diff --git a/storage/maria/ma_pagecrc.c b/storage/maria/ma_pagecrc.c index 698cc8b95e0..f573ba132d2 100644 --- a/storage/maria/ma_pagecrc.c +++ b/storage/maria/ma_pagecrc.c @@ -305,6 +305,10 @@ my_bool maria_page_filler_set_none(uchar *page __attribute__((unused)), __attribute__((unused)), uchar *data_ptr __attribute__((unused))) { +#ifdef HAVE_purify + int4store_aligned(page + ((MARIA_SHARE *)data_ptr)->block_size - CRC_SIZE, + 0); +#endif return 0; }