# Cached Tables

__*Cached Table*__

+ Cache the contents of the table into the memory of the `TiDB` Server
+ The amount of data in the table is small and hardly changes
+ Cache control: **`ALTER TABLE {table_name} CACHE|NOCACHE`**
+ Executing DDL statements on a cached table will fail, except **`ALTER TABLE {table_name} NOCACHE`**

```
tidb> TRACE SELECT * FROM test.c1;
+-------------------------------------------+-----------------+------------+
| operation                                 | startTS         | duration   |
+-------------------------------------------+-----------------+------------+
| trace                                     | 18:39:25.485266 | 501.582µs  |
|   ├─session.ExecuteStmt                   | 18:39:25.485270 | 432.208µs  |
|   │ ├─executor.Compile                    | 18:39:25.485281 | 132.616µs  |
|   │ └─session.runStmt                     | 18:39:25.485433 | 249.488µs  |
|   │   └─UnionScanExec.Open                | 18:39:25.485572 | 72.776µs   |
|   │     ├─TableReaderExecutor.Open        | 18:39:25.485575 | 13.24µs    |
|   │     ├─buildMemTableReader             | 18:39:25.485605 | 3.283µs    |
|   │     └─~!@memTableReader.getMemRows@!~       | 18:39:25.485615 | 20.558µs   |
|   ├─*executor.ProjectionExec.Next         | 18:39:25.485712 | 12.911µs   |
|   │ └─*executor.UnionScanExec.Next        | 18:39:25.485714 | 3.823µs    |
|   └─*executor.ProjectionExec.Next         | 18:39:25.485733 | 8.943µs    |
|     └─*executor.UnionScanExec.Next        | 18:39:25.485735 | 1.33µs     |
+-------------------------------------------+-----------------+------------+
12 rows in set (0.00 sec)
```

------------------------------------------------------------
This function is suitable for hot tables that are frequently accessed and rarely modify. That is, load the entire table data into the memory of the TiDB server, get the table data directly from the memory, and avoid getting the table data from TiKV, thereby improving read performance.

In addition to TRACE, you can also use EXPLAIN ANALYZE to observe the cache hit ratio to get clues about memory access.

It is important to note that cached tables do not support DDL operations. For example:

```
tidb> drop table test.c1;
ERROR 8242 (HY000): 'Drop Table' is unsupported on cache tables.
```
