[jOOQ/jOOQ#7284] Some trivial predicate transform patterns

This commit is contained in:
Lukas Eder 2022-01-14 18:37:09 +01:00
parent 40a709e6cc
commit 2951b113a8
3 changed files with 124 additions and 0 deletions

View File

@ -124,6 +124,8 @@ public class Settings
@XmlElement(defaultValue = "true")
protected Boolean transformPatternsNotNotDistinct = true;
@XmlElement(defaultValue = "true")
protected Boolean transformPatternsTrivialPredicates = true;
@XmlElement(defaultValue = "true")
protected Boolean transformPatternsNegNeg = true;
@XmlElement(defaultValue = "true")
protected Boolean transformPatternsBitNotBitNot = true;
@ -1253,6 +1255,8 @@ public class Settings
* <p>
* This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
* <p>
* To enable this feature, {@link #transformPatterns} must be enabled as well.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
@ -1281,6 +1285,8 @@ public class Settings
* <p>
* This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
* <p>
* To enable this feature, {@link #transformPatterns} must be enabled as well.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
@ -1304,6 +1310,34 @@ public class Settings
this.transformPatternsNotNotDistinct = value;
}
/**
* Transform trivial predicates like <code>1 = 1</code> to <code>TRUE</code>.
* <p>
* This transformation removes any trivial predicates.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isTransformPatternsTrivialPredicates() {
return transformPatternsTrivialPredicates;
}
/**
* Sets the value of the transformPatternsTrivialPredicates property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setTransformPatternsTrivialPredicates(Boolean value) {
this.transformPatternsTrivialPredicates = value;
}
/**
* Transform <code>-(-(x))</code> to <code>x</code>
* <p>
@ -1379,6 +1413,8 @@ public class Settings
* <li><code>LOWER(LOWER(s))</code> to <code>LOWER(s)</code></li>
* </ul>
* <p>
* To enable this feature, {@link #transformPatterns} must be enabled as well.
* <p>
* This feature is available in the commercial distribution only.
*
* @return
@ -3668,6 +3704,11 @@ public class Settings
return this;
}
public Settings withTransformPatternsTrivialPredicates(Boolean value) {
setTransformPatternsTrivialPredicates(value);
return this;
}
public Settings withTransformPatternsNegNeg(Boolean value) {
setTransformPatternsNegNeg(value);
return this;
@ -4512,6 +4553,7 @@ public class Settings
builder.append("transformPatternsNotTruthValue", transformPatternsNotTruthValue);
builder.append("transformPatternsNotComparison", transformPatternsNotComparison);
builder.append("transformPatternsNotNotDistinct", transformPatternsNotNotDistinct);
builder.append("transformPatternsTrivialPredicates", transformPatternsTrivialPredicates);
builder.append("transformPatternsNegNeg", transformPatternsNegNeg);
builder.append("transformPatternsBitNotBitNot", transformPatternsBitNotBitNot);
builder.append("transformPatternsIdempotentFunctionRepetition", transformPatternsIdempotentFunctionRepetition);
@ -4964,6 +5006,15 @@ public class Settings
return false;
}
}
if (transformPatternsTrivialPredicates == null) {
if (other.transformPatternsTrivialPredicates!= null) {
return false;
}
} else {
if (!transformPatternsTrivialPredicates.equals(other.transformPatternsTrivialPredicates)) {
return false;
}
}
if (transformPatternsNegNeg == null) {
if (other.transformPatternsNegNeg!= null) {
return false;
@ -5890,6 +5941,7 @@ public class Settings
result = ((prime*result)+((transformPatternsNotTruthValue == null)? 0 :transformPatternsNotTruthValue.hashCode()));
result = ((prime*result)+((transformPatternsNotComparison == null)? 0 :transformPatternsNotComparison.hashCode()));
result = ((prime*result)+((transformPatternsNotNotDistinct == null)? 0 :transformPatternsNotNotDistinct.hashCode()));
result = ((prime*result)+((transformPatternsTrivialPredicates == null)? 0 :transformPatternsTrivialPredicates.hashCode()));
result = ((prime*result)+((transformPatternsNegNeg == null)? 0 :transformPatternsNegNeg.hashCode()));
result = ((prime*result)+((transformPatternsBitNotBitNot == null)? 0 :transformPatternsBitNotBitNot.hashCode()));
result = ((prime*result)+((transformPatternsIdempotentFunctionRepetition == null)? 0 :transformPatternsIdempotentFunctionRepetition.hashCode()));

View File

@ -60,10 +60,12 @@ import java.util.Arrays;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import org.jooq.BindContext;
import org.jooq.Condition;
import org.jooq.Configuration;
import org.jooq.Constants;
import org.jooq.False;
@ -88,6 +90,7 @@ import org.jooq.conf.Settings;
import org.jooq.conf.SettingsTools;
import org.jooq.exception.ControlFlowSignal;
import org.jooq.exception.DataAccessException;
import org.jooq.impl.QOM.And;
import org.jooq.impl.QOM.BitNot;
import org.jooq.impl.QOM.Eq;
import org.jooq.impl.QOM.FieldCondition;
@ -100,6 +103,7 @@ import org.jooq.impl.QOM.Ltrim;
import org.jooq.impl.QOM.Ne;
import org.jooq.impl.QOM.Neg;
import org.jooq.impl.QOM.Not;
import org.jooq.impl.QOM.Or;
import org.jooq.impl.QOM.Rtrim;
import org.jooq.impl.QOM.Trim;
import org.jooq.impl.QOM.Upper;
@ -108,6 +112,8 @@ import org.jooq.impl.ScopeMarker.ScopeContent;
import org.jooq.tools.JooqLogger;
import org.jooq.tools.StringUtils;
import org.jetbrains.annotations.NotNull;
/**
* @author Lukas Eder
*/
@ -964,6 +970,58 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren

View File

@ -317,6 +317,8 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
<p>
This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
<p>
To enable this feature, {@link #transformPatterns} must be enabled as well.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -325,6 +327,16 @@ This feature is available in the commercial distribution only.]]></jxb:javadoc><
<p>
This transformation removes a redundant logical negation from the <code>DISTINCT</code> predicate.
<p>
To enable this feature, {@link #transformPatterns} must be enabled as well.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="transformPatternsTrivialPredicates" type="boolean" minOccurs="0" maxOccurs="1" default="true">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Transform trivial predicates like <code>1 = 1</code> to <code>TRUE</code>.
<p>
This transformation removes any trivial predicates.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
@ -363,6 +375,8 @@ Idempotent functions that are covered so far, include:
<li><code>LOWER(LOWER(s))</code> to <code>LOWER(s)</code></li>
</ul>
<p>
To enable this feature, {@link #transformPatterns} must be enabled as well.
<p>
This feature is available in the commercial distribution only.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>