Include Query Timings

  • When making a query,
    you can request to get detailed stats of the time spent by RavenDB on each part of the query.
    E.g. duration of search, loading documents, transforming results, total duration, etc.

  • By default, the timings stats are Not included in the query results, to avoid the measuring overhead.

  • To include the query timings in the query results:
    add a call to timings() in your query code, or add include timings() to an RQL query.
    See examples below.

  • In this page:

Include timings in a query

// Define an object that will receive the timings results
let timingsResults;

const results = await session.query({ collection: "Products" })
    // Call timings, pass a callback function
    // Output param 'timingsResults' will be filled with the timings details when query returns 
    .timings(t => timingsResults = t)
    // Define query criteria
    // i.e. search for docs containing Syrup -or- Lager in their Name field
    .search("Name", "Syrup Lager")
    // Execute the query

// Get total query duration:
// =========================    
const totalQueryDuration = timingsResults.durationInMs;

// Get specific parts duration:
// ============================
const optimizerDuration = timingsResults.timings.optimizer.durationInMs;
// or: timingsResults.timings["optimizer"].durationInMs;    
const luceneDuration = timingsResults.timings.query.timings.lucene.durationInMs;
// or: timingsResults.timings["query"].timings.["lucene"].durationInMs;
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
include timings()

View timings

  • The detailed timings can be viewed from the Query view in the Studio.

  • Running an RQL query with include timings() will show an additional Timings Tab
    with a graphical representation of the time spent in each query part.

Figure 1. Include timings graphical results

Include timings results


Parameter Type Description
timingsCallback (timingsCallback) => void
  • A callback function with an output parameter.
  • The parameter passed to the callback will be filled with the QueryTimings object when query returns.
durationInMs number Total duration
timings Record<string, QueryTimings> Dictionary with QueryTimings info per time part

Timings in a sharded database