INSERT INTO F_PTY_INDIV
(PTY_ID,
PTY_NAME,
GENDER_CD,
BIRTHDAY,
CERT_TYPE,
CERT_NO,
SOCINSUR_NO,
COUNTRY_CD,
NATION,
POLITICS_CD,
MARRIAGE_STAT,
FAMILY_ADDR,
FAMILYZIP,
EMAILADD,
HOME_PHONE,
SPU_MOBILE,
UNITKIND,
CUST_NAME,
COMPANY_ADDR,
COMPANY_TEL,
VOCATION_CD,
TITLE_CD,
TOPEDU_CD,
TOP_DEGREE_CD,
FINANCE_OR_NOT,
OWNBANK_FLAG,
INPUT_ORG,
INPUTUSERID,
UPDATE_DATE,
ADDRESS,
COMMZIP,
NATIVEADD,
WORKZIP,
DUTY_CD,
WORKBEGINDATE,
LIVESTAT_CD,
FARMERFLAG2,
CORP_BUS_CLASS,
RELATIVEFLAG,
COUNTRYCODE,
REGION,
CORP_ORG,
CERT_PUT_DATE,
CERT_END_DATE,
SOURCE_CODE,
START_DT,
END_DT,
DW_DATA_DT)
SELECT PTY_ID,
PTY_NAME,
GENDER_CD,
BIRTHDAY,
CERT_TYPE,
CERT_NO,
SOCINSUR_NO,
COUNTRY_CD,
NATION,
POLITICS_CD,
MARRIAGE_STAT,
FAMILY_ADDR,
FAMILYZIP,
EMAILADD,
HOME_PHONE,
SPU_MOBILE,
UNITKIND,
CUST_NAME,
COMPANY_ADDR,
COMPANY_TEL,
VOCATION_CD,
TITLE_CD,
TOPEDU_CD,
TOP_DEGREE_CD,
FINANCE_OR_NOT,
OWNBANK_FLAG,
INPUT_ORG,
INPUTUSERID,
UPDATE_DATE,
ADDRESS,
COMMZIP,
NATIVEADD,
WORKZIP,
DUTY_CD,
WORKBEGINDATE,
LIVESTAT_CD,
FARMERFLAG2,
CORP_BUS_CLASS,
RELATIVEFLAG,
COUNTRYCODE,
REGION,
CORP_ORG,
CERT_PUT_DATE,
CERT_END_DATE,
SOURCE_CODE,
START_DT,
END_DT,
DW_DATA_DT
FROM F_PTY_INDIV_TMP O
WHERE EXISTS
(SELECT 1
FROM F_PTY_INDIV F
WHERE O.PTY_ID = F.PTY_ID
AND O.CORP_ORG = F.CORP_ORG
AND O.SOURCE_CODE = F.SOURCE_CODE)
AND O.PTY_NAME || O.GENDER_CD || O.BIRTHDAY || O.CERT_TYPE ||
O.CERT_NO || O.SOCINSUR_NO || O.COUNTRY_CD || O.NATION ||
O.POLITICS_CD || O.MARRIAGE_STAT || O.FAMILY_ADDR || O.CUST_NAME ||
O.VOCATION_CD || O.TITLE_CD || O.TOPEDU_CD || O.TOP_DEGREE_CD ||
O.FINANCE_OR_NOT || O.OWNBANK_FLAG || O.INPUT_ORG || O.ADDRESS ||
O.DUTY_CD || O.LIVESTAT_CD || O.FARMERFLAG2 || O.CORP_BUS_CLASS ||
O.RELATIVEFLAG || O.COUNTRYCODE || O.REGION || O.CERT_PUT_DATE ||
O.CERT_END_DATE NOT IN
(SELECT PTY_NAME || GENDER_CD || BIRTHDAY || CERT_TYPE || CERT_NO ||
SOCINSUR_NO || COUNTRY_CD || NATION || POLITICS_CD ||
MARRIAGE_STAT || FAMILY_ADDR || CUST_NAME || VOCATION_CD ||
TITLE_CD || TOPEDU_CD || TOP_DEGREE_CD || FINANCE_OR_NOT ||
OWNBANK_FLAG || INPUT_ORG || ADDRESS || DUTY_CD ||
LIVESTAT_CD || FARMERFLAG2 || CORP_BUS_CLASS ||
RELATIVEFLAG || COUNTRYCODE || REGION || CERT_PUT_DATE ||
CERT_END_DATE
FROM F_PTY_INDIV
WHERE END_DT = TO_DATE('29991231', 'YYYY-MM-DD')
AND O.PTY_ID = PTY_ID
AND O.CORP_ORG = CORP_ORG
AND O.SOURCE_CODE = SOURCE_CODE) SQL> select * from table(dbms_xplan.display()); PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2391619437 -------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 1 | 244 | | 8587 (1)| 00:01:44 |
|* 1 | FILTER | | | | | | |
|* 2 | HASH JOIN RIGHT SEMI| | 1 | 244 | 16M| 5905 (1)| 00:01:11 |
| 3 | TABLE ACCESS FULL | F_PTY_INDIV | 451K| 11M| | 2645 (1)| 00:00:32 |
| 4 | TABLE ACCESS FULL | F_PTY_INDIV_TMP | 131K| 27M| | 1000 (2)| 00:00:12 |
|* 5 | TABLE ACCESS FULL | F_PTY_INDIV | 1 | 142 | | 2681 (2)| 00:00:33 |
------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "F_PTY_INDIV" "F_PTY_INDIV" WHERE
"PTY_ID"=:B1 AND "CORP_ORG"=:B2 AND "SOURCE_CODE"=:B3 AND
"END_DT"=TO_DATE('29991231','YYYY-MM-DD') AND
LNNVL(:B4||:B5||:B6||:B7||:B8||:B9||:B10||:B11||:B12||:B13||:B14||:B15||:B16||:B17||:B18|
|:B19||:B20||:B21||:B22||:B23||:B24||:B25||:B26||:B27||:B28||:B29||:B30||:B31||:B32<>"PTY
_NAME"||"GENDER_CD"||INTERNAL_FUNCTION("BIRTHDAY")||"CERT_TYPE"||"CERT_NO"||"SOCINSUR_NO"
||"COUNTRY_CD"||"NATION"||"POLITICS_CD"||"MARRIAGE_STAT"||"FAMILY_ADDR"||"CUST_NAME"||"VO
CATION_CD"||"TITLE_CD"||"TOPEDU_CD"||"TOP_DEGREE_CD"||"FINANCE_OR_NOT"||"OWNBANK_FLAG"||"
INPUT_ORG"||"ADDRESS"||"DUTY_CD"||"LIVESTAT_CD"||"FARMERFLAG2"||"CORP_BUS_CLASS"||"RELATI
VEFLAG"||"COUNTRYCODE"||"REGION"||"CERT_PUT_DATE"||"CERT_END_DATE")))
2 - access("O"."PTY_ID"="F"."PTY_ID" AND "O"."CORP_ORG"="F"."CORP_ORG" AND
"O"."SOURCE_CODE"="F"."SOURCE_CODE")
5 - filter("PTY_ID"=:B1 AND "CORP_ORG"=:B2 AND "SOURCE_CODE"=:B3 AND
"END_DT"=TO_DATE('29991231','YYYY-MM-DD') AND
LNNVL(:B4||:B5||:B6||:B7||:B8||:B9||:B10||:B11||:B12||:B13||:B14||:B15||:B16||:B17||:B18|
|:B19||:B20||:B21||:B22||:B23||:B24||:B25||:B26||:B27||:B28||:B29||:B30||:B31||:B32<>"PTY
_NAME"||"GENDER_CD"||INTERNAL_FUNCTION("BIRTHDAY")||"CERT_TYPE"||"CERT_NO"||"SOCINSUR_NO"
||"COUNTRY_CD"||"NATION"||"POLITICS_CD"||"MARRIAGE_STAT"||"FAMILY_ADDR"||"CUST_NAME"||"VO
CATION_CD"||"TITLE_CD"||"TOPEDU_CD"||"TOP_DEGREE_CD"||"FINANCE_OR_NOT"||"OWNBANK_FLAG"||"
INPUT_ORG"||"ADDRESS"||"DUTY_CD"||"LIVESTAT_CD"||"FARMERFLAG2"||"CORP_BUS_CLASS"||"RELATI
VEFLAG"||"COUNTRYCODE"||"REGION"||"CERT_PUT_DATE"||"CERT_END_DATE")) 37 rows selected. 改写成exists后;
SELECT PTY_ID,
PTY_NAME,
GENDER_CD,
BIRTHDAY,
CERT_TYPE,
CERT_NO,
SOCINSUR_NO,
COUNTRY_CD,
NATION,
POLITICS_CD,
MARRIAGE_STAT,
FAMILY_ADDR,
FAMILYZIP,
EMAILADD,
HOME_PHONE,
SPU_MOBILE,
UNITKIND,
CUST_NAME,
COMPANY_ADDR,
COMPANY_TEL,
VOCATION_CD,
TITLE_CD,
TOPEDU_CD,
TOP_DEGREE_CD,
FINANCE_OR_NOT,
OWNBANK_FLAG,
INPUT_ORG,
INPUTUSERID,
UPDATE_DATE,
ADDRESS,
COMMZIP,
NATIVEADD,
WORKZIP,
DUTY_CD,
WORKBEGINDATE,
LIVESTAT_CD,
FARMERFLAG2,
CORP_BUS_CLASS,
RELATIVEFLAG,
COUNTRYCODE,
REGION,
CORP_ORG,
CERT_PUT_DATE,
CERT_END_DATE,
SOURCE_CODE,
START_DT,
END_DT,
DW_DATA_DT
FROM F_PTY_INDIV_TMP O
WHERE EXISTS (SELECT 1
FROM F_PTY_INDIV F
WHERE O.PTY_ID = F.PTY_ID
AND O.CORP_ORG = F.CORP_ORG
AND O.SOURCE_CODE = F.SOURCE_CODE)
AND NOT EXISTS
(SELECT null
FROM F_PTY_INDIV
WHERE O.PTY_NAME || O.GENDER_CD || O.BIRTHDAY || O.CERT_TYPE ||
O.CERT_NO || O.SOCINSUR_NO || O.COUNTRY_CD || O.NATION ||
O.POLITICS_CD || O.MARRIAGE_STAT || O.FAMILY_ADDR ||
O.CUST_NAME || O.VOCATION_CD || O.TITLE_CD || O.TOPEDU_CD ||
O.TOP_DEGREE_CD || O.FINANCE_OR_NOT || O.OWNBANK_FLAG ||
O.INPUT_ORG || O.ADDRESS || O.DUTY_CD || O.LIVESTAT_CD ||
O.FARMERFLAG2 || O.CORP_BUS_CLASS || O.RELATIVEFLAG ||
O.COUNTRYCODE || O.REGION || O.CERT_PUT_DATE ||
O.CERT_END_DATE =
PTY_NAME || GENDER_CD || BIRTHDAY || CERT_TYPE || CERT_NO ||
SOCINSUR_NO || COUNTRY_CD || NATION || POLITICS_CD ||
MARRIAGE_STAT || FAMILY_ADDR || CUST_NAME || VOCATION_CD ||
TITLE_CD || TOPEDU_CD || TOP_DEGREE_CD || FINANCE_OR_NOT ||
OWNBANK_FLAG || INPUT_ORG || ADDRESS || DUTY_CD ||
LIVESTAT_CD || FARMERFLAG2 || CORP_BUS_CLASS || RELATIVEFLAG ||
COUNTRYCODE || REGION || CERT_PUT_DATE || CERT_END_DATE
and END_DT = TO_DATE('29991231', 'YYYY-MM-DD'))
AND O.PTY_ID = PTY_ID
AND O.CORP_ORG = CORP_ORG
AND O.SOURCE_CODE = SOURCE_CODE)
子查询还是无法展开 改写成关联;
SELECT o.PTY_ID,
o.PTY_NAME,
o.GENDER_CD,
o.BIRTHDAY,
o.CERT_TYPE,
o.CERT_NO,
o.SOCINSUR_NO,
o.COUNTRY_CD,
o.NATION,
o.POLITICS_CD,
o.MARRIAGE_STAT,
o.FAMILY_ADDR,
o.FAMILYZIP,
o.EMAILADD,
o.HOME_PHONE,
o.SPU_MOBILE,
o.UNITKIND,
o.CUST_NAME,
o.COMPANY_ADDR,
o.COMPANY_TEL,
o.VOCATION_CD,
o.TITLE_CD,
o.TOPEDU_CD,
o.TOP_DEGREE_CD,
o.FINANCE_OR_NOT,
o.OWNBANK_FLAG,
o.INPUT_ORG,
o.INPUTUSERID,
o.UPDATE_DATE,
o.ADDRESS,
o.COMMZIP,
o.NATIVEADD,
o.WORKZIP,
o.DUTY_CD,
o.WORKBEGINDATE,
o.LIVESTAT_CD,
o.FARMERFLAG2,
o.CORP_BUS_CLASS,
o.RELATIVEFLAG,
o.COUNTRYCODE,
o.REGION,
o.CORP_ORG,
o.CERT_PUT_DATE,
o.CERT_END_DATE,
o.SOURCE_CODE,
o.START_DT,
o.END_DT,
o.DW_DATA_DT
FROM F_PTY_INDIV_TMP O,
(SELECT *
FROM F_PTY_INDIV F
WHERE END_DT = TO_DATE('29991231', 'YYYY-MM-DD')) F
where O.PTY_ID = F.PTY_ID
AND O.CORP_ORG = F.CORP_ORG
AND O.SOURCE_CODE = F.SOURCE_CODE
AND O.PTY_NAME || O.GENDER_CD || O.BIRTHDAY || O.CERT_TYPE || O.CERT_NO ||
O.SOCINSUR_NO || O.COUNTRY_CD || O.NATION || O.POLITICS_CD ||
O.MARRIAGE_STAT || O.FAMILY_ADDR || O.CUST_NAME || O.VOCATION_CD ||
O.TITLE_CD || O.TOPEDU_CD || O.TOP_DEGREE_CD || O.FINANCE_OR_NOT ||
O.OWNBANK_FLAG || O.INPUT_ORG || O.ADDRESS || O.DUTY_CD ||
O.LIVESTAT_CD || O.FARMERFLAG2 || O.CORP_BUS_CLASS || O.RELATIVEFLAG ||
O.COUNTRYCODE || O.REGION || O.CERT_PUT_DATE || O.CERT_END_DATE <>
F.PTY_NAME || F.GENDER_CD || F.BIRTHDAY || F.CERT_TYPE || F.CERT_NO ||
F.SOCINSUR_NO || F.COUNTRY_CD || F.NATION || F.POLITICS_CD ||
F.MARRIAGE_STAT || F.FAMILY_ADDR || F.CUST_NAME || F.VOCATION_CD ||
F.TITLE_CD || F.TOPEDU_CD || F.TOP_DEGREE_CD || F.FINANCE_OR_NOT ||
F.OWNBANK_FLAG || F.INPUT_ORG || F.ADDRESS || F.DUTY_CD ||
F.LIVESTAT_CD || F.FARMERFLAG2 || F.CORP_BUS_CLASS || F.RELATIVEFLAG ||
F.COUNTRYCODE || F.REGION || F.CERT_PUT_DATE || F.CERT_END_DATE;
SQL> select * from table(dbms_xplan.display()); PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2193563055 --------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 13 | 4667 | 3696 (3)| 00:00:45 |
|* 1 | HASH JOIN | | 13 | 4667 | 3696 (3)| 00:00:45 |
|* 2 | TABLE ACCESS FULL| F_PTY_INDIV | 871 | 120K| 2695 (3)| 00:00:33 |
| 3 | TABLE ACCESS FULL| F_PTY_INDIV_TMP | 131K| 27M| 1000 (2)| 00:00:12 |
-------------------------------------------------------------------------------------- Predicate Information (identified by operation id):
--------------------------------------------------- 1 - access("O"."PTY_ID"="F"."PTY_ID" AND "O"."CORP_ORG"="F"."CORP_ORG" AND
"O"."SOURCE_CODE"="F"."SOURCE_CODE")
filter("O"."PTY_NAME"||"O"."GENDER_CD"||INTERNAL_FUNCTION("O"."BIRTHDAY
")||"O"."CERT_TYPE"||"O"."CERT_NO"||"O"."SOCINSUR_NO"||"O"."COUNTRY_CD"||"O"."
NATION"||"O"."POLITICS_CD"||"O"."MARRIAGE_STAT"||"O"."FAMILY_ADDR"||"O"."CUST_
NAME"||"O"."VOCATION_CD"||"O"."TITLE_CD"||"O"."TOPEDU_CD"||"O"."TOP_DEGREE_CD"
||"O"."FINANCE_OR_NOT"||"O"."OWNBANK_FLAG"||"O"."INPUT_ORG"||"O"."ADDRESS"||"O
"."DUTY_CD"||"O"."LIVESTAT_CD"||"O"."FARMERFLAG2"||"O"."CORP_BUS_CLASS"||"O"."
RELATIVEFLAG"||"O"."COUNTRYCODE"||"O"."REGION"||"O"."CERT_PUT_DATE"||"O"."CERT
_END_DATE"<>"F"."PTY_NAME"||"F"."GENDER_CD"||INTERNAL_FUNCTION("F"."BIRTHDAY")
||"F"."CERT_TYPE"||"F"."CERT_NO"||"F"."SOCINSUR_NO"||"F"."COUNTRY_CD"||"F"."NA
TION"||"F"."POLITICS_CD"||"F"."MARRIAGE_STAT"||"F"."FAMILY_ADDR"||"F"."CUST_NA
ME"||"F"."VOCATION_CD"||"F"."TITLE_CD"||"F"."TOPEDU_CD"||"F"."TOP_DEGREE_CD"||
"F"."FINANCE_OR_NOT"||"F"."OWNBANK_FLAG"||"F"."INPUT_ORG"||"F"."ADDRESS"||"F".
"DUTY_CD"||"F"."LIVESTAT_CD"||"F"."FARMERFLAG2"||"F"."CORP_BUS_CLASS"||"F"."RE
LATIVEFLAG"||"F"."COUNTRYCODE"||"F"."REGION"||"F"."CERT_PUT_DATE"||"F"."CERT_E
ND_DATE")
2 - filter("END_DT"=TO_DATE('29991231','YYYY-MM-DD')) 32 rows selected. 优化到此结束。

NOT EXISTS优化的更多相关文章

  1. NOT EXISTS优化的一个案例 .

    原始语句: SELECT * FROM dcf_account.t_posting_transaction t1 WHERE NOT EXISTS ( SELECT * FROM dcf_loan.t ...

  2. SQL语句优化 -- 以Mysql为例

     本文参考下面的文章:    1: [真·干货]MySQL 索引及优化实战 2:  Mysql语句的执行过程 3:  sql优化的几种方法 我将  sql语句优化分为三个方面,(此处不包括 业务逻辑的 ...

  3. MySQL之查询性能优化(三)

    MySQL查询优化器的局限性 MySQL的万能“嵌套循环”并不是对每种查询都是最优的.不过还好,MySQL查询优化只对少部分查询不适用,而且我们往往可以通过改写查询让MySQL高效地完成工作. 关联子 ...

  4. oracle查询优化之子查询条件优化

    环境:oracle 11g 现有a表与b表通过a01字段关联,要查询出a表的数据在b表没有数据的数据:sql如下 ) ) 因为flag是虚拟字段没有走不了索引导致这条sql执行起来特别慢 310W条数 ...

  5. 工作中遇到的99%SQL优化,这里都能给你解决方案(三)

    -- 示例表 CREATE TABLE `employees` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(24) NOT NULL ...

  6. MySQL高级学习笔记(四):索引优化分析

    文章目录 性能下降 SQL慢 执行时间长 等待时间长 查询语句写的烂 查询数据过多 关联了太多的表,太多join 没有利用到索引 单值 复合 服务器调优及各个参数设置(缓冲.线程数等)(不重要DBA的 ...

  7. SQL优化(三)—— 索引、explain分析

    SQL优化(三)—— 索引.explain分析   一.什么是索引 索引是一种排好序的快速查找的数据结构,它帮助数据库高效的查询数据 在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据 ...

  8. MySQL索引优化深入

    创建 test 测试表 CREATE TABLE `test` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `c1` varchar(10) DEFAULT N ...

  9. MySQL之SQL语句优化

    语句优化 即优化器利用自身的优化器来对我们写的SQL进行优化,然后再将其放入InnoDB引擎中执行. 条件简化 移除不必要的括号 select * from x where ((a = 5)); 上面 ...

随机推荐

  1. 程序员带你十天快速入门Python,玩转电脑软件开发(二)

    关注今日头条-做全栈攻城狮,学代码也要读书,爱全栈,更爱生活.提供程序员技术及生活指导干货. 如果你真想学习,请评论学过的每篇文章,记录学习的痕迹. 请把所有教程文章中所提及的代码,最少敲写三遍,达到 ...

  2. 学习java随笔第十篇:java线程

    线程生命周期 线程的生命周期:新建状态.准备状态.运行状态.等待/阻塞状态.死亡状态 示意图: 定义.创建及运行线程 线程: package threadrun; //定义一个实现Runnable接口 ...

  3. xml处理相关文章收藏

    XPath语法 在C#中使用XPath示例:http://blog.csdn.net/yukaizhao/article/details/6630613 .Net那点事儿系列:C#操作Xml:通过Xm ...

  4. ios专题 -动画

    知识点 : 1)ios 核心动画的基础是图层.图层的基础是CALayer,它是所有核心图层类的父类. 2)CATransaction是核心动画类负责协调多个动画原子显示更新.事务支持嵌套使用. 3)图 ...

  5. 最小生成树之 prim算法和kruskal算法(以 hdu 1863为例)

    最小生成树的性质 MST性质:设G = (V,E)是连通带权图,U是V的真子集.如果(u,v)∈E,且u∈U,v∈V-U,且在所有这样的边中, (u,v)的权c[u][v]最小,那么一定存在G的一棵最 ...

  6. Memcached认知[分布式]

    Memcached是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载. Memcached的服务器客户端通信使用简单的基于文本行的协议. Memcached基于一个存储键/值对的 ...

  7. codeblocks调试(转载)

    单步调试  1)设置断点  在需要设置断点处,右击左边行号,Add breakpoint,则出现一个红色的点(可以同时设置多个,前提是不能在debug的运行模式下). 2)调试运行 Debug-> ...

  8. 滑动开关效果 css3滑动开关】纯CSS3代码实现滑动开关效果-css3滑动效果-css3左右滑动

    今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动效果. 今天看到一篇有关 css3事件的博文,一时兴起便整理下相关的资料. 点击按钮,可以实现开关的滑动 ...

  9. 中文版Chrome浏览器不支持12px以下字体的解决方案

    中文版Chrome浏览器不支持12px以下字体的解决方案 Chrome 27之前的中文版桌面浏览器会默认设定页面的最小字号是12px,英文版则没有限制,主要是因为chrome认为汉字小于12px就会增 ...

  10. PHP设计模式之:装饰模式

    <?php// 人类class Person{    private $name;    public function __construct($name)    {        $this ...