| 1 |
# |
| 2 |
# Basic syntax related to indexes: |
| 3 |
# unique and non-unique keys, |
| 4 |
# single- and multi-column keys, |
| 5 |
# index option COMMENT. |
| 6 |
# |
| 7 |
# See other index* tests for operations |
| 8 |
# which are less likely to be supported |
| 9 |
# |
| 10 |
# PRIMARY KEY syntax is covered in index_primary test. |
| 11 |
# Index types BTREE|HASH -- in index_type_btree|hash tests. |
| 12 |
# SPATIAL -- in type_spatial_indexes test. |
| 13 |
# FULLTEXT -- in fulltext_search test. |
| 14 |
# KEY_BLOCK_SIZE -- in index_key_block_size test. |
| 15 |
# |
| 16 |
# Usage to call the test from another test: |
| 17 |
# |
| 18 |
# A calling test may define $index_type, in which case |
| 19 |
# USING clause will be added to the syntax. |
| 20 |
# |
| 21 |
|
| 22 |
let $using_index_type = ; |
| 23 |
if ($index_type) |
| 24 |
{ |
| 25 |
let $using_index_type = USING $index_type; |
| 26 |
} |
| 27 |
|
| 28 |
--source have_engine.inc |
| 29 |
|
| 30 |
--let $continue = 1 |
| 31 |
--source have_default_index.inc |
| 32 |
|
| 33 |
if ($have_default_index) |
| 34 |
{ |
| 35 |
|
| 36 |
let $create_definition = |
| 37 |
a $int_indexed_col, |
| 38 |
b $char_col, |
| 39 |
$default_index $using_index_type (a) |
| 40 |
; |
| 41 |
--source create_table.inc |
| 42 |
if ($mysql_errname) |
| 43 |
{ |
| 44 |
--let $my_last_stmt = $create_statement |
| 45 |
--source unexpected_result.inc |
| 46 |
} |
| 47 |
if (!$mysql_errname) |
| 48 |
{ |
| 49 |
# Cardinality is not the exact science, so here and further |
| 50 |
# we'll be masking it |
| 51 |
--replace_column 6 # 7 # 10 # |
| 52 |
SHOW KEYS IN t1; |
| 53 |
DROP TABLE t1; |
| 54 |
} |
| 55 |
|
| 56 |
let $create_definition = |
| 57 |
a $int_indexed_col, |
| 58 |
b $char_indexed_col, |
| 59 |
$default_index a_b $using_index_type (a,b) COMMENT 'a_b index' |
| 60 |
; |
| 61 |
--source create_table.inc |
| 62 |
if ($mysql_errname) |
| 63 |
{ |
| 64 |
--let $functionality = Multi-part indexes |
| 65 |
--let $my_last_stmt = $create_statement |
| 66 |
--source unexpected_result.inc |
| 67 |
} |
| 68 |
if (!$mysql_errname) |
| 69 |
{ |
| 70 |
--replace_column 6 # 7 # 10 # |
| 71 |
SHOW KEYS IN t1; |
| 72 |
DROP TABLE t1; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
let $create_definition = |
| 77 |
a $int_indexed_col, |
| 78 |
b $char_indexed_col, |
| 79 |
$default_index $using_index_type (a), |
| 80 |
$default_index $using_index_type (b) |
| 81 |
; |
| 82 |
--source create_table.inc |
| 83 |
if ($mysql_errname) |
| 84 |
{ |
| 85 |
--let $functionality = Multiple indexes |
| 86 |
--let $my_last_stmt = $create_statement |
| 87 |
--source unexpected_result.inc |
| 88 |
} |
| 89 |
if (!$mysql_errname) |
| 90 |
{ |
| 91 |
--replace_column 6 # 7 # 10 # |
| 92 |
SHOW KEYS IN t1; |
| 93 |
DROP TABLE t1; |
| 94 |
} |
| 95 |
|
| 96 |
let $create_definition = |
| 97 |
a $int_indexed_col, |
| 98 |
b $char_col, |
| 99 |
UNIQUE INDEX $using_index_type (a) |
| 100 |
; |
| 101 |
--source create_table.inc |
| 102 |
if ($mysql_errname) |
| 103 |
{ |
| 104 |
--let $functionality = Unique indexes |
| 105 |
--let $my_last_stmt = $create_statement |
| 106 |
--source unexpected_result.inc |
| 107 |
} |
| 108 |
if (!$mysql_errname) |
| 109 |
{ |
| 110 |
--replace_column 6 # 7 # 10 # |
| 111 |
SHOW KEYS IN t1; |
| 112 |
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); |
| 113 |
--let $error_codes = ER_DUP_ENTRY,ER_DUP_KEY |
| 114 |
INSERT INTO t1 (a,b) VALUES (1,'c'); |
| 115 |
--source check_errors.inc |
| 116 |
|
| 117 |
DROP TABLE t1; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
# |
| 122 |
# ALTER TABLE |
| 123 |
# |
| 124 |
|
| 125 |
--let $create_definition = a $int_indexed_col, b $char_col |
| 126 |
--source create_table.inc |
| 127 |
if ($mysql_errname) |
| 128 |
{ |
| 129 |
--let $functionality = Column options |
| 130 |
--let $my_last_stmt = $create_statement |
| 131 |
--source unexpected_result.inc |
| 132 |
} |
| 133 |
if (!$mysql_errname) |
| 134 |
{ |
| 135 |
INSERT INTO t1 (a,b) VALUES (100,'z'); |
| 136 |
|
| 137 |
--let $alter_definition = ADD $default_index (a) $using_index_type COMMENT 'simple index on a' |
| 138 |
--source alter_table.inc |
| 139 |
if ($mysql_errname) |
| 140 |
{ |
| 141 |
--let $functionality = ALTER TABLE .. ADD INDEX |
| 142 |
--let $my_last_stmt = $alter_statement |
| 143 |
--source unexpected_result.inc |
| 144 |
} |
| 145 |
if (!$mysql_errname) |
| 146 |
{ |
| 147 |
--replace_column 6 # 7 # 10 # |
| 148 |
SHOW INDEX FROM t1; |
| 149 |
--let $alter_definition = DROP KEY a |
| 150 |
--source alter_table.inc |
| 151 |
} |
| 152 |
DROP TABLE t1; |
| 153 |
} |
| 154 |
|
| 155 |
let $create_definition = |
| 156 |
a $int_indexed_col, |
| 157 |
b $char_col, |
| 158 |
UNIQUE INDEX $using_index_type (a) |
| 159 |
; |
| 160 |
--source create_table.inc |
| 161 |
if ($mysql_errname) |
| 162 |
{ |
| 163 |
--let $functionality = Unique indexes |
| 164 |
--let $my_last_stmt = $create_statement |
| 165 |
--source unexpected_result.inc |
| 166 |
} |
| 167 |
if (!$mysql_errname) |
| 168 |
{ |
| 169 |
--replace_column 6 # 7 # 10 # |
| 170 |
SHOW KEYS IN t1; |
| 171 |
INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); |
| 172 |
--let $error_codes = ER_DUP_ENTRY,ER_DUP_KEY |
| 173 |
INSERT INTO t1 (a,b) VALUES (1,'c'); |
| 174 |
--source check_errors.inc |
| 175 |
|
| 176 |
--let $alter_definition = DROP INDEX a |
| 177 |
--source alter_table.inc |
| 178 |
if ($mysql_errname) |
| 179 |
{ |
| 180 |
--let $functionality = ALTER TABLE .. DROP INDEX |
| 181 |
--let $my_last_stmt = $alter_statement |
| 182 |
--source unexpected_result.inc |
| 183 |
} |
| 184 |
if (!$mysql_errname) |
| 185 |
{ |
| 186 |
INSERT INTO t1 (a,b) VALUES (1,'c'); |
| 187 |
--let $error_codes = ER_DUP_ENTRY,ER_DUP_KEY |
| 188 |
--let $alter_definition = ADD UNIQUE INDEX a(a) $using_index_type |
| 189 |
--source alter_table.inc |
| 190 |
} |
| 191 |
DROP TABLE t1; |
| 192 |
} |
| 193 |
} |
| 194 |
|