I have a performance problem in the JDBC Delete statement on sql server. The Config table contains about 7 million rows, table data:
Columns:
- TERMINAL_ID (varchar (50))
- Attribute (VARCHAR (50))
- VALUE (nvarchar (1000))
Clustered Unique Index TERMINAL_ID AND ATTRIBUTE
The code looks like this: the length of the attributes is 1500, and it takes about 1 hour to run this program, which is very slow to remove:
PreparedStatement statement = null; String sql = "DELETE FROM Config WHERE TERMINAL_ID = ? AND ATTRIBUTE = ?"); for (String attribute : attributes) { if (statement == null) { statement = connection.prepareStatement(sqlDelete); } statement.setString(1, terminalId); statement.setString(2, attribute); statement.executeUpdate(); }
When I run this query 1,500 times in Management Studio, it only needs a few seconds to delete. The implementation plan is as follows:
The problem disappears when the number of rows is small.
The problem disappears when I use createStatement instead of prepareStatement.
Any idea?
source share