
oracle 11g sql优化之行迁移处理(加大BLOCK块)
发布日期:2021-05-09 03:08:00
浏览次数:19
分类:博客文章
本文共 3141 字,大约阅读时间需要 10 分钟。
行链接产生原因:当一行数据大于一个数据块,ORACLE会同时分配两个数据块,并在第一个块上登记第二个块的地址,从而形成行链接。
预防方法:针对表空间扩大数据块大小。
检查:analyze table 表名 validate structure cascade into chained_rows;
--- PCTFREE试验准备之建表
DROP TABLE EMPLOYEES PURGE;CREATE TABLE EMPLOYEES AS SELECT * FROM HR.EMPLOYEES ;desc EMPLOYEES;create index idx_emp_id on employees(employee_id); --- PCTFREE试验准备之扩大字段alter table EMPLOYEES modify FIRST_NAME VARCHAR2(2000);alter table EMPLOYEES modify LAST_NAME VARCHAR2(2000);alter table EMPLOYEES modify EMAIL VARCHAR2(2000);alter table EMPLOYEES modify PHONE_NUMBER VARCHAR2(2000);--- PCTFREE试验准备之更新表
UPDATE EMPLOYEES SET FIRST_NAME = LPAD('1', 2000, '*'), LAST_NAME = LPAD('1', 2000, '*'), EMAIL = LPAD('1', 2000, '*'), PHONE_NUMBER = LPAD('1', 2000, '*');COMMIT; ---行链接移优化前,先看看该语句逻辑读情况SET AUTOTRACE traceonly set linesize 1000select /*+index(EMPLOYEES,idx_emp_id)*/ * from EMPLOYEES where employee_id>0/
set autotrace off
----- 发现存在行链接的方法
--首先建chaind_rows相关表,这是必需的步骤--sqlplus "/ as sysdba"sqlplus ljb/ljb
drop table chained_rows purge;@?/rdbms/admin/utlchain.sql----以下命令针对EMPLOYEES表和EMPLOYEES_BK做分析,将产生行迁移的记录插入到chained_rows表中analyze table EMPLOYEES list chained rows into chained_rows;select count(*) from chained_rows where table_name='EMPLOYEES';---用消除行迁移的方法根本无法消除行链接!!!
drop table EMPLOYEES_TMP;
create table EMPLOYEES_TMP as select * from EMPLOYEES where rowid in (select head_rowid from chained_rows);Delete from EMPLOYEES where rowid in (select head_rowid from chained_rows);Insert into EMPLOYEES select * from EMPLOYEES_TMP;delete from chained_rows ;commit;--发现用消除行迁移的方法根本无法消除行链接!analyze table EMPLOYEES list chained rows into chained_rows;select count(*) from chained_rows where table_name='EMPLOYEES';SET AUTOTRACE traceonly
set linesize 1000select /*+index(EMPLOYEES,idx_emp_id)*/ * from EMPLOYEES where employee_id>0/
---------------------------------------------------------------------------------
---启动大小为16K的块新建表空间(WINDOWS下只能使用2K,4K,8K和16K)
--行链接只有通过加大BLOCK块的方式才可以避免,如下:alter system set db_16k_cache_size=50m scope=spfile; --由于我的是RAC,且节点2关闭,不能直接scope=both,还有就是设置的50m是根据表的总的数据量和热数据设置的,具体生产情况,需要酌情设置。shutdown immediate;
startup;
show parameter db_
DROP TABLE EMPLOYEES_BK PURGE;
CREATE TABLE EMPLOYEES_BK TABLESPACE TBS_LJB_16K AS SELECT * FROM EMPLOYEES;delete from chained_rows ;commit;analyze table EMPLOYEES_BK list chained rows into chained_rows;select count(*) from chained_rows where table_name='EMPLOYEES_BK'; ***************发现用消除行迁移的方法根本无法消除行链接************SQL> analyze table EMPLOYEES list chained rows into chained_rows;表已分析。SQL> select count(*) from chained_rows where table_name='EMPLOYEES'; COUNT(*)---------- 107 ***********行链接只有通过加大BLOCK块的方式才可以避免**********************如下:
SQL> DROP TABLE EMPLOYEES_BK PURGE;表已删除。SQL> CREATE TABLE EMPLOYEES_BK TABLESPACE TBS_LJB_16K AS SELECT * FROM EMPLOYEES; ---也可以直接用alter table table_name move tablespace TBS_LJB_16K,但是索引需要重建;表已创建。SQL> delete from chained_rows ;已删除107行。SQL> commit;提交完成。SQL> analyze table EMPLOYEES_BK list chained rows into chained_rows;表已分析。SQL> select count(*) from chained_rows where table_name='EMPLOYEES_BK'; COUNT(*)---------- 0发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2025年04月23日 17时37分30秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Python IO编程
2019-03-06
CSS入门总结
2019-03-06
使用 TortoiseGit 时,报 Access denied 错误
2019-03-06
基于 HTML5 WebGL 的污水处理厂泵站自控系统
2019-03-06
c++之程序流程控制
2019-03-06
spring-boot-2.0.3之redis缓存实现,不是你想的那样哦!
2019-03-06
有道云笔记 同步到我的博客园
2019-03-06
李笑来必读书籍整理
2019-03-06
Hadoop(十六)之使用Combiner优化MapReduce
2019-03-06
《机器学习Python实现_10_06_集成学习_boosting_gbdt分类实现》
2019-03-06
CoreCLR源码探索(八) JIT的工作原理(详解篇)
2019-03-06
C语言编译错误列表
2019-03-07
看明白这两种情况,才敢说自己懂跨链! | 喵懂区块链24期
2019-03-07
python中列表 元组 字典 集合的区别
2019-03-07
Android DEX加固方案与原理
2019-03-07
iOS_Runtime3_动态添加方法
2019-03-07
Leetcode第557题---翻转字符串中的单词
2019-03-07
Problem G. The Stones Game【取石子博弈 & 思维】
2019-03-07
Java多线程
2019-03-07