Skip to content

Commit 18c3da1

Browse files
authored
Merge pull request sleuthkit#3379 from sleuthkit/merge-in-4.14
Merge in 4.14
2 parents 43ac55e + 4676c55 commit 18c3da1

1 file changed

Lines changed: 34 additions & 5 deletions

File tree

bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,15 +755,44 @@ public void select(CaseDbPreparedStatement preparedStatement, boolean runOptimiz
755755
} catch (SQLException ex) {
756756
throw new TskCoreException("An error occurred while attempting to optimize the call", ex);
757757
}
758-
try (Statement optimizeStmt = preparedStatement.connection.createStatement()) {
759-
optimizeStmt.executeQuery("ANALYZE");
760-
preparedStatement.connection.commitTransaction();
758+
}
759+
760+
select(preparedStatement, queryCallback);
761+
}
762+
763+
/**
764+
* Runs the ANALYZE SQL command to refresh query-planner statistics.
765+
*
766+
* This is primarily useful for SQLite after large data changes (bulk
767+
* inserts, updates, deletes) or index/schema changes, or when query plans
768+
* appear suboptimal. For PostgreSQL, statistics are refreshed automatically,
769+
* so manually running ANALYZE is usually unnecessary.
770+
*
771+
* @throws TskCoreException
772+
*/
773+
@Beta
774+
public void runAnalyze() throws TskCoreException {
775+
CaseDbTransaction localTrans = tskDB.beginTransaction();
776+
777+
try {
778+
CaseDbConnection connection = localTrans.getConnection();
779+
780+
try (Statement statement = connection.createStatement()) {
781+
statement.executeUpdate("ANALYZE");
761782
} catch (SQLException ex) {
762783
throw new TskCoreException("An error occurred while attempting to run ANALYZE", ex);
763784
}
785+
localTrans.commit();
786+
localTrans = null;
787+
} finally {
788+
if (null != localTrans) {
789+
try {
790+
localTrans.rollback();
791+
} catch (TskCoreException ex) {
792+
logger.log(Level.SEVERE, "Failed to rollback transaction after exception", ex);
793+
}
794+
}
764795
}
765-
766-
select(preparedStatement, queryCallback);
767796
}
768797

769798
/**

0 commit comments

Comments
 (0)