---
title: "oracle多条件外连接执行计划"
author: "mzhj"
date: "2012-03-27T10:33:40Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2012-03-27T10:33:40Z"
id: 1464773
url: "https://mzhj.iteye.com/blog/1464773"
---

（1）
select host.id from itr_host_v host left join itr_ci_ref r on host.id = r .to_ci
                                                   and r.from_template_id =
                                                       '0301010101' ;



 （2）                                                      
select host.id   from itr_host_v   host, itr_ci_ref r  where   host.id = r. to_ci(+)
                                                   and  r.from_template_id(+) =
                                                       '0301010101';
                                                    
（3）
select host.id   from itr_host_v   host, itr_ci_ref r  where   host.id = r. to_ci(+)
                                                   and  r.from_template_id =
                                                       '0301010101';

（4）select host.id from itr_host_v host left join itr_ci_ref r on host.id = r .to_ci
                                                  where r.from_template_id =
                                                       '0301010101' ;

上面三条sql，1==2，不等于3。3==4;1是多条件的左外连接。4是单条件左外连接。

（1）、（2)的执行计划为
     
![](http://dl.iteye.com/upload/attachment/0065/5166/310c3356-98d4-363a-adf9-af15712ccf02.jpg)
   

（3）的执行计划为

![](http://dl.iteye.com/upload/attachment/0065/5168/2625d8ca-54fe-35f3-b0ae-85544e78ca57.jpg)

可以看到，3的sql里面，左外连接的条件失效了，这是因为条件里面多了一个 r.from_template_id = '0301010101';，字段r.from_template_id为被外连接的条件，必须要加上（+）才能使前面左外连接有效，否则，查看执行计划，就成了普通的内连接。有多个连接条件，必须全部加上(+).