12
返回列表 发新帖
楼主: icer_repls

[笔记] MySQL学习笔记--InnoDB存储引擎的索引的问题

[复制链接]
论坛徽章:
4
参与2007年甲骨文全球大会(中国上海)纪念
日期:2007-08-06 15:19:02ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
11#
发表于 2011-11-8 17:07 | 只看该作者
本帖最后由 philip_zhong 于 2011-11-8 17:08 编辑

在给你贴下Cluster (Oracle)的解释

In Oracle database, multiple tables can be joined into a cluster (not to be confused with clustered index described above). The records for the tables sharing the value of a cluster key shall be stored together in the same or nearby data blocks. This may improve the joins of these tables on the cluster key, since the matching records are stored together and less I/O is required to locate them.
The data layout in the tables which are parts of the cluster is defined by the cluster configuration. A cluster can be keyed with a B-Tree index or a hash table. The data block in which the table record will be stored is defined by the value of the cluster key.

使用道具 举报

回复
论坛徽章:
4
参与2007年甲骨文全球大会(中国上海)纪念
日期:2007-08-06 15:19:02ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
12#
发表于 2011-11-8 17:32 | 只看该作者
Oracle Index-organized tables (IOTs) are a unique style of table structure that is stored in a B-tree index structure. Besides storing the primary key values of an Oracle indexed-organized tables row, each index entry in the B-tree also stores the non-key column values. Oracle Indexed-organized tables provide faster access to table rows by the primary key or any key that is a valid prefix of the primary key. Because the non-key columns of a row are present in the B-tree leaf block itself, there is no additional block access for index blocks.

使用道具 举报

回复
论坛徽章:
11
鲜花蛋
日期:2011-09-03 18:52:38鲜花蛋
日期:2011-11-09 10:10:12茶鸡蛋
日期:2011-11-19 22:46:41茶鸡蛋
日期:2011-12-14 15:16:572012新春纪念徽章
日期:2012-01-04 11:57:56奥运会纪念徽章:赛艇
日期:2012-09-26 21:40:11ITPUB 11周年纪念徽章
日期:2012-10-09 18:16:002013年新春福章
日期:2013-02-25 14:51:24
13#
 楼主| 发表于 2011-11-8 19:06 | 只看该作者
本帖最后由 icer_repls 于 2011-11-8 19:09 编辑
philip_zhong 发表于 2011-11-8 17:05
@icer_repls,mysql中,mysql innodb的pk默认就是cluster index,并且叶子节点上是挂接数据的,而普通索引 ...


thxs.

我理解你的意思。
1.cluster index就是数据在物理磁盘上的存储和索引组织顺序一模一样。然后由于MySQL中不存在rowid,也就是叶子节点上不是放得rowid,而是实际的每一行的数据,那么在定位叶子节点时,不要再像oracle那样通过rowid再去读物理磁盘。这样确实是效率高,但是跟IOT应该一样吧,在效率上。

2.mysql innodb只要创建了主键,那么默认的就会创建cluster index。那么如果表没有创建主键(当然实际可能出现得比较少,我是假设),那么这个表的数据在物理磁盘上的组织是不是就是无序的呢?只有创建了主键的表的数据在物理磁盘上的组织才是有序的?

使用道具 举报

回复
论坛徽章:
52
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:25生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:32:552012新春纪念徽章
日期:2012-02-07 09:59:35
14#
发表于 2011-11-8 21:23 | 只看该作者
icer_repls 发表于 2011-11-8 19:06
thxs.

我理解你的意思。

www.mysqlops.com上曾经写过一篇文章:InnoDB主键选型  

先回答你这个问题:
1.有主键则是cluster index
2.无主键存在NOT NULL的UNIQUE INDEX则 作为cluster index
3.无主键 无符合要求的UNIQUE INDEX,则默认创建一个6个字节的字段,内部使用作为cluster index,可以理解为这是类似Oracle 或SQL Server 的rowid

使用道具 举报

回复
论坛徽章:
11
鲜花蛋
日期:2011-09-03 18:52:38鲜花蛋
日期:2011-11-09 10:10:12茶鸡蛋
日期:2011-11-19 22:46:41茶鸡蛋
日期:2011-12-14 15:16:572012新春纪念徽章
日期:2012-01-04 11:57:56奥运会纪念徽章:赛艇
日期:2012-09-26 21:40:11ITPUB 11周年纪念徽章
日期:2012-10-09 18:16:002013年新春福章
日期:2013-02-25 14:51:24
15#
 楼主| 发表于 2011-11-8 21:33 | 只看该作者
jinguanding 发表于 2011-11-8 21:23
www.mysqlops.com上曾经写过一篇文章:InnoDB主键选型  

先回答你这个问题:

你好,对于第三点:
除了创建一个6字节的字段外,那么这个表的数据的组织形式是怎么样的呢?  是不是普通的无序文件,也就是常说的heap 文件?

使用道具 举报

回复
论坛徽章:
4
参与2007年甲骨文全球大会(中国上海)纪念
日期:2007-08-06 15:19:02ITPUB十周年纪念徽章
日期:2011-11-01 16:21:152012新春纪念徽章
日期:2012-01-04 11:51:222013年新春福章
日期:2013-02-25 14:51:24
16#
发表于 2011-11-9 08:11 | 只看该作者
icer_repls 发表于 2011-11-8 21:33
你好,对于第三点:
除了创建一个6字节的字段外,那么这个表的数据的组织形式是怎么样的呢?  是不是普通 ...

“则默认创建一个6个字节的字段,内部使用作为cluster index”,因此任然是排序的,非heap文件

使用道具 举报

回复
论坛徽章:
25
ITPUB元老
日期:2005-02-28 12:57:00咸鸭蛋
日期:2013-02-07 11:51:42咸鸭蛋
日期:2013-02-08 09:48:51蜘蛛蛋
日期:2013-02-21 15:47:392013年新春福章
日期:2013-02-25 14:51:24咸鸭蛋
日期:2013-02-28 17:08:42蜘蛛蛋
日期:2013-03-29 16:17:14双黄蛋
日期:2013-04-11 16:11:04咸鸭蛋
日期:2013-05-07 11:55:14咸鸭蛋
日期:2013-05-28 10:46:24
17#
发表于 2011-11-9 08:59 | 只看该作者
InnoDB是没有Heap表的,只有索引!!

使用道具 举报

回复
论坛徽章:
52
2015年新春福章
日期:2015-03-06 11:57:312012新春纪念徽章
日期:2012-02-13 15:12:252012新春纪念徽章
日期:2012-02-13 15:12:25生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:33:22生肖徽章2007版:龙
日期:2012-02-07 10:32:552012新春纪念徽章
日期:2012-02-07 09:59:35
18#
发表于 2011-11-9 09:59 | 只看该作者
icer_repls 发表于 2011-11-8 21:33
你好,对于第三点:
除了创建一个6字节的字段外,那么这个表的数据的组织形式是怎么样的呢?  是不是普通 ...

兄弟,索引组织表,肯定是有序的,创建了一个6个字节隐形字段,也会按这个字段的顺序排序的...

使用道具 举报

回复
论坛徽章:
11
鲜花蛋
日期:2011-09-03 18:52:38鲜花蛋
日期:2011-11-09 10:10:12茶鸡蛋
日期:2011-11-19 22:46:41茶鸡蛋
日期:2011-12-14 15:16:572012新春纪念徽章
日期:2012-01-04 11:57:56奥运会纪念徽章:赛艇
日期:2012-09-26 21:40:11ITPUB 11周年纪念徽章
日期:2012-10-09 18:16:002013年新春福章
日期:2013-02-25 14:51:24
19#
 楼主| 发表于 2011-11-9 10:08 | 只看该作者
@philip_zhong,@kerlion,@jinguanding
谢谢你们了,懂了, 在Innodb中无论怎么样表在物理存储上都是有序的。

使用道具 举报

回复
论坛徽章:
2
2013年新春福章
日期:2013-02-25 14:51:24紫蛋头
日期:2013-04-26 14:30:13
20#
发表于 2011-11-22 10:10 | 只看该作者
所以INNODB的PK尽量简短有序。一般都建议用自增ID作为PK

普通索引存储的是PK,PK越大,普通索引越大。

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表