# Logical Transformation - Eliminate `MAX/MIN` Example
+ The **`MAX/MIN`** functions can be replaced with index scan
+ **`TopN (N=1) LIMIT`** operation on index
+ Does not function with **`GROUP BY`**
```
EXPLAIN SELECT MAX(gravity), MIN(gravity) FROM planets;
+----------------------------+----------+-----------+---------------+
| id                         | estRows  | task      | access object |
+----------------------------+----------+-----------+---------------+
| HashAgg_11                 | 1.00     | root      |               |
| └─TableReader_12           | 1.00     | root      |               |
|   └─HashAgg_5              | 1.00     | cop[tikv] |               |
|     └─~!@TableFullScan_10@!~     | 10000.00 | cop[tikv] | table:planets |
+----------------------------+----------+-----------+---------------+

CREATE INDEX gravity_idx ON planets (gravity);
EXPLAIN SELECT MAX(gravity), MIN(gravity) FROM planets;
+----------------------------------+---------+-----------+-------------------------------------------+
| id                               | estRows | task      | access object                             |
+----------------------------------+---------+-----------+-------------------------------------------+
| HashJoin_16                      | 1.00    | root      |                                           |
| ├─StreamAgg_33(Build)            | 1.00    | root      |                                           |
| │ └─Limit_37                     | 1.00    | root      |                                           |
| │   └─IndexReader_45             | 1.00    | root      |                                           |
| │     └─~!@Limit_44@!~                 | 1.00    | cop[tikv] |                                           |
| │       └─~!@IndexFullScan_43@!~       | 1.00    | cop[tikv] | table:planets, index:gravity_idx(gravity) |
| └─StreamAgg_19(Probe)            | 1.00    | root      |                                           |
|   └─Limit_23                     | 1.00    | root      |                                           |
|     └─IndexReader_31             | 1.00    | root      |                                           |
|       └─~!@Limit_30@!~                 | 1.00    | cop[tikv] |                                           |
|         └─~!@IndexFullScan_29@!~       | 1.00    | cop[tikv] | table:planets, index:gravity_idx(gravity) |
+----------------------------------+---------+-----------+-------------------------------------------+
```
------------------------------------------------------------------------------
When a SQL statement includes `MAX` or `MIN` functions, the query optimizer tries to enhance efficiency by converting these aggregate functions into the `TopN` operator through the `MAX/MIN` optimization rule. This conversion enables TiDB to execute the query more efficiently by utilizing indexes.