The way JCR queries are constructed has dramatic impact on their performance. This article is about writing queries that won’t kill the AEM instance.
What are JCR queries?
AEM stores data in Jackrabbit Oak, a Java Content Repository (JCR) implementation. JCR queries allow searching the repository and retrieving selected nodes.
There are three query languages supported and one of them is JCR-SQL2. It is similar to SQL used in relative database management systems and - similarly to SQL - it is easy to write a query that is time and resource consuming. However, it is often possible to rewrite a query to make it much faster.
Read Full Blog
Please use this thread to ask the related questions.