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 the timings() method in your query code, or add include timings() to an RQL query.
    See examples below.

  • In this page:


Include timings in a query

$timings = new QueryTimings();

/** @var array<Product> $resultsWithTimings */
$resultsWithTimings = $session->advanced()->documentQuery(Product::class)
    ->timings($timings)
    ->search("Name", "Syrup")
    ->toList();

/** @var array<QueryTimings> $timingsMap */
$timingsMap = $timings->getTimings();
from "Products"
where search(Name, "Syrup") or search(Name, "Lager")
include timings()

View timings

  • The detailed timings can be viewed from Studio's Query view.

  • 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

Syntax

function timings(QueryTimings &$timings): DocumentQueryInterface;
Parameter Type Description
&$timings QueryTimings A callback function (action) that takes QueryTimings as an argument. It will be called by the client with the resulting QueryTimings. You can interact with the resulting QueryTimings inside your callback.