Код: Выделить всё
PreparedStatement.executeQuery()Запрос и некоторая информация о БД (на данный момент игнорируем проблему Java):< /p>
Код: Выделить всё
mysql> SELECT username from users where user_id = 1;Выполнение одного и того же запроса 1000 раз через mysqlslap также молниеносно.
Код: Выделить всё
mysqlslap --create-schema=mydb --user=root -p --query="select username from phpbb_users where user_id = 1" --number-of-queries=1000 --concurrency=1
Benchmark
Average number of seconds to run all queries: 0.051 seconds
Minimum number of seconds to run all queries: 0.051 seconds
Maximum number of seconds to run all queries: 0.051 seconds
Number of clients running queries: 1
Average number of queries per client: 1000
Код: Выделить всё
public static String queryUsername() {
String username = "";
// DBCore.getConnection() returns HikariDataSource.getConnection() implementation exactly as per https://www.baeldung.com/hikaricp
try (Connection connection = DBCore.getConnection();
PreparedStatement stmt = connection.prepareStatement("SELECT username from phpbb_users where user_id = ?");) {
stmt.setInt(1, 1); // just looking for user_id 1 for now
// Google timer used to measure how long executeQuery() is taking
// Another Timer is used outside of this method call to see how long
// total execution takes.
// Approximately 1 second in for loop calling this method 1000 times
Stopwatch s = Stopwatch.createStarted();
try (ResultSet rs = stmt.executeQuery();) {
s.stop(); // stopping the timer after executeQuery() has been called
timeElapsed += s.elapsed(TimeUnit.MICROSECONDS);
while (rs.next())
{
username = rs.getString("username"); // the query returns 1 record
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return username;
}
[img]https:// i.sstatic.net/qeoCW.png[/img]

- открыто несколько таблиц, но у всех есть In_use=0 и Name_locked=0.
Код: Выделить всё
SHOW OPEN TABLESВ - выглядит исправно.
Код: Выделить всё
SHOW FULL PROCESSLIST - user_id — это индексированный первичный ключ.
- Сервер представляет собой одноядерный сервер Upcloud стоимостью 5 долларов в месяц и 1 ГБ ОЗУ. Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-66-generic x86_64). Mysql версии 8.0.23-0ubuntu0.20.04.1 для Linux на x86_64 ((Ubuntu))
- Драйвер JDBC — mysql-connector-java_8.0.23.jar, полученный из mysql- разъем-java_8.0.23-1ubuntu20.04_все через https://dev.mysql.com/downloads/connector/j/
Подробнее здесь: https://stackoverflow.com/questions/664 ... -and-mysql
Мобильная версия