ITPUB??ì3
新一届的微软MVP评选已经开始,欢迎各位推荐!
ITPUB论坛 » Oracle新技术/11g » When 11g SQL is faster than 10g without any plan change…

标题: [Tips] When 11g SQL is faster than 10g without any plan change…
离线 玉面飞龙
斧头帮帮主


精华贴数 1
个人空间 0
技术积分 10048 (118)
社区积分 3336 (407)
注册日期 2002-1-20
论坛徽章:23
现任管理团队成员ITPUB元老ITPUB北京九华山庄2008年会纪念徽章参与2007年甲骨文全球大会(中国上海)纪念管理团队2006纪念徽章蓝锆石
会员2007贡献徽章会员2006贡献徽章授权会员生肖徽章2007版:蛇生肖徽章2007版:龙2008北京奥运纪念徽章:排球

发表于 2007-8-10 10:44 
When 11g SQL is faster than 10g without any plan change…

还是看看原版的链接

http://www.pythian.com/blogs/542/my-work-before-12g-goes-out


« Oracle 11g (11.1.0.6) and Documentation Available on OTNWhen 11g SQL is faster than 10g without any plan change…
August 9th, 2007 - by Gregory Guillou
11g is out !

We all know what Oracle Marketing will say : 11g is x% faster than 10g. And guess what ? I’ll need 3 more years to decipher all those changes that enhance the 11g optimizer and the query algorithms. This will probably be time for 12g then !

To avoid being too far behind you guys that are already upgrading to 11g, I’ve decided to invest on 11g during the Beta Program. This has been a lot of fun and I wish I can share some of my findings with you. For example, did you know that 11g can go faster without any change at all ? The queries below will illustrate the change made to the Nested Loop Algorithm in 11g :

1°- First, you have to create and fill a table to run your query :

create table gark
  (id1 number not null,
   id2 number not null,
   id3 number not null);

begin
for i in 1..100000 loop
insert into gark(id1, id2, id3)
values (i, i, i);
end loop;
commit;
end;
/

create unique index gark_idx on gark(id1, id3);

begin
dbms_stats.gather_table_stats(
   user,
   'GARK',
   cascade=>true,
   estimate_percent=>100,
   method_opt=>'FOR ALL COLUMNS SIZE 254',
   no_invalidate=> false);
end;
/2°- Then, run the query below on a 10g database :

set autotrace traceonly

select /*+ use_nl(A B) */count(a.id3)
from gark a, gark b
where a.id1=b.id2;

Execution Plan
----------------------------
Plan hash value: 3137705415

--------------------------------------------------------
| Id  | Operation           | Name     | Rows  |  Cost |
--------------------------------------------------------
|   0 | SELECT STATEMENT    |          |     1 |  100K |
|   1 |  SORT AGGREGATE     |          |     1 |       |
|   2 |   NESTED LOOPS      |          |   100K|  100K |
|   3 |    TABLE ACCESS FULL| GARK     |   100K|    65 |
|*  4 |    INDEX RANGE SCAN | GARK_IDX |     1 |     1 |
--------------------------------------------------------

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

4 - access("A"."ID1"="B"."ID2"

Statistics
----------------------------------------------------------
       0  recursive calls
       0  db block gets
  100556  consistent gets
       0  physical reads
       0  redo size
     415  bytes sent via SQL*Net to client
     385  bytes received via SQL*Net from client
       2  SQL*Net roundtrips to/from client
       0  sorts (memory)
       0  sorts (disk)
       1  rows processed3°- Run the same query on 11g (There is no trick here, the plan is the right plan, I’ve check it with dbms_xplan.display_cursor) :

set autotrace traceonly

select /*+ use_nl(A B) */count(a.id3)
from gark a, gark b
where a.id1=b.id2;

Execution Plan
----------------------------------------------------------
Plan hash value: 3137705415

-------------------------------------------------------
| Id  | Operation           | Name     | Rows  | Cost |
-------------------------------------------------------
|   0 | SELECT STATEMENT    |          |     1 | 100K |
|   1 |  SORT AGGREGATE     |          |     1 |      |
|   2 |   NESTED LOOPS      |          |   100K| 100K |
|   3 |    TABLE ACCESS FULL| GARK     |   100K|  105 |
|*  4 |    INDEX RANGE SCAN | GARK_IDX |     1 |   11 |
-------------------------------------------------------

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

4 - access("A"."ID1"="B"."ID2"

Statistics
----------------------------------------------------------
       0  recursive calls
       0  db block gets
    3373  consistent gets
       0  physical reads
       0  redo size
     422  bytes sent via SQL*Net to client
     415  bytes received via SQL*Net from client
       2  SQL*Net roundtrips to/from client
       0  sorts (memory)
       0  sorts (disk)
       1  rows processedIf you know how the NL algorithm works in 10g, it’s quite easy to understand how it has been modified. The good news with that is that it won’t only speed up queries with optimal plans but also speed up queries with sub optimal plans that are using Nested Loops.

-Grégory

PS : Don’t dream, it won’t be so huge with a real workload and of course HASH JOIN stays the most efficient plan to solve this particular query.


__________________
只看该作者    顶部
离线 blue_prince
永远的巴乔


精华贴数 21
个人空间 0
技术积分 16894 (58)
社区积分 5956 (253)
注册日期 2003-10-15
论坛徽章:64
现任管理团队成员     
      

发表于 2007-8-10 13:36 
我测试了一下10G下的,过会看看11G
PHP code:


SQL
select from v$version



BANNER

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

Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 64bi

PL
/SQL Release 10.2.0.2.0 Production

CORE    10.2.0.2.0      Production

TNS 
for IBM/AIX RISC System/6000Version 10.2.0.2.0 Productio

NLSRTL Version 10.2.0.2.0 
Production



Elapsed
00:00:00.07

SQL
create table gark

  2  
(id1 number not null,

  
3  id2 number not null,

  
4  id3 number not null);





Table created.



Elapsed00:00:00.10

SQL
SQL

SQLbegin

  2  
for i in 1..100000 loop

  3  insert into gark
(id1id2id3)

  
4  values (iii);

  
5  end loop;

  
6  commit;

  
7  end;

  
8  /



PL/SQL procedure successfully completed.



Elapsed00:00:04.43

SQL
create unique index gark_idx on gark(id1id3);



Index created.



Elapsed00:00:00.25

SQL
begin

  2  dbms_stats
.gather_table_stats(

  
3  user,

  
4  'GARK',

  
5  cascade=>true,

  
6  estimate_percent=>100,

  
7  method_opt=>'FOR ALL COLUMNS SIZE 254',

  
8  no_invalidate=> false);

  
9  end;

 
10  /



PL/SQL procedure successfully completed.



Elapsed00:00:03.32

SQL
set autotrace traceonly

SQL


SQLselect /*+ use_nl(A B) */count(a.id3)

  
2  from gark agark b

  3  where a
.id1=b.id2;



Elapsed00:00:00.60



Execution Plan

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

Plan hash value3257338542



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

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

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

|   
SELECT STATEMENT    |          |     |    10 |   100K  (1)| 00:23:22 |

|   
|  SORT AGGREGATE     |          |     |    10 |            |          |

|   
|   NESTED LOOPS      |          |   100K|   976K|   100K  (1)| 00:23:22 |

|   
|    TABLE ACCESS FULLGARK     |   100K|   488K|    58   (2)| 00:00:01 |

|*  
|    INDEX RANGE SCAN GARK_IDX |     |     |     1   (0)| 00:00:01 |

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



Predicate Information (identified by operation id):

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



   
access(&quot;A&quot;.&quot;ID1&quot;=&quot;B&quot;.&quot;ID2&quot<img src="images/smilies/23.gif" smilieid="206" border="0" alt="" />





Statistics

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

          
1  recursive calls

          0  db block gets

     100327  consistent gets

          0  physical reads

          0  redo size

        519  bytes sent via SQL
*Net to client

        469  bytes received via SQL
*Net from client

          2  SQL
*Net roundtrips to/from client

          0  sorts 
(memory)

          
0  sorts (disk)

          
1  rows processed

..

BTW,NND,本来都下好了,结果磁盘空间不够,最后一分钟硬生生地把我给弄没了,害我重新下载,郁闷。


__________________
淘宝DBA团队Blog        我的Blog

We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle
只看该作者    顶部
离线 hotiice
版主


精华贴数 10
个人空间 0
技术积分 16699 (62)
社区积分 1796 (648)
注册日期 2004-9-9
论坛徽章:21
现任管理团队成员会员2007贡献徽章铁扇公主生肖徽章2007版:牛2008北京奥运纪念徽章:帆船2008北京奥运纪念徽章:游泳
设计板块每日发贴之星设计板块每日发贴之星生肖徽章2007版:蛇2008年新春纪念徽章生肖徽章2007版:龙生肖徽章2007版:兔

发表于 2007-8-10 13:39 


QUOTE:
最初由 blue_prince 发布
我测试了一下10G下的,过会看看11G


BTW,NND,本来都下好了,结果磁盘空间不够,最后一分钟硬生生地把我给弄没了,害我重新下载,郁闷。


用下载工具啊


__________________
①②⑧

只看该作者    顶部
离线 blue_prince
永远的巴乔


精华贴数 21
个人空间 0
技术积分 16894 (58)
社区积分 5956 (253)
注册日期 2003-10-15
论坛徽章:64
现任管理团队成员     
      

发表于 2007-8-10 13:41 


QUOTE:
最初由 hotiice 发布

用下载工具啊


公司不能用下载工具的


__________________
淘宝DBA团队Blog        我的Blog

We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle
只看该作者    顶部
离线 alantany
版主


精华贴数 2
个人空间 0
技术积分 11903 (100)
社区积分 354 (1708)
注册日期 2001-9-28
论坛徽章:38
现任管理团队成员2008北京奥运纪念徽章:跳水2008北京奥运纪念徽章:柔道2008北京奥运纪念徽章:垒球2008北京奥运纪念徽章:排球2008北京奥运纪念徽章:篮球
      

发表于 2007-8-10 14:46 
下的好慢,只有70K,估计全世界都在下


__________________
世事洞明皆学问,人情练达即文章。 MSN:alantany@gmail.com
只看该作者    顶部
离线 blue_prince
永远的巴乔


精华贴数 21
个人空间 0
技术积分 16894 (58)
社区积分 5956 (253)
注册日期 2003-10-15
论坛徽章:64
现任管理团队成员     
      

发表于 2007-8-10 15:45 
11G的结果出来了
PHP code:


SQL
select from v$version;



BANNER

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

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 Production

PL
/SQL Release 11.1.0.6.0 Production

CORE    11.1.0.6.0      Production

TNS 
for LinuxVersion 11.1.0.6.0 Production

NLSRTL Version 11.1.0.6.0 
Production



Elapsed
00:00:00.00

SQL
create table gark

  2  
(id1 number not null,

  
3  id2 number not null,

  
4  id3 number not null);



Table created.



Elapsed00:00:00.15

SQL
begin

  2  
for i in 1..100000 loop

  3  insert into gark
(id1id2id3)

  
4  values (iii);

  
5  end loop;

  
6  commit;

  
7  end;

  
8  /



PL/SQL procedure successfully completed.



Elapsed00:00:04.34

SQL
create unique index gark_idx on gark(id1id3);



Index created.



Elapsed00:00:00.28

SQL
begin

  2  dbms_stats
.gather_table_stats(

  
3  user,

  
4  'GARK',

  
5  cascade=>true,

  
6  estimate_percent=>100,

  
7  method_opt=>'FOR ALL COLUMNS SIZE 254',

  
8  no_invalidate=> false);

  
9  end;

 
10  /



PL/SQL procedure successfully completed.



Elapsed00:00:01.97

SQL
set autotrace traceonly



select 
/*+ use_nl(A B) */count(a.id3)

from gark agark b

SQL
SQL>   2    3  where a.id1=b.id2;



Elapsed00:00:00.14



Execution Plan

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

Plan hash value3137705415



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

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

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

|   
SELECT STATEMENT    |          |     |    10 |   100K  (1)| 00:20:02 |

|   
|  SORT AGGREGATE     |          |     |    10 |            |          |

|   
|   NESTED LOOPS      |          |   100K|   976K|   100K  (1)| 00:20:02 |

|   
|    TABLE ACCESS FULLGARK     |   100K|   488K|   103   (1)| 00:00:02 |

|*  
|    INDEX RANGE SCAN GARK_IDX |     |     |     1   (0)| 00:00:01 |

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



Predicate Information (identified by operation id):

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



   
access(&quot;A&quot;.&quot;ID1&quot;=&quot;B&quot;.&quot;ID2&quot<img src="images/smilies/23.gif" smilieid="206" border="0" alt="" />





Statistics

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

          
1  recursive calls

          0  db block gets

       3323  consistent gets

          0  physical reads

          0  redo size

        415  bytes sent via SQL
*Net to client

        385  bytes received via SQL
*Net from client

          2  SQL
*Net roundtrips to/from client

          0  sorts 
(memory)

          
0  sorts (disk)

          
1  rows processed



..




__________________
淘宝DBA团队Blog        我的Blog

We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle
只看该作者    顶部
离线 blue_prince
永远的巴乔


精华贴数 21
个人空间 0
技术积分 16894 (58)
社区积分 5956 (253)
注册日期 2003-10-15
论坛徽章:64
现任管理团队成员     
      

发表于 2007-8-10 15:46 
果然性能有了大幅的提升


__________________
淘宝DBA团队Blog        我的Blog

We are what we repeatedly do. Excellence, then, is not an act, but a habit.——Aristotle
只看该作者    顶部
离线 waityou81
好好生活


精华贴数 0
个人空间 0
技术积分 3644 (398)
社区积分 943 (983)
注册日期 2004-9-1
论坛徽章:12
ITPUB元老会员2007贡献徽章授权会员2008北京奥运纪念徽章:自行车2008北京奥运纪念徽章:体操2008北京奥运纪念徽章:赛艇
2008北京奥运纪念徽章:跆拳道生肖徽章2007版:鼠ITPUB新首页上线纪念徽章生肖徽章:蛇生肖徽章:蛇数据库板块每日发贴之星

发表于 2007-8-13 15:09 
的确有意思


__________________
Metalink§AskTom§ITPUB§Tahiti
这个国家让我伤心也很无奈
只看该作者    顶部
离线 mustapha
高级会员


来自 没的看了
精华贴数 1
个人空间 0
技术积分 5127 (263)
社区积分 81 (3851)
注册日期 2006-5-18
论坛徽章:13
会员2007贡献徽章授权会员2008北京奥运纪念徽章:沙滩排球生肖徽章2007版:猴生肖徽章2007版:鼠生肖徽章2007版:鸡
ITPUB新首页上线纪念徽章生肖徽章:虎数据库板块每日发贴之星生肖徽章:龙生肖徽章:马生肖徽章:羊

发表于 2007-8-13 15:51 
刚出来就下载好了,忙的一直没顾上装,只能看你们玩了


__________________
没事就运动运动~~~~~~~~~~~~~
只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问