mariadb/mysql-test/main/long_unique_innodb.test
Nikita Malyavin d10c42b425 MDEV-20131 Assertion `!pk->has_virtual()' failed
Assertion `!pk->has_virtual()' failed in dict_index_build_internal_clust
while creating PRIMARY key longer than possible to store in the page.

This happened because the key was wrongly deduced as Long UNIQUE supported,
however PRIMARY KEY cannot be of that type. The main reason is that
only 8 bytes are used to store the hash, see HA_HASH_FIELD_LENGTH.

This is also why HA_NOSAME flag is removed (and caused the assertion in
turn) in open_table_from_share:
      if (key_info->algorithm == HA_KEY_ALG_LONG_HASH)
      {
        key_part_end++;
        key_info->flags&= ~HA_NOSAME;
      }

To make it unique, the additional check is done by
check_duplicate_long_entries call from ha_write_row, and similar one from
ha_update_row.

PRIMARY key is already forbidden, which is checked by the first test in
main.long_unique, however is_hash_field_needed was wrongly deduced to true
in mysql_prepare_create_table in this particular case.

FIX:

* Improve the check for Key::PRIMARY type
* Simplify is_hash_field_needed deduction for a more neat reading
2021-10-20 16:49:28 +03:00

145 lines
3.1 KiB
Text

--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;
--echo # MDEV-20131 Assertion `!pk->has_virtual()' failed
--error ER_TOO_LONG_KEY
create table t1 (a text, primary key(a(1871))) engine=innodb;