- 浏览: 203595 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
Prepared:
Hadoop的几个明显缺点 -
CSunDNan:
...
openjdk jvm 方法字节码执行过程 -
幻影之蚀:
...
mysql 源码分析2 源码调试环境建立 -
shukongchengje:
紧急呼唤楼主,mysql代码从哪里弄?官网wiki上看的一头雾 ...
mysql源码分析 整体架构 -
yeshaoting:
好文章.不介意的话转载了.
jvm 字节码中文含义
1.哈希表的概述
hash表的实现是innodb的基础功能之一,通过关键值进行映射,从而迅速进行查询、插入、删除的操作。
hash表算法,在数据库内核里面被广泛的使用,举个例子,这个结构将会在下文中继续使用的。
/* Data structure for a column in a table */
struct dict_col_struct{
hash_node_t hash; /* hash chain node */
ulint ind; /* table column position (they are numbered
starting from 0) */
ulint clust_pos;/* position of the column in the
clustered index */
ulint ord_part;/* count of how many times this column
appears in ordering fields of an index */
const char* name; /* name */
dtype_t type; /* data type */
dict_table_t* table; /* back pointer to table of this column */
ulint aux; /* this is used as an auxiliary variable
in some of the functions below */
};
从数据结构的名称上来看,这个关于列结构的,具有相同hash值的col结构,通过hash字段进行连接。该字段的定义如下:
typedef void* hash_node_t;
col结构里面的其它字段表明该列的一些属性:name表示列名,type表明列的值类型,table表明该列所属的表结构。
2.数据结构
typedef struct hash_table_struct hash_table_t;
typedef struct hash_cell_struct hash_cell_t;
typedef void* hash_node_t;
/* The hash table structure */
struct hash_table_struct {
ibool adaptive;/* TRUE if this is the hash table of the
adaptive hash index */
ulint n_cells;/* number of cells in the hash table */
hash_cell_t* array; /* pointer to cell array */
ulint n_mutexes;/* if mutexes != NULL, then the number of
mutexes, must be a power of 2 */
mutex_t* mutexes;/* NULL, or an array of mutexes used to
protect segments of the hash table */
mem_heap_t** heaps; /* if this is non-NULL, hash chain nodes for
external chaining can be allocated from these
memory heaps; there are then n_mutexes many of
these heaps */
mem_heap_t* heap;
ulint magic_n;
};
struct hash_cell_struct{
void* node; /* hash chain node, NULL if none */
};
1)创建hash表
n_cells表明hash表的大小,我们都知道hash表常用的是进行素数的模操作。先看下创建hash表的函数的实现。
/*****************************************************************
Creates a hash table with >= n array cells. The actual number of cells is
chosen to be a prime number slightly bigger than n. */
hash_table_t*
hash_create(
/*========*/
/* out, own: created table */
ulint n) /* in: number of array cells */
{
hash_cell_t* array;
ulint prime;
hash_table_t* table;
ulint i;
hash_cell_t* cell;
prime = ut_find_prime(n);
table = mem_alloc(sizeof(hash_table_t));
array = ut_malloc(sizeof(hash_cell_t) * prime);
table->adaptive = FALSE;
table->array = array;
table->n_cells = prime;
table->n_mutexes = 0;
table->mutexes = NULL;
table->heaps = NULL;
table->heap = NULL;
table->magic_n = HASH_TABLE_MAGIC_N;
/* Initialize the cell array */
for (i = 0; i < prime; i++) {
cell = hash_get_nth_cell(table, i);
cell->node = NULL;
}
return(table);
}
在创建hash表的时候,我们提供的常用是一个普通的数字,来指明hash表的大小。这个n的值可能不是素数,所以需要通过ut_find_prime(n)来产生一个稍大于n的素数,当然这个素数不一定是大于n的最小素数。ut_find_prime的具体实现见文件ut0rnd.c。
接着调用mem_alloc函数来分配hash表结构,为该结构分配空间,这个比较简单。接着分配数量为prime个的hash单元,并通过后面的循环语句将单元的node指针置为空。
2)基础的函数
提供值之后,我们需要进行映射,获取对应的单元的编号。
/******************************************************************
Calculates the hash value from a folded value. */
UNIV_INLINE
ulint
hash_calc_hash(
/*===========*/
/* out: hashed value */
ulint fold, /* in: folded value */
hash_table_t* table) /* in: hash table */
{
return(ut_hash_ulint(fold, table->n_cells));
}
其中ut_hash_ulint函数的实现如下:
/***********************************************************
The following function generates a hash value for a ulint integer
to a hash table of size table_size, which should be a prime
or some random number for the hash table to work reliably. */
UNIV_INLINE
ulint
ut_hash_ulint(
/*=========*/
/* out: hash value */
ulint key, /* in: value to be hashed */
ulint table_size) /* in: hash table size */
{
key = key ^ UT_HASH_RANDOM_MASK2;
return(key % table_size);
}
通过模操作获得了对应的hash表单元的数值,然后就可以通过该数值找到hash表的该单元节点,调用hash_get_nth_cell函数,函数实现如下:
/****************************************************************
Gets the nth cell in a hash table. */
UNIV_INLINE
hash_cell_t*
hash_get_nth_cell(
/*==============*/
/* out: pointer to cell */
hash_table_t* table, /* in: hash table */
ulint n) /* in: cell index */
{
ut_ad(n < table->n_cells);
return(table->array + n);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/whyangwanfu/archive/2008/09/21/2958762.aspx
发表评论
-
mysql 核心内幕
2010-03-30 17:34 1326目录 第1章 MySQL的前世今生 1.1 MySQ ... -
并发控制原理
2010-03-30 17:31 938事务之间的相互影响可能导致数据库状态的不一致,即使各个事务能保 ... -
聚集索引与非聚集索引的基本概念
2010-03-30 17:14 1269聚集索引,是一种指明 ... -
bitmap索引的深入研究
2010-03-30 17:03 1352位图(bitmap)索引是另外一种索引类型,它的组织形式与B树 ... -
Mysql源代码分析系列
2010-03-30 16:51 5832Mysql源代码分析系列(2): 源代码结构 Mysql ... -
并发控制原理
2010-03-30 16:46 890事务之间的相互影响可能导致数据库状态的不一致,即使各个事务能保 ... -
数据库性能调优技术
2010-03-30 16:45 703一、概述 随着数据库在各个领域的使用不断增长,越来越多 ... -
日志系统原理
2010-03-30 16:40 967一:事务系统 1.事务的工作模型 事务必须满足原子性,所 ... -
Mysql查询优化器浅析
2010-03-30 16:33 9451 定义 Mysql查询优化器的工作是为查询语句选择 ... -
InnoDB页结构浅析
2010-03-30 16:32 1144InnoDB将所有的记录存放在数据库页中(也可以称为数据块)。 ... -
InnoDB记录结构浅析
2010-03-30 16:31 694InnoDB记录由三个部分组成,见表1: 表1:InnoDB的 ... -
mysql5.1在windows下的编译方法
2010-03-30 16:28 1254编译步骤 1、从mysql.com ... -
mysql 在 VS2005上面单步调试
2010-03-30 13:39 1476mysql 在 VS2005上面单步调试 收藏 http:/ ... -
mysql 源码分析2 源码调试环境建立
2010-03-05 12:57 13231.下载源码 2.建立工程 3.调试 待续。。。 -
memcached 架构分析
2009-12-13 21:08 1072memcached 架构分析 -
无法抗衡关系型数据库 NoSQL革命仍要等待
2009-08-04 02:40 1106NoSQL架构可以省去将Web或者Java 应用和数据转换成S ... -
no sql
2009-08-04 02:31 896什么是NoSQL 1.不要叫它们数据库。 2.它们可以处理超大 ... -
B树
2009-07-28 16:35 1029B树 即二叉搜索树: 1.所有 ... -
索引基础
2009-07-28 14:43 8741.索引是什么? 索引是一个单独的、物理的数据库结构, ... -
mysql源码分析 整体架构
2009-07-28 03:13 8583大致分析完了mysql整体架构 明确了mysql架构,其实也就 ...
相关推荐
yum install make gcc flex bison cd /root/undrop-for-innodb-master make 会产生三个文件c_parser innochecksum_changer stream_parser
8.MySQL存储引擎--MyISAM与InnoDB区别1
percona-data-recovery-tool-for-innodb-0.5.tar.tar
接着以InnoDB的内部实现为切入点,逐一详细讲解了InnoDB存储引擎内部的各个功能模块,包括InnoDB存储引擎的体系结构、内存中的数据结构、基于InnoDB存储引擎的表和页的物理存储、索引与算法、文件、锁、事务、备份,...
LNH_MySQL 09-MySQL服务InnoDB引擎特点讲解.mp4
MySQL内核 InnoDB存储引擎 卷1 超高清 带书签 pdf文档
LNH_MySQL 10-MySQL服务InnoDB引擎适合的生产应用场景.mp4
LNH_MySQL 08-MySQL服务InnoDB引擎介绍及磁盘文件格式.mp4
LNH_MySQL 11-MySQL服务InnoDB引擎调优及不同引擎功能对比.mp4
mysql-shell-8.0.18-windows-x86-64bit.zip MySQL Shell is an advanced command-line client and code ... MySQL Shell includes the AdminAPI that enables you to work with InnoDB cluster, see InnoDB Cluster.
# 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证 #mysql_native_password default_authentication_plugin=mysql_native_password [mysql] # 设置...
MySQL内核 INNODB存储引擎-卷1-高清-完整目录-2014年5月
MySQL内核_InnoDB存储引擎(卷1)_753281.pdf
InnoDB 查询优化实现分析 -- MySQL
2020年1月13日,MySQL官方发布了今年的第一个8.0版本-8.0.19,自2018年4月19日发布第一个稳定版本8.0.11到如今已经历了近两年共9个小版本的迭代,产品稳定性持续增强。极具吸引力的是官方在8.0版本上对MGR bug 的...
Linux运维-运维课程d4-MySQL备份与恢复(重点)-11-InnoDB引擎存储结构.mp4
mysql 5.6 新特性 innodb
卷1》由资深MySQL专家,机工畅销图书作者亲自执笔,在以往出版的两本InnoDB介绍性图书的基础之上,更深入地介绍InnoDB存储引擎的内核,例如latch、B+树索引、事务、锁等,从源代码的角度深度解析了InnoDB的体系结构...
解压版mysql安装教程 my.ini配置文件 [mysqld] # 设置mysql的安装目录 basedir=D:/Program Files (x86)/mysql-8.0.11-winx64 # 设置mysql数据库的数据的存放目录,必须是data datadir=D:/Program Files (x86)/mysql-...
TwinDB数据恢复工具包是一组工具,可在较低级别上与MySQL文件一起使用,并允许在不同的故障情况后恢复InnoDB数据库。 该工具箱也称为InnoDB的UnDrop ,其名称更准确,因为该工具箱可用于InnoDB表。 当备份不可用时...