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################################################ 23# TODO: 24# A part of the test is disabled because unique indexes 25# are not currently supported 26################################################ 27 28 29let $using_index_type = ; 30if ($index_type) 31{ 32 let $using_index_type = USING $index_type; 33} 34 35 36eval CREATE TABLE t1 (a INT, 37 b CHAR(8), 38 pk INT PRIMARY KEY, 39 KEY $using_index_type (a) 40) ENGINE=rocksdb; 41 42--replace_column 7 # 43SHOW KEYS IN t1; 44DROP TABLE t1; 45 46eval CREATE TABLE t1 (a INT, 47 b CHAR(8), 48 pk INT PRIMARY KEY, 49 KEY a_b $using_index_type (a,b) COMMENT 'a_b index' 50) ENGINE=rocksdb; 51 52--replace_column 7 # 53SHOW KEYS IN t1; 54DROP TABLE t1; 55 56eval CREATE TABLE t1 (a INT, 57 b CHAR(8), 58 pk INT PRIMARY KEY, 59 KEY $using_index_type (a), 60 KEY $using_index_type (b) 61) ENGINE=rocksdb; 62 63--replace_column 7 # 64SHOW KEYS IN t1; 65DROP TABLE t1; 66 67--disable_parsing 68 69eval CREATE TABLE t1 (a INT, 70 b CHAR(8), 71 pk INT PRIMARY KEY, 72 UNIQUE INDEX $using_index_type (a) 73) ENGINE=rocksdb; 74 75--replace_column 7 # 76SHOW KEYS IN t1; 77INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); 78--error ER_DUP_ENTRY,ER_DUP_KEY 79INSERT INTO t1 (a,b) VALUES (1,'c'); 80 81DROP TABLE t1; 82 83--source drop_table_sync.inc 84 85--enable_parsing 86 87# 88# ALTER TABLE 89# 90 91CREATE TABLE t1 (a INT, b CHAR(8), pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=rocksdb; 92INSERT INTO t1 (a,b) VALUES (100,'z'); 93 94eval ALTER TABLE t1 ADD KEY (a) $using_index_type COMMENT 'simple index on a'; 95--replace_column 7 # 96SHOW INDEX FROM t1; 97ALTER TABLE t1 DROP KEY a; 98DROP TABLE t1; 99 100--disable_parsing 101 102eval CREATE TABLE t1 (a INT, 103 b CHAR(8), 104 pk INT AUTO_INCREMENT PRIMARY KEY, 105 UNIQUE INDEX $using_index_type (a) 106) ENGINE=rocksdb; 107 108--replace_column 7 # 109SHOW KEYS IN t1; 110INSERT INTO t1 (a,b) VALUES (1,'a'),(2,'b'); 111--error ER_DUP_ENTRY,ER_DUP_KEY 112INSERT INTO t1 (a,b) VALUES (1,'c'); 113 114ALTER TABLE t1 DROP INDEX a; 115INSERT INTO t1 (a,b) VALUES (1,'c'); 116--error ER_DUP_ENTRY 117eval ALTER TABLE t1 ADD UNIQUE INDEX a(a) $using_index_type; 118DROP TABLE t1; 119 120--enable_parsing 121 122# 123# Test index prefix length limits. 124# 125set global rocksdb_large_prefix=0; 126 127CREATE TABLE t1 ( 128 a BLOB(1024), 129 KEY (a(767)) 130) ENGINE=rocksdb; 131DROP TABLE t1; 132 133# Should display warning 134CREATE TABLE t1 ( 135 a BLOB(1024), 136 KEY (a(768)) 137) ENGINE=rocksdb; 138DROP TABLE t1; 139 140set global rocksdb_large_prefix=1; 141 142CREATE TABLE t1 ( 143 a BLOB(4096), 144 KEY (a(3072)) 145) ENGINE=rocksdb; 146DROP TABLE t1; 147 148# Should display warning 149CREATE TABLE t1 ( 150 a BLOB(4096), 151 KEY (a(3073)) 152) ENGINE=rocksdb; 153DROP TABLE t1; 154 155set global rocksdb_large_prefix=DEFAULT; 156