summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/storage_engine/index_primary.test
blob: 55671d99e46f79530f010c5974144548c14832ad (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# 
# Basic syntax related to primary keys 
#

--source have_engine.inc

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

let $create_definition =
  a $int_indexed_col PRIMARY KEY,
  b $char_col
;
--source create_table.inc
if ($mysql_errname)
{
  --let $my_last_stmt =  $create_statement
  --let $functionality = PRIMARY KEY
  --source unexpected_result.inc
}
if (!$mysql_errname)
{
  --replace_column 6 # 7 # 10 # 11 #
  SHOW KEYS IN t1;

  INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b');
  --let $error_codes = ER_DUP_ENTRY,ER_DUP_KEY
  INSERT INTO t1 (a,b) VALUES (1,'c');
  --source check_errors.inc

  DROP TABLE t1;
}

--let $error_codes = ER_MULTIPLE_PRI_KEY
let $create_definition = 
  a $int_indexed_col PRIMARY KEY,
  b $char_indexed_col PRIMARY KEY
;
--source create_table.inc
if ($mysql_errname != ER_MULTIPLE_PRI_KEY)
{
  --let $my_last_stmt = $create_statement
  --let $functionality = PRIMARY KEY
  --source unexpected_result.inc
}

let $create_definition = 
  a $int_indexed_col,
  b $char_indexed_col,
  PRIMARY KEY (a,b)
;
--source create_table.inc
if ($mysql_errname)
{
  --let $my_last_stmt =  $create_statement
  --let $functionality = Multi-part keys
  --source unexpected_result.inc
}
if (!$mysql_errname)
{
  --replace_column 6 # 7 # 10 # 11 #
  SHOW INDEX IN t1;
  INSERT INTO t1 (a,b) VALUES (1,'a'),(1,'b'),(2,'a'),(2,'b');
  --let $error_codes = ER_DUP_ENTRY,ER_DUP_KEY
  INSERT INTO t1 (a,b) VALUES (1,'b');
  --source check_errors.inc
  DROP TABLE t1;
}


--let $continue = 1
--source have_default_index.inc
if ($have_default_index)
{
  # KEY in a column definition means PK!
  let $create_definition = 
    a $int_indexed_col KEY,
    b $char_indexed_col,
    $default_index (b)
  ;
  --source create_table.inc
  if ($mysql_errname)
  {
    --let $my_last_stmt =  $create_statement
    --let $functionality = Multiple keys or PK or keys on CHAR columns
    --source unexpected_result.inc
  }
  if (!$mysql_errname)
  {
    --replace_column 6 # 7 # 10 # 11 #
    SHOW INDEX IN t1;
    DROP TABLE t1;
  }
}

let $create_definition =
  a $int_indexed_col,
  b $char_indexed_col PRIMARY KEY
;
--source create_table.inc
if ($mysql_errname)
{
  --let $my_last_stmt =  $create_statement
  --source unexpected_result.inc
}
if (!$mysql_errname)
{

  --replace_column 6 # 7 # 10 # 11 #
  SHOW INDEX IN t1;

  --let $alter_definition = DROP INDEX `PRIMARY`
  --source alter_table.inc
  if ($mysql_errname)
  {
    --let $my_last_stmt =  $alter_statement
    --let $functionality = ALTER TABLE
    --source unexpected_result.inc
  }
  if (!$mysql_errname)
  {
    --let $alter_definition = ADD CONSTRAINT PRIMARY KEY pk (a)
    --source alter_table.inc
    --source mask_engine.inc
    --replace_column 6 # 7 # 10 # 11 #
    SHOW KEYS IN t1;
    --let $alter_definition = DROP PRIMARY KEY
    --source alter_table.inc
  }

  DROP TABLE t1;
}

--source cleanup_engine.inc