第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

MySQL中對(duì)于not in和minus使用的優(yōu)化

標(biāo)簽:
MySQL

优化前:

?

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647select count(t.id) from test t where t.status = 1  and t.id not in (select distinct a.app_id           from test2 a           where a.type = 1            and a.rule_id in (152, 153, 154))        17:20:57 laojiu>@plan PLAN_TABLE_OUTPUT————————————————————————————————————————-Plan hash value: 684502086 —————————————————————————————-| Id | Operation      | Name       | Rows | Bytes | Cost (%CPU)| Time   |—————————————————————————————-|  0 | SELECT STATEMENT  |         |   1 |  18 |  176K (2)| 00:35:23 ||  1 | SORT AGGREGATE   |         |   1 |  18 |      |     ||* 2 |  FILTER      |         |    |    |      |     ||* 3 |  TABLE ACCESS FULL| test   | 1141 | 20538 |  845  (2)| 00:00:11 ||* 4 |  TABLE ACCESS FULL| test2 |   1 |  12 |  309  (2)| 00:00:04 |—————————————————————————————- Predicate Information (identified by operation id):—————————————————   2 – filter( NOT EXISTS (SELECT /*+ */ 0 FROM “test2″ “A” WHERE       “A”.”type”=1 AND (“A”.”RULE_ID”=152 OR “A”.”RULE_ID”=153 OR       “A”.”RULE_ID”=154) AND LNNVL(“A”.”APP_ID”<>:B1)))  3 – filter(“T”.”status”=1)  4 – filter(“A”.”type”=1 AND (“A”.”RULE_ID”=152 OR “A”.”RULE_ID”=153 OR       “A”.”RULE_ID”=154) AND LNNVL(“A”.”APP_ID”<>:B1))Statistics———————————————————-     0 recursive calls     0 db block gets  1762169 consistent gets     0 physical reads     0 redo size    519 bytes sent via SQL*Net to client    492 bytes received via SQL*Net from client     2 SQL*Net roundtrips to/from client     0 sorts (memory)     0 sorts (disk)     1 rows processed21 rows selected.

优化后:

?

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849select count(*) from( select t.id  from test t where t.status = 1 minus select distinct a.app_id  from test2 a where a.type = 1  and a.rule_id in (152, 153, 154))17:23:33 laojiu>@plan PLAN_TABLE_OUTPUT————————————————————————————————————————-Plan hash value: 631655686 ————————————————————————————————–| Id | Operation       | Name       | Rows | Bytes |TempSpc| Cost (%CPU)| Time   |————————————————————————————————–|  0 | SELECT STATEMENT   |         |   1 |    |    | 1501  (2)| 00:00:19 ||  1 | SORT AGGREGATE    |         |   1 |    |    |      |     ||  2 |  VIEW        |         | 1141 |    |    | 1501  (2)| 00:00:19 ||  3 |  MINUS       |         |    |    |    |      |     ||  4 |   SORT UNIQUE    |         | 1141 | 20538 |    |  846  (2)| 00:00:11 ||* 5 |   TABLE ACCESS FULL| test   | 1141 | 20538 |    |  845  (2)| 00:00:11 ||  6 |   SORT UNIQUE    |         | 69527 |  814K| 3632K|  654  (2)| 00:00:08 ||* 7 |   TABLE ACCESS FULL| test2 | 84140 |  986K|    |  308  (2)| 00:00:04 |————————————————————————————————– Predicate Information (identified by operation id):—————————————————   5 – filter(“T”.”status”=1)  7 – filter(“A”.”type”=1 AND (“A”.”RULE_ID”=152 OR “A”.”RULE_ID”=153 OR       “A”.”RULE_ID”=154)) 21 rows selected.Statistics———————————————————-     1 recursive calls     0 db block gets    2240 consistent gets     0 physical reads     0 redo size    516 bytes sent via SQL*Net to client    492 bytes received via SQL*Net from client     2 SQL*Net roundtrips to/from client     2 sorts (memory)     0 sorts (disk)     1 rows processed

在优化sql的时候,我们需要转变一下思路,等价的改写sql;

改写后的sql由于逻辑读得到了天翻地覆的改变,很快得到结果。

第一条sql执行计划中有一个函数,LNNVL(“A”.”APP_ID”<>:B1),lnnvl(exp)

如果exp的结果是false或者是unknown,那么lnnvl返回true;

如果exp的结果是true,返回false.

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消