日期:2014-05-16  浏览次数:20485 次

not exists和not in的对比

第一次意义上的sql优化,得瑟一下,虽然只是对sql的改写而已,但中间涉及到not in, or 和ort exist ,union, union all 和null值的处理。还是做下笔记。

?

EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False。

NOT EXISTS 的作用与 EXISTS 正相反。如果子查询没有返回行,则满足 NOT EXISTS 中的 WHERE 子句

?

起因是巡检的时候发现cpu使用很高,就检查了cpu的top 10

?

System: xxxx ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Mon Apr 14 09:52:25 2014

Load averages: 2.22, 2.56, 2.75

1055 processes: 918 sleeping, 108 running, 29 zombies?

Cpu states: (avg)

?LOAD ? USER ? NICE ? ?SYS ? IDLE ?BLOCK ?SWAIT ? INTR ? SSYS

?2.22 ?16.1% ? 5.3% ?77.7% ? 0.9% ? 0.0% ? 0.0% ? 0.0% ? 0.0%

?

System Page Size: 4Kbytes

Memory: 31740652K (7913112K) real, 35398200K (9552472K) virtual, 8472480K free ?Page# 1/82 ?

?

CPU TTY ?PID USERNAME PRI NI ? SIZE ? ?RES STATE ? ?TIME %WCPU ?%CPU COMMAND

28 ? ? 28996 oracle ? 178 22 50750M ? 118M run ? ? 44:46 176.38 176.07 oracleods1

24 ? ? 22336 oracle ? 178 20 50640M ?8496K run ? ?277:45 171.64 171.34 oracleods1

16 ? ? ?8200 oracle ? 178 20 50637M ?5636K run ? ? ?0:29 125.10 98.55 oracleods1?

?2 ? ? ?8427 oracle ? 178 20 50637M ?5636K run ? ? ?0:12 102.05 53.84 oracleods1

?4 ? ? ?9004 oracle ? 178 20 50640M ?8900K sleep 9886:22 49.43 49.35 oracleods1?

?4 ? ? ?9385 oracle ? 178 20 50645M ?9128K sleep ? ?0:47 44.09 44.02 oracleods1

16 ? ? ?8442 oracle ? 178 20 50637M ?5632K sleep ? ?0:08 83.33 41.95 oracleods1?

?1 ? ? ?8436 oracle ? 178 20 50637M ?5632K sleep ? ?0:08 82.80 41.68 oracleods1?

?1 ? ? ?8446 oracle ? 178 20 50637M ?5632K sleep ? ?0:09 85.73 40.98 oracleods1

13 ? ? ?8407 oracle ? 178 20 ? 248M ?5180K run ? ? ?0:12 67.42 40.01 oracleods1

26 ? ? ?8449 oracle ? 178 20 50637M ?5624K sleep ? ?0:08 92.36 39.07 oracleods1

29 ? ? ?8490 oracle ? 178 20 ? 248M ?5180K run ? ? ?0:07 102.37 33.75 oracleods1

?

?

SQL> select sql_id, prev_sql_id, s.username, status,logon_time from v$session s , v$process p where s.paddr = p.addr and spid = 28996;

?

SQL_ID ? ? ? ?PREV_SQL_ID ? USERNAME ? ? ? ? ? ? ? ? ? ? ? STATUS ? LOGON_TIME

------------- ------------- ------------------------------ -------- ------------

gpffra78um5zh 08p8kbs837tdp xxx ? ? ? ? ? ? ? ? ? ? ? ? ACTIVE ? 14-APR-14

?

?

NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? VALUE_STRING

------------------------------------------------------------ --------------------

:B1