千家信息网

records_per_block参数的使用

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,1、BLOCK是数据库中的最小存储和处理单位,包含块本身的头信息数据或PL/SQL代码。RECORDS_PER_BLOCK参数用于设定每个BLOCK中记录数的最大值,其先找到当前表所有BLOCK中容纳
千家信息网最后更新 2026年11月01日records_per_block参数的使用

1、BLOCK是数据库中的最小存储和处理单位,包含块本身的头信息数据或PL/SQL代码。RECORDS_PER_BLOCK参数用于设定每个BLOCK中记录数的最大值,其先找到当前表所有BLOCK中容纳的最大行数,并会把这个数字记录到数据字典,以后任何导致BLOCK行数超过这个数字的插入都会被拒绝(插入另一个块中)。

2、不能对空表设定此参数。
3、每个BLOCK中可以包含的记录数的最低下限是2。
4、不能在已经有 bitmap 的表中使用records_per_block参数,也就是说,如果要使用records_per_block参数,必须先alter table xxx minimize records_per_block,然后才能在表上建立索引。
官方解释:

This facility improves the storage performance of bitmap indexes and has a direct
effect on query performance. The way in which bitmap indexes operate is that the
maximum possible number of records that can fit in a block is computed from the
table definition, and a bit allocated for each of these records. This calculated value
may be much larger than any actual value resulting in many unnecessary zero bits at
the end of each block having to be compressed. By detecting the actual value with the
ALTER TABLE command, bitmap storage is improved.
If the row size decreases after the minimization step, poor table storage may result, as
blocks will be restricted to the calculated maximum. The feature is aimed at static
environments, such as data warehouses.
It is not possible to minimize RECORDS_PER_BLOCK if the table has an existing
bitmap index.
The MINIMIZE RECORDS_PER_BLOCK syntax populates TAB$ with a value in the
SPARE1 column. With this syntax, the maximum number of records currently stored
in any data block is recorded. There is currently no view available to query this
column.
A table that is not minimized will have a value in TAB$.SPARE1. The value varies
depending on block size, for example, it is 178 for a 2 KB block, and 736 for an 8 KB
block.
测试过程:
1、SQL> create table test(id int,name varchar2(10));

Table created.

SQL> alter table test minimize records_per_block;
alter table test minimize records_per_block
*
ERROR at line 1:
ORA-28603: statement not permitted on empty tables

----表明不能对空表使用此参数
所以接下来,我们往表里插入点具体数:
2、
SQL> BEGIN
2 FOR I IN 1..10 LOOP
3 INSERT INTO test VALUES(1,'test'||I);
4 END LOOP;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL> select * from test;

    ID NAME     1 test1     1 test2     1 test3     1 test4     1 test5     1 test6     1 test7     1 test8     1 test9     1 test10

10 rows selected.

SQL> commit;

Commit complete.

SQL> CREATE BITMAP INDEX IDX_TEST_NAME ON TEST(NAME);

Index created.

SQL> alter table test minimize records_per_block;
alter table test minimize records_per_block
*
ERROR at line 1:
ORA-28602: statement not permitted on tables containing bitmap indexes

---表明在已经有 bitmap 的表中不能使用records_per_block参数。
SQL> drop index IDX_TEST_NAME;

Index dropped.

SQL> create index IDX_TEST_NAME ON TEST(NAME);

Index created.

SQL> alter table test minimize records_per_block;

Table altered.

----如果存在b 树索引,就没有事;普通表,没索引的,也可以使用此参数。
3、SQL> select dbms_rowid.rowid_block_number(rowid),count(*) from test group by dbms_rowid.rowid_block_number(rowid);

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)


                            1439         10

我们可以看到,10行数据,全都集中在一个Block,
这时候,我们都知道,如果没有minimize records_per_block,那么后面继续插入的数据,还会在1439号block,
但是由于我们使用了minimize records_per_block,可以观察一下,继续插入后的情况:

SQL> BEGIN
2 FOR I IN 1..10 LOOP
3 INSERT INTO test VALUES(1,'test'||I);
4 END LOOP;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL> BEGIN
2 FOR I IN 1..10 LOOP
3 INSERT INTO test VALUES(1,'test'||I);
4 END LOOP;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL> BEGIN
2 FOR I IN 1..11 LOOP
3 INSERT INTO test VALUES(1,'test'||I);
4 END LOOP;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL> select dbms_rowid.rowid_block_number(rowid),count(*) from test group by dbms_rowid.rowid_block_number(rowid);

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)


                            1436         10                            1439         10                            1435         10                            1437         10                            1438          1

这里我们可以看见,所有的已使用的block中,最多只有10条记录,
也就是使用minimize records_per_block之前的块中最大记录数,最后一次的插入,我故意插入了11条,就是为了能够看的更清楚。即使是11条,由于之前最大记录数是10条,所以一个块中最多只能存10条,另外一条数据数据存储在另一个块中,分开了。
所以records_per_block能够限定表中每个块的最大大小
4、
SQL> drop table test purge;

Table dropped.

SQL> create table test(id int,name varchar2(10));

Table created.

SQL> insert into test values(1,'aaa');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table test minimize records_per_block;

Table altered.

SQL> select dbms_rowid.rowid_block_number(rowid),count(*) from test group by dbms_rowid.rowid_block_number(rowid);

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)


                            1439          1

SQL> BEGIN
2 FOR I IN 1..10 LOOP
3 INSERT INTO test VALUES(1,'test'||I);
4 END LOOP;
5 END;
6 /

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> select dbms_rowid.rowid_block_number(rowid),count(*) from test group by dbms_rowid.rowid_block_number(rowid);

DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) COUNT(*)


                            1436          2                            1439          2                            1435          2                            1437          2                            1438          2                            1443          1

6 rows selected.

---使用records_per_block参数之前,表里只有一条数据,存储在1443块中,然后使用records_per_block参数,插入10条数据,并不是每个块中存一条数据,而是2条,所以,records_per_block最小值为2。

数据 参数 最大 索引 存储 最小 也就是 只有 数字 表里 普通 最低 清楚 接下来 下限 也就是说 代码 信息 全都 单位 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 广东猪兼强互联网科技有限公司 华服互联网科技怎么样 互联网科技活动banner 互联网和科技技术 互联网科技公司电话 广州宏创互联网科技 奇士达互联网科技 长亮科技互联网金融 互联网科技视频素材 太原新华互联网科技学校怎么样 深圳国际航运科技和互联网 常德市电业局互联网科技部 赶超互联网科技 微信多开 长沙茂晟互联网科技有限公司 梅州GM互联网络科技有限公司 工业互联网科技成果转化 南京一网一红互联网科技有限公司 萌小萌互联网科技河南有限公司 北京品多多互联网科技有限公司 保山浩联互联网科技有限公司 北京互联网科技 互联网科技的发展 深圳互联网络科技有限公司 农村开互联网科技讲堂 现代科技和互联网有关系吗 青岛科技大学互联网大赛研究生 青海科技产业互联网发展 畅思互联网科技 爱医互联网络科技 互联网科技博主张洲
0