Tamino XML Server Version 9.7
 —  X-Query Reference Guide  —

ino:explain

Retrieve information about query execution for analysis and optimization.


Syntax

ino:explain (query[, level])

Top of page

Description

This function provides information about the execution plan of a given query. As it is a Tamino-internal function, it has the namespace prefix ino. It takes as argument any valid query expression (OrExpr) and an optional level of explanation, which can be one of the values "path" and "tree". If level is omitted, then basic information about the processing steps involved is provided. It returns information about the execution plan of the query inside the regular <xql:result> node of the standard <ino:response>. This information is wrapped up in a new element <ino:explanation>.

The execution time of a query depends on the number and kind of processes that are needed to resolve the query. A query is processed in Tamino as follows:

  1. Query Parser
    It takes as input the query string and parses it. If it does not conform to the syntax rules of X-Query then an error message will be returned indicating the type of error. If the query can be successfully parsed, it delivers an input tree for the optimizer.

  2. Query Optimizer
    The optimizer tries to optimize queries on the level of X-Query by applying a number of transformations and using the information from the corresponding schema. It performs amongst others the following kinds of transformation as far as they are applicable:

    Example: You use an abbreviated location path in your query such as in patient[.//surname ~= 'Atkins']. From the schema, the optimizer detects that the element surname can occur at six different positions in a document tree: patient/name/surname, patient/nextofkin/name/surname, and doctor/name/surname, where doctor can appear under patient/submitted, result/discharged, result/transferred, and result/deceased. The optimizer then transforms the filter expression into the following disjunction:

    patient[./name/surname ~= 'Atkins' or
            ./nextofkin/name/surname ~= 'Atkins' or
            ./submitted/doctor/name/surname ~= 'Atkins' or
            ./result/discharged/doctor/name/surname ~= 'Atkins' or
            ./result/transferred/doctor/name/surname ~= 'Atkins' or
            ./result/deceased/doctor/name/surname ~= 'Atkins']

    Instead of searching the complete document tree only these nodes must be visited to see if the predicate expression holds. As a result, the optimizer delivers a modified tree.

  3. Processor-specific Optimizer
    This component optimizes the tree with regard to the special needs of the next processing components. For both, the index processor and the postprocessor, a tree will be generated that best suits their needs.

  4. Index Processor
    This component evaluates all predicates containing indexed element nodes. It is further responsible for accessing documents and schemas from the database as well as for composing the XML document that contains the query result. It is possible that the index processor creates a superset of the query result which then has to be restricted in the next step. If no further processing is necessary, then the index processor returns the result set as an instance of xql:result.

  5. Postprocessor
    Since typically not every node is indexed, there is another processing stage that evaluates expression with non-indexed nodes. The postprocessor also restricts the result set if the index processor generated a superset by scanning a doctype or collection. Furthermore it also makes calls to any query functions. If invoked it will return the complete query result.

A call to ino:explain provides information about which processing components are involved, to what degree the query can be optimized, and the work load of the index processor and the postprocessor. According to the selected explanation level a different amount of information is returned inside an element called ino:explanation. This element uses two attributes, ino:document_processing and ino:preselection that are used as flags and indicate the way the query is processed. Inside ino:explanation a set of elements can appear that share the namespace prefix xop. They correspond to expressions in X-Query. For example, the element xop:matches represents the match operator '~=', and the node <xop:literal xop:value="Atkins" /> represents the literal string constant "Atkins". The sections below describing the explanation levels contain more information about which principal elements and attributes of the xop namespace are important and how they can be used for the purpose of query analysis and optimization.

Note:
The information that is returned by a call of ino:explain() shows the internal structure of query processing and is subject to change without prior notice if this is necessary because of improvements in the underlying mechanism.

No Explanation Level

In the query result only ino:explanation appears along with its two required attributes. They mean:

To retrieve the execution plan for a query looking for patient whose surname contains "Atkins":

ino:explain(patient[.//surname ~= "Atkins"])

The result from the server looks like this (only showing the relevant <xql:result> node):

<xql:result>
  <ino:explanation ino:preselection="TRUE" ino:postprocessing="TRUE" />
</xql:result>

Explanation Level "path"

This level shows the query after the optimizer run. Each step of a location path is represented by its own xop:path element. Nesting of xop:path elements means traversing the location path one step further along the child axis. Any instance of xop:path uses these attributes:

Using the example from above the returned ino:explanation node contains the following series of xop:path elements (the larger middle part deleted for brevity):

<xop:path xop:name="patient" xop:maptype="native">
  <xop:path xop:name="name" xop:maptype="infofield">
    <xop:path xop:name="surname" xop:maptype="infofield" />
  </xop:path>
  <xop:path xop:name="nextofkin" xop:maptype="infofield">
    <xop:path xop:name="name" xop:maptype="infofield">
      <xop:path xop:name="surname" xop:maptype="infofield" />
    </xop:path>
  </xop:path>
  ...
  <xop:path xop:name="address" xop:maptype="infofield" />
</xop:path>

The "patient" element contains the element name which in turn contains the element surname, each of them with their schema mapping type definition in the xop:maptype attribute.

Explanation Level "tree"

The structure of ino:explanation acknowledges the query trees that are built and modified during query processing. For each tree that is used during processing, there is a corresponding xop:querytree element that are distinguished by the attribute xop:treetype as follows.

Top of page

Compatibility

Neither in XPath nor in XSLT is there an equivalent for this Tamino-specific function.

Top of page

Example

Retrieve information about the execution plan of a query looking for patients whose surnames contain "Atkins":

ino:explain(patient[.//surname ~= "Atkins"])

The result from the server looks as follows (only showing the relevant <xql:result> node):

<xql:result>
  <ino:explanation ino:preselection="FALSE" ino:postprocessing="TRUE"/>
</xql:result>

So there is no index on the surname element node and a postprocessor run is necessary. You can do the following to minimize processing costs:

Top of page