改进MySQL的table_cache(3)
{}
}
if (table)
************
从unused_tables链表中移除刚找到的table
************
else
***********
创建一个新的table实例,并插入到open cache中
***********
while (open_cache.records > table_cache_size && unused_tables) //当cache满时,从中释放未使用的TABLE实例
hash_delete(&open_cache,(uchar*) unused_tables);
if (table_list->create) //创建一个新表
{
*******
检查表是否存在:check_if_table_exists
*******
在table cache的hash中创建一个placeholder(占位符):table_cache_insert_placeholder
将占位符链到open tables list上:
table->open_placeholder= 1;
table->next= thd->open_tables;
thd->open_tables= table;
return table
}
创建一个新的table实例
分配内存table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME))
error= open_unireg_entry(thd, table, table_list, alias, key, key_length,
mem_root, (flags & OPEN_VIEW_NO_PARSE));
如果是视图or error < 0 释放内存,返回;
my_hash_insert(&open_cache,(uchar*) table)
------------------------------------------------
patch:http://bugs.mysql.com/bug.php?id=33948
增加3个指针:
hash_head:
hash_prev: always point to unused table cached items
hash_next: always point to used table cached items
修改的函数:
free_cache_entry //释放一个表的内存。
close_thread_table //move one table to free list
reopen_name_locked_table //重新打开表,保持链表结构
table_cache_insert_placeholder
open_table
------------------------------------------------------------------------
总结:
增加了三个指针:
hash_head:
hash_prev:
hash_next:
!.............................!head!.........................!
head的左边为空闲item链表
head的右边为占用的item链表
所有item通过hash_prev和hash_next进行双向指针
右边的item的hash_head指向head
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>