文档performance tuning 第299页有段话先记录下来;

本文深入探讨SQL查询优化器在选择执行计划中连接方式时考虑的因素,包括利用unique和primary key约束进行优化,特别关注了在不同类型的连接(如内连接、外连接和子查询)下优化器的选择策略及其背后的逻辑。

--查询优化器如何选择执行计划中的连接方式?

The Query Optimizer 11-23

How the Query Optimizer Chooses Execution Plans for Joins

The query optimizer considers the following when choosing an execution plan:

--大意是说对于含有unique,primary key的列,在做表连接时会先将此类表放在表连接顺序的第一位然后再做剩余表的连接;

■The optimizer first determines whether joining two or more tables definitely results in a row source containing at most one row. The optimizer recognizes such situations based on UNIQUE and PRIMARY KEY constraints on the tables. If such a situation exists, then the optimizer places these tables first in the join order. The optimizer then optimizes the join of the remaining set of tables.

--但对于这段就不能很好理解!

■For join statements with outer join conditions, the table with the outer join operator must come after the other table in the condition in the join order. The optimizer does not consider join orders that violate this rule. Similarly, when a subquery has been converted into an antijoin or semijoin, the tables from the subquery must come after those tables in the outer query block to which they were connected or correlated. However, hash antijoins and semijoins are able to override this ordering condition in certain circumstances.


SQL> select count(1) from t1;

  COUNT(1)
----------
     72620

SQL> select count(1) from t3;

  COUNT(1)
----------
         2

SQL> select t1.status,t3.status 
  2  from t1,t3
  3  where t1.object_id(+)=t3.object_id
  4  /


Execution Plan
----------------------------------------------------------
Plan hash value: 2157823540

------------------------------------------------------------------------------------------
| Id  | Operation                    | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |           |     2 |    72 |     7   (0)| 00:00:01 |
|   1 |  NESTED LOOPS OUTER          |           |     2 |    72 |     7   (0)| 00:00:01 |
|   2 |   TABLE ACCESS FULL          | T3        |     2 |    36 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS BY INDEX ROWID| T1        |     1 |    18 |     2   (0)| 00:00:01 |
|*  4 |    INDEX RANGE SCAN          | IDX_T1_ID |     1 |       |     1   (0)| 00:00:01 |
------------------------------------------------------------------------------------------

SQL> select t1.status,t3.status 
  2  from t1,t3
  3  where t1.object_id=t3.object_id(+)
  4  /

72620 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 3402958174

------------------------------------------------------------------------------
| Id  | Operation             | Name | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |      | 79534 |  2796K|   294   (1)| 00:00:04 |
|*  1 |  HASH JOIN RIGHT OUTER|      | 79534 |  2796K|   294   (1)| 00:00:04 |
|   2 |   TABLE ACCESS FULL   | T3   |     2 |    36 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL   | T1   | 79534 |  1398K|   291   (1)| 00:00:04 |
------------------------------------------------------------------------------

--无论hash还是nl,都是T1跟在T3后面;
--换成子查询格式看看,文档意思是说子查询块要跟在外查询块,可结果确是先执行了T3再执行外查询块的T1,跟文档相反感觉;
SQL> select t1.status
  2  from t1 
  3  where     exists (select 1 from t3 where t1.object_id=t3.object_id);


Execution Plan
----------------------------------------------------------
Plan hash value: 2149433430

------------------------------------------------------------------------------------------
| Id  | Operation                    | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |           |     2 |    62 |     6  (17)| 00:00:01 |
|   1 |  NESTED LOOPS                |           |       |       |            |          |
|   2 |   NESTED LOOPS               |           |     2 |    62 |     6  (17)| 00:00:01 |
|   3 |    SORT UNIQUE               |           |     2 |    26 |     3   (0)| 00:00:01 |
|   4 |     TABLE ACCESS FULL        | T3        |     2 |    26 |     3   (0)| 00:00:01 |
|*  5 |    INDEX RANGE SCAN          | IDX_T1_ID |     1 |       |     1   (0)| 00:00:01 |
|   6 |   TABLE ACCESS BY INDEX ROWID| T1        |     1 |    18 |     2   (0)| 00:00:01 |
------------------------------------------------------------------------------------------




基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值