# Reviewing the Execution Plan - Execution Order
![`smart`](InterpretExecutionPlan_en_001_20231113.png)
```8
SELECT t5.name FROM
(SELECT p.name, p.gravity, p.distance_from_sun FROM universe.planets p JOIN universe.stars s
 ON s.id = p.sun_id AND s.name = 'Sun'
 ORDER BY p.distance_from_sun ASC LIMIT 5) t5
ORDER BY t5.gravity DESC LIMIT 3
```
```7
+-----------------------------------+----------+-----------+---------------------------+
| id                                | estRows  | task      | access object             |
+-----------------------------------+----------+-----------+---------------------------+
| Projection_~!@16@!~                     | 3.00     | root      |                           |
| └─TopN_~!@19@!~                         | 3.00     | root      |                           |
|   └─TopN_~!@26@!~                       | 5.00     | root      |                           |
|     └─HashJoin_~!@44@!~                 | 5.00     | root      |                           |
|       ├─IndexReader_~!@48@!~(Build)     | 1.00     | root      |                           |
|       │ └─IndexRangeScan_~!@47@!~       | 1.00     | cop[tikv] | table:s, index:name(name) |
|       └─TableReader_~!@46@!~(Probe)     | 10.00    | root      |                           |
|         └─TableFullScan_~!@45@!~        | 10.00    | cop[tikv] | table:p                   |
+-----------------------------------+----------+-----------+---------------------------+
```
------------------------------------------------------------------------------
The example query illustrates how to interpret the execution order of an execution plan. The slide presents a query along with its associated execution plan and a tree format representation of the same plan.

The query aims to identify the three planets with the highest gravitational accelerations among the five closest planets to the Sun. It uses a `SELECT` statement to query two tables, with a subquery to determine the planets' proximity to the Sun.

To help comprehend the execution plan's order, remember this rule of thumb: execute the rightmost node first, and among nodes at the same level, execute the uppermost node first. Refer to the execution order of this query. According to the example from the slide, the execution order, based on the operator's unique ID, is `47 - 48 - 45 - 46 - 44 - 26 - 19 - 16`.

- `47:` The plan begins with an index range scan on the `stars` table's `name` column. Note that node `47` is both the rightmost and uppermost in the execution plan tree.
- `48:` The index reader retrieves all the `id` values of the relevant `stars`.
- `45:` A full table scan is performed on the `planets` table.
- `46:` The table reader fetches all data from `planets`.
- `44:` All index entries from `48` are hash-joined with the rows from `46` on `id` (from the index) and `sun_id` (from the `planets` table).
- `26:` Filters to retain the top 5 planets based on `distance_from_sun`, in ascending order.
- `19:` Filters to retain the top 3 planets based on `gravity`, in descending order.
- `16:` The final projection retains only the planet names in the result set.