Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
Signed-off-by: wjhuang2016 <[email protected]>
  • Loading branch information
wjhuang2016 committed Sep 14, 2024
1 parent b7f5e9d commit 743f710
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@
- [`schema_unused_indexes`](/sys-schema/sys-schema-unused-indexes.md)
- [元数据锁](/metadata-lock.md)
- [TiDB 加速建表](/accelerated-table-creation.md)
- [schema 缓存](/schema-cache.md)
- UI
- TiDB Dashboard
- [简介](/dashboard/dashboard-intro.md)
Expand Down
25 changes: 25 additions & 0 deletions schema-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: schema 缓存
aliases: ['/docs-cn/dev/information-schema-cache']
summary: TiDB 对于 schema 信息采用缓存机制,在大量数据库和表的场景下能够显著减少 schema 信息的内存占用以及提高性能。
---

# schema 缓存

在一些多租户的场景下,可能会存在几十万甚至上百万个数据库和表。这些数据库和表的 schema 信息如果全部加载到内存中,一方面会占用大量的内存,另一方面会导致相关的访问性能变差。
为了解决这个问题,TiDB 引入了 schema 缓存机制。采用类似于 LRU 的机制,只将最近用到的数据库和表的 schema 信息中缓存到内存中。

## 配置

可以通过配置系统变量 [`tidb_schema_cache_size`](/system-variables.md#tidb_schema_cache_size-从-v800-版本开始引入) 来打开 schema 缓存特性。

## 最佳实践

- 在大量数据库和表的场景下,建议打开 schema 缓存特性。
- 建议关闭 [`performance.force-init-stats`](/tidb-configuration-file.md#force-init-stats-从-v657-和-v710-版本开始引入) 以减少 TiDB 的启动时间。
- 建议关闭 [`split-table`](/tidb-configuration-file.md#split-table) 以减少 region 数量,从而降低 TiKV 的内存。

## 已知限制

- 在大量数据库和表的场景下,统计信息不一定能够及时收集。
- 在大量数据库和表的场景下,一些元数据信息的访问会变慢。

0 comments on commit 743f710

Please sign in to comment.