Class DefaultDiagnosticsListener
- java.lang.Object
-
- org.jooq.impl.DefaultDiagnosticsListener
-
- All Implemented Interfaces:
DiagnosticsListener
public class DefaultDiagnosticsListener extends java.lang.Object implements DiagnosticsListener
A publicly available default implementation ofDiagnosticsListener.Use this to stay compatible with future API changes (i.e. added methods to
DiagnosticsListener)- Author:
- Lukas Eder
-
-
Constructor Summary
Constructors Constructor Description DefaultDiagnosticsListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidduplicateStatements(DiagnosticsContext ctx)The executed JDBC statement has duplicates.voidmissingWasNullCall(DiagnosticsContext ctx)The fetched JDBCResultSetreturned a primitive type value for a column, which could have been null, butResultSet.wasNull()was not called.voidrepeatedStatements(DiagnosticsContext ctx)The executed JDBC statement is repeated consecutively on the same JDBCConnection.voidtooManyColumnsFetched(DiagnosticsContext ctx)The fetched JDBCResultSetreturned more columns than necessary.voidtooManyRowsFetched(DiagnosticsContext ctx)The fetched JDBCResultSetreturned more rows than necessary.voidunnecessaryWasNullCall(DiagnosticsContext ctx)The fetched JDBCResultSetreturned a value for a column, on whichResultSet.wasNull()was called unnecessarily (more than once, or for a non-primitive type).
-
-
-
Method Detail
-
tooManyRowsFetched
public void tooManyRowsFetched(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe fetched JDBCResultSetreturned more rows than necessary.An event indicating that a JDBC
ResultSetwas fetched withArows, but onlyBrows (B < A) were consumed.Typically, this problem can be remedied by applying the appropriate
LIMITclause in SQL, orSelectLimitStep.limit(int)clause in jOOQ.- Specified by:
tooManyRowsFetchedin interfaceDiagnosticsListener
-
tooManyColumnsFetched
public void tooManyColumnsFetched(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe fetched JDBCResultSetreturned more columns than necessary.An event indicating that a JDBC
ResultSetwas fetched withAcolumns, but onlyB(B < A) were consumed.Typically, this problem can be remedied by not running a
SELECT *query when this isn't strictly required.- Specified by:
tooManyColumnsFetchedin interfaceDiagnosticsListener
-
unnecessaryWasNullCall
public void unnecessaryWasNullCall(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe fetched JDBCResultSetreturned a value for a column, on whichResultSet.wasNull()was called unnecessarily (more than once, or for a non-primitive type).- Specified by:
unnecessaryWasNullCallin interfaceDiagnosticsListener
-
missingWasNullCall
public void missingWasNullCall(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe fetched JDBCResultSetreturned a primitive type value for a column, which could have been null, butResultSet.wasNull()was not called.- Specified by:
missingWasNullCallin interfaceDiagnosticsListener
-
duplicateStatements
public void duplicateStatements(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe executed JDBC statement has duplicates.Many databases maintain an execution plan cache, which remembers execution plans for a given SQL string. These caches often use the verbatim SQL string (or a hash thereof) as a key, meaning that "similar" but not identical statements will produce different keys. This may be desired in rare cases when querying skewed data, as a hack to force the optimiser to calculate a new plan for a given "similar" but not identical query, but mostly, this is not desirable as calculating execution plans can turn out to be expensive.
Examples of such duplicate statements include:
Whitespace differences
SELECT * FROM actor; SELECT * FROM actor;
Inline bind values
SELECT * FROM actor WHERE id = 1; SELECT * FROM actor WHERE id = 2;
Aliasing and qualification
SELECT a1.* FROM actor a1 WHERE id = ?; SELECT * FROM actor a2 WHERE a2.id = ?;
Examples of identical statements (which are not considered duplicate, but
DiagnosticsListener.repeatedStatements(DiagnosticsContext), if on the sameConnection) are:SELECT * FROM actor WHERE id = ?; SELECT * FROM actor WHERE id = ?;
This is a system-wide diagnostic that is not specific to individual
Connectioninstances.- Specified by:
duplicateStatementsin interfaceDiagnosticsListener
-
repeatedStatements
public void repeatedStatements(DiagnosticsContext ctx)
Description copied from interface:DiagnosticsListenerThe executed JDBC statement is repeated consecutively on the same JDBCConnection.This problem goes by many names, the most famous one being the N + 1 problem, when a single (1) query for a parent entity requires many (N) subsequent queries for child entities. This could have been prevented by rewriting the parent query to use a JOIN. If such a rewrite is not possible (or not easy), the subsequent N queries could at least profit (depending on the exact query):
- From reusing the
PreparedStatement - From being batched
- From being re-written as a bulk fetch or write query
This problem can be aggravated if combined with the
DiagnosticsListener.duplicateStatements(DiagnosticsContext)problem, in case of which the repeated statements might not be diagnosed as easily.Repeated statements may or may not be "identical". In the following example, there are two repeated and identical statements:
SELECT * FROM actor WHERE id = ?; SELECT * FROM actor WHERE id = ?;
In this example, we have three repeated statements, only some of which are also identical:
SELECT * FROM actor WHERE id = ?; SELECT * FROM actor WHERE id = ?; SELECT * FROM actor WHERE id = ?;
This is a
Connection-specific diagnostic that is reset every timeConnection.close()is called.- Specified by:
repeatedStatementsin interfaceDiagnosticsListener
- From reusing the
-
-