Attaching a patch that makes OrderByAndSortAvoidance populate the two large tables (table1 and table2) using prepared statements that are reused.
The test runs about three times faster in my environment with this patch applied. On my workstation the time is reduced from 24 seconds to 8 seconds. On a somewhat less powerful machine where I sometimes run tests, the time is reduced from 5 minutes to 1.5 minutes.
As an extra bonus, the test is now almost 7000 lines shorter.
For good measure, I also removed the following unnecessary calls in decorateSQL():
That these calls are unnecessary can be seen from the javadoc for the super-method, CleanDatabaseTestSetup.decorateSQL():
- Once this method returns the statement will be closed,
- commit called and the connection closed. The connection
- returned by s.getConnection() is the default connection
- and is in auto-commit false mode.