编号相同的数据为赋值条件,id自增 sql语句怎么写应该怎么写

2008年 总版技术专家分年内排行榜第二
2010年 总版技术专家分年内排行榜第四2009年 总版技术专家分年内排行榜第五2007年 总版技术专家分年内排行榜第六
2008年 总版技术专家分年内排行榜第二
2010年 总版技术专家分年内排行榜第四2009年 总版技术专家分年内排行榜第五2007年 总版技术专家分年内排行榜第六
2006年 总版技术专家分年内排行榜第九
2007年10月 总版技术专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。查看: 6353|回复: 8
同一个SQL语句,相同查询条件,查询赋值不一样,执行计划却有很大的差别?
论坛徽章:1
同一条SQL语句
select max(pdh) from ration_data where scrq_ps=;
只是查询条件的赋值不一样,执行计划差别很大,
当scrq_ps=
&&scrq_ps=
&&scrq_ps=
的时候,执行全表扫描
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=241590 pr=153520 pw=0 time= us)
&&32496& &TABLE ACCESS FULL RATION_DATA (cr=241590 pr=153520 pw=0 time= us)
********************************************************************************
当scrq_ps=
&&scrq_ps=& &
或者其他的值的时候,却使用了索引
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=16154 pr=0 pw=0 time=898428 us)
246893& &TABLE ACCESS BY INDEX ROWID RATION_DATA (cr=16154 pr=0 pw=0 time=740878 us)
246893& & INDEX RANGE SCAN IDX_RATION2 (cr=665 pr=0 pw=0 time=294 us)(object id 106642)
什么原因呢,困惑中。。。
以下是SQL TRACE 的结果:
TKPROF: Release 10.2.0.4.0 - Production on Thu Dec 16 20:23:02 2010
Copyright (c) , Oracle.&&All rights reserved.
Trace file: caskdb1_ora_696546.trc
Sort options: default
********************************************************************************
count& & = number of times OCI procedure was executed
cpu& && &= cpu time in seconds executing
elapsed&&= elapsed time in seconds executing
disk& &&&= number of physical reads of buffers from disk
query& & = number of buffers gotten for consistent read
current&&= number of buffers gotten in current mode (usually for update)
rows& &&&= number of rows processed by the fetch or execute call
********************************************************************************
select max(pdh)
ration_data where scrq_ps=
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&2& &&&25.21& &&&102.88& &&&153520& &&&241590& && && & 0& && && &&&1
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&4& &&&25.21& &&&102.88& &&&153520& &&&241590& && && & 0& && && &&&1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 76&&
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=241590 pr=153520 pw=0 time= us)
&&32496& &TABLE ACCESS FULL RATION_DATA (cr=241590 pr=153520 pw=0 time= us)
********************************************************************************
select max(pdh)
ration_data where scrq_ps=
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&2& && &0.00& && & 0.00& && && & 0& && && & 3& && && & 0& && && &&&1
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&4& && &0.00& && & 0.00& && && & 0& && && & 3& && && & 0& && && &&&1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 76&&
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=3 pr=0 pw=0 time=122 us)
& && &0& &TABLE ACCESS BY INDEX ROWID RATION_DATA (cr=3 pr=0 pw=0 time=93 us)
& && &0& & INDEX RANGE SCAN IDX_RATION2 (cr=3 pr=0 pw=0 time=64 us)(object id 106642)
********************************************************************************
select max(pdh)
ration_data where scrq_ps=
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&2& && &0.16& && & 0.18& && && &75& && & 5861& && && & 0& && && &&&1
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&4& && &0.16& && & 0.18& && && &75& && & 5861& && && & 0& && && &&&1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 76&&
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=5861 pr=75 pw=0 time=184695 us)
&&30753& &TABLE ACCESS BY INDEX ROWID RATION_DATA (cr=5861 pr=75 pw=0 time=139517 us)
&&30753& & INDEX RANGE SCAN IDX_RATION2 (cr=76 pr=75 pw=0 time=15812 us)(object id 106642)
********************************************************************************
select max(pdh)
ration_data where scrq_ps=
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&2& && &0.89& && & 0.89& && && & 0& && &16154& && && & 0& && && &&&1
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&4& && &0.89& && & 0.90& && && & 0& && &16154& && && & 0& && && &&&1
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 76&&
Rows& &&&Row Source Operation
-------&&---------------------------------------------------
& && &1&&SORT AGGREGATE (cr=16154 pr=0 pw=0 time=898428 us)
246893& &TABLE ACCESS BY INDEX ROWID RATION_DATA (cr=16154 pr=0 pw=0 time=740878 us)
246893& & INDEX RANGE SCAN IDX_RATION2 (cr=665 pr=0 pw=0 time=294 us)(object id 106642)
********************************************************************************
alter session set sql_trace=false
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &1& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&0& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&2& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Misses in library cache during parse: 0
Parsing user id: 76&&
********************************************************************************
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&5& && &0.00& && & 0.01& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &5& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&8& &&&26.26& &&&103.96& &&&153595& &&&263608& && && & 0& && && &&&4
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && & 18& &&&26.26& &&&103.98& &&&153595& &&&263608& && && & 0& && && &&&4
Misses in library cache during parse: 4
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call& &&&count& && & cpu& & elapsed& && & disk& && &query& & current& && &&&rows
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
Parse& && &&&0& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Execute& && &0& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Fetch& && &&&0& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
------- ------&&-------- ---------- ---------- ---------- ----------&&----------
total& && &&&0& && &0.00& && & 0.00& && && & 0& && && & 0& && && & 0& && && &&&0
Misses in library cache during parse: 0
& & 5&&user&&SQL statements in session.
& & 0&&internal SQL statements in session.
& & 5&&SQL statements in session.
********************************************************************************
Trace file: caskdb1_ora_696546.trc
Trace file compatibility: 10.01.00
Sort options: default
& && & 1&&session in tracefile.
& && & 5&&user&&SQL statements in trace file.
& && & 0&&internal SQL statements in trace file.
& && & 5&&SQL statements in trace file.
& && & 5&&unique SQL statements in trace file.
& && &70&&lines in trace file.
& &&&207&&elapsed seconds in trace file.
[ 本帖最后由 sudaemon 于
21:16 编辑 ]
论坛徽章:13
选择率不同,当查询的数据量超过一定比例,就会选择全表扫描
论坛徽章:7
这很正常,谓词的值对查询性能影响很大,所以才会对table、index进行分析、统计。
论坛徽章:12
可以参考对象统计,分析的知识,自己建个表,给一列建个索引(这一列进行一些极端情况的模拟,有些值可以有N多,有些值只有1个),按照不同的比例(estimate_percent)进行分析,然后进行谓词条件查询,做了这个实验就会知道为什么执行计划不同了!
论坛徽章:1
认真读了下 冰冻奶茶 的blog
开始有些认识了。
也谢谢以上各位的指点。
论坛徽章:2
Cardinality Feedback机制
不是说oracle有个Cardinality Feedback机制,不管用?
论坛徽章:86
看看每个值都有多少条记录?
论坛徽章:12
把柱状图去了,就一样了
论坛徽章:1088
有直方图吧
itpub.net All Right Reserved. 北京皓辰网域网络信息技术有限公司版权所有    
 北京市公安局海淀分局网监中心备案编号: 广播电视节目制作经营许可证:编号(京)字第1149号

我要回帖

更多关于 insert语句怎么写 的文章

 

随机推荐