diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java index 6adefc57fe..d52be57f42 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxCountConstraintComponent.java @@ -44,9 +44,20 @@ import org.eclipse.rdf4j.sail.shacl.ast.planNodes.ValidationTuple; import org.eclipse.rdf4j.sail.shacl.ast.targets.EffectiveTarget; import org.eclipse.rdf4j.sail.shacl.wrapper.data.ConnectionsGroup; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MaxCountConstraintComponent extends AbstractConstraintComponent { + private static final Logger logger = LoggerFactory.getLogger(MaxCountConstraintComponent.class); + + // Performance degrades quickly as the maxCount increases when using a SPARQL Validation Approach. The default is 5, + // but it can be tuned using the system property below. + private static final String SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY = "org.eclipse.rdf4j.sail.shacl.ast.constraintcomponents.MaxCountConstraintComponent.sparqlValidationApproachLimit"; + private static final long SPARQL_VALIDATION_APPROACH_LIMIT = System + .getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY) == null ? 5 + : Long.parseLong(System.getProperty(SPARQL_VALIDATION_APPROACH_LIMIT_PROPERTY)); + private final long maxCount; public MaxCountConstraintComponent(long maxCount) { @@ -216,8 +227,12 @@ public ValidationQuery generateSparqlValidationQuery(ConnectionsGroup connection @Override public ValidationApproach getOptimalBulkValidationApproach() { - // performance of large maxCount is terrible - if (maxCount > 5) { + if (maxCount > SPARQL_VALIDATION_APPROACH_LIMIT) { + if (logger.isDebugEnabled()) { + logger.debug( + "maxCount is {}, which is greater than the limit of {}, using ValidationApproach.Transactional instead of ValidationApproach.SPARQL for {}", + maxCount, SPARQL_VALIDATION_APPROACH_LIMIT, stringRepresentationOfValue(getId())); + } return ValidationApproach.Transactional; } return ValidationApproach.SPARQL; @@ -244,6 +259,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (maxCount ^ (maxCount >>> 32)) + "MaxCountConstraintComponent".hashCode(); + return Long.hashCode(maxCount) + "MaxCountConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java index a24d9d312b..25259b0520 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MaxLengthConstraintComponent.java @@ -89,6 +89,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (maxLength ^ (maxLength >>> 32)) + "MaxLengthConstraintComponent".hashCode(); + return Long.hashCode(maxLength) + "MaxLengthConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java index 7d67d7fc85..090c4310ef 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinCountConstraintComponent.java @@ -227,6 +227,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (minCount ^ (minCount >>> 32)) + "MinCountConstraintComponent".hashCode(); + return Long.hashCode(minCount) + "MinCountConstraintComponent".hashCode(); } } diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java index 47e9ec119a..9b8ef2ce96 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/constraintcomponents/MinLengthConstraintComponent.java @@ -89,6 +89,6 @@ public boolean equals(Object o) { @Override public int hashCode() { - return (int) (minLength ^ (minLength >>> 32)) + "MinLengthConstraintComponent".hashCode(); + return Long.hashCode(minLength) + "MinLengthConstraintComponent".hashCode(); } }