一个sql语句的改写

--1、创建订购黑名单临时表和索引
create table mig_US_USERINFORMATIONEXT (OperType varchar2(4),UserType varchar2(4),msisdn varchar2(11),MOBILE VARCHAR2(32),UserID VARCHAR2(128)) tablespace tbs_mread_dat;
create index idx_mig_US_USERinfoext_1 on mig_US_USERINFORMATIONEXT (msisdn) tablespace tbs_mread_idx;
 
--2、生成订购黑名单数据
truncate table mig_US_USERINFORMATIONEXT;
insert into mig_US_USERINFORMATIONEXT (OperType,UserType,msisdn)
SELECT DISTINCT
       '1' AS OperType--操作类型:1=加入特殊名单,2=退出
       ,'1' AS UserType--用户类型:1=黑名单;2=灰名单
       ,b.msisdn AS UserID--手机号码
FROM US_USERINFORMATIONEXT b
WHERE b.ORDERBLANKFLAG='1';
 
--3、生成订购灰名单数据
insert into mig_US_USERINFORMATIONEXT (OperType,UserType,msisdn)
SELECT DISTINCT
       '1' AS OperType--操作类型:1=加入特殊名单,2=退出
       ,'2' AS UserType--用户类型:1=黑名单;2=灰名单
       ,g.msisdn AS UserID--手机号码
FROM CON_READ_BLACKLIST_EXT g
WHERE  g.MSISDN NOT IN (select  msisdn from mig_US_USERINFORMATIONEXT where UserType = '1');


执行到第三不hang 住了,等待事件 latch free  

查看执行计划:


Plan hash value: 1648364032
--------------------------------------------------------------------------------
| Id  | Operation                | Name                          | Rows  | Bytes
--------------------------------------------------------------------------------
|   0 | INSERT STATEMENT         |                               |       |
|   1 |  LOAD TABLE CONVENTIONAL |                               |       |
|   2 |   HASH UNIQUE            |                               |     1 |    26
|*  3 |    HASH JOIN ANTI NA     |                               |     1 |    26
|   4 |     INDEX FAST FULL SCAN | CON_READ_BLACKLIST_EXT_MSISDN |  2372K|    27
|*  5 |     TABLE ACCESS FULL    | MIG_US_USERINFORMATIONEXT     |  3297K|    44

933051 rows inserted



将语句改写:


insert into huang (OperType,UserType,msisdn)
SELECT DISTINCT
       '1' AS OperType--操作类型:1=加入特殊名单,2=退出
       ,'2' AS UserType--用户类型:1=黑名单;2=灰名单
       ,g.msisdn AS UserID--手机号码
FROM CON_READ_BLACKLIST_EXT g
WHERE  g.MSISDN  IN (
  select msisdn from CON_READ_BLACKLIST_EXT 
  minus
  select msisdn from mig_US_USERINFORMATIONEXT);
933032 rows inserted



Plan hash value: 2055671167
--------------------------------------------------------------------------------
| Id  | Operation                  | Name                          | Rows  | Byt
--------------------------------------------------------------------------------
|   0 | INSERT STATEMENT           |                               |       |
|   1 |  LOAD TABLE CONVENTIONAL   |                               |       |
|   2 |   HASH UNIQUE              |                               |     1 |
|*  3 |    HASH JOIN               |                               |  2628K|
|   4 |     VIEW                   | VW_NSO_1                      |  2372K|
|   5 |      MINUS                 |                               |       |
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
|   6 |       SORT UNIQUE          |                               |  2372K|
|   7 |        INDEX FAST FULL SCAN| CON_READ_BLACKLIST_EXT_MSISDN |  2372K|
|   8 |       SORT UNIQUE          |                               |  3297K|
|   9 |        TABLE ACCESS FULL   | MIG_US_USERINFORMATIONEXT     |  3297K|
|  10 |     INDEX FAST FULL SCAN   | CON_READ_BLACKLIST_EXT_MSISDN |  2372K|
--------------------------------------------------------------------------------





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huangliang0703

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值