I'm having a performance issue with MySQL (v5.5) while running a local Java application using mysql-connector v5.1.30
I have 2 tables called A and B. I run something like this:
PreparedStatement stmtA = conn.prepareStatement("select x, y, z, u, v, w from A");
PreparedStatement stmtB = conn.prepareStatement("select val from B where something = ?");
ResultSet result = stmtA.executeQuery();
while ( resultA.next() ){
// do something with result row
if (some condition) { // true approx. 80% of the time
ResultSet resultB = stmtB.executeQuery(some_value_from_resultA);
// do something with result row
resultB.close();
}
}
stmtA.close();
The problem is that this takes ~12 minutes to complete every time. Here's a few relevant bits of information:
- The
mysqldprocess is using 95-99% CPU for the 12 minute duration - The java process is using 1-4% CPU for the 12 minute duration
- Memory usage for both processes is negligable
- Table A has 65,000 records, 18 columns (all VARCHAR except for Id) and uses MYISAM
- Table B has 51,000 records, 4 columns (3 INT and 1 VARCHAR) and uses MYISAM
- There is no index/key on the Table B column that I'm querying
- I'm running Ubuntu 12.04 with a Core i5 and 4GB RAM
Aside from the fact that the CPU usage of the mysql process is crazy, the reason I think there is a problem is because the application has additional functionality that runs an almost identical method against a different database table. This table has a similar number of columns to table A (also using MYISAM) but one big difference is that there is no table B here. So it works the same as above but without having to query a second table while iterating the rows of the first table.
This other table has 4,500 rows and the iteration takes less than 1 second.
So it would appear that the nested query of table B is causing the problem, but I'm not sure. I have limited experience with MySQL. If you need any more info, please ask.