123
返回列表 发新帖
楼主: 红叶DBA

[讨论] 关于数据库 Block 存储细节问题的讨论

[复制链接]
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
21#
发表于 2011-7-13 05:08 | 只看该作者
You're right. Thanks for the correction. I definitely read that part of Tom's and others' writing but forgot. Your test is not exactly what I want but I can prove it. Basically, I'd like to see one index entry taking one block. So I use a database with smaller block size (you can use a tablespace with smaller block size). Something like this:

create table t (x char(2000));
create index ind_t on t (x);
insert into t values ('a');
insert into t values ('b');
insert into t values ('c');
analyze index ind_t validate structure;

SQL> select lf_blks,br_blks,btree_space from index_stats;

     LF_BLKS      BR_BLKS  BTREE_SPACE
------------ ------------ ------------
           3            1        15648

delete from t;
analyze index ind_t validate structure;

SQL> select lf_blks,br_blks,btree_space from index_stats;

     LF_BLKS      BR_BLKS  BTREE_SPACE
------------ ------------ ------------
           3            1        15648

insert into t values ('d');
insert into t values ('e');
insert into t values ('f');
analyze index ind_t validate structure;

SQL> select lf_blks,br_blks,btree_space from index_stats;

     LF_BLKS      BR_BLKS  BTREE_SPACE
------------ ------------ ------------
           3            1        15648

So it still uses 3 leaf blocks.

Yong Huang

使用道具 举报

回复
论坛徽章:
4
鲜花蛋
日期:2011-07-21 16:06:54双黄蛋
日期:2011-09-02 20:36:17ITPUB十周年纪念徽章
日期:2011-11-01 16:26:29奥运会纪念徽章:射箭
日期:2012-07-26 19:04:19
22#
发表于 2011-7-13 09:11 | 只看该作者

回复 #21 Yong Huang 的帖子

hi,Yong Huang

      Your test is very clear,and can directly prove it...

      and I found an interesting phenomenon in it,when i did a little changing.


...created a tablespace with blocksize 4k...

SQL> create table t (x char(2000));

表已创建。

SQL> create index ind_t on t (x);

索引已创建。

SQL> insert into t values ('a');

已创建 1 行。

SQL> insert into t values ('b');

已创建 1 行。

SQL> insert into t values ('c');

已创建 1 行。

SQL> analyze index ind_t validate structure;

索引已分析

SQL> select lf_blks,br_blks,btree_space from index_stats;

   LF_BLKS    BR_BLKS BTREE_SPACE
---------- ---------- -----------
         3          1       15648

SQL> delete from t;

已删除3行。

SQL> select lf_blks,br_blks,btree_space from index_stats;

   LF_BLKS    BR_BLKS BTREE_SPACE
---------- ---------- -----------
         3          1       15648

                                                                                                    ——>I did not do analyzing at this point
                                                                                                    ——>so the space in the leaf block can not be reused in the same transaction.

SQL> insert into t values ('d');

已创建 1 行。

SQL> insert into t values ('e');

已创建 1 行。

SQL> insert into t values ('f');

已创建 1 行。

SQL> analyze index ind_t validate structure;

索引已分析

SQL> select lf_blks,br_blks,btree_space from index_stats;

   LF_BLKS    BR_BLKS BTREE_SPACE
---------- ---------- -----------
         6          1       27360                                               ——>the num of leaf block is 6,it directly proves the space in the leaf block is not reused.




                 freas
                 junior

使用道具 举报

回复
论坛徽章:
0
23#
发表于 2011-7-13 10:58 | 只看该作者
新人报道,学习一下

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
24#
发表于 2011-7-14 03:46 | 只看该作者
原帖由 freas 于 2011-7-12 19:11 发表
...

SQL> select lf_blks,br_blks,btree_space from index_stats;

   LF_BLKS    BR_BLKS BTREE_SPACE
---------- ---------- -----------
         6          1       27360                                               ——>the num of leaf block is 6,it directly proves the space in the leaf block is not reused.


I noticed that (but I didn't post it here yesterday). If the transaction is not committed, the space will be preserved by the current transaction in case of rollback. That's not unique to index blocks. Table blocks should behave like that too.

Analyze is a DDL which implicitly commits, although it doesn't update xxx_objects.last_ddl_time as most other DDL's do.

Yong Huang

使用道具 举报

回复

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

本版积分规则 发表回复

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