Execution of a Lava query plan involves five phases:
Acquire – acquires resources needed for execution, such as memory buffers and creating worktables.
Open – prepares to return result rows.
Next – generates the next result row.
Close – cleans up; for example, notifies the access layer that scanning is complete or truncates worktables
Release – releases resources acquired during Acquire, such as memory buffers, drops worktables.
Each Lava operator has a method with the same name as the phase, which is invoked for each of these phases.
Figure 1-2 demonstrates query plan execution:
Acquire phase
The acquire method of the Emit operator is invoked. The Emit operator calls Acquire of its child, the NLJoin operator, which in turn calls Acquire on its left-child operator (the index scan of sysobjects) and then on its right child operator (the index scan of syscolumns).
Open phase
The Open method of the Emit operator is invoked. The Emit operator calls Open on the NLJoin operator, which calls Open only on its left-child operator.
Next phase
The Next method of the Emit operator is invoked. Emit calls Next on the NLJoin operator, which calls Next on its left child, the Index Scan of sysobjects. The index scan operator reads the first row from sysobjects and returns it to the NLJoin operator. The NLJoin operator then calls the Open method of its right child operator, the Index Scan of syscolumns. Then the NLJoin operator calls the Next method of the Index Scan of syscolumns to get a row that matches the joining key of the row from sysobjects. When a matching row has been found, it is returned to the Emit operator, which sends it back to the client. Repeated invocations of the Next method of the Emit operator generate more result rows.
Close phase
After all rows have been returned, the Close method of the Emit operator is invoked, which in turn calls Close of the NLJoin operator, which in turn calls Close on both of its child operators.
Release phase
The Release method of the Emit operator is invoked and the calls to the Release method of the other operators is propagated down the query plan.
After successfully completing the Release phase of execution, the Lava query engine returns control to the Procedural Execution Engine for final statement processing.