forked from sqlancer/sqlancer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTiDBAnalyzeTableGenerator.java
More file actions
36 lines (30 loc) · 1.34 KB
/
TiDBAnalyzeTableGenerator.java
File metadata and controls
36 lines (30 loc) · 1.34 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
package sqlancer.tidb.gen;
import java.sql.SQLException;
import sqlancer.Randomly;
import sqlancer.common.query.ExpectedErrors;
import sqlancer.common.query.SQLQueryAdapter;
import sqlancer.tidb.TiDBErrors;
import sqlancer.tidb.TiDBProvider.TiDBGlobalState;
import sqlancer.tidb.TiDBSchema.TiDBTable;
public final class TiDBAnalyzeTableGenerator {
private TiDBAnalyzeTableGenerator() {
}
public static SQLQueryAdapter getQuery(TiDBGlobalState globalState) throws SQLException {
ExpectedErrors errors = ExpectedErrors.newErrors().with(TiDBErrors.getExpressionErrors()).build();
TiDBTable table = globalState.getSchema().getRandomTable(t -> !t.isView());
boolean analyzeIndex = !table.getIndexes().isEmpty() && Randomly.getBoolean();
StringBuilder sb = new StringBuilder("ANALYZE TABLE ");
sb.append(table.getName());
if (analyzeIndex) {
sb.append(" INDEX ");
sb.append(table.getRandomIndex().getIndexName());
}
if (Randomly.getBoolean()) {
sb.append(" WITH ");
sb.append(Randomly.getNotCachedInteger(1, 1024));
sb.append(" BUCKETS");
}
errors.add("Fast analyze hasn't reached General Availability and only support analyze version 1 currently");
return new SQLQueryAdapter(sb.toString(), errors);
}
}