[jOOQ/jOOQ#7527] diagnosticsConcatenationInPredicates

This commit is contained in:
Lukas Eder 2022-11-14 11:04:09 +01:00
parent 246edb9050
commit e9095af4eb
6 changed files with 224 additions and 10 deletions

View File

@ -41,12 +41,25 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import org.jooq.conf.DiagnosticsConnection;
import org.jooq.conf.Settings;
import org.jooq.impl.DSL;
import org.jooq.impl.LoggingDiagnosticsListener;
import org.jooq.impl.ParserException;
/**
* A diagnostics listener.
* <p>
* Users can implement this in order to receive and handle diagnostics events
* explicitly. A default implementation is available via
* {@link LoggingDiagnosticsListener}, which can be activated using
* {@link Settings#isDiagnosticsLogging()}.
* <p>
* Events are received on any {@link DSLContext#diagnosticsConnection()} or
* {@link DSLContext#diagnosticsDataSource()}, if
* {@link Settings#getDiagnosticsConnection()} is not turned
* {@link DiagnosticsConnection#OFF}. Use {@link DiagnosticsConnection#ON} to
* turn diagnostics on for all of jOOQ's {@link ConnectionProvider} usage.
*
* @author Lukas Eder
*/
@ -62,6 +75,9 @@ public interface DiagnosticsListener {
* Typically, this problem can be remedied by applying the appropriate
* <code>LIMIT</code> clause in SQL, or
* {@link SelectLimitStep#limit(Number)} clause in jOOQ.
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsTooManyRowsFetched()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -76,6 +92,9 @@ public interface DiagnosticsListener {
* <p>
* Typically, this problem can be remedied by not running a
* <code>SELECT *</code> query when this isn't strictly required.
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsTooManyColumnsFetched()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -85,6 +104,9 @@ public interface DiagnosticsListener {
* The fetched JDBC {@link ResultSet} returned a value for a column, on
* which {@link ResultSet#wasNull()} was called unnecessarily (more than
* once, or for a non-primitive type).
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsUnnecessaryWasNullCall()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -94,6 +116,9 @@ public interface DiagnosticsListener {
* The fetched JDBC {@link ResultSet} returned a primitive type value for a
* column, which could have been null, but {@link ResultSet#wasNull()} was
* not called.
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsMissingWasNullCall()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -115,36 +140,54 @@ public interface DiagnosticsListener {
* <p>
* <h3>Whitespace differences</h3>
* <p>
* <pre><code>
*
* <pre>
* <code>
* SELECT * FROM actor;
* SELECT * FROM actor;
* </code></pre>
* </code>
* </pre>
* <p>
* <h3>Inline bind values</h3>
* <p>
* <pre><code>
*
* <pre>
* <code>
* SELECT * FROM actor WHERE id = 1;
* SELECT * FROM actor WHERE id = 2;
* </code></pre>
* </code>
* </pre>
* <p>
* <h3>Aliasing and qualification</h3>
* <p>
* <pre><code>
*
* <pre>
* <code>
* SELECT a1.* FROM actor a1 WHERE id = ?;
* SELECT * FROM actor a2 WHERE a2.id = ?;
* </code></pre>
* </code>
* </pre>
* <p>
* Examples of identical statements (which are not considered duplicate, but
* {@link #repeatedStatements(DiagnosticsContext)}, if on the same
* {@link Connection}) are:
* <p>
* <pre><code>
*
* <pre>
* <code>
* SELECT * FROM actor WHERE id = ?;
* SELECT * FROM actor WHERE id = ?;
* </code></pre>
* </code>
* </pre>
* <p>
* This is a system-wide diagnostic that is not specific to individual
* {@link Connection} instances.
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsDuplicateStatements()}.
* <p>
* Advanced duplicate statement recognition can be turned off using
* {@link Settings#isDiagnosticsDuplicateStatementsUsingTransformPatterns()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -186,6 +229,9 @@ public interface DiagnosticsListener {
* <p>
* This is a {@link Connection}-specific diagnostic that is reset every time
* {@link Connection#close()} is called.
* <p>
* This diagnostic can be turned off using
* {@link Settings#isDiagnosticsRepeatedStatements()}.
*
* @param ctx The context containing information about the diagnostic.
*/
@ -274,6 +320,68 @@ public interface DiagnosticsListener {

View File

@ -127,6 +127,8 @@ public class Settings
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsConsecutiveAggregation = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsConcatenationInPredicates = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsTooManyColumnsFetched = true;
@XmlElement(defaultValue = "true")
protected Boolean diagnosticsTooManyRowsFetched = true;
@ -1440,6 +1442,35 @@ public class Settings
this.diagnosticsConsecutiveAggregation = value;
}
/**
* Whether to run the {@link org.jooq.DiagnosticsListener#concatenationInPredicates(org.jooq.DiagnosticsContext) diagnostic.
* <p>
* Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured.
* Once configured, this diagnostic is turned on by default.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isDiagnosticsConcatenationInPredicates() {
return diagnosticsConcatenationInPredicates;
}
/**
* Sets the value of the diagnosticsConcatenationInPredicates property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setDiagnosticsConcatenationInPredicates(Boolean value) {
this.diagnosticsConcatenationInPredicates = value;
}
/**
* Whether to run the {@link org.jooq.DiagnosticsListener#tooManyColumnsFetched(org.jooq.DiagnosticsContext) diagnostic.
* <p>
@ -5641,6 +5672,11 @@ public class Settings
return this;
}
public Settings withDiagnosticsConcatenationInPredicates(Boolean value) {
setDiagnosticsConcatenationInPredicates(value);
return this;
}
public Settings withDiagnosticsTooManyColumnsFetched(Boolean value) {
setDiagnosticsTooManyColumnsFetched(value);
return this;
@ -6819,6 +6855,7 @@ public class Settings
builder.append("diagnosticsMissingWasNullCall", diagnosticsMissingWasNullCall);
builder.append("diagnosticsRepeatedStatements", diagnosticsRepeatedStatements);
builder.append("diagnosticsConsecutiveAggregation", diagnosticsConsecutiveAggregation);
builder.append("diagnosticsConcatenationInPredicates", diagnosticsConcatenationInPredicates);
builder.append("diagnosticsTooManyColumnsFetched", diagnosticsTooManyColumnsFetched);
builder.append("diagnosticsTooManyRowsFetched", diagnosticsTooManyRowsFetched);
builder.append("diagnosticsUnnecessaryWasNullCall", diagnosticsUnnecessaryWasNullCall);
@ -7342,6 +7379,15 @@ public class Settings
return false;
}
}
if (diagnosticsConcatenationInPredicates == null) {
if (other.diagnosticsConcatenationInPredicates!= null) {
return false;
}
} else {
if (!diagnosticsConcatenationInPredicates.equals(other.diagnosticsConcatenationInPredicates)) {
return false;
}
}
if (diagnosticsTooManyColumnsFetched == null) {
if (other.diagnosticsTooManyColumnsFetched!= null) {
return false;
@ -8827,6 +8873,7 @@ public class Settings
result = ((prime*result)+((diagnosticsMissingWasNullCall == null)? 0 :diagnosticsMissingWasNullCall.hashCode()));
result = ((prime*result)+((diagnosticsRepeatedStatements == null)? 0 :diagnosticsRepeatedStatements.hashCode()));
result = ((prime*result)+((diagnosticsConsecutiveAggregation == null)? 0 :diagnosticsConsecutiveAggregation.hashCode()));
result = ((prime*result)+((diagnosticsConcatenationInPredicates == null)? 0 :diagnosticsConcatenationInPredicates.hashCode()));
result = ((prime*result)+((diagnosticsTooManyColumnsFetched == null)? 0 :diagnosticsTooManyColumnsFetched.hashCode()));
result = ((prime*result)+((diagnosticsTooManyRowsFetched == null)? 0 :diagnosticsTooManyRowsFetched.hashCode()));
result = ((prime*result)+((diagnosticsUnnecessaryWasNullCall == null)? 0 :diagnosticsUnnecessaryWasNullCall.hashCode()));

View File

@ -73,7 +73,12 @@ import org.jooq.RenderContext;
// ...
import org.jooq.Select;
import org.jooq.conf.Settings;
import org.jooq.impl.QOM.CompareCondition;
import org.jooq.impl.QOM.Concat;
import org.jooq.impl.QOM.Eq;
import org.jooq.impl.QOM.In;
import org.jooq.impl.QOM.InList;
import org.jooq.impl.QOM.NotInList;
import org.jooq.tools.jdbc.DefaultConnection;
/**
@ -300,6 +305,16 @@ final class DiagnosticsConnection extends DefaultConnection {
@ -334,6 +349,27 @@ final class DiagnosticsConnection extends DefaultConnection {
private final Set<String> duplicates(Map<String, Set<String>> map, String sql, String normalised) {
synchronized (map) {
Set<String> v = map.computeIfAbsent(normalised, k -> new HashSet<>());

View File

@ -151,6 +151,13 @@ final class DiagnosticsListeners implements DiagnosticsListener {

View File

@ -39,8 +39,6 @@ package org.jooq.impl;
import static java.util.stream.Collectors.toList;
import java.util.stream.Collectors;
import org.jooq.DiagnosticsContext;
import org.jooq.DiagnosticsListener;
import org.jooq.tools.JooqLogger;
@ -147,6 +145,15 @@ public class LoggingDiagnosticsListener implements DiagnosticsListener {

View File

@ -322,6 +322,15 @@ Once configured, this diagnostic is turned on by default.
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="diagnosticsConcatenationInPredicates" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to run the {@link org.jooq.DiagnosticsListener#concatenationInPredicates(org.jooq.DiagnosticsContext) diagnostic.
<p>
Diagnostics are turned off if no {@link org.jooq.Configuration#diagnosticsListenerProviders()} are configured.
Once configured, this diagnostic is turned on by default.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="diagnosticsTooManyColumnsFetched" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether to run the {@link org.jooq.DiagnosticsListener#tooManyColumnsFetched(org.jooq.DiagnosticsContext) diagnostic.
<p>