Skip to main content

Access paths

Ditto Server

Primary access paths are determined internally in the subscription server with DQL only supplying relevant predicates. The one current exception is the countScan (see below). The predicates and details of plan type selection can be seen in the scan operator in the EXPLAIN output (plan) for a statement.

Ditto SDK

With the event of indexing the Query planner now has multiple options when deciding how to execute a query. The details of the access path chosen can be seen in the EXPLAIN output (plan) for the statement. The access path selected is determined by the statement’s filters, ordering and directives.

Types of access paths

Collection scan

A collection scan retrieves all the (complete) documents in a collection sequentially without any guarantee of order. A collection scan is the fall-back when a statement can’t be implemented with another access path. It can be forced with an empty or null index directive. Example:
    {
      "#operator": "scan",
      "collection": "test",
      "datasource": "default",
      "descriptor": {
        "path": {
          "_id": "query_details",
          "full_scan": {}
        }
      }
    }
If any portion of a query is to be served by a collection scan then no other scan will be used.

Index scan

An index scan is a scan of an index on the collection which returns document IDs matching the noted spans. (A “span” is a filter for an index key and indicates a range of values to return.) An index scan is picked based on filtering and possibly ordering present in the statement. A specific index can be forced if it still applies to the statement via the index directive. Example (filter: WHERE field1 = "test filter"):
    {
      "#operator": "indexScan",
      "collection": "test",
      "datasource": "default",
      "desc": {
        "index": "ix1",
        "spans": [
          {
            "index_key": {
              "direction": "asc",
              "include_missing": true,
              "key": [
                "field1"
              ]
            },
            "range": {
              "high": {
                "included": true,
                "value": "test filter"
              },
              "low": {
                "included": true,
                "value": "test filter"
              }
            }
          }
        ]
      }
    }