Debian Codegraph @

mysql-test/suite/innodb/t/innodb_bug51378.test

raw
1 --source include/have_innodb.inc
2 # This is the test for bug 51378. Unique index created
3 # through "create index" and "alter table add unique index"
4 # interfaces should not be treated as primary index if indexed
5 # columns contain one or more column prefix(es) (only prefix/part of
6 # the column is indexed)
7 # On the other hand, if there is a unique index covers all
8 # columns of a table, and they are non-null columns, and
9 # full length of the column are indexed, then this index
10 # will be created as primary index
11 # Following queries test various scenario, no mismatch
12 # error message should be printed.
13
14 # Create a table contains a BLOB column
15 create table bug51378 (
16 col1 int not null,
17 col2 blob not null,
18 col3 time not null) engine = innodb;
19
20 # Create following unique indexes on 'col1' and 'col2(31)'
21 # of the table, the index should not be treated as primary
22 # key because it indexes only first 31 bytes of col2.
23 # Thus it contains "column prefix", and will not be
24 # upgraded to primary index.
25 # There should not be mismatch message printed in the
26 # errorlog
27 create unique index idx on bug51378(col1, col2(31));
28
29 alter table bug51378 add unique index idx2(col1, col2(31));
30
31 # Unique index on 'col1' and 'col3' will be created as primary index,
32 # since the index does not contain column prefix
33 create unique index idx3 on bug51378(col1, col3);
34
35 # Show create table would show idx3 created as unique index, internally,
36 # idx3 is treated as primary index both by MySQL and Innodb
37 SHOW CREATE TABLE bug51378;
38
39 # "GEN_CLUST_INDEX" will be re-created as default primary index
40 # after idx3 is dropped
41 drop index idx3 on bug51378;
42
43 SHOW CREATE TABLE bug51378;
44
45 # Or we can add the primary key through alter table interfaces
46 alter table bug51378 add primary key idx3(col1, col2(31));
47
48 SHOW CREATE TABLE bug51378;
49
50 drop table bug51378;
51
52 # Or we can create such primary key through create table interfaces
53 create table bug51378 (
54 col1 int not null,
55 col2 blob not null,
56 col3 time not null, primary key(col1, col2(31))) engine = innodb;
57
58 # Unique index on one or more column prefix(es) will be created
59 # as non-cluster index
60 create unique index idx on bug51378(col1, col2(31));
61
62 SHOW CREATE TABLE bug51378;
63
64 drop table bug51378;
65
66 # If a table has a NULLABLE column, unique index on it will not
67 # be treated as primary index.
68 create table bug51378 (
69 col1 int not null,
70 col2 int ) engine = innodb;
71
72 # This will be created as non-cluster index since col2 is nullable
73 create unique index idx on bug51378(col1, col2);
74
75 SHOW CREATE TABLE bug51378;
76
77 drop table bug51378;