Skip to content

Commit

Permalink
cached-tables: add description about mysql.table_cache_meta table (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomShawn committed Dec 23, 2022
1 parent 288076c commit ef111a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cached-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ SELECT * FROM users;
>
> The write latency of cached tables is high, because the cached table feature is implemented with a complex mechanism that requires a lease to be set for each cache. When there are multiple TiDB instances, one instance does not know whether the other instances have cached data. If an instance modifies the table data directly, the other instances read the old cache data. To ensure correctness, the cached table implementation uses a lease mechanism to ensure that the data is not modified before the lease expires. That is why the write latency is high.
The metadata of cached tables is stored in the `mysql.table_cache_meta` table. This table records the IDs of all cached tables, the current lock status (`lock_type`), and the lock lease information (`lease`). This table is only internally used in TiDB and you are not recommended to modify it. Otherwise, unexpected errors might occur.

```sql
SHOW CREATE TABLE mysql.table_cache_meta\G
*************************** 1. row ***************************
Table: table_cache_meta
Create Table: CREATE TABLE `table_cache_meta` (
`tid` bigint(11) NOT NULL DEFAULT '0',
`lock_type` enum('NONE','READ','INTEND','WRITE') NOT NULL DEFAULT 'NONE',
`lease` bigint(20) NOT NULL DEFAULT '0',
`oldReadLease` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`tid`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)
```

### Revert a cached table to a normal table

> **Note:**
Expand Down
4 changes: 4 additions & 0 deletions mysql-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Currently, the `help_topic` is NULL.

- `gc_delete_range`: to record the data to be deleted

## System tables related to cached tables

* `table_cache_meta` stores the metadata of cached tables.

## Miscellaneous system tables

- `GLOBAL_VARIABLES`: global system variable table
Expand Down

0 comments on commit ef111a9

Please sign in to comment.