-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLDropIndex.java
More file actions
51 lines (45 loc) · 1.72 KB
/
MySQLDropIndex.java
File metadata and controls
51 lines (45 loc) · 1.72 KB
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
package sqlancer.mysql.gen;
import sqlancer.IgnoreMeException;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.mysql.MySQLGlobalState;
import sqlancer.mysql.MySQLSchema.MySQLTable;
/**
* @see <a href="https://dev.mysql.com/doc/refman/8.0/en/drop-index.html">DROP INDEX Statement</a>
*/
public final class MySQLDropIndex {
private MySQLDropIndex() {
}
// DROP INDEX index_name ON tbl_name
// [algorithm_option | lock_option] ...
//
// algorithm_option:
// ALGORITHM [=] {DEFAULT|INPLACE|COPY}
//
// lock_option:
// LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE}
public static SQLQueryAdapter generate(MySQLGlobalState globalState) {
MySQLTable table = globalState.getSchema().getRandomTable();
if (!table.hasIndexes()) {
throw new IgnoreMeException();
}
StringBuilder sb = new StringBuilder();
sb.append("DROP INDEX ");
sb.append(table.getRandomIndex().getIndexName());
sb.append(" ON ");
sb.append(table.getName());
if (Randomly.getBoolean()) {
sb.append(" ALGORITHM=");
sb.append(Randomly.fromOptions("DEFAULT", "INPLACE", "COPY"));
}
if (Randomly.getBoolean()) {
sb.append(" LOCK=");
sb.append(Randomly.fromOptions("DEFAULT", "NONE", "SHARED", "EXCLUSIVE"));
}
return new SQLQueryAdapter(sb.toString(),
ExpectedErrors.from("LOCK=NONE is not supported", "ALGORITHM=INPLACE is not supported",
"Data truncation", "Data truncated for functional index",
"A primary key index cannot be invisible"));
}
}