博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
看看这同一句sql,scan index占用的资源大了很多!!
阅读量:2426 次
发布时间:2019-05-10

本文共 4083 字,大约阅读时间需要 13 分钟。

users: 1815331行 index: inx_mobilephone inx_status pk_username

spool: 1073行 pk_username

SQL>

SQL> select spool.username, spool.sender, spool.message, spool.sid,
users.mobilephone from spool, users
where spool.username = users.username and users.status = '0'
and spool.sender!='pica' and
and users.mobilephone is not null and rownum <= 30; 2 3 4 5

no rows selected

Elapsed: 00:00:01.21

Execution Plan

----------------------------------------------------------
Plan hash value: 119197225

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

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

| Id | Operation | Name | Rows | Bytes | Cost

(%CPU)| Time |

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

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

| 0 | SELECT STATEMENT | | 30 | 66390 | 6

1 (22)| 00:00:01 |

|* 1 | COUNT STOPKEY | | | |

| |

|* 2 | HASH JOIN | | 564 | 1218K| 6

1 (22)| 00:00:01 |

|* 3 | TABLE ACCESS FULL | SPOOL | 564 | 1188K| 3

2 (0)| 00:00:01 |

|* 4 | TABLE ACCESS BY INDEX ROWID| USERS | 334K| 9148K| 1

6 (0)| 00:00:01 |

|* 5 | INDEX FULL SCAN | INDEX_MOBILEPHONE | 1967K| |

1 (0)| 00:00:01 |

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

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

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter(ROWNUM<=30)

2 - access("SPOOL"."USERNAME"="USERS"."USERNAME")
3 - filter("SPOOL"."SENDER"<>'pica' AND "SPOOL"."SENDER"<>'@pica')
4 - filter("USERS"."STATUS"='0')
5 - filter("USERS"."MOBILEPHONE" IS NOT NULL)

Note

-----
- dynamic sampling used for this statement

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
252154 consistent gets
0 physical reads
0 redo size
292 bytes sent via SQL*Net to client
235 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

发现 consistent gets : 252154 ,比较大,其中用了全表索引扫描,应该是这个导致了consistent gets很高

我下面加了hint,不用全索引扫描,性能得到大的提高!

SQL> select /*+ no_index(users,INDEX_MOBILEPHONE,INX_STATUS) */ spool.username, spool.sender, spool.message, spool.sid,

users.mobilephone from spool, users
where spool.username = users.username and users.status = '0'
and spool.sender!='pica' and
and users.mobilephone is not null and rownum <= 30;
2 3 4 5
no rows selected

Elapsed: 00:00:00.09

SQL>
SQL> set autotrace traceonly
SQL>
SQL> /

no rows selected

Elapsed: 00:00:00.04

Execution Plan

----------------------------------------------------------
Plan hash value: 2723135770

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

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

| Id | Operation | Name | Rows | Bytes | Cost (%CPU

)| Time |

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

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

| 0 | SELECT STATEMENT | | 30 | 65550 | 202 (1

)| 00:00:03 |

|* 1 | COUNT STOPKEY | | | |

| |

| 2 | NESTED LOOPS | | 564 | 1203K| 202 (1

)| 00:00:03 |

|* 3 | TABLE ACCESS FULL | SPOOL | 564 | 1188K| 4 (0

)| 00:00:01 |

|* 4 | TABLE ACCESS BY INDEX ROWID| USERS | 1 | 28 | 1 (0

)| 00:00:01 |

|* 5 | INDEX UNIQUE SCAN | PK_USERS_UN | 1 | | 1 (0

)| 00:00:01 |

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

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

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter(ROWNUM<=30)

3 - filter("SPOOL"."SENDER"<>'pica' AND "SPOOL"."SENDER"<>'@pica')
4 - filter("USERS"."MOBILEPHONE" IS NOT NULL AND "USERS"."STATUS"='0')
5 - access("SPOOL"."USERNAME"="USERS"."USERNAME")

Note

-----
- dynamic sampling used for this statement

Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2053 consistent gets
0 physical reads
0 redo size
285 bytes sent via SQL*Net to client
235 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7916042/viewspace-1002057/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7916042/viewspace-1002057/

你可能感兴趣的文章
余生,做个不焦虑的程序员!
查看>>
世界排名第 3 的滴滴裁员,开春求职必知的独角兽排行榜
查看>>
Spring Boot 中的响应式编程和 WebFlux 入门
查看>>
阿里终结裁员危机!坚决不拿 10 万阿里人祭天!
查看>>
如何从零开始两天撸一个微信小程序?!(内含源码)
查看>>
女神?御姐?文艺?这样的程序媛你绝没见过! | 程序员有话说
查看>>
“软件外包城”下的马鞍山 | 程序员有话说
查看>>
那些上相亲网站的程序员,后来怎么样了?
查看>>
程序员如何实现财富自由?
查看>>
你我的父母,都在被互联网“割韭菜”
查看>>
程序员下班后都忙些啥?| 程序员有话说
查看>>
网易不再从容
查看>>
万万没想到你们竟是这样的程序员 | 程序员有话说
查看>>
Java 帝国对 Python 的渗透能成功吗?
查看>>
从培训机构出来的程序员,后来都怎么样了? | 程序员有话说
查看>>
程序员写代码没激情该怎么破?
查看>>
我是如何从低端面畜到高端面霸的?
查看>>
他修过车、杀过鱼,最终进入阿里巴巴打造 9 个本地版支付宝!
查看>>
百面机器学习!算法工程师面试宝典!| 码书
查看>>
苹果无人驾驶拿 124 个工程师祭天!
查看>>