发新话题
打印

关于mysql中heap表的使用

关于mysql中heap表的使用

HEAP表是访问数据速度最快的MySQL表,他使用保存在内存中的散列索引。但如果MySQL或者服务器重新启动,表中数据将会丢失.

HEAP表格使用一个杂凑(hashed)索引并且存储在内存中。这使他们更快,但是如果MySQL崩溃,你将失去所有存储的数据。HEAP作为临时表很可用!

CREATE TABLE test TYPE=HEAP SELECT ip,SUM(downloads) as down FROM log_table GROUP BY ip; SELECT COUNT(ip),AVG(down) FROM test; DROP TABLE test;当你使用HEAP表时,这里是你应该考虑的一些事情:

你应该总是在CREATE语句中指定MAX_ROWS以保证你有意不使用所有的内存。
索引将只能与与=和<=>一起使用(但是很快)。
HEAP表使用一个固定的记录长度格式。
HEAP不支持BLOB/TEXT列。
HEAP不支持AUTO_INCREMENT列。
HEAP不支持在一个NULL列上的索引。
你可以在一个HEAP表中有非唯一键(杂凑表一般不这样)。
HEAP表格在所有的客户之间被共享(就象任何其他的表)。
HEAP表的数据以小块分配。表是100%动态的(在插入时),无需溢出区和额外的键空间。删除的行放入一个链接表并且当你把新数据插入到表时,它将被再次使用。
为了释放内存,你应该执行DELETE FROM heap_table或DROP TABLE heap_table。
为了保证你不会偶然做些愚蠢的事情,你不能创建比max_heap_table_size大的HEAP表。
实际操作:
mysql HEAP MEMORY tables 提高行数支持的方法

别人问到的 记一下
mysql MEMORY tables 如果目前支持的行数到上限还不够用 可以把 my.cnf 配置里面
max_heap_table_size = 256M
改大

设置 MAX_ROWS
在跑着 可以 ALTER TABLE tbl_name MAX_ROWS=
MAX_ROWS 依赖于 max_heap_table_size 设置

相关帮助:
max_heap_table_size
This variable sets the maximum size to which MEMORY tables are allowed to grow.
The value of the variable is used to calculate MEMORY table MAX_ROWS values.
Setting this variable has no effect on any existing MEMORY table,
unless the table is re-created with a statement such as CREATE TABLE or
altered with ALTER TABLE or TRUNCATE TABLE.

The MEMORY (HEAP) Storage Engine
MEMORY tables are never converted to disk tables. To ensure that you
don’t accidentally do anything foolish, you can set the max_heap_table_size
system variable to impose a maximum size on MEMORY tables. For individual tables,
you can also specify a MAX_ROWS table option in the CREATE TABLE statement.

TOP

发新话题