Package org.intermine.sql.precompute
Class BestQueryExplainer
- java.lang.Object
-
- org.intermine.sql.precompute.BestQuery
-
- org.intermine.sql.precompute.BestQueryExplainer
-
- Direct Known Subclasses:
BestQueryExplainerVerbose
public class BestQueryExplainer extends BestQuery
Gets the database to explain each Query added and keeps hold of the best one so far.- Author:
- Andrew Varley
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
BestQueryExplainer.Candidate
A class representing a candidate optimised query.
-
Field Summary
Fields Modifier and Type Field Description protected static int
ALWAYS_EXPLAIN_TABLES
protected BestQueryExplainer.Candidate
bestCandidate
protected java.util.List<BestQueryExplainer.Candidate>
candidates
protected int
candidateTables
protected java.sql.Connection
con
protected static int
NEVER_EXPLAIN_TABLES
protected java.util.Date
start
protected long
timeLimit
-
Constructor Summary
Constructors Constructor Description BestQueryExplainer()
Constructs an empty BestQueryExplainer for testing purposesBestQueryExplainer(java.sql.Connection con, long timeLimit)
Constructs a BestQueryExplainer that will use the given Connection to explain Queries.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String q)
Allows a Query to be added to this tracker.protected void
add(BestQueryExplainer.Candidate c)
Allows a Candidate to be added to this tracker.void
add(Query q)
Allows a Query to be added to this tracker.protected void
didNotExplain(BestQueryExplainer.Candidate c)
Internal method that records that a query was not explained.protected BestQueryExplainer.Candidate
getBest()
Gets the best Candidate found so far.ExplainResult
getBestExplainResult()
Gets the ExpainResult for the best Query found so far.Query
getBestQuery()
Gets the best Query found so farjava.lang.String
getBestQueryString()
Gets the best query String found so far.protected ExplainResult
getExplainResult(java.lang.String q)
Internal method that creates an ExplainResult.protected ExplainResult
getExplainResult(Query q)
Internal method that creates an ExplainResult.void
throwBestQueryException(java.lang.String message)
Throws an exception.
-
-
-
Field Detail
-
ALWAYS_EXPLAIN_TABLES
protected static final int ALWAYS_EXPLAIN_TABLES
- See Also:
- Constant Field Values
-
NEVER_EXPLAIN_TABLES
protected static final int NEVER_EXPLAIN_TABLES
- See Also:
- Constant Field Values
-
candidates
protected java.util.List<BestQueryExplainer.Candidate> candidates
-
candidateTables
protected int candidateTables
-
bestCandidate
protected BestQueryExplainer.Candidate bestCandidate
-
con
protected java.sql.Connection con
-
start
protected java.util.Date start
-
timeLimit
protected long timeLimit
-
-
Constructor Detail
-
BestQueryExplainer
public BestQueryExplainer()
Constructs an empty BestQueryExplainer for testing purposes
-
BestQueryExplainer
public BestQueryExplainer(java.sql.Connection con, long timeLimit)
Constructs a BestQueryExplainer that will use the given Connection to explain Queries.- Parameters:
con
- the Connection to usetimeLimit
- a time limit in milliseconds
-
-
Method Detail
-
add
public void add(Query q) throws BestQueryException, java.sql.SQLException
Allows a Query to be added to this tracker.- Specified by:
add
in classBestQuery
- Parameters:
q
- a Query to be added to the tracker- Throws:
BestQueryException
- if the current best Query is the best we think we are going to getjava.sql.SQLException
- if error occurs in the underlying database
-
add
public void add(java.lang.String q) throws BestQueryException, java.sql.SQLException
Allows a Query to be added to this tracker.- Specified by:
add
in classBestQuery
- Parameters:
q
- a query String to be added to the tracker- Throws:
BestQueryException
- if the current best Query is the best we think we are going to getjava.sql.SQLException
- if error occurs in the underlying database
-
add
protected void add(BestQueryExplainer.Candidate c) throws BestQueryException, java.sql.SQLException
Allows a Candidate to be added to this tracker.- Parameters:
c
- the Candidate- Throws:
BestQueryException
- if the current best Candidate is the best we think we are going to getjava.sql.SQLException
- if an error occurs in the underlying database
-
getExplainResult
protected ExplainResult getExplainResult(Query q) throws java.sql.SQLException
Internal method that creates an ExplainResult. It can be overridden by subclasses.- Parameters:
q
- the Query- Returns:
- an ExplainResult
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
getExplainResult
protected ExplainResult getExplainResult(java.lang.String q) throws java.sql.SQLException
Internal method that creates an ExplainResult. It can be overridden by subclasses.- Parameters:
q
- the query String- Returns:
- an ExplainResult
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
didNotExplain
protected void didNotExplain(BestQueryExplainer.Candidate c)
Internal method that records that a query was not explained. It can be overridden by subclasses.- Parameters:
c
- the Candidate
-
getBestQuery
public Query getBestQuery() throws java.sql.SQLException
Gets the best Query found so far- Specified by:
getBestQuery
in classBestQuery
- Returns:
- the best Query, or null if no Queries added to this object
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
getBestQueryString
public java.lang.String getBestQueryString() throws java.sql.SQLException
Gets the best query String found so far.- Specified by:
getBestQueryString
in classBestQuery
- Returns:
- the best Query, or null if no Queries added to this object
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
getBestExplainResult
public ExplainResult getBestExplainResult() throws java.sql.SQLException
Gets the ExpainResult for the best Query found so far.- Returns:
- the best ExplainResult, or null if no Queries added to this object
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
getBest
protected BestQueryExplainer.Candidate getBest() throws java.sql.SQLException
Gets the best Candidate found so far.- Returns:
- the best Candidate
- Throws:
java.sql.SQLException
- if an error occurs in the underlying database
-
throwBestQueryException
public void throwBestQueryException(java.lang.String message) throws BestQueryException
Throws an exception. This gives the subclasses a chance to intercept it.- Parameters:
message
- a message- Throws:
BestQueryException
- with the message
-
-