Overview of query plan

A query execution plan is internally structured as a tree of plan iterators.

Each kind of iterator evaluates a different kind of expression that may appear in a query. In general, the choice of index and the kind of associated index predicates can have a drastic effect on query performance. As a result, you as a developer often want to see what index is used by a query and what predicates have been pushed down to it. Based on this information, you may want to force the use of a different index via index hints. This information is contained in the query execution plan. All Oracle NoSQL drivers provide APIs to display the execution plan of a query. All Oracle NoSQL graphical UIs including the IntelliJ, VSCode, and Eclipse plugins along with the Oracle Cloud Infrastructure Console include controls for displaying the query execution plan.

Some of the most common and important iterators used in queries are :

TABLE iterator

A table iterator is responsible for

Note: An index is called a covering index with respect to a query if the query can be evaluated using only the entries of that index, that is, without the need to retrieve the associated rows.

A TABLE iterator will always have the following properties:

A TABLE iterator has 2 more optional properties:

SELECT iterator

It is responsible for executing the SELECT expression.

RECEIVE iterator

It is a special internal iterator that separates the query plan into 2 parts:

  1. The RECEIVE iterator itself and all iterators that are above it in the iterator tree are executed at the driver.

  2. All iterators below the RECEIVE iterator are executed at the replication nodes (RNs); these iterators form a subtree rooted at the unique child of the RECEIVE iterator.

In general, the RECEIVE iterator acts as a query coordinator. It sends its subplan to appropriate RNs for execution and collects the results. It may perform additional operations such as sorting and duplicate elimination and propagates the results to its ancestor iterators (if any) for further processing.

Distribution kinds

A distribution kind specifies how the query will be distributed for execution across the RNs participating in an Oracle NoSQL database (a store). The distribution kind is a property of the RECEIVE iterator.

Different choices of Distribution kinds are:

Populating the tables to view the query execution plan :

If you want to follow along with the examples, download the script baggageschema_loaddata.sql and run it as shown below. This script creates the table used in the example and loads data into the table.

Start your KVSTORE or KVLite and open the SQL.shell.

java -jar lib/kvstore.jar kvlite -secure-config disable
java -jar lib/sql.jar -helper-hosts localhost:5000 -store kvstore

Using the load command, run the script.

load -file baggageschema_loaddata.sql

Creating indexes:

Create the following indexes in the baggageInfo table as shown below.

  1. Create an index on passengers reservation code.

    CREATE INDEX fixedschema_conf ON baggageInfo confNo)
  2. Create an index on the full name and phone number of passengers

    CREATE INDEX compindex_namephone ON baggageInfo (fullName,contactPhone)
  3. Create an index on three fields, when the bag was last seen, the last seen station, and the arrival date and time.

    CREATE INDEX simpleindex_arrival ON
    baggageInfo(bagInfo[].lastSeenTimeGmt as ANYATOMIC,
    bagInfo[].bagArrivalDate as ANYATOMIC,
    bagInfo[].lastSeenTimeStation as ANYATOMIC)