(联动北方技术论坛 - Powered by Landingbj) [网际游航]1、优化器模式(联动北方技术论坛 - Powered by Landingbj) [网际游航]Oracle9i有两种优化器模式可以选择:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]• Rule-based:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]– Uses a ranking system
(联动北方技术论坛 - Powered by Landingbj) [网际游航]– Syntax- and data dictionary–driven
(联动北方技术论坛 - Powered by Landingbj) [网际游航]• Cost-based:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]– Chooses least-cost path
(联动北方技术论坛 - Powered by Landingbj) [网际游航]– Statistics-driven
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Rule-based模式满足向后兼容,而Cost-based模式中的成本大部分来自于逻辑读的次数,推荐使用Cost-based模式。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]2、固定optimizer plan(联动北方技术论坛 - Powered by Landingbj) [网际游航]1)概念
(联动北方技术论坛 - Powered by Landingbj) [网际游航]对于每一个查询,optimizer都会准备一个定义了操作执行顺序和方法的操作树(执行计划),oracle server根据这个执行计划执行语句。通过固定执行计划,可以强制应用通过一种理想的方式访问数据,并且一个稳定的执行计划可以经历数据库的变化而保持不变。固定执行计划通过创建stored outline实现,outline使用cost-based的optimizer,因为其由一系列的hints组成。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]执行计划的固定依赖于当判定一个查询是否存在stored outline时查询语句是否完全一致,与判定shared pool里一个执行计划是否可以重用时的匹配方式是一致的。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Outline��保存在outln schema中。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]2) 创建stored outline
(联动北方技术论坛 - Powered by Landingbj) [网际游航]alter session set CREATE_STORED_OUTLINES = train;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]create or replace OUTLINE co_cl_join
(联动北方技术论坛 - Powered by Landingbj) [网际游航]FOR CATEGORY train ON
(联动北方技术论坛 - Powered by Landingbj) [网际游航]select co.crs_id, ...
(联动北方技术论坛 - Powered by Landingbj) [网际游航]from courses co,classes cl
(联动北方技术论坛 - Powered by Landingbj) [网际游航]where co.crs_id = cl.crs_id;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]stored outline通过category组织,相同的sql语句可以在多个category同时��有stored outline,如果categoey没有指定,缺省是default category。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]当CREATE_STORED_OUTLINES等于true或category名时,oracle会为所有被执行的sql语句创建stored outline,也可以通过create outline手工创建。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]3) 使用stored outline
(联动北方技术论坛 - Powered by Landingbj) [网际游航]将USE_STORED_OUTLINES设置为true或category名。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]alter session set USE_STORED_OUTLINES = train;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]当为一个查询寻找stored outline时,查询语句与stored outline里的语句必须完全一致,在outline里的hints也必须在查询语句中出现。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]3、private outline(联动北方技术论坛 - Powered by Landingbj) [网际游航]Private outline是当前保存的stored outline的副本,可以被编辑而不影响正在运行的系统,一个private outline只能被当前session看到,它的数据被保存在当前被解析的schema里。,知道显示的将其公布。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]当USE_PRIVATE_OUTLINES=TRUE时,一个已有outline的sql被提交时,optimizer会检查是否存在private outline,如果不存在,optimizer就不使用optimizer编译语句,而不会去检查公布的stored outline。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]4、在sql中使用hints(联动北方技术论坛 - Powered by Landingbj) [网际游航]Create index gen_idx on customers(cust_gender);
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Select
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Cust_last_name,cust_street_address,cust_postal_code
(联动北方技术论坛 - Powered by Landingbj) [网际游航]From sh.customers where upper(gender)=’M’;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]5、EXPLAIN PLAN(联动北方技术论坛 - Powered by Landingbj) [网际游航]可以不通过tracing,需要建立plan_table表:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Sql>@oracle_home/rdbms/admin/utlxplan;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]建立explain plan:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Explain plan for select last_name from hr.emp;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]查询plan_table中的explain plan,可以直接查询,也可以通过脚本utlxplx.sql(隐藏并行查询信息)、utlxplp.sql(显示并行查询信息)查询。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]6、管理统计信息(联动北方技术论坛 - Powered by Landingbj) [网际游航]利用analyize命令���集或删除信息。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]参数:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Compute:统计精确的数据;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]Estimate:估计的统计数据。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]各类统计数据的位置:
(联动北方技术论坛 - Powered by Landingbj) [网际游航]表:dba_tables;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]索引:dba_indexes;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]列:user_tab_col_statistics;
(联动北方技术论坛 - Powered by Landingbj) [网际游航]柱状图(histogram)详细的描述了一个特定列中数据的分布情况,可以通过analyize table ... for columns... 命令创建,保存在dba_histogram/dba_tab_histograms中。
(联动北方技术论坛 - Powered by Landingbj) [网际游航]