File: innodb_bug51378.test

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (77 lines) | stat: -rw-r--r-- 2,591 bytes parent folder | download | duplicates (11)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--source include/have_innodb.inc
# This is the test for bug 51378. Unique index created
# through "create index" and "alter table add unique index"
# interfaces should not be treated as primary index if indexed
# columns contain one or more column prefix(es) (only prefix/part of
# the column is indexed)
# On the other hand, if there is a unique index covers all
# columns of a table, and they are non-null columns, and
# full length of the column are indexed, then this index
# will be created as primary index
# Following queries test various scenario, no mismatch
# error message should be printed.

# Create a table contains a BLOB column
create table bug51378 (
	col1 int not null,
	col2 blob not null,
	col3 time not null) engine = innodb;

# Create following unique indexes on 'col1' and 'col2(31)'
# of the table, the index should not be treated as primary
# key because it indexes only first 31 bytes of col2.
# Thus it contains "column prefix", and will not be
# upgraded to primary index.
# There should not be mismatch message printed in the
# errorlog
create unique index idx on bug51378(col1, col2(31));

alter table bug51378 add unique index idx2(col1, col2(31));

# Unique index on 'col1' and 'col3' will be created as primary index,
# since the index does not contain column prefix
create unique index idx3 on bug51378(col1, col3);

# Show create table would show idx3 created as unique index, internally,
# idx3 is treated as primary index both by MySQL and Innodb
SHOW CREATE TABLE bug51378;

# "GEN_CLUST_INDEX" will be re-created as default primary index
# after idx3 is dropped
drop index idx3 on bug51378;

SHOW CREATE TABLE bug51378;

# Or we can add the primary key through alter table interfaces
alter table bug51378 add primary key idx3(col1, col2(31));

SHOW CREATE TABLE bug51378;

drop table bug51378;

# Or we can create such primary key through create table interfaces
create table bug51378 (
        col1 int not null,
        col2 blob not null,
        col3 time not null, primary key(col1, col2(31))) engine = innodb;

# Unique index on one or more column prefix(es) will be created
# as non-cluster index
create unique index idx on bug51378(col1, col2(31));

SHOW CREATE TABLE bug51378;

drop table bug51378;

# If a table has a NULLABLE column, unique index on it will not
# be treated as primary index.
create table bug51378 (
	col1 int not null,
        col2 int ) engine = innodb;

# This will be created as non-cluster index since col2 is nullable
create unique index idx on bug51378(col1, col2);

SHOW CREATE TABLE bug51378;

drop table bug51378;