加入收藏 | 设为首页 | 会员中心 | 我要投稿 52站长网 (https://www.52zhanzhang.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL中关于Table cache当如何设置

发布时间:2022-01-13 14:54:55 所属栏目:MySql教程 来源:互联网
导读:这篇文章将为大家详细讲解有关MySQL中关于Table cache该如何设置,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。 因为今天突然有个凌晨5点值班任务,随意翻起同事的书来,看到表对象缓存,这个跟自己平
      这篇文章将为大家详细讲解有关MySQL中关于Table cache该如何设置,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
 
      因为今天突然有个凌晨5点值班任务,随意翻起同事的书来,看到表对象缓存,这个跟自己平时理解,稍微有差异。所以整理了一下table_definition_cache,table_open_cache和table_open_cache_instances。
 
先看看官网怎么说:
 
1.table_definition_cache
 
the number of table definitions (from .frm files) that can be stored in the definition cache. If you use a large number of tables, you can create a large table definition cache to speed up opening of tables. The table definition cache takes less space and does not use file descriptors, unlike the normal table cache.
 
理解下来,就是控制总frm文件的数量,还是个hash表,内部维护。如果打开的表实例的数量超过了table_definition_cache设置,
 
LRU机制将开始标记表实例以进行清除,并最终将它们从数据字典缓存中删除。
 
简单通俗点frm文件有多少,就设置多少了。
 
2.table_open_cache
 
The number of open tables for all threads. Increasing this value increases the number of file descriptors that mysqld requires. You can check whether you need to increase the table cache by checking the Opened_tables status variable
 
所有线程打开的表的数量。增加这个值会增加mysqld需要的文件描述符的数量。可以通过检查Opened_tables状态变量来检查是否需要增加表缓存。
 
是不是可以理解为ibd/MYI/MYD 文件,打开数量了。但mysql内部需要对表进行操作的时候,第一需要找到最上层文件的句柄信息,table_open_cache_instances是能提供的,之后对应的寻找ibd,MYI,MYD文件。官网对于这部分没有明确说明
 
3.table_open_cache_instances
 
The number of open tables cache instances. To improve scalability by reducing contention among sessions, the open tables cache can be partitioned into several smaller cache instances of size table_open_cache / table_open_cache_instances . A session needs to lock only one instance to access it for DML statements. This segments cache access among instances, permitting higher performance for operations that use the cache when there are many sessions accessing tables.
 
打开的表缓存实例的数量。为了通过减少会话间的争用来提高可伸缩性,可以将打开的表缓存划分为几个大小为table_open_cache / table_open_cache_instances的较小缓存实例。一个会话只需要锁定一个实例就可以访问DML语句。写到这里就已经大致了解到 如下关系:
 
table_definition_cache > table_open_cache_instances > table_open_cache
 
4.table相关的限制有哪些?
 
mysql是多线程,对于并发同一个文件,不同数据的情况下,会打开多个文件,会存在哪些限制呢?下面是源代码里逻辑是怎样

(编辑:52站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读