Oak JCR Query Analysis

Objective

How to analyze slow Oak JCR query performance.

Environment

AEM 6.x / Oak 1.x

Steps

I. Enable Debug Logging

The first step in debugging JCR query performance is to enable debug logging:
1. Go to http://host:port/system/console/slinglog
2. Click Add new logger
3. Configure the logger with the following:
Log file: query.log
Log Level: Debug
Loggers:
org.apache.jackrabbit.core.query.QueryImpl
3. Go to http://aemhost:port/crx/de/index.jsp and log in
4. Click on Tools => Query
5. In the bottom Query box, paste the query and click Execute
6. Log in to the AEM server OS and find the crx-quickstart/logs/query.log
7. Open that file in a viewer and you will see details about the query's execution

Use the Explain Query Tool

You can also leverage the Explain Query Tool which is an out of the box tool in AEM to help you debug query performance.
1. Log in to AEM
2. Go to this URLhttp://aemhost:port/libs/granite/operations/content/diagnosis/tool.html/_granite_queryperformance
3. Click on the Explain tab
4. Enter the query and click Explain
5. It will show you which Oak index is being used for the query