zoukankan      html  css  js  c++  java
  • tmp_table_size参数

    1、参数查看
    方法一:mysql> show variables like 'tmp_table_size';
    方法二:直接查看my.cnf文件tmp_table_size参数值

    2、参数配置
    方法一:mysql> set global tmp_table_size=16*1024*1024; 重启后会丢失使用my.cnf参数
    方法二:直接修改my.cnf文件tmp_table_size参数值,但需要重启实例生效

    3、参数值意义

      tmp_table_size参数配置内部内存临时表的大小。 此参数不适用用户创建的MEMORY表,用户创建的MEMORY表用max_heap_table_size参数配置。

    实际限制由tmp_table_size和max_heap_table_size的值中较小的一个确定,如果内存中的临时表超出限制,MySQL自动将其转换为磁盘上的MyISAM表。如果要执行许多 GROUP BY查询,可以增加tmp_table_size的值(或如有必要,也可以使用max_heap_table_size)。

      执行计划中Extra字段包含有“Using temporary” 时会产生临时表。

    4、外料
      MySQL中临时表主要有两类,包括外部临时表和内部临时表。外部临时表是通过语句create temporary table...创建的临时表,临时表只在本会话有效,会话断开后,临时表数据会自动清理。内部临时表主要有两类,一类是information_schema中临时表,另一类是会话执行查询时,如果执行计划中包含有“Using temporary”时,会产生临时表。内部临时表与外部临时表的一个区别在于,我们看不到内部临时表的表结构定义文件frm。而外部临时表的表定义文件frm,一般是以#sql{进程id}_{线程id}_序列号组成,因此不同会话可以创建同名的临时表。

      临时表与普通表的主要区别在于是否在实例,会话,或语句结束后,自动清理数据。比如,内部临时表,我们在一个查询中,如果要存储中间结果集,而查询结束后,临时表就会自动回收,不会影响用户表结构和数据。另外就是,不同会话的临时表可以重名,所有多个会话执行查询时,如果要使用临时表,不会有重名的担忧。5.7引入了临时表空间后,所有临时表都存储在临时表空间(非压缩)中,临时表空间的数据可以复用。临时表并非只支持Innodb引擎,还支持myisam引擎,memory引擎等。因此,临时表我们看不到实体(idb文件),但其实不一定是内存表,也可能存储在临时表空间中。

      临时表既可以innodb引擎表,也可以是memory引擎表。这里所谓的内存表,是说memory引擎表,通过建表语句create table ...engine=memory,数据全部在内存,表结构通过frm管理,同样的内部的memory引擎表,也是看不到frm文件中,甚至看不到information_schema在磁盘上的目录。在MySQL内部,information_schema里面的临时表就包含两类:innodb引擎的临时表和memory引擎的临时表。比如TABLES表属于memory临时表,而columns,processlist,属于innodb引擎临时表。内存表所有数据都在内存中,在内存中数据结构是一个数组(堆表),所有数据操作都在内存中完成,对于小数据量场景,速度比较快(不涉及物理IO操作)。但内存毕竟是有限的资源,因此,如果数据量比较大,则不适合用内存表,而是选择用磁盘临时表(innodb引擎),这种临时表采用B+树存储结构(innodb引擎),innodb的bufferpool资源是共享的,临时表的数据可能会对bufferpool的热数据有一定的影响,另外,操作可能涉及到物理IO。memory引擎表实际上也是可以创建索引的,包括Btree索引和Hash索引,所以查询速度很快,主要缺陷是内存资源有限。
    5、官网信息

    Property

     Value
    Command-Line Format --tmp-table-size=#
    System Variable tmp_table_size
    Scope Global, Session
    Dynamic Yes
    Type integer
    Default Value 16777216
    Minimum Value 1024
    Maximum Value 18446744073709551615

    The maximum size of internal in-memory temporary tables. This variable does not apply to user-
    created MEMORY tables.
    The actual limit is determined from whichever of the values of tmp_table_size and
    max_heap_table_size is smaller. If an in-memory temporary table exceeds the limit, MySQL
    automatically converts it to an on-disk MyISAM table. Increase the value of tmp_table_size (and
    max_heap_table_size if necessary) if you do many advanced GROUP BY queries and you have
    lots of memory.
    You can compare the number of internal on-disk temporary tables created to the total number of
    internal temporary tables created by comparing the values of the Created_tmp_disk_tables and
    Created_tmp_tables variables.

     6、针对报错信息:Table '/mysql/data3001/tmp/#sql_ca3c_0' is marked as crashed and should be repaired

  • 相关阅读:
    面向对象并不是必要的
    linq 总结
    垃圾自动回收的一个方案
    随手记 手机软件的不足,和开发自己理财软件的想法
    以人的角度去解决问题
    浮点数比较
    集中原则——软件设计之道
    云在何方
    我遇到了DLL地狱
    在C#.net中如何操作XML
  • 原文地址:https://www.cnblogs.com/uphold/p/11378109.html
Copyright © 2011-2022 走看看