diff options
author | Sachin <sachin.setiya@mariadb.com> | 2019-02-25 13:42:43 +0530 |
---|---|---|
committer | Sachin <sachin.setiya@mariadb.com> | 2019-02-25 13:42:43 +0530 |
commit | 5ddae0e0551bfaa64187ab6f3738065475310c79 (patch) | |
tree | 444b449d5827ff21344930d5982967f31ae6f075 | |
parent | 9011fa1ace3c6a49afdf05c714844d938a8c6f99 (diff) | |
download | mariadb-git-bb-10.4-release-long_unique.tar.gz |
Fix Inndb alter table and fix innodb not null long unique.bb-10.4-release-long_unique
Also make long_unique a universal test so that it can be used for innodb,
myisam and other storage engine in future.
-rw-r--r-- | mysql-test/include/long_unique.inc | 519 | ||||
-rw-r--r-- | mysql-test/main/long_unique_debug.result | 6 | ||||
-rw-r--r-- | mysql-test/main/long_unique_innodb.result | 1480 | ||||
-rw-r--r-- | mysql-test/main/long_unique_innodb.test | 140 | ||||
-rw-r--r-- | mysql-test/main/long_unique_innodb_transaction.result | 133 | ||||
-rw-r--r-- | mysql-test/main/long_unique_innodb_transaction.test | 140 | ||||
-rw-r--r-- | mysql-test/main/long_unique_myisam.result | 1402 | ||||
-rw-r--r-- | mysql-test/main/long_unique_myisam.test | 18 | ||||
-rw-r--r-- | sql/handler.cc | 5 | ||||
-rw-r--r-- | sql/sql_table.cc | 19 | ||||
-rw-r--r-- | sql/table.cc | 8 |
11 files changed, 3597 insertions, 273 deletions
diff --git a/mysql-test/include/long_unique.inc b/mysql-test/include/long_unique.inc new file mode 100644 index 00000000000..7a0033118ca --- /dev/null +++ b/mysql-test/include/long_unique.inc @@ -0,0 +1,519 @@ +--source include/have_partition.inc + +# +# MDEV-371 Unique indexes for blobs +# + +--echo #Structure of tests +--echo #First we will check all option for +--echo #table containing single unique column +--echo #table containing keys like unique(a,b,c,d) etc +--echo #then table containing 2 blob unique etc +set @allowed_packet= @@max_allowed_packet; +--echo #table with single long blob column; +create table t1(a blob unique ); +insert into t1 values(1),(2),(3),(56),('sachin'),('maria'),(123456789034567891),(null),(null),(123456789034567890); +--echo #blob with primary key not allowed +--error ER_TOO_LONG_KEY +create table t2(a blob,primary key(a(10000))); +--error ER_TOO_LONG_KEY +create table t3(a varchar(10000) primary key); + +--error ER_DUP_ENTRY +insert into t1 values(2); +--echo #table structure; +desc t1; +show create table t1; +query_vertical show keys from t1; +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +query_vertical select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +--echo # table select we should not be able to see db_row_hash_column; +select * from t1 order by a; +--error ER_BAD_FIELD_ERROR +select db_row_hash_1 from t1; +--echo #duplicate entry test; +--error ER_DUP_ENTRY +insert into t1 values(2); +--error ER_DUP_ENTRY +insert into t1 values('sachin'); +--error ER_DUP_ENTRY +insert into t1 values(123456789034567891); +select * from t1 order by a; +insert into t1 values(11),(22),(33); +--error ER_DUP_ENTRY +insert into t1 values(12),(22); +select * from t1 order by a; +insert into t1 values(repeat('s',4000*10)),(repeat('s',4001*10)); +--error ER_DUP_ENTRY +insert into t1 values(repeat('m',4000*10)),(repeat('m',4000*10)); +insert into t1 values(repeat('m',4001)),(repeat('m',4002)); +truncate table t1; +insert into t1 values(1),(2),(3),(4),(5),(8),(7); +--echo #now some alter commands; +alter table t1 add column b int; +desc t1; +show create table t1; +--error ER_DUP_ENTRY +insert into t1 values(1,2); +--error ER_DUP_ENTRY +insert into t1 values(2,2); +--error ER_BAD_FIELD_ERROR +select db_row_hash_1 from t1; +--echo #now try to change db_row_hash_1 column; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop column db_row_hash_1; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 add column d int , add column e int , drop column db_row_hash_1; +--error ER_BAD_FIELD_ERROR +alter table t1 modify column db_row_hash_1 int ; +--error ER_BAD_FIELD_ERROR +alter table t1 add column a int , add column b int, modify column db_row_hash_1 int ; +--error ER_BAD_FIELD_ERROR +alter table t1 change column db_row_hash_1 dsds int; +--error ER_BAD_FIELD_ERROR +alter table t1 add column asd int, change column db_row_hash_1 dsds int; +alter table t1 drop column b , add column c int; +show create table t1; + +--echo #now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +show create table t1; +--error ER_DUP_ENTRY +insert into t1 values(45,1,55),(46,1,55); +--error ER_DUP_ENTRY +insert into t1 values(45,1,55),(45,1,55); +alter table t1 add column db_row_hash_2 int, add column db_row_hash_3 int; +desc t1; +--echo #this should also drop the unique index ; +alter table t1 drop column a; +show create table t1; +show keys from t1; +--echo #add column with unique index on blob ; +alter table t1 add column a blob unique; +show create table t1; +--echo # try to change the blob unique name; +alter table t1 change column a aa blob ; +show create table t1; +show keys from t1; +--echo # try to change the blob unique datatype; +--echo #this will change index to b tree; +alter table t1 modify column aa int ; +show create table t1; +show keys from t1; +alter table t1 add column clm blob unique; +--echo #try changing the name ; +alter table t1 change column clm clm_changed blob; +show create table t1; +show keys from t1; +--echo #now drop the unique key; +alter table t1 drop key clm; +show create table t1; +show keys from t1; +drop table t1; + +create table t1 (a TEXT CHARSET latin1 COLLATE latin1_german2_ci unique); +desc t1; +show keys from t1; + insert into t1 values ('ae'); +--error ER_DUP_ENTRY +insert into t1 values ('AE'); +insert into t1 values ('Ä'); +drop table t1; +create table t1 (a int primary key, b blob unique); +desc t1; +show keys from t1; +insert into t1 values(1,1),(2,2),(3,3); +--error ER_DUP_ENTRY +insert into t1 values(1,1); +--error ER_DUP_ENTRY +insert into t1 values(7,1); +drop table t1; + +--echo #table with multiple long blob column and varchar text column ; +create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(5000) unique); +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555), +('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'), +(123456789034567891,353534,53453453453456,64565464564564,45435345345345), +(123456789034567890,43545,657567567567,78967657567567,657567567567567676); + +--echo #table structure; +desc t1; +show create table t1; +show keys from t1; +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +--echo #table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +--error ER_BAD_FIELD_ERROR +select db_row_hash_1 from t1; +--error ER_BAD_FIELD_ERROR +select db_row_hash_2 from t1; +--error ER_BAD_FIELD_ERROR +select db_row_hash_3 from t1; +--echo #duplicate entry test; +--error ER_DUP_ENTRY +insert into t1 values(21,2,3,42,51); +--error ER_DUP_ENTRY +insert into t1 values('sachin',null,null,null,null); +--error ER_DUP_ENTRY +insert into t1 values(1234567890345671890,4353451,6575675675617,789676575675617,657567567567567676); +select * from t1 order by a; +insert into t1 values(repeat('s',4000*10),100,repeat('s',4000*10),repeat('s',4000*10), +repeat('s',400)),(repeat('s',4001*10),1000,repeat('s',4001*10),repeat('s',4001*10), +repeat('s',2995)); +--error ER_DUP_ENTRY +insert into t1 values(repeat('m',4000*11),10,repeat('s',4000*11),repeat('s',4000*11),repeat('s',2995)); +truncate table t1; +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555); +--echo #now some alter commands; +alter table t1 add column f int; +desc t1; +show create table t1; +--echo #unique key should not break; +--error ER_DUP_ENTRY +insert into t1 values(1,2,3,4,5,6); +--error ER_BAD_FIELD_ERROR +select db_row_hash_1 , db_row_hash_2, db_row_hash_3 from t1; +--echo #now try to change db_row_hash_1 column; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +--error ER_BAD_FIELD_ERROR +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +--error ER_BAD_FIELD_ERROR +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +--error ER_BAD_FIELD_ERROR +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +--error ER_BAD_FIELD_ERROR +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; +alter table t1 drop column b , add column g int; +show create table t1; + +--echo #now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +alter table t1 add column db_row_hash_2 int unique; +alter table t1 add column db_row_hash_3 int unique; +show create table t1; + +alter table t1 add column db_row_hash_7 int, add column db_row_hash_5 int , add column db_row_hash_4 int ; +alter table t1 drop column db_row_hash_7,drop column db_row_hash_3, drop column db_row_hash_4; +desc t1; +--echo #this should not break anything; +--error ER_DUP_ENTRY +insert into t1 values(1,2,3,4,5,6,23,5,6); +--echo #this should also drop the unique index; +alter table t1 drop column a, drop column c; +show create table t1; +show keys from t1; +--echo #add column with unique index on blob; +alter table t1 add column a blob unique; +show create table t1; +show keys from t1; +--echo #try to change the blob unique column name; +--echo #this will change index to b tree; +alter table t1 modify column a int , modify column e int; +show create table t1; +show keys from t1; +alter table t1 add column clm1 blob unique,add column clm2 blob unique; +--echo #try changing the name; +alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob; +show create table t1; +show keys from t1; +--echo #now drop the unique key; +alter table t1 drop key clm1, drop key clm2; +show create table t1; +show keys from t1; +drop table t1; +--echo #now the table with key on multiple columns; the ultimate test; +create table t1(a blob, b int , c varchar(2000) , d text , e varchar(5000) , f longblob , g int , h text , + unique(a,b,c), unique(c,d,e),unique(e,f,g,h), unique(b,d,g,h)); + +insert into t1 values(1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3),(4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5), +('maria',6,'maria','maria','maria','maria',6,'maria'),('mariadb',7,'mariadb','mariadb','mariadb','mariadb',8,'mariadb') +,(null,null,null,null,null,null,null,null),(null,null,null,null,null,null,null,null); + +--echo #table structure; +desc t1; +show create table t1; +show keys from t1; +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +--echo # table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +--error ER_BAD_FIELD_ERROR +select db_row_hash_1 from t1; +--error ER_BAD_FIELD_ERROR +select db_row_hash_2 from t1; +--error ER_BAD_FIELD_ERROR +select db_row_hash_3 from t1; +--echo #duplicate entry test; +--echo #duplicate keys entry; +--error ER_DUP_ENTRY +insert into t1 values(1,1,1,0,0,0,0,0); +--error ER_DUP_ENTRY +insert into t1 values(0,0,1,1,1,0,0,0); +--error ER_DUP_ENTRY +insert into t1 values(0,0,0,0,1,1,1,1); +--error ER_DUP_ENTRY +insert into t1 values(1,1,1,1,1,0,0,0); +--error ER_DUP_ENTRY +insert into t1 values(0,0,0,0,1,1,1,1); +--error ER_DUP_ENTRY +insert into t1 values(1,1,1,1,1,1,1,1); +--error ER_BAD_FIELD_ERROR +select db_row_hash_1,db_row_hash_2,db_row_hash_3,db_row_hash_4,db_row_hash_5 from t1; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +--error ER_CANT_DROP_FIELD_OR_KEY +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +--error ER_BAD_FIELD_ERROR +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +--error ER_BAD_FIELD_ERROR +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +--error ER_BAD_FIELD_ERROR +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +--error ER_BAD_FIELD_ERROR +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; + +show create table t1; +--echo # add column named db_row_hash_*; +alter table t1 add column db_row_hash_7 int , add column db_row_hash_5 int, + add column db_row_hash_1 int, add column db_row_hash_2 int; +show create table t1; +show keys from t1; +alter table t1 drop column db_row_hash_7 , drop column db_row_hash_5 , + drop column db_row_hash_1, drop column db_row_hash_2 ; +show create table t1; +show keys from t1; + +--echo #try to change column names; +alter table t1 change column a aa blob , change column b bb blob , change column d dd blob; +show create table t1; +show keys from t1; +alter table t1 change column aa a blob , change column bb b blob , change column dd d blob; +show create table t1; +show keys from t1; + +--echo #now we will change the data type to int and varchar limit so that we no longer require hash_index; +--echo #on key a_b_c; +alter table t1 modify column a varchar(20) , modify column b varchar(20) , modify column c varchar(20); +show create table t1; +show keys from t1; +--echo #change it back; +alter table t1 modify column a blob , modify column b blob , modify column c blob; +show create table t1; +show keys from t1; + +--echo #try to delete blob column in unique; +truncate table t1; +## this feature removed in 10.2 +#alter table t1 drop column a, drop column b, drop column c; +#show create table t1; +#show keys from t1; +--echo #now try to delete keys; +alter table t1 drop key c, drop key e; +show create table t1; +show keys from t1; +drop table t1; + +--echo #now alter table containing some data basically some tests with ignore; +create table t1 (a blob); +insert into t1 values(1),(2),(3); +--echo #normal alter table; +alter table t1 add unique key(a); +alter table t1 drop key a; +truncate table t1; +insert into t1 values(1),(1),(2),(2),(3); +--error ER_DUP_ENTRY +alter table t1 add unique key(a); +alter ignore table t1 add unique key(a); +select * from t1 order by a; +--error ER_DUP_ENTRY +insert into t1 values(1); +show create table t1; +show keys from t1; +drop table t1; + +--echo #Now with multiple keys; +create table t1(a blob , b blob, c blob , d blob , e int); +insert into t1 values (1,1,1,1,1); +insert into t1 values (1,1,1,1,1); +insert into t1 values (2,1,1,1,1); +insert into t1 values (2,2,2,2,2); +insert into t1 values (3,3,4,4,4); +insert into t1 values (4,4,4,4,4); +--error ER_DUP_ENTRY +alter table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +alter ignore table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +select * from t1 order by a; +--error ER_DUP_ENTRY +insert into t1 values (1,12,1,13,14); +--error ER_DUP_ENTRY +insert into t1 values (12,1,14,1,14); +--error ER_DUP_ENTRY +insert into t1 values (13,12,13,14,4); +show create table t1; +show keys from t1; +drop table t1; + +--echo #visibility of db_row_hash +create table t1 (a blob unique , b blob unique); +desc t1; +insert into t1 values(1,19); +insert into t1 values(2,29); +insert into t1 values(3,39); +insert into t1 values(4,49); +create table t2 (DB_ROW_HASH_1 int, DB_ROW_HASH_2 int); +insert into t2 values(11,1); +insert into t2 values(22,2); +insert into t2 values(33,3); +insert into t2 values(44,4); +select * from t1 order by a; +select * from t2 order by DB_ROW_HASH_1; +--error ER_BAD_FIELD_ERROR +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1; +--echo #bug +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2; +--error ER_BAD_FIELD_ERROR +select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1) order by DB_ROW_HASH_1; +--error ER_BAD_FIELD_ERROR +select DB_ROW_HASH_1 from t1,t2 where t1.DB_ROW_HASH_1 = t2.DB_ROW_HASH_2; +select DB_ROW_HASH_1 from t1 inner join t2 on t1.a = t2.DB_ROW_HASH_2; +drop table t1,t2; + +--echo #very long blob entry; +SET @@GLOBAL.max_allowed_packet=67108864; + +connect ('newcon', localhost, root,,); +--connection newcon +show variables like 'max_allowed_packet'; +create table t1(a longblob unique, b longblob , c longblob , unique(b,c)); +desc t1; +show create table t1; +show keys from t1; +insert into t1 values(concat(repeat('sachin',10000000),'1'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'1')); +--error ER_DUP_ENTRY +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'4')); +--error ER_DUP_ENTRY +insert into t1 values(concat(repeat('sachin',10000000),'3'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +drop table t1; + +--echo #long key unique with different key length +create table t1(a blob, unique(a(5000))); +desc t1; +show keys from t1; +show create table t1; +insert into t1 value(concat(repeat('s',5000),'1')); +--error ER_DUP_ENTRY +insert into t1 value(concat(repeat('s',5000),'2')); +insert into t1 value(concat(repeat('a',5000),'2')); +drop table t1; + +create table t1(a varchar(4000), b longblob , c varchar(5000), d longblob, +unique(a(3500), b), unique(c(4500), d)); +desc t1; +show create table t1; +show keys from t1; +drop table t1; +disconnect newcon; +--connection default +SET @@GLOBAL.max_allowed_packet=4194304; +--echo #ext bug +create table t1(a int primary key, b blob unique, c int, d blob , index(c)); +show create table t1; +insert into t1 values(1,23,1,33); +--error ER_DUP_ENTRY +insert into t1 values(2,23,1,33); +drop table t1; +create table t2 (a blob unique , c int , index(c)); +show create table t2; +insert into t2 values(1,1); +insert into t2 values(2,1); +drop table t2; +--echo #not null test +create table t1(a blob unique not null); +desc t1; +show create table t1; +insert into t1 values(1); +insert into t1 values(3); +--error ER_DUP_ENTRY +insert into t1 values(1); +drop table t1; +create table t1(a int primary key, b blob unique , c blob unique not null); +insert into t1 values(1,1,1); +--error ER_DUP_ENTRY +insert into t1 values(2,1,2); +--error ER_DUP_ENTRY +insert into t1 values(3,3,1); +drop table t1; +create table t1 (a blob unique not null, b blob not null, c blob not null, unique(b,c)); +desc t1; +show create table t1; +insert into t1 values (1, 2, 3); +insert into t1 values (2, 1, 3); +--error ER_DUP_ENTRY +insert into t1 values (2, 1, 3); +drop table t1; + +--echo #partition +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +create table t1(a blob unique) partition by hash(a); +--echo #key length > 2^16 -1 +--error ER_TOO_LONG_KEYPART +create table t1(a blob, unique(a(65536))); +create table t1(a blob, unique(a(65535))); +show create table t1; +drop table t1; + +--echo #64 indexes +--let $create_table=create table t1 ( +--let $insert_data_1=insert into t1 values( +--let $insert_data_2=insert into t1 values( +--let $count= 63 +--let $index= 0 +while ($count) +{ + --let $create_table=$create_table a$count blob unique, + --let $insert_data_1=$insert_data_1 $count, + --let $insert_data_2=$insert_data_2 $index, + --dec $count + --inc $index +} +--let $create_table=$create_table a blob unique); +--let $insert_data_1=$insert_data_1 0); +--let $insert_data_2=$insert_data_2 63); + +--eval $create_table +--eval $insert_data_1 +--error ER_DUP_ENTRY +--eval $insert_data_1 +--eval $insert_data_2 +--error ER_DUP_ENTRY +--eval $insert_data_2 +drop table t1; + +--error ER_BLOB_KEY_WITHOUT_LENGTH +create table t1(a blob , key(a)); +create table t1(a blob); +--error ER_BLOB_KEY_WITHOUT_LENGTH +alter table t1 add index(a); +drop table t1; + +--error ER_BLOB_KEY_WITHOUT_LENGTH +create table t1(a text , key(a)); +create table t1(a varchar(4000)); +alter table t1 add index(a); +show create table t1; +drop table t1; +set @@GLOBAL.max_allowed_packet= @allowed_packet; diff --git a/mysql-test/main/long_unique_debug.result b/mysql-test/main/long_unique_debug.result index fb56a9d024b..4ec1c22e086 100644 --- a/mysql-test/main/long_unique_debug.result +++ b/mysql-test/main/long_unique_debug.result @@ -389,7 +389,7 @@ Printing table->key_info[2].key_part[0] info key_part->offset = 33 key_part->field_name = DB_ROW_HASH_2 key_part->length = 8 -key_part->null_bit = 0 +key_part->null_bit = 4 key_part->null_offset = 0 Printing share->key_info[2].key_part[0] info @@ -428,8 +428,8 @@ table->field[3]->null_bit_pos = 2 table->field[4]->field_name DB_ROW_HASH_2 table->field[4]->offset = 33 table->field[4]->field_length = 8 -table->field[4]->null_pos wrt to record 0 = -1 -table->field[4]->null_bit_pos = 0 +table->field[4]->null_pos wrt to record 0 = 0 +table->field[4]->null_bit_pos = 4 SET debug_dbug=""; drop table t1; diff --git a/mysql-test/main/long_unique_innodb.result b/mysql-test/main/long_unique_innodb.result index cb8c3ea4858..ce3ecb2671d 100644 --- a/mysql-test/main/long_unique_innodb.result +++ b/mysql-test/main/long_unique_innodb.result @@ -1,133 +1,1381 @@ -create table t1(a blob unique) engine= InnoDB; -insert into t1 values('RUC'); -insert into t1 values ('RUC'); -ERROR 23000: Duplicate entry 'RUC' for key 'a' -drop table t1; -create table t1 (a blob unique , c int unique) engine=innodb; +set default_storage_engine=innodb; +#Structure of tests +#First we will check all option for +#table containing single unique column +#table containing keys like unique(a,b,c,d) etc +#then table containing 2 blob unique etc +set @allowed_packet= @@max_allowed_packet; +#table with single long blob column; +create table t1(a blob unique ); +insert into t1 values(1),(2),(3),(56),('sachin'),('maria'),(123456789034567891),(null),(null),(123456789034567890); +#blob with primary key not allowed +create table t2(a blob,primary key(a(10000))); +ERROR 42000: Specified key was too long; max key length is 3072 bytes +create table t3(a varchar(10000) primary key); +ERROR 42000: Specified key was too long; max key length is 3072 bytes +insert into t1 values(2); +ERROR 23000: Duplicate entry '2' for key 'a' +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table t1 +Non_unique 0 +Key_name a +Seq_in_index 1 +Column_name a +Collation A +Cardinality NULL +Sub_part NULL +Packed NULL +Null YES +Index_type HASH +Comment +Index_comment +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG def +CONSTRAINT_SCHEMA test +CONSTRAINT_NAME a +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME a +ORDINAL_POSITION 1 +POSITION_IN_UNIQUE_CONSTRAINT NULL +REFERENCED_TABLE_SCHEMA NULL +REFERENCED_TABLE_NAME NULL +REFERENCED_COLUMN_NAME NULL +# table select we should not be able to see db_row_hash_column; +select * from t1 order by a; +a +NULL +NULL +1 +123456789034567890 +123456789034567891 +2 +3 +56 +maria +sachin +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#duplicate entry test; +insert into t1 values(2); +ERROR 23000: Duplicate entry '2' for key 'a' +insert into t1 values('sachin'); +ERROR 23000: Duplicate entry 'sachin' for key 'a' +insert into t1 values(123456789034567891); +ERROR 23000: Duplicate entry '123456789034567891' for key 'a' +select * from t1 order by a; +a +NULL +NULL +1 +123456789034567890 +123456789034567891 +2 +3 +56 +maria +sachin +insert into t1 values(11),(22),(33); +insert into t1 values(12),(22); +ERROR 23000: Duplicate entry '22' for key 'a' +select * from t1 order by a; +a +NULL +NULL +1 +11 +123456789034567890 +123456789034567891 +2 +22 +3 +33 +56 +maria +sachin +insert into t1 values(repeat('s',4000*10)),(repeat('s',4001*10)); +insert into t1 values(repeat('m',4000*10)),(repeat('m',4000*10)); +ERROR 23000: Duplicate entry 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' for key 'a' +insert into t1 values(repeat('m',4001)),(repeat('m',4002)); +truncate table t1; +insert into t1 values(1),(2),(3),(4),(5),(8),(7); +#now some alter commands; +alter table t1 add column b int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t1 values(1,2); +ERROR 23000: Duplicate entry '1' for key 'a' +insert into t1 values(2,2); +ERROR 23000: Duplicate entry '2' for key 'a' +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#now try to change db_row_hash_1 column; +alter table t1 drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column d int , add column e int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column a int , add column b int, modify column db_row_hash_1 int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, change column db_row_hash_1 dsds int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 drop column b , add column c int; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` blob DEFAULT NULL, `c` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +#now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, UNIQUE KEY `a` (`a`) USING HASH, - UNIQUE KEY `c` (`c`) + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t1 values(45,1,55),(46,1,55); +ERROR 23000: Duplicate entry '55' for key 'db_row_hash_1' +insert into t1 values(45,1,55),(45,1,55); +ERROR 23000: Duplicate entry '45' for key 'a' +alter table t1 add column db_row_hash_2 int, add column db_row_hash_3 int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +c int(11) YES NULL +db_row_hash_1 int(11) YES UNI NULL +db_row_hash_2 int(11) YES NULL +db_row_hash_3 int(11) YES NULL +#this should also drop the unique index ; +alter table t1 drop column a; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +#add column with unique index on blob ; +alter table t1 add column a blob unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `a` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +# try to change the blob unique name; +alter table t1 change column a aa blob ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) USING HASH ) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 a 1 aa A NULL NULL NULL YES HASH +# try to change the blob unique datatype; +#this will change index to b tree; +alter table t1 modify column aa int ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 a 1 aa A 2 NULL NULL YES BTREE +alter table t1 add column clm blob unique; +#try changing the name ; +alter table t1 change column clm clm_changed blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + `clm_changed` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`), + UNIQUE KEY `clm` (`clm_changed`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 a 1 aa A 2 NULL NULL YES BTREE +t1 0 clm 1 clm_changed A NULL NULL NULL YES HASH +#now drop the unique key; +alter table t1 drop key clm; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + `clm_changed` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 a 1 aa A 2 NULL NULL YES BTREE +drop table t1; +create table t1 (a TEXT CHARSET latin1 COLLATE latin1_german2_ci unique); +desc t1; +Field Type Null Key Default Extra +a text YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +insert into t1 values ('ae'); +insert into t1 values ('AE'); +ERROR 23000: Duplicate entry 'AE' for key 'a' +insert into t1 values ('Ä'); drop table t1; -#test for concurrent insert of long unique in innodb -create table t1(a blob unique) engine= InnoDB; +create table t1 (a int primary key, b blob unique); +desc t1; +Field Type Null Key Default Extra +a int(11) NO PRI NULL +b blob YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 a A 0 NULL NULL BTREE +t1 0 b 1 b A NULL NULL NULL YES HASH +insert into t1 values(1,1),(2,2),(3,3); +insert into t1 values(1,1); +ERROR 23000: Duplicate entry '1' for key 'b' +insert into t1 values(7,1); +ERROR 23000: Duplicate entry '1' for key 'b' +drop table t1; +#table with multiple long blob column and varchar text column ; +create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(5000) unique); +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555), +('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'), +(123456789034567891,353534,53453453453456,64565464564564,45435345345345), +(123456789034567890,43545,657567567567,78967657567567,657567567567567676); +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL +def test t1 c 3 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text UNI NEVER NULL +def test t1 e 5 NULL YES varchar 5000 5000 NULL NULL NULL latin1 latin1_swedish_ci varchar(5000) UNI NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +def test t1 0 test c 1 c A NULL NULL NULL YES HASH +def test t1 0 test d 1 d A NULL NULL NULL YES HASH +def test t1 0 test e 1 e A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +def test a def test t1 a 1 NULL NULL NULL NULL +def test c def test t1 c 1 NULL NULL NULL NULL +def test d def test t1 d 1 NULL NULL NULL NULL +def test e def test t1 e 1 NULL NULL NULL NULL +#table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +a b c d e +1 2 3 4 5 +123456789034567890 43545 657567567567 78967657567567 657567567567567676 +123456789034567891 353534 53453453453456 64565464564564 45435345345345 +2 11 22 33 44 +3111 222 333 444 555 +5611 2222 3333 4444 5555 +maria 345 frter dasd utyuty +sachin 341 fdf gfgfgfg hghgr +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +select db_row_hash_2 from t1; +ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list' +select db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list' +#duplicate entry test; +insert into t1 values(21,2,3,42,51); +ERROR 23000: Duplicate entry '3' for key 'c' +insert into t1 values('sachin',null,null,null,null); +ERROR 23000: Duplicate entry 'sachin' for key 'a' +insert into t1 values(1234567890345671890,4353451,6575675675617,789676575675617,657567567567567676); +ERROR 23000: Duplicate entry '657567567567567676' for key 'e' +select * from t1 order by a; +a b c d e +1 2 3 4 5 +123456789034567890 43545 657567567567 78967657567567 657567567567567676 +123456789034567891 353534 53453453453456 64565464564564 45435345345345 +2 11 22 33 44 +3111 222 333 444 555 +5611 2222 3333 4444 5555 +maria 345 frter dasd utyuty +sachin 341 fdf gfgfgfg hghgr +insert into t1 values(repeat('s',4000*10),100,repeat('s',4000*10),repeat('s',4000*10), +repeat('s',400)),(repeat('s',4001*10),1000,repeat('s',4001*10),repeat('s',4001*10), +repeat('s',2995)); +insert into t1 values(repeat('m',4000*11),10,repeat('s',4000*11),repeat('s',4000*11),repeat('s',2995)); +ERROR 23000: Duplicate entry 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' for key 'e' +truncate table t1; +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555); +#now some alter commands; +alter table t1 add column f int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +f int(11) YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +#unique key should not break; +insert into t1 values(1,2,3,4,5,6); +ERROR 23000: Duplicate entry '1' for key 'a' +select db_row_hash_1 , db_row_hash_2, db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#now try to change db_row_hash_1 column; +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 drop column b , add column g int; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +#now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +alter table t1 add column db_row_hash_2 int unique; +alter table t1 add column db_row_hash_3 int unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `db_row_hash_3` (`db_row_hash_3`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +alter table t1 add column db_row_hash_7 int, add column db_row_hash_5 int , add column db_row_hash_4 int ; +alter table t1 drop column db_row_hash_7,drop column db_row_hash_3, drop column db_row_hash_4; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +f int(11) YES NULL +g int(11) YES NULL +db_row_hash_1 int(11) YES UNI NULL +db_row_hash_2 int(11) YES UNI NULL +db_row_hash_5 int(11) YES NULL +#this should not break anything; +insert into t1 values(1,2,3,4,5,6,23,5,6); +ERROR 23000: Duplicate entry '1' for key 'a' +#this should also drop the unique index; +alter table t1 drop column a, drop column c; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A 2 NULL NULL YES BTREE +#add column with unique index on blob; +alter table t1 add column a blob unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), UNIQUE KEY `a` (`a`) USING HASH ) ENGINE=InnoDB DEFAULT CHARSET=latin1 -connect 'con1', localhost, root,,; -connect 'con2', localhost, root,,; -connection con1; -set innodb_lock_wait_timeout= 2; -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values('RUC'); -connection con2; -set innodb_lock_wait_timeout= 2; -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values ('RUC'); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -connection con1; -commit; -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values('RC'); -connection con2; -commit; -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values ('RC'); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -commit; -connection con1; -commit; -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values('RR'); -connection con2; -commit; -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values ('RR'); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -connection con1; -commit; -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values('S'); -connection con2; -commit; -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values ('S'); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -commit; -connection con1; -commit; -select * from t1; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A 2 NULL NULL YES BTREE +t1 0 a 1 a A NULL NULL NULL YES HASH +#try to change the blob unique column name; +#this will change index to b tree; +alter table t1 modify column a int , modify column e int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A 2 NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A 2 NULL NULL YES BTREE +t1 0 a 1 a A 2 NULL NULL YES BTREE +alter table t1 add column clm1 blob unique,add column clm2 blob unique; +#try changing the name; +alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `clm_changed1` blob DEFAULT NULL, + `clm_changed2` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`), + UNIQUE KEY `clm1` (`clm_changed1`) USING HASH, + UNIQUE KEY `clm2` (`clm_changed2`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A 2 NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A 2 NULL NULL YES BTREE +t1 0 a 1 a A 2 NULL NULL YES BTREE +t1 0 clm1 1 clm_changed1 A NULL NULL NULL YES HASH +t1 0 clm2 1 clm_changed2 A NULL NULL NULL YES HASH +#now drop the unique key; +alter table t1 drop key clm1, drop key clm2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `clm_changed1` blob DEFAULT NULL, + `clm_changed2` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A 2 NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A 2 NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A 2 NULL NULL YES BTREE +t1 0 a 1 a A 2 NULL NULL YES BTREE +drop table t1; +#now the table with key on multiple columns; the ultimate test; +create table t1(a blob, b int , c varchar(2000) , d text , e varchar(5000) , f longblob , g int , h text , +unique(a,b,c), unique(c,d,e),unique(e,f,g,h), unique(b,d,g,h)); +insert into t1 values(1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3),(4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5), +('maria',6,'maria','maria','maria','maria',6,'maria'),('mariadb',7,'mariadb','mariadb','mariadb','mariadb',8,'mariadb') +,(null,null,null,null,null,null,null,null),(null,null,null,null,null,null,null,null); +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES MUL NULL +b int(11) YES MUL NULL +c varchar(2000) YES MUL NULL +d text YES NULL +e varchar(5000) YES MUL NULL +f longblob YES NULL +g int(11) YES NULL +h text YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob MUL NEVER NULL +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) MUL NEVER NULL +def test t1 c 3 NULL YES varchar 2000 2000 NULL NULL NULL latin1 latin1_swedish_ci varchar(2000) MUL NEVER NULL +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL +def test t1 e 5 NULL YES varchar 5000 5000 NULL NULL NULL latin1 latin1_swedish_ci varchar(5000) MUL NEVER NULL +def test t1 f 6 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob NEVER NULL +def test t1 g 7 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL +def test t1 h 8 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +def test t1 0 test a 2 b A NULL NULL NULL YES HASH +def test t1 0 test a 3 c A NULL NULL NULL YES HASH +def test t1 0 test c 1 c A NULL NULL NULL YES HASH +def test t1 0 test c 2 d A NULL NULL NULL YES HASH +def test t1 0 test c 3 e A NULL NULL NULL YES HASH +def test t1 0 test e 1 e A NULL NULL NULL YES HASH +def test t1 0 test e 2 f A NULL NULL NULL YES HASH +def test t1 0 test e 3 g A NULL NULL NULL YES HASH +def test t1 0 test e 4 h A NULL NULL NULL YES HASH +def test t1 0 test b 1 b A NULL NULL NULL YES HASH +def test t1 0 test b 2 d A NULL NULL NULL YES HASH +def test t1 0 test b 3 g A NULL NULL NULL YES HASH +def test t1 0 test b 4 h A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +def test a def test t1 a 1 NULL NULL NULL NULL +def test a def test t1 b 2 NULL NULL NULL NULL +def test a def test t1 c 3 NULL NULL NULL NULL +def test c def test t1 c 1 NULL NULL NULL NULL +def test c def test t1 d 2 NULL NULL NULL NULL +def test c def test t1 e 3 NULL NULL NULL NULL +def test e def test t1 e 1 NULL NULL NULL NULL +def test e def test t1 f 2 NULL NULL NULL NULL +def test e def test t1 g 3 NULL NULL NULL NULL +def test e def test t1 h 4 NULL NULL NULL NULL +def test b def test t1 b 1 NULL NULL NULL NULL +def test b def test t1 d 2 NULL NULL NULL NULL +def test b def test t1 g 3 NULL NULL NULL NULL +def test b def test t1 h 4 NULL NULL NULL NULL +# table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +a b c d e f g h +NULL NULL NULL NULL NULL NULL NULL NULL +NULL NULL NULL NULL NULL NULL NULL NULL +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 +4 4 4 4 4 4 4 4 +5 5 5 5 5 5 5 5 +maria 6 maria maria maria maria 6 maria +mariadb 7 mariadb mariadb mariadb mariadb 8 mariadb +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +select db_row_hash_2 from t1; +ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list' +select db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list' +#duplicate entry test; +#duplicate keys entry; +insert into t1 values(1,1,1,0,0,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +insert into t1 values(0,0,1,1,1,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'c' +insert into t1 values(0,0,0,0,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1-1' for key 'e' +insert into t1 values(1,1,1,1,1,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +insert into t1 values(0,0,0,0,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1-1' for key 'e' +insert into t1 values(1,1,1,1,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +select db_row_hash_1,db_row_hash_2,db_row_hash_3,db_row_hash_4,db_row_hash_5 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +# add column named db_row_hash_*; +alter table t1 add column db_row_hash_7 int , add column db_row_hash_5 int, +add column db_row_hash_1 int, add column db_row_hash_2 int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + `db_row_hash_7` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +alter table t1 drop column db_row_hash_7 , drop column db_row_hash_5 , +drop column db_row_hash_1, drop column db_row_hash_2 ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#try to change column names; +alter table t1 change column a aa blob , change column b bb blob , change column d dd blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `aa` blob DEFAULT NULL, + `bb` blob DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `dd` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`aa`,`bb`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`dd`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`bb`,`dd`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 aa A NULL NULL NULL YES HASH +t1 0 a 2 bb A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 dd A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 bb A NULL NULL NULL YES HASH +t1 0 b 2 dd A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +alter table t1 change column aa a blob , change column bb b blob , change column dd d blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#now we will change the data type to int and varchar limit so that we no longer require hash_index; +#on key a_b_c; +alter table t1 modify column a varchar(20) , modify column b varchar(20) , modify column c varchar(20); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(20) DEFAULT NULL, + `b` varchar(20) DEFAULT NULL, + `c` varchar(20) DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`), + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A 2 NULL NULL YES BTREE +t1 0 a 2 b A 2 NULL NULL YES BTREE +t1 0 a 3 c A 2 NULL NULL YES BTREE +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#change it back; +alter table t1 modify column a blob , modify column b blob , modify column c blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#try to delete blob column in unique; +truncate table t1; +#now try to delete keys; +alter table t1 drop key c, drop key e; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +drop table t1; +#now alter table containing some data basically some tests with ignore; +create table t1 (a blob); +insert into t1 values(1),(2),(3); +#normal alter table; +alter table t1 add unique key(a); +alter table t1 drop key a; +truncate table t1; +insert into t1 values(1),(1),(2),(2),(3); +alter table t1 add unique key(a); +ERROR 23000: Duplicate entry '1' for key 'a' +alter ignore table t1 add unique key(a); +select * from t1 order by a; a -RUC -RC -RR -S -drop table t1; -create table t1(a blob unique) engine=Innodb; -connection con1; -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values('RUC'); -connection con2; -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values ('RUC');; -connection con1; -rollback; -connection con2; -commit; -connection con1; -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values('RC'); -connection con2; -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values ('RC');; -connection con1; -rollback; -connection con2; -commit; -connection con1; -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values('RR'); -connection con2; -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values ('RR');; -connection con1; -rollback; -connection con2; -commit; -connection con1; -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values('S'); -connection con2; -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values ('S');; -connection con1; -rollback; -connection con2; -commit; +1 +2 +3 +insert into t1 values(1); +ERROR 23000: Duplicate entry '1' for key 'a' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +drop table t1; +#Now with multiple keys; +create table t1(a blob , b blob, c blob , d blob , e int); +insert into t1 values (1,1,1,1,1); +insert into t1 values (1,1,1,1,1); +insert into t1 values (2,1,1,1,1); +insert into t1 values (2,2,2,2,2); +insert into t1 values (3,3,4,4,4); +insert into t1 values (4,4,4,4,4); +alter table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +ERROR 23000: Duplicate entry '1-1' for key 'a' +alter ignore table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +select * from t1 order by a; +a b c d e +1 1 1 1 1 +2 2 2 2 2 +3 3 4 4 4 +insert into t1 values (1,12,1,13,14); +ERROR 23000: Duplicate entry '1-1' for key 'a' +insert into t1 values (12,1,14,1,14); +ERROR 23000: Duplicate entry '1-1' for key 'b' +insert into t1 values (13,12,13,14,4); +ERROR 23000: Duplicate entry '4' for key 'e' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`,`c`) USING HASH, + UNIQUE KEY `b` (`b`,`d`) USING HASH, + UNIQUE KEY `e` (`e`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 c A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 e 1 e A 1 NULL NULL YES BTREE +drop table t1; +#visibility of db_row_hash +create table t1 (a blob unique , b blob unique); +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b blob YES UNI NULL +insert into t1 values(1,19); +insert into t1 values(2,29); +insert into t1 values(3,39); +insert into t1 values(4,49); +create table t2 (DB_ROW_HASH_1 int, DB_ROW_HASH_2 int); +insert into t2 values(11,1); +insert into t2 values(22,2); +insert into t2 values(33,3); +insert into t2 values(44,4); +select * from t1 order by a; +a b +1 19 +2 29 +3 39 +4 49 +select * from t2 order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +22 2 +33 3 +44 4 +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1; +ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'field list' +#bug +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +11 1 +11 1 +11 1 +22 2 +22 2 +22 2 +22 2 +33 3 +33 3 +33 3 +33 3 +44 4 +44 4 +44 4 +44 4 +select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'IN/ALL/ANY subquery' +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +11 1 +11 1 +11 1 +22 2 +22 2 +22 2 +22 2 +33 3 +33 3 +33 3 +33 3 +44 4 +44 4 +44 4 +44 4 +select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1) order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +22 2 +33 3 +44 4 +select DB_ROW_HASH_1 from t1,t2 where t1.DB_ROW_HASH_1 = t2.DB_ROW_HASH_2; +ERROR 42S22: Unknown column 't1.DB_ROW_HASH_1' in 'where clause' +select DB_ROW_HASH_1 from t1 inner join t2 on t1.a = t2.DB_ROW_HASH_2; +DB_ROW_HASH_1 +11 +22 +33 +44 +drop table t1,t2; +#very long blob entry; +SET @@GLOBAL.max_allowed_packet=67108864; +connect 'newcon', localhost, root,,; +connection newcon; +show variables like 'max_allowed_packet'; +Variable_name Value +max_allowed_packet 67108864 +create table t1(a longblob unique, b longblob , c longblob , unique(b,c)); +desc t1; +Field Type Null Key Default Extra +a longblob YES UNI NULL +b longblob YES MUL NULL +c longblob YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` longblob DEFAULT NULL, + `b` longblob DEFAULT NULL, + `c` longblob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `b` (`b`,`c`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 c A NULL NULL NULL YES HASH +insert into t1 values(concat(repeat('sachin',10000000),'1'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'1')); +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'4')); +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'a' +insert into t1 values(concat(repeat('sachin',10000000),'3'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'b' +drop table t1; +#long key unique with different key length +create table t1(a blob, unique(a(5000))); +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL 5000 NULL YES HASH +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`(5000)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 value(concat(repeat('s',5000),'1')); +insert into t1 value(concat(repeat('s',5000),'2')); +ERROR 23000: Duplicate entry 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' for key 'a' +insert into t1 value(concat(repeat('a',5000),'2')); +drop table t1; +create table t1(a varchar(4000), b longblob , c varchar(5000), d longblob, +unique(a(3500), b), unique(c(4500), d)); +desc t1; +Field Type Null Key Default Extra +a varchar(4000) YES MUL NULL +b longblob YES NULL +c varchar(5000) YES MUL NULL +d longblob YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(4000) DEFAULT NULL, + `b` longblob DEFAULT NULL, + `c` varchar(5000) DEFAULT NULL, + `d` longblob DEFAULT NULL, + UNIQUE KEY `a` (`a`(3500),`b`) USING HASH, + UNIQUE KEY `c` (`c`(4500),`d`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL 3500 NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL 4500 NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +drop table t1; +disconnect newcon; connection default; +SET @@GLOBAL.max_allowed_packet=4194304; +#ext bug +create table t1(a int primary key, b blob unique, c int, d blob , index(c)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `d` blob DEFAULT NULL, + PRIMARY KEY (`a`), + UNIQUE KEY `b` (`b`) USING HASH, + KEY `c` (`c`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t1 values(1,23,1,33); +insert into t1 values(2,23,1,33); +ERROR 23000: Duplicate entry '23' for key 'b' +drop table t1; +create table t2 (a blob unique , c int , index(c)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + KEY `c` (`c`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t2 values(1,1); +insert into t2 values(2,1); +drop table t2; +#not null test +create table t1(a blob unique not null); +desc t1; +Field Type Null Key Default Extra +a blob NO UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob NOT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t1 values(1); +insert into t1 values(3); +insert into t1 values(1); +ERROR 23000: Duplicate entry '1' for key 'a' +drop table t1; +create table t1(a int primary key, b blob unique , c blob unique not null); +insert into t1 values(1,1,1); +insert into t1 values(2,1,2); +ERROR 23000: Duplicate entry '1' for key 'b' +insert into t1 values(3,3,1); +ERROR 23000: Duplicate entry '1' for key 'c' +drop table t1; +create table t1 (a blob unique not null, b blob not null, c blob not null, unique(b,c)); +desc t1; +Field Type Null Key Default Extra +a blob NO UNI NULL +b blob NO MUL NULL +c blob NO NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob NOT NULL, + `b` blob NOT NULL, + `c` blob NOT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `b` (`b`,`c`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +insert into t1 values (1, 2, 3); +insert into t1 values (2, 1, 3); +insert into t1 values (2, 1, 3); +ERROR 23000: Duplicate entry '2' for key 'a' +drop table t1; +#partition +create table t1(a blob unique) partition by hash(a); +ERROR HY000: A BLOB field is not allowed in partition function +#key length > 2^16 -1 +create table t1(a blob, unique(a(65536))); +ERROR 42000: Specified key part was too long; max key part length is 65535 bytes +create table t1(a blob, unique(a(65535))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`(65535)) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop table t1; +#64 indexes +create table t1 ( a63 blob unique, a62 blob unique, a61 blob unique, a60 blob unique, a59 blob unique, a58 blob unique, a57 blob unique, a56 blob unique, a55 blob unique, a54 blob unique, a53 blob unique, a52 blob unique, a51 blob unique, a50 blob unique, a49 blob unique, a48 blob unique, a47 blob unique, a46 blob unique, a45 blob unique, a44 blob unique, a43 blob unique, a42 blob unique, a41 blob unique, a40 blob unique, a39 blob unique, a38 blob unique, a37 blob unique, a36 blob unique, a35 blob unique, a34 blob unique, a33 blob unique, a32 blob unique, a31 blob unique, a30 blob unique, a29 blob unique, a28 blob unique, a27 blob unique, a26 blob unique, a25 blob unique, a24 blob unique, a23 blob unique, a22 blob unique, a21 blob unique, a20 blob unique, a19 blob unique, a18 blob unique, a17 blob unique, a16 blob unique, a15 blob unique, a14 blob unique, a13 blob unique, a12 blob unique, a11 blob unique, a10 blob unique, a9 blob unique, a8 blob unique, a7 blob unique, a6 blob unique, a5 blob unique, a4 blob unique, a3 blob unique, a2 blob unique, a1 blob unique, a blob unique);; +insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);; +insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);; +ERROR 23000: Duplicate entry '63' for key 'a63' +insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; +insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; +ERROR 23000: Duplicate entry '0' for key 'a63' +drop table t1; +create table t1(a blob , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a blob); +alter table t1 add index(a); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +drop table t1; +create table t1(a text , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a varchar(4000)); +alter table t1 add index(a); +Warnings: +Warning 1071 Specified key was too long; max key length is 3072 bytes +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(4000) DEFAULT NULL, + KEY `a` (`a`(3072)) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 drop table t1; -disconnect con1; -disconnect con2; +set @@GLOBAL.max_allowed_packet= @allowed_packet; diff --git a/mysql-test/main/long_unique_innodb.test b/mysql-test/main/long_unique_innodb.test index aac68cd2271..dfc38b2e19b 100644 --- a/mysql-test/main/long_unique_innodb.test +++ b/mysql-test/main/long_unique_innodb.test @@ -1,140 +1,6 @@ --source include/have_innodb.inc - # -# MDEV-371 Unique indexes for blobs +# MDEV-371 Unique indexes for blobs for innodb # - -create table t1(a blob unique) engine= InnoDB; -insert into t1 values('RUC'); ---error ER_DUP_ENTRY -insert into t1 values ('RUC'); -drop table t1; - -create table t1 (a blob unique , c int unique) engine=innodb; -show create table t1; -drop table t1; - ---echo #test for concurrent insert of long unique in innodb -create table t1(a blob unique) engine= InnoDB; -show create table t1; -connect ('con1', localhost, root,,); -connect ('con2', localhost, root,,); - ---connection con1 -set innodb_lock_wait_timeout= 2; -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values('RUC'); ---connection con2 -set innodb_lock_wait_timeout= 2; -set transaction isolation level READ UNCOMMITTED; -start transaction; ---error ER_LOCK_WAIT_TIMEOUT -insert into t1 values ('RUC'); - ---connection con1 -commit; -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values('RC'); ---connection con2 -commit; -set transaction isolation level READ COMMITTED; -start transaction; ---error ER_LOCK_WAIT_TIMEOUT -insert into t1 values ('RC'); -commit; - ---connection con1 -commit; -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values('RR'); ---connection con2 -commit; -set transaction isolation level REPEATABLE READ; -start transaction; ---error ER_LOCK_WAIT_TIMEOUT -insert into t1 values ('RR'); - ---connection con1 -commit; -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values('S'); ---connection con2 -commit; -set transaction isolation level SERIALIZABLE; -start transaction; ---error ER_LOCK_WAIT_TIMEOUT -insert into t1 values ('S'); -commit; - ---connection con1 -commit; - -select * from t1; -drop table t1; - -create table t1(a blob unique) engine=Innodb; - ---connection con1 -set transaction isolation level READ UNCOMMITTED; -start transaction; -insert into t1 values('RUC'); ---connection con2 -set transaction isolation level READ UNCOMMITTED; -start transaction; ---send insert into t1 values ('RUC'); ---connection con1 -rollback; ---connection con2 ---reap -commit; - ---connection con1 -set transaction isolation level READ COMMITTED; -start transaction; -insert into t1 values('RC'); ---connection con2 -set transaction isolation level READ COMMITTED; -start transaction; ---send insert into t1 values ('RC'); ---connection con1 -rollback; ---connection con2 ---reap -commit; - ---connection con1 -set transaction isolation level REPEATABLE READ; -start transaction; -insert into t1 values('RR'); ---connection con2 -set transaction isolation level REPEATABLE READ; -start transaction; ---send insert into t1 values ('RR'); ---connection con1 -rollback; ---connection con2 ---reap -commit; - ---connection con1 -set transaction isolation level SERIALIZABLE; -start transaction; -insert into t1 values('S'); ---connection con2 -set transaction isolation level SERIALIZABLE; -start transaction; ---send insert into t1 values ('S'); ---connection con1 -rollback; ---connection con2 ---reap -commit; - -connection default; -drop table t1; -disconnect con1; -disconnect con2; +set default_storage_engine=innodb; +--source include/long_unique.inc diff --git a/mysql-test/main/long_unique_innodb_transaction.result b/mysql-test/main/long_unique_innodb_transaction.result new file mode 100644 index 00000000000..cb8c3ea4858 --- /dev/null +++ b/mysql-test/main/long_unique_innodb_transaction.result @@ -0,0 +1,133 @@ +create table t1(a blob unique) engine= InnoDB; +insert into t1 values('RUC'); +insert into t1 values ('RUC'); +ERROR 23000: Duplicate entry 'RUC' for key 'a' +drop table t1; +create table t1 (a blob unique , c int unique) engine=innodb; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop table t1; +#test for concurrent insert of long unique in innodb +create table t1(a blob unique) engine= InnoDB; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +connect 'con1', localhost, root,,; +connect 'con2', localhost, root,,; +connection con1; +set innodb_lock_wait_timeout= 2; +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values('RUC'); +connection con2; +set innodb_lock_wait_timeout= 2; +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values ('RUC'); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +connection con1; +commit; +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values('RC'); +connection con2; +commit; +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values ('RC'); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +commit; +connection con1; +commit; +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values('RR'); +connection con2; +commit; +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values ('RR'); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +connection con1; +commit; +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values('S'); +connection con2; +commit; +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values ('S'); +ERROR HY000: Lock wait timeout exceeded; try restarting transaction +commit; +connection con1; +commit; +select * from t1; +a +RUC +RC +RR +S +drop table t1; +create table t1(a blob unique) engine=Innodb; +connection con1; +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values('RUC'); +connection con2; +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values ('RUC');; +connection con1; +rollback; +connection con2; +commit; +connection con1; +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values('RC'); +connection con2; +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values ('RC');; +connection con1; +rollback; +connection con2; +commit; +connection con1; +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values('RR'); +connection con2; +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values ('RR');; +connection con1; +rollback; +connection con2; +commit; +connection con1; +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values('S'); +connection con2; +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values ('S');; +connection con1; +rollback; +connection con2; +commit; +connection default; +drop table t1; +disconnect con1; +disconnect con2; diff --git a/mysql-test/main/long_unique_innodb_transaction.test b/mysql-test/main/long_unique_innodb_transaction.test new file mode 100644 index 00000000000..aac68cd2271 --- /dev/null +++ b/mysql-test/main/long_unique_innodb_transaction.test @@ -0,0 +1,140 @@ +--source include/have_innodb.inc + +# +# MDEV-371 Unique indexes for blobs +# + +create table t1(a blob unique) engine= InnoDB; +insert into t1 values('RUC'); +--error ER_DUP_ENTRY +insert into t1 values ('RUC'); +drop table t1; + +create table t1 (a blob unique , c int unique) engine=innodb; +show create table t1; +drop table t1; + +--echo #test for concurrent insert of long unique in innodb +create table t1(a blob unique) engine= InnoDB; +show create table t1; +connect ('con1', localhost, root,,); +connect ('con2', localhost, root,,); + +--connection con1 +set innodb_lock_wait_timeout= 2; +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values('RUC'); +--connection con2 +set innodb_lock_wait_timeout= 2; +set transaction isolation level READ UNCOMMITTED; +start transaction; +--error ER_LOCK_WAIT_TIMEOUT +insert into t1 values ('RUC'); + +--connection con1 +commit; +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values('RC'); +--connection con2 +commit; +set transaction isolation level READ COMMITTED; +start transaction; +--error ER_LOCK_WAIT_TIMEOUT +insert into t1 values ('RC'); +commit; + +--connection con1 +commit; +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values('RR'); +--connection con2 +commit; +set transaction isolation level REPEATABLE READ; +start transaction; +--error ER_LOCK_WAIT_TIMEOUT +insert into t1 values ('RR'); + +--connection con1 +commit; +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values('S'); +--connection con2 +commit; +set transaction isolation level SERIALIZABLE; +start transaction; +--error ER_LOCK_WAIT_TIMEOUT +insert into t1 values ('S'); +commit; + +--connection con1 +commit; + +select * from t1; +drop table t1; + +create table t1(a blob unique) engine=Innodb; + +--connection con1 +set transaction isolation level READ UNCOMMITTED; +start transaction; +insert into t1 values('RUC'); +--connection con2 +set transaction isolation level READ UNCOMMITTED; +start transaction; +--send insert into t1 values ('RUC'); +--connection con1 +rollback; +--connection con2 +--reap +commit; + +--connection con1 +set transaction isolation level READ COMMITTED; +start transaction; +insert into t1 values('RC'); +--connection con2 +set transaction isolation level READ COMMITTED; +start transaction; +--send insert into t1 values ('RC'); +--connection con1 +rollback; +--connection con2 +--reap +commit; + +--connection con1 +set transaction isolation level REPEATABLE READ; +start transaction; +insert into t1 values('RR'); +--connection con2 +set transaction isolation level REPEATABLE READ; +start transaction; +--send insert into t1 values ('RR'); +--connection con1 +rollback; +--connection con2 +--reap +commit; + +--connection con1 +set transaction isolation level SERIALIZABLE; +start transaction; +insert into t1 values('S'); +--connection con2 +set transaction isolation level SERIALIZABLE; +start transaction; +--send insert into t1 values ('S'); +--connection con1 +rollback; +--connection con2 +--reap +commit; + +connection default; +drop table t1; +disconnect con1; +disconnect con2; diff --git a/mysql-test/main/long_unique_myisam.result b/mysql-test/main/long_unique_myisam.result new file mode 100644 index 00000000000..4b58ded148e --- /dev/null +++ b/mysql-test/main/long_unique_myisam.result @@ -0,0 +1,1402 @@ +set default_storage_engine=myisam; +#Structure of tests +#First we will check all option for +#table containing single unique column +#table containing keys like unique(a,b,c,d) etc +#then table containing 2 blob unique etc +set @allowed_packet= @@max_allowed_packet; +#table with single long blob column; +create table t1(a blob unique ); +insert into t1 values(1),(2),(3),(56),('sachin'),('maria'),(123456789034567891),(null),(null),(123456789034567890); +#blob with primary key not allowed +create table t2(a blob,primary key(a(10000))); +ERROR 42000: Specified key was too long; max key length is 1000 bytes +create table t3(a varchar(10000) primary key); +ERROR 42000: Specified key was too long; max key length is 1000 bytes +insert into t1 values(2); +ERROR 23000: Duplicate entry '2' for key 'a' +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table t1 +Non_unique 0 +Key_name a +Seq_in_index 1 +Column_name a +Collation A +Cardinality NULL +Sub_part NULL +Packed NULL +Null YES +Index_type HASH +Comment +Index_comment +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG def +CONSTRAINT_SCHEMA test +CONSTRAINT_NAME a +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME a +ORDINAL_POSITION 1 +POSITION_IN_UNIQUE_CONSTRAINT NULL +REFERENCED_TABLE_SCHEMA NULL +REFERENCED_TABLE_NAME NULL +REFERENCED_COLUMN_NAME NULL +# table select we should not be able to see db_row_hash_column; +select * from t1 order by a; +a +NULL +NULL +1 +123456789034567890 +123456789034567891 +2 +3 +56 +maria +sachin +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#duplicate entry test; +insert into t1 values(2); +ERROR 23000: Duplicate entry '2' for key 'a' +insert into t1 values('sachin'); +ERROR 23000: Duplicate entry 'sachin' for key 'a' +insert into t1 values(123456789034567891); +ERROR 23000: Duplicate entry '123456789034567891' for key 'a' +select * from t1 order by a; +a +NULL +NULL +1 +123456789034567890 +123456789034567891 +2 +3 +56 +maria +sachin +insert into t1 values(11),(22),(33); +insert into t1 values(12),(22); +ERROR 23000: Duplicate entry '22' for key 'a' +select * from t1 order by a; +a +NULL +NULL +1 +11 +12 +123456789034567890 +123456789034567891 +2 +22 +3 +33 +56 +maria +sachin +insert into t1 values(repeat('s',4000*10)),(repeat('s',4001*10)); +insert into t1 values(repeat('m',4000*10)),(repeat('m',4000*10)); +ERROR 23000: Duplicate entry 'mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm' for key 'a' +insert into t1 values(repeat('m',4001)),(repeat('m',4002)); +truncate table t1; +insert into t1 values(1),(2),(3),(4),(5),(8),(7); +#now some alter commands; +alter table t1 add column b int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values(1,2); +ERROR 23000: Duplicate entry '1' for key 'a' +insert into t1 values(2,2); +ERROR 23000: Duplicate entry '2' for key 'a' +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#now try to change db_row_hash_1 column; +alter table t1 drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column d int , add column e int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column a int , add column b int, modify column db_row_hash_1 int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, change column db_row_hash_1 dsds int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 drop column b , add column c int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +#now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values(45,1,55),(46,1,55); +ERROR 23000: Duplicate entry '55' for key 'db_row_hash_1' +insert into t1 values(45,1,55),(45,1,55); +ERROR 23000: Duplicate entry '45' for key 'a' +alter table t1 add column db_row_hash_2 int, add column db_row_hash_3 int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +c int(11) YES NULL +db_row_hash_1 int(11) YES UNI NULL +db_row_hash_2 int(11) YES NULL +db_row_hash_3 int(11) YES NULL +#this should also drop the unique index ; +alter table t1 drop column a; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +#add column with unique index on blob ; +alter table t1 add column a blob unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `a` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +# try to change the blob unique name; +alter table t1 change column a aa blob ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 a 1 aa A NULL NULL NULL YES HASH +# try to change the blob unique datatype; +#this will change index to b tree; +alter table t1 modify column aa int ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 a 1 aa A NULL NULL NULL YES BTREE +alter table t1 add column clm blob unique; +#try changing the name ; +alter table t1 change column clm clm_changed blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + `clm_changed` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`), + UNIQUE KEY `clm` (`clm_changed`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 a 1 aa A NULL NULL NULL YES BTREE +t1 0 clm 1 clm_changed A NULL NULL NULL YES HASH +#now drop the unique key; +alter table t1 drop key clm; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + `aa` int(11) DEFAULT NULL, + `clm_changed` blob DEFAULT NULL, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `a` (`aa`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 a 1 aa A NULL NULL NULL YES BTREE +drop table t1; +create table t1 (a TEXT CHARSET latin1 COLLATE latin1_german2_ci unique); +desc t1; +Field Type Null Key Default Extra +a text YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +insert into t1 values ('ae'); +insert into t1 values ('AE'); +ERROR 23000: Duplicate entry 'AE' for key 'a' +insert into t1 values ('Ä'); +drop table t1; +create table t1 (a int primary key, b blob unique); +desc t1; +Field Type Null Key Default Extra +a int(11) NO PRI NULL +b blob YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 a A 0 NULL NULL BTREE +t1 0 b 1 b A NULL NULL NULL YES HASH +insert into t1 values(1,1),(2,2),(3,3); +insert into t1 values(1,1); +ERROR 23000: Duplicate entry '1' for key 'b' +insert into t1 values(7,1); +ERROR 23000: Duplicate entry '1' for key 'b' +drop table t1; +#table with multiple long blob column and varchar text column ; +create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(5000) unique); +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555), +('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'), +(123456789034567891,353534,53453453453456,64565464564564,45435345345345), +(123456789034567890,43545,657567567567,78967657567567,657567567567567676); +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL +def test t1 c 3 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob UNI NEVER NULL +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text UNI NEVER NULL +def test t1 e 5 NULL YES varchar 5000 5000 NULL NULL NULL latin1 latin1_swedish_ci varchar(5000) UNI NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +def test t1 0 test c 1 c A NULL NULL NULL YES HASH +def test t1 0 test d 1 d A NULL NULL NULL YES HASH +def test t1 0 test e 1 e A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +def test a def test t1 a 1 NULL NULL NULL NULL +def test c def test t1 c 1 NULL NULL NULL NULL +def test d def test t1 d 1 NULL NULL NULL NULL +def test e def test t1 e 1 NULL NULL NULL NULL +#table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +a b c d e +1 2 3 4 5 +123456789034567890 43545 657567567567 78967657567567 657567567567567676 +123456789034567891 353534 53453453453456 64565464564564 45435345345345 +2 11 22 33 44 +3111 222 333 444 555 +5611 2222 3333 4444 5555 +maria 345 frter dasd utyuty +sachin 341 fdf gfgfgfg hghgr +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +select db_row_hash_2 from t1; +ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list' +select db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list' +#duplicate entry test; +insert into t1 values(21,2,3,42,51); +ERROR 23000: Duplicate entry '3' for key 'c' +insert into t1 values('sachin',null,null,null,null); +ERROR 23000: Duplicate entry 'sachin' for key 'a' +insert into t1 values(1234567890345671890,4353451,6575675675617,789676575675617,657567567567567676); +ERROR 23000: Duplicate entry '657567567567567676' for key 'e' +select * from t1 order by a; +a b c d e +1 2 3 4 5 +123456789034567890 43545 657567567567 78967657567567 657567567567567676 +123456789034567891 353534 53453453453456 64565464564564 45435345345345 +2 11 22 33 44 +3111 222 333 444 555 +5611 2222 3333 4444 5555 +maria 345 frter dasd utyuty +sachin 341 fdf gfgfgfg hghgr +insert into t1 values(repeat('s',4000*10),100,repeat('s',4000*10),repeat('s',4000*10), +repeat('s',400)),(repeat('s',4001*10),1000,repeat('s',4001*10),repeat('s',4001*10), +repeat('s',2995)); +insert into t1 values(repeat('m',4000*11),10,repeat('s',4000*11),repeat('s',4000*11),repeat('s',2995)); +ERROR 23000: Duplicate entry 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' for key 'e' +truncate table t1; +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555); +#now some alter commands; +alter table t1 add column f int; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b int(11) YES NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +f int(11) YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +#unique key should not break; +insert into t1 values(1,2,3,4,5,6); +ERROR 23000: Duplicate entry '1' for key 'a' +select db_row_hash_1 , db_row_hash_2, db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +#now try to change db_row_hash_1 column; +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 drop column b , add column g int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +#now add some column with name db_row_hash; +alter table t1 add column db_row_hash_1 int unique; +alter table t1 add column db_row_hash_2 int unique; +alter table t1 add column db_row_hash_3 int unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_3` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `c` (`c`) USING HASH, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `db_row_hash_3` (`db_row_hash_3`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 add column db_row_hash_7 int, add column db_row_hash_5 int , add column db_row_hash_4 int ; +alter table t1 drop column db_row_hash_7,drop column db_row_hash_3, drop column db_row_hash_4; +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +c blob YES UNI NULL +d text YES UNI NULL +e varchar(5000) YES UNI NULL +f int(11) YES NULL +g int(11) YES NULL +db_row_hash_1 int(11) YES UNI NULL +db_row_hash_2 int(11) YES UNI NULL +db_row_hash_5 int(11) YES NULL +#this should not break anything; +insert into t1 values(1,2,3,4,5,6,23,5,6); +ERROR 23000: Duplicate entry '1' for key 'a' +#this should also drop the unique index; +alter table t1 drop column a, drop column c; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE +#add column with unique index on blob; +alter table t1 add column a blob unique; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`) USING HASH, + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE +t1 0 a 1 a A NULL NULL NULL YES HASH +#try to change the blob unique column name; +#this will change index to b tree; +alter table t1 modify column a int , modify column e int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE +t1 0 a 1 a A NULL NULL NULL YES BTREE +alter table t1 add column clm1 blob unique,add column clm2 blob unique; +#try changing the name; +alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `clm_changed1` blob DEFAULT NULL, + `clm_changed2` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`), + UNIQUE KEY `clm1` (`clm_changed1`) USING HASH, + UNIQUE KEY `clm2` (`clm_changed2`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 0 clm1 1 clm_changed1 A NULL NULL NULL YES HASH +t1 0 clm2 1 clm_changed2 A NULL NULL NULL YES HASH +#now drop the unique key; +alter table t1 drop key clm1, drop key clm2; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` text DEFAULT NULL, + `e` int(11) DEFAULT NULL, + `f` int(11) DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `a` int(11) DEFAULT NULL, + `clm_changed1` blob DEFAULT NULL, + `clm_changed2` blob DEFAULT NULL, + UNIQUE KEY `d` (`d`) USING HASH, + UNIQUE KEY `e` (`e`), + UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`), + UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`), + UNIQUE KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 d 1 d A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES BTREE +t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE +t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE +t1 0 a 1 a A NULL NULL NULL YES BTREE +drop table t1; +#now the table with key on multiple columns; the ultimate test; +create table t1(a blob, b int , c varchar(2000) , d text , e varchar(5000) , f longblob , g int , h text , +unique(a,b,c), unique(c,d,e),unique(e,f,g,h), unique(b,d,g,h)); +insert into t1 values(1,1,1,1,1,1,1,1),(2,2,2,2,2,2,2,2),(3,3,3,3,3,3,3,3),(4,4,4,4,4,4,4,4),(5,5,5,5,5,5,5,5), +('maria',6,'maria','maria','maria','maria',6,'maria'),('mariadb',7,'mariadb','mariadb','mariadb','mariadb',8,'mariadb') +,(null,null,null,null,null,null,null,null),(null,null,null,null,null,null,null,null); +#table structure; +desc t1; +Field Type Null Key Default Extra +a blob YES MUL NULL +b int(11) YES MUL NULL +c varchar(2000) YES MUL NULL +d text YES NULL +e varchar(5000) YES MUL NULL +f longblob YES NULL +g int(11) YES NULL +h text YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +select TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_NAME,COLLATION_NAME,COLUMN_TYPE,COLUMN_KEY,EXTRA,COLUMN_COMMENT,IS_GENERATED,GENERATION_EXPRESSION from information_schema.columns where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION COLUMN_DEFAULT IS_NULLABLE DATA_TYPE CHARACTER_MAXIMUM_LENGTH CHARACTER_OCTET_LENGTH NUMERIC_PRECISION NUMERIC_SCALE DATETIME_PRECISION CHARACTER_SET_NAME COLLATION_NAME COLUMN_TYPE COLUMN_KEY EXTRA COLUMN_COMMENT IS_GENERATED GENERATION_EXPRESSION +def test t1 a 1 NULL YES blob 65535 65535 NULL NULL NULL NULL NULL blob MUL NEVER NULL +def test t1 b 2 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) MUL NEVER NULL +def test t1 c 3 NULL YES varchar 2000 2000 NULL NULL NULL latin1 latin1_swedish_ci varchar(2000) MUL NEVER NULL +def test t1 d 4 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL +def test t1 e 5 NULL YES varchar 5000 5000 NULL NULL NULL latin1 latin1_swedish_ci varchar(5000) MUL NEVER NULL +def test t1 f 6 NULL YES longblob 4294967295 4294967295 NULL NULL NULL NULL NULL longblob NEVER NULL +def test t1 g 7 NULL YES int NULL NULL 10 0 NULL NULL NULL int(11) NEVER NULL +def test t1 h 8 NULL YES text 65535 65535 NULL NULL NULL latin1 latin1_swedish_ci text NEVER NULL +select * from information_schema.statistics where table_schema = 'test' and table_name = 't1'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME NON_UNIQUE INDEX_SCHEMA INDEX_NAME SEQ_IN_INDEX COLUMN_NAME COLLATION CARDINALITY SUB_PART PACKED NULLABLE INDEX_TYPE COMMENT INDEX_COMMENT +def test t1 0 test a 1 a A NULL NULL NULL YES HASH +def test t1 0 test a 2 b A NULL NULL NULL YES HASH +def test t1 0 test a 3 c A NULL NULL NULL YES HASH +def test t1 0 test c 1 c A NULL NULL NULL YES HASH +def test t1 0 test c 2 d A NULL NULL NULL YES HASH +def test t1 0 test c 3 e A NULL NULL NULL YES HASH +def test t1 0 test e 1 e A NULL NULL NULL YES HASH +def test t1 0 test e 2 f A NULL NULL NULL YES HASH +def test t1 0 test e 3 g A NULL NULL NULL YES HASH +def test t1 0 test e 4 h A NULL NULL NULL YES HASH +def test t1 0 test b 1 b A NULL NULL NULL YES HASH +def test t1 0 test b 2 d A NULL NULL NULL YES HASH +def test t1 0 test b 3 g A NULL NULL NULL YES HASH +def test t1 0 test b 4 h A NULL NULL NULL YES HASH +select * from information_schema.key_column_usage where table_schema= 'test' and table_name= 't1'; +CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +def test a def test t1 a 1 NULL NULL NULL NULL +def test a def test t1 b 2 NULL NULL NULL NULL +def test a def test t1 c 3 NULL NULL NULL NULL +def test c def test t1 c 1 NULL NULL NULL NULL +def test c def test t1 d 2 NULL NULL NULL NULL +def test c def test t1 e 3 NULL NULL NULL NULL +def test e def test t1 e 1 NULL NULL NULL NULL +def test e def test t1 f 2 NULL NULL NULL NULL +def test e def test t1 g 3 NULL NULL NULL NULL +def test e def test t1 h 4 NULL NULL NULL NULL +def test b def test t1 b 1 NULL NULL NULL NULL +def test b def test t1 d 2 NULL NULL NULL NULL +def test b def test t1 g 3 NULL NULL NULL NULL +def test b def test t1 h 4 NULL NULL NULL NULL +# table select we should not be able to see db_row_hash_1 column; +select * from t1 order by a; +a b c d e f g h +NULL NULL NULL NULL NULL NULL NULL NULL +NULL NULL NULL NULL NULL NULL NULL NULL +1 1 1 1 1 1 1 1 +2 2 2 2 2 2 2 2 +3 3 3 3 3 3 3 3 +4 4 4 4 4 4 4 4 +5 5 5 5 5 5 5 5 +maria 6 maria maria maria maria 6 maria +mariadb 7 mariadb mariadb mariadb mariadb 8 mariadb +select db_row_hash_1 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +select db_row_hash_2 from t1; +ERROR 42S22: Unknown column 'db_row_hash_2' in 'field list' +select db_row_hash_3 from t1; +ERROR 42S22: Unknown column 'db_row_hash_3' in 'field list' +#duplicate entry test; +#duplicate keys entry; +insert into t1 values(1,1,1,0,0,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +insert into t1 values(0,0,1,1,1,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'c' +insert into t1 values(0,0,0,0,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1-1' for key 'e' +insert into t1 values(1,1,1,1,1,0,0,0); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +insert into t1 values(0,0,0,0,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1-1' for key 'e' +insert into t1 values(1,1,1,1,1,1,1,1); +ERROR 23000: Duplicate entry '1-1-1' for key 'a' +select db_row_hash_1,db_row_hash_2,db_row_hash_3,db_row_hash_4,db_row_hash_5 from t1; +ERROR 42S22: Unknown column 'db_row_hash_1' in 'field list' +alter table t1 drop column db_row_hash_1, drop column db_row_hash_2, drop column db_row_hash_3; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 add column dg int , add column ef int , drop column db_row_hash_1; +ERROR 42000: Can't DROP COLUMN `db_row_hash_1`; check that it exists +alter table t1 modify column db_row_hash_1 int , modify column db_row_hash_2 int, modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column ar int , add column rb int, modify column db_row_hash_1 int , modify column db_row_hash_3 int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 change column db_row_hash_1 dsds int , change column db_row_hash_2 dfdf int , change column db_row_hash_3 gdfg int ; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +alter table t1 add column asd int, drop column a, change column db_row_hash_1 dsds int, change db_row_hash_3 fdfdfd int; +ERROR 42S22: Unknown column 'db_row_hash_1' in 't1' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +# add column named db_row_hash_*; +alter table t1 add column db_row_hash_7 int , add column db_row_hash_5 int, +add column db_row_hash_1 int, add column db_row_hash_2 int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + `db_row_hash_7` int(11) DEFAULT NULL, + `db_row_hash_5` int(11) DEFAULT NULL, + `db_row_hash_1` int(11) DEFAULT NULL, + `db_row_hash_2` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +alter table t1 drop column db_row_hash_7 , drop column db_row_hash_5 , +drop column db_row_hash_1, drop column db_row_hash_2 ; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` int(11) DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` text DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#try to change column names; +alter table t1 change column a aa blob , change column b bb blob , change column d dd blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `aa` blob DEFAULT NULL, + `bb` blob DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `dd` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`aa`,`bb`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`dd`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`bb`,`dd`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 aa A NULL NULL NULL YES HASH +t1 0 a 2 bb A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 dd A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 bb A NULL NULL NULL YES HASH +t1 0 b 2 dd A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +alter table t1 change column aa a blob , change column bb b blob , change column dd d blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` varchar(2000) DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#now we will change the data type to int and varchar limit so that we no longer require hash_index; +#on key a_b_c; +alter table t1 modify column a varchar(20) , modify column b varchar(20) , modify column c varchar(20); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(20) DEFAULT NULL, + `b` varchar(20) DEFAULT NULL, + `c` varchar(20) DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`), + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES BTREE +t1 0 a 2 b A NULL NULL NULL YES BTREE +t1 0 a 3 c A NULL NULL NULL YES BTREE +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#change it back; +alter table t1 modify column a blob , modify column b blob , modify column c blob; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `c` (`c`,`d`,`e`) USING HASH, + UNIQUE KEY `e` (`e`,`f`,`g`,`h`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL NULL NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +t1 0 c 3 e A NULL NULL NULL YES HASH +t1 0 e 1 e A NULL NULL NULL YES HASH +t1 0 e 2 f A NULL NULL NULL YES HASH +t1 0 e 3 g A NULL NULL NULL YES HASH +t1 0 e 4 h A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +#try to delete blob column in unique; +truncate table t1; +#now try to delete keys; +alter table t1 drop key c, drop key e; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` varchar(5000) DEFAULT NULL, + `f` longblob DEFAULT NULL, + `g` int(11) DEFAULT NULL, + `h` text DEFAULT NULL, + UNIQUE KEY `a` (`a`,`b`,`c`) USING HASH, + UNIQUE KEY `b` (`b`,`d`,`g`,`h`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 a 3 c A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 b 3 g A NULL NULL NULL YES HASH +t1 0 b 4 h A NULL NULL NULL YES HASH +drop table t1; +#now alter table containing some data basically some tests with ignore; +create table t1 (a blob); +insert into t1 values(1),(2),(3); +#normal alter table; +alter table t1 add unique key(a); +alter table t1 drop key a; +truncate table t1; +insert into t1 values(1),(1),(2),(2),(3); +alter table t1 add unique key(a); +ERROR 23000: Duplicate entry '1' for key 'a' +alter ignore table t1 add unique key(a); +select * from t1 order by a; +a +1 +2 +3 +insert into t1 values(1); +ERROR 23000: Duplicate entry '1' for key 'a' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +drop table t1; +#Now with multiple keys; +create table t1(a blob , b blob, c blob , d blob , e int); +insert into t1 values (1,1,1,1,1); +insert into t1 values (1,1,1,1,1); +insert into t1 values (2,1,1,1,1); +insert into t1 values (2,2,2,2,2); +insert into t1 values (3,3,4,4,4); +insert into t1 values (4,4,4,4,4); +alter table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +ERROR 23000: Duplicate entry '1-1' for key 'a' +alter ignore table t1 add unique key(a,c), add unique key(b,d), add unique key(e); +select * from t1 order by a; +a b c d e +1 1 1 1 1 +2 2 2 2 2 +3 3 4 4 4 +insert into t1 values (1,12,1,13,14); +ERROR 23000: Duplicate entry '1-1' for key 'a' +insert into t1 values (12,1,14,1,14); +ERROR 23000: Duplicate entry '1-1' for key 'b' +insert into t1 values (13,12,13,14,4); +ERROR 23000: Duplicate entry '4' for key 'e' +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + `b` blob DEFAULT NULL, + `c` blob DEFAULT NULL, + `d` blob DEFAULT NULL, + `e` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`,`c`) USING HASH, + UNIQUE KEY `b` (`b`,`d`) USING HASH, + UNIQUE KEY `e` (`e`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 a 2 c A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 d A NULL NULL NULL YES HASH +t1 0 e 1 e A 0 NULL NULL YES BTREE +drop table t1; +#visibility of db_row_hash +create table t1 (a blob unique , b blob unique); +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +b blob YES UNI NULL +insert into t1 values(1,19); +insert into t1 values(2,29); +insert into t1 values(3,39); +insert into t1 values(4,49); +create table t2 (DB_ROW_HASH_1 int, DB_ROW_HASH_2 int); +insert into t2 values(11,1); +insert into t2 values(22,2); +insert into t2 values(33,3); +insert into t2 values(44,4); +select * from t1 order by a; +a b +1 19 +2 29 +3 39 +4 49 +select * from t2 order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +22 2 +33 3 +44 4 +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1; +ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'field list' +#bug +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +11 1 +11 1 +11 1 +22 2 +22 2 +22 2 +22 2 +33 3 +33 3 +33 3 +33 3 +44 4 +44 4 +44 4 +44 4 +select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'IN/ALL/ANY subquery' +select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2) order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +11 1 +11 1 +11 1 +22 2 +22 2 +22 2 +22 2 +33 3 +33 3 +33 3 +33 3 +44 4 +44 4 +44 4 +44 4 +select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1) order by DB_ROW_HASH_1; +DB_ROW_HASH_1 DB_ROW_HASH_2 +11 1 +22 2 +33 3 +44 4 +select DB_ROW_HASH_1 from t1,t2 where t1.DB_ROW_HASH_1 = t2.DB_ROW_HASH_2; +ERROR 42S22: Unknown column 't1.DB_ROW_HASH_1' in 'where clause' +select DB_ROW_HASH_1 from t1 inner join t2 on t1.a = t2.DB_ROW_HASH_2; +DB_ROW_HASH_1 +11 +22 +33 +44 +drop table t1,t2; +#very long blob entry; +SET @@GLOBAL.max_allowed_packet=67108864; +connect 'newcon', localhost, root,,; +connection newcon; +show variables like 'max_allowed_packet'; +Variable_name Value +max_allowed_packet 67108864 +create table t1(a longblob unique, b longblob , c longblob , unique(b,c)); +desc t1; +Field Type Null Key Default Extra +a longblob YES UNI NULL +b longblob YES MUL NULL +c longblob YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` longblob DEFAULT NULL, + `b` longblob DEFAULT NULL, + `c` longblob DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `b` (`b`,`c`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL NULL NULL YES HASH +t1 0 b 1 b A NULL NULL NULL YES HASH +t1 0 b 2 c A NULL NULL NULL YES HASH +insert into t1 values(concat(repeat('sachin',10000000),'1'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'1')); +insert into t1 values(concat(repeat('sachin',10000000),'2'),concat(repeat('sachin',10000000),'2'), +concat(repeat('sachin',10000000),'4')); +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'a' +insert into t1 values(concat(repeat('sachin',10000000),'3'),concat(repeat('sachin',10000000),'1'), +concat(repeat('sachin',10000000),'1')); +ERROR 23000: Duplicate entry 'sachinsachinsachinsachinsachinsachinsachinsachinsachinsachinsach' for key 'b' +drop table t1; +#long key unique with different key length +create table t1(a blob, unique(a(5000))); +desc t1; +Field Type Null Key Default Extra +a blob YES UNI NULL +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL 5000 NULL YES HASH +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`(5000)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 value(concat(repeat('s',5000),'1')); +insert into t1 value(concat(repeat('s',5000),'2')); +ERROR 23000: Duplicate entry 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss' for key 'a' +insert into t1 value(concat(repeat('a',5000),'2')); +drop table t1; +create table t1(a varchar(4000), b longblob , c varchar(5000), d longblob, +unique(a(3500), b), unique(c(4500), d)); +desc t1; +Field Type Null Key Default Extra +a varchar(4000) YES MUL NULL +b longblob YES NULL +c varchar(5000) YES MUL NULL +d longblob YES NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(4000) DEFAULT NULL, + `b` longblob DEFAULT NULL, + `c` varchar(5000) DEFAULT NULL, + `d` longblob DEFAULT NULL, + UNIQUE KEY `a` (`a`(3500),`b`) USING HASH, + UNIQUE KEY `c` (`c`(4500),`d`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 a 1 a A NULL 3500 NULL YES HASH +t1 0 a 2 b A NULL NULL NULL YES HASH +t1 0 c 1 c A NULL 4500 NULL YES HASH +t1 0 c 2 d A NULL NULL NULL YES HASH +drop table t1; +disconnect newcon; +connection default; +SET @@GLOBAL.max_allowed_packet=4194304; +#ext bug +create table t1(a int primary key, b blob unique, c int, d blob , index(c)); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) NOT NULL, + `b` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + `d` blob DEFAULT NULL, + PRIMARY KEY (`a`), + UNIQUE KEY `b` (`b`) USING HASH, + KEY `c` (`c`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values(1,23,1,33); +insert into t1 values(2,23,1,33); +ERROR 23000: Duplicate entry '23' for key 'b' +drop table t1; +create table t2 (a blob unique , c int , index(c)); +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` blob DEFAULT NULL, + `c` int(11) DEFAULT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + KEY `c` (`c`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t2 values(1,1); +insert into t2 values(2,1); +drop table t2; +#not null test +create table t1(a blob unique not null); +desc t1; +Field Type Null Key Default Extra +a blob NO UNI NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob NOT NULL, + UNIQUE KEY `a` (`a`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values(1); +insert into t1 values(3); +insert into t1 values(1); +ERROR 23000: Duplicate entry '1' for key 'a' +drop table t1; +create table t1(a int primary key, b blob unique , c blob unique not null); +insert into t1 values(1,1,1); +insert into t1 values(2,1,2); +ERROR 23000: Duplicate entry '1' for key 'b' +insert into t1 values(3,3,1); +ERROR 23000: Duplicate entry '1' for key 'c' +drop table t1; +create table t1 (a blob unique not null, b blob not null, c blob not null, unique(b,c)); +desc t1; +Field Type Null Key Default Extra +a blob NO UNI NULL +b blob NO MUL NULL +c blob NO NULL +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob NOT NULL, + `b` blob NOT NULL, + `c` blob NOT NULL, + UNIQUE KEY `a` (`a`) USING HASH, + UNIQUE KEY `b` (`b`,`c`) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +insert into t1 values (1, 2, 3); +insert into t1 values (2, 1, 3); +insert into t1 values (2, 1, 3); +ERROR 23000: Duplicate entry '2' for key 'a' +drop table t1; +#partition +create table t1(a blob unique) partition by hash(a); +ERROR HY000: A BLOB field is not allowed in partition function +#key length > 2^16 -1 +create table t1(a blob, unique(a(65536))); +ERROR 42000: Specified key part was too long; max key part length is 65535 bytes +create table t1(a blob, unique(a(65535))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` blob DEFAULT NULL, + UNIQUE KEY `a` (`a`(65535)) USING HASH +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +#64 indexes +create table t1 ( a63 blob unique, a62 blob unique, a61 blob unique, a60 blob unique, a59 blob unique, a58 blob unique, a57 blob unique, a56 blob unique, a55 blob unique, a54 blob unique, a53 blob unique, a52 blob unique, a51 blob unique, a50 blob unique, a49 blob unique, a48 blob unique, a47 blob unique, a46 blob unique, a45 blob unique, a44 blob unique, a43 blob unique, a42 blob unique, a41 blob unique, a40 blob unique, a39 blob unique, a38 blob unique, a37 blob unique, a36 blob unique, a35 blob unique, a34 blob unique, a33 blob unique, a32 blob unique, a31 blob unique, a30 blob unique, a29 blob unique, a28 blob unique, a27 blob unique, a26 blob unique, a25 blob unique, a24 blob unique, a23 blob unique, a22 blob unique, a21 blob unique, a20 blob unique, a19 blob unique, a18 blob unique, a17 blob unique, a16 blob unique, a15 blob unique, a14 blob unique, a13 blob unique, a12 blob unique, a11 blob unique, a10 blob unique, a9 blob unique, a8 blob unique, a7 blob unique, a6 blob unique, a5 blob unique, a4 blob unique, a3 blob unique, a2 blob unique, a1 blob unique, a blob unique);; +insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);; +insert into t1 values( 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);; +ERROR 23000: Duplicate entry '63' for key 'a63' +insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; +insert into t1 values( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63);; +ERROR 23000: Duplicate entry '0' for key 'a63' +drop table t1; +create table t1(a blob , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a blob); +alter table t1 add index(a); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +drop table t1; +create table t1(a text , key(a)); +ERROR 42000: BLOB/TEXT column 'a' used in key specification without a key length +create table t1(a varchar(4000)); +alter table t1 add index(a); +Warnings: +Warning 1071 Specified key was too long; max key length is 1000 bytes +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(4000) DEFAULT NULL, + KEY `a` (`a`(1000)) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; +set @@GLOBAL.max_allowed_packet= @allowed_packet; +myisamchk commands +create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(3000) unique); +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555), +('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'), +(123456789034567891,353534,53453453453456,64565464564564,45435345345345), +(123456789034567890,43545,657567567567,78967657567567,657567567567567676); + +MyISAM file: DATADIR/test/t1 +Record format: Packed +Character set: latin1_swedish_ci (8) +Data records: 8 Deleted blocks: 0 +Recordlength: 3072 + +table description: +Key Start Len Index Type +1 3039 8 multip. ulonglong NULL +2 3047 8 multip. ulonglong NULL +3 3055 8 multip. ulonglong NULL +4 3063 8 multip. ulonglong NULL +drop table t1; diff --git a/mysql-test/main/long_unique_myisam.test b/mysql-test/main/long_unique_myisam.test new file mode 100644 index 00000000000..9a85f27936e --- /dev/null +++ b/mysql-test/main/long_unique_myisam.test @@ -0,0 +1,18 @@ +set default_storage_engine=myisam; #not needed but just for consistency +# +# MDEV-371 Unique indexes for blobs for myisam +# +--source include/long_unique.inc + +--echo myisamchk commands + +let datadir=`select @@datadir`; +create table t1(a blob unique, b int , c blob unique , d text unique , e varchar(3000) unique); +insert into t1 values(1,2,3,4,5),(2,11,22,33,44),(3111,222,333,444,555),(5611,2222,3333,4444,5555), +('sachin',341,'fdf','gfgfgfg','hghgr'),('maria',345,'frter','dasd','utyuty'), +(123456789034567891,353534,53453453453456,64565464564564,45435345345345), +(123456789034567890,43545,657567567567,78967657567567,657567567567567676); + +replace_result $datadir DATADIR; +exec $MYISAMCHK -d $datadir/test/t1; +drop table t1; diff --git a/sql/handler.cc b/sql/handler.cc index 47cf6aab19f..beff80795fd 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6495,9 +6495,8 @@ static int check_duplicate_long_entry_key(TABLE *table, handler *h, uchar *new_r int result, error= 0; KEY *key_info= table->key_info + key_no; hash_field= key_info->key_part->field; - DBUG_ASSERT((key_info->flags & HA_NULL_PART_KEY && - key_info->key_length == HA_HASH_KEY_LENGTH_WITH_NULL) - || key_info->key_length == HA_HASH_KEY_LENGTH_WITHOUT_NULL); + DBUG_ASSERT(key_info->flags & HA_NULL_PART_KEY && + key_info->key_length == HA_HASH_KEY_LENGTH_WITH_NULL); uchar ptr[HA_HASH_KEY_LENGTH_WITH_NULL]; if (hash_field->is_real_null()) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5cb836f6bd0..96bb7b20f57 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4187,13 +4187,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, hash_fld->offset= record_offset; hash_fld->charset= create_info->default_table_charset; record_offset+= hash_fld->pack_length; - if (key_info->flags & HA_NULL_PART_KEY) - null_fields++; - else - { - hash_fld->flags|= NOT_NULL_FLAG; - hash_fld->pack_flag&= ~FIELDFLAG_MAYBE_NULL; - } + key_info->flags|= HA_NULL_PART_KEY; + null_fields++; } if (validate_comment_length(thd, &key->key_create_info.comment, INDEX_COMMENT_MAXLEN, @@ -9197,6 +9192,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, uint order_num, ORDER *order, bool ignore) { DBUG_ENTER("mysql_alter_table"); + bool long_unique_table= false; /* Check if we attempt to alter mysql.slow_log or @@ -9804,8 +9800,15 @@ do_continue:; /* Remember that we have not created table in storage engine yet. */ bool no_ha_table= true; + for(uint i= 0; i < key_count; i++) + if (key_info[i].algorithm == HA_KEY_ALG_LONG_HASH) + { + long_unique_table= true; + break; + } - if (alter_info->requested_algorithm != Alter_info::ALTER_TABLE_ALGORITHM_COPY) + if (alter_info->requested_algorithm != Alter_info::ALTER_TABLE_ALGORITHM_COPY && + !long_unique_table) { Alter_inplace_info ha_alter_info(create_info, alter_info, key_info, key_count, diff --git a/sql/table.cc b/sql/table.cc index 13f4e200e2f..ad640553bcb 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -824,7 +824,7 @@ static bool create_key_infos(const uchar *strpos, const uchar *frm_image_end, } if (keyinfo->algorithm == HA_KEY_ALG_LONG_HASH) { - keyinfo->key_length= HA_HASH_KEY_LENGTH_WITHOUT_NULL; + keyinfo->key_length= HA_HASH_KEY_LENGTH_WITH_NULL; //Storing key hash key_part++; } @@ -1218,11 +1218,7 @@ bool parse_vcol_defs(THD *thd, MEM_ROOT *mem_root, TABLE *table, field->vcol_info->expr= hash_item; key->user_defined_key_parts= key->ext_key_parts= key->usable_key_parts= 1; key->key_part+= parts; - - if (key->flags & HA_NULL_PART_KEY) - key->key_length= HA_HASH_KEY_LENGTH_WITH_NULL; - else - key->key_length= HA_HASH_KEY_LENGTH_WITHOUT_NULL; + key->key_length= HA_HASH_KEY_LENGTH_WITH_NULL; *(vfield_ptr++)= *field_ptr; } |