EXPLAIN

EXPLAIN

The EXPLAIN statement when used before any N1QL statement, provides information about the execution plan for the statement.

RBAC Privileges

User executing the EXPLAIN statement must have the privileges required for the N1QL statement that is being explained. For more details about user roles, see Authorization.

For example,

To execute the following statement, user must have the Query Insert privilege on `travel-sample` and the Query Select privilege on `beer-sample`.

EXPLAIN INSERT INTO `travel-sample` (KEY foo, VALUE bar) SELECT foo, bar FROM `beer-sample`

To execute the following statement, user must have the Query Insert, Query Update, and Query Select privileges on testbucket.

EXPLAIN UPSERT INTO testbucket VALUES ("key1", { "a" : "b" }) RETURNING meta().cas

Example

EXPLAIN SELECT title, genre, runtime FROM catalog.details ORDER BY title

"results": [
   {
     "#operator": "Sequence",
     "~children": [
         {
            "#operator": "Sequence",
            "~children": [
                {
                   "#operator": "PrimaryScan",
                   "index": "#primary",
                   "keyspace": "catalog",
                   "namespace": "default"
                },
                {
                   "#operator": "Parallel",
                   "~child": {
                        "#operator": "Sequence",
                        "~children": [
                             {
                                "#operator": "Fetch",
                                "keyspace": "catalog",
                                "namespace": "default",
                                "projection": "`details`"
                             },
                             {
                                "#operator": "InitialProject",
                                "result_terms": [
                                    {
                                      "expr": "(`details`.`title`)"
                                    },
                                    {
                                      "expr": "(`details`.`genre`)"
                                    },
                                    {
                                       "expr": "(`details`.`runtime`)"
                                    }
                                    ]
                             }
                       ]
                }
                        }
                    ]
                },
                {
                    "#operator": "Order",
                    "sort_terms": [
                        {
                            "expr": "(`details`.`title`)"
                        }
                    ]
                },
                {
                    "#operator": "Parallel",
                    "~child": {
                        "#operator": "FinalProject"
                    }
         }
      ]
    }
]