Skip to content

Commit

Permalink
cached table: add links (#18000)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden authored Jun 27, 2024
1 parent cfe81c7 commit ceae4d7
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions cached-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ This section describes the usage of cached tables by examples.

Suppose that there is a table `users`:

{{< copyable "sql" >}}

```sql
CREATE TABLE users (
id BIGINT,
Expand All @@ -45,8 +43,6 @@ CREATE TABLE users (

To set this table to a cached table, use the `ALTER TABLE` statement:

{{< copyable "sql" >}}

```sql
ALTER TABLE users CACHE;
```
Expand All @@ -59,8 +55,6 @@ Query OK, 0 rows affected (0.01 sec)

To verify a cached table, use the `SHOW CREATE TABLE` statement. If the table is cached, the returned result contains the `CACHED ON` attribute:

{{< copyable "sql" >}}

```sql
SHOW CREATE TABLE users;
```
Expand All @@ -78,9 +72,7 @@ SHOW CREATE TABLE users;
1 row in set (0.00 sec)
```

After reading data from a cached table, TiDB loads the data in memory. You can use the `trace` statement to check whether the data is loaded into memory. When the cache is not loaded, the returned result contains the `regionRequest.SendReqCtx` attribute, which indicates that TiDB reads data from TiKV.

{{< copyable "sql" >}}
After reading data from a cached table, TiDB loads the data in memory. You can use the [`TRACE`](/sql-statements/sql-statement-trace.md) statement to check whether the data is loaded into memory. When the cache is not loaded, the returned result contains the `regionRequest.SendReqCtx` attribute, which indicates that TiDB reads data from TiKV.

```sql
TRACE SELECT * FROM users;
Expand All @@ -106,9 +98,7 @@ TRACE SELECT * FROM users;
12 rows in set (0.01 sec)
```

After executing `trace` again, the returned result no longer contains the `regionRequest.SendReqCtx` attribute, which indicates that TiDB no longer reads data from TiKV but reads data from the memory instead.

{{< copyable "sql" >}}
After executing [`TRACE`](/sql-statements/sql-statement-trace.md) again, the returned result no longer contains the `regionRequest.SendReqCtx` attribute, which indicates that TiDB no longer reads data from TiKV but reads data from the memory instead.

```sql
+----------------------------------------+-----------------+------------+
Expand All @@ -127,8 +117,6 @@ After executing `trace` again, the returned result no longer contains the `regio

Note that the `UnionScan` operator is used to read the cached tables, so you can see `UnionScan` in the execution plan of the cached tables through `explain`:

{{< copyable "sql" >}}

```sql
+-------------------------+---------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
Expand All @@ -144,8 +132,6 @@ Note that the `UnionScan` operator is used to read the cached tables, so you can

Cached tables support data writes. For example, you can insert a record into the `users` table:

{{< copyable "sql" >}}

```sql
INSERT INTO users(id, name) VALUES(1001, 'Davis');
```
Expand All @@ -154,8 +140,6 @@ INSERT INTO users(id, name) VALUES(1001, 'Davis');
Query OK, 1 row affected (0.00 sec)
```

{{< copyable "sql" >}}

```sql
SELECT * FROM users;
```
Expand Down Expand Up @@ -201,8 +185,6 @@ Create Table: CREATE TABLE `table_cache_meta` (
>
> Executing DDL statements on a cached table will fail. Before executing DDL statements on a cached table, you need to remove the cache attribute first and set the cached table back to a normal table.
{{< copyable "sql" >}}

```sql
TRUNCATE TABLE users;
```
Expand All @@ -211,8 +193,6 @@ TRUNCATE TABLE users;
ERROR 8242 (HY000): 'Truncate Table' is unsupported on cache tables.
```

{{< copyable "sql" >}}

```sql
mysql> ALTER TABLE users ADD INDEX k_id(id);
```
Expand All @@ -223,8 +203,6 @@ ERROR 8242 (HY000): 'Alter Table' is unsupported on cache tables.

To revert a cached table to a normal table, use `ALTER TABLE t NOCACHE`:

{{< copyable "sql" >}}

```sql
ALTER TABLE users NOCACHE;
```
Expand Down

0 comments on commit ceae4d7

Please sign in to comment.