改进MySQL的table_cache(3)

来源:未知 责任编辑:责任编辑 发表时间:2013-12-22 14:56 点击:

              {}

 

}

 

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

发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • mysql-mmm
  • mysqldump命令——MySQL数据库备份还原
  • Oracle数据导入MySQL的快捷工具:MySQL Migration Toolkit
  • 简简单单储存过程——循环一个select结果集
  • MySQL数据库十大优化技巧
  • Mysql主主复制架构配置
  • Mysql安装笔记
  • Mysql的Procedure 参数为NULL问题分析
  • MySQL Stmt预处理提高效率问题的小研究
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1