[ https://issues.apache.org/jira/browse/SLING-11229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17513385#comment-17513385 ]
Thomas Mueller edited comment on SLING-11229 at 3/28/22, 1:33 PM: ------------------------------------------------------------------ I agree about the limit. The offset, in my experience, is almost never useful: it isn't a good solution for pagination. See also https://jackrabbit.apache.org/oak/docs/query/query-engine.html#Keyset_Pagination "Note that “offset” with large values (more than a few hundred) should be avoided, as it can lead to performance and memory issues." I recommend to simplify this a bit, to: {noformat} public static QueryResult query(Session session, String query, String language, long limit) throws RepositoryException { {noformat} This simplification also ensures that the parameters are not passed in the wrong order by mistake (limit + offset, vs. offset + limit). was (Author: tmueller): I agree about the limit. The offset, in my experience, is almost never useful: it isn't a good solution for pagination. See also https://jackrabbit.apache.org/oak/docs/query/query-engine.html#Keyset_Pagination "Note that “offset” with large values (more than a few hundred) should be avoided, as it can lead to performance and memory issues." I recommend to simplify this a bit: {noformat} public static QueryResult query(Session session, String query, String language, long limit) throws RepositoryException { {noformat} This simplification also ensures that the parameters are not passed in the wrong order by mistake (limit + offset, vs. offset + limit). > Add Option to Limit JCR Resource Provider Queries > ------------------------------------------------- > > Key: SLING-11229 > URL: https://issues.apache.org/jira/browse/SLING-11229 > Project: Sling > Issue Type: Improvement > Components: JCR > Affects Versions: JCR Resource 3.2.0 > Reporter: Dan Klco > Assignee: Dan Klco > Priority: Major > Fix For: JCR Resource 3.2.2 > > Time Spent: 20m > Remaining Estimate: 0h > > **Problem Statement** > Currently, the [BasicQueryLanguageProvider > |https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/18edb8d7e7106c1e1e3333b89bf4d2a49c686e3b/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/BasicQueryLanguageProvider.java] > used by the > [JCRResourceProvider|https://github.com/apache/sling-org-apache-sling-jcr-resource/blob/8345f4ed4857ed5ca240ac20050b68c84c61646c/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java] > for executing queries for methods like findResources executes a query > without a limit set. > At the same time, in Apache Jackrabbit Oak, queries will fail if the query > reads more than a configurable limit of nodes: > [https://jackrabbit.apache.org/oak/docs/query/query-engine.html#Slow_Queries_and_Read_Limits] > This means that it's entirely possible to create a well indexed, well crafted > query in Apache Sling that will still throw an Exception at runtime for > larger repositories when using > [ResourceResolver.findResources|https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ResourceResolver.html#findResources-java.lang.String-java.lang.String-] > or > [ResourceResolver.queryResources|https://sling.apache.org/apidocs/sling12/org/apache/sling/api/resource/ResourceResolver.html#queryResources-java.lang.String-java.lang.String-] > if the query returns more than the Oak Read limit number of results. > **Solution** > Add an optional setting to the JCR Resource Provider to set a limit on the > number of returned results from queries. While this would mean that in > certain cases the queries would return an incomplete set of results, they > would still nevertheless return results rather than failing. -- This message was sent by Atlassian Jira (v8.20.1#820001)