I have a moderately big table on Sql Server, about 40 million rows. In particular this table has an xml column which could be large in size.
I am experiencing very poor performance on retrieving data from this table using last version of mssql-jdbc. I am looking for ways to improve performance both on java side and database side.
On java side this is the relevant code for fetching data:
String connectionUrl = "jdbc:sqlserver://10.10.10.28:1433;databaseName=MYDB;user=MYUSER;password=MYPWD;selectMethod=direct;sendStringParametersAsUnicode=false;responseBuffering=adaptive;";
String query = "SELECT * FROM MYTABLE WHERE DateTimeField > '2019-03-25 00:00:00.0' AND DateTimeField < '2019-03-25 13:00:00.0'";
try (Connection sourceConnection = DriverManager.getConnection(connectionUrl);
Statement stmt = sourceConnection.createStatement(SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY, SQLServerResultSet.CONCUR_READ_ONLY) ) {
stmt.setFetchSize(100);
resultSet = stmt.executeQuery(query);
while (resultSet.next()) {
// do something
}
}
I've set the fetch size on 100 rows because I've noticed problems if I set the fetch size too big, probably because of the xml column which is heavy to send on the network.
Does anyone have any suggestion to improve performance for fetching data in this scenario?