Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MySQL Index Merge 测试
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 测试 merge index
*
* @author 桔子
* @since 2021/2/17 19:44
*/
public class TestMergeIndex {
public static final String URL = "jdbc:mysql://localhost:3306/test";
public static final String USER = "root";
public static final String PASSWORD = "root";
public static void main(String[] args) throws ClassNotFoundException {
Class.forName("com.mysql.cj.jdbc.Driver");
ExecutorService executorService = Executors.newFixedThreadPool(300);
for (int i = 1; i <= 100; i++) {
final int index = i;
executorService.submit(() -> {
try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD)) {
for (int j = 0; j < 10000; j++) {
conn.createStatement().executeUpdate("update student set name = \"xx\" WHERE class_id=" + index + " and teacher_id = " + index + ";");
}
} catch (SQLException e) {
e.printStackTrace();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment