Profilo di haiOracle & StarcraftBlogElenchi Strumenti Guida
04 agosto

dbms_stats和leaf_blocks

dbms_stats是oracle用来代替原有的analyze功能的一个包,与analyze相比dbms_stats具有很多优势,比如并行,比如分区信息统计等,但是dbms_stats再分析index的时候处理方式并不是太理想,dbms_stats分析index时将会只统计leaf_blocks为当前有数据的leaf block,而analyze则会统计为所有曾经被使用过的leaf block number,很显然dbms_stats的统计结果会使index fast full scan的成本被严重低估,在某些情况下会错误得选择index fast full scan做为执行路径。下面来看一个例子:
 
先清空原来的表
SQL 10G>truncate table t1;
Table truncated.
 
插入数据
SQL 10G>insert into t1 select
  2  rownum id,
  3  trunc(100 * dbms_random.normal) val,
  4  rpad('x',100) padding
  5  from
  6  all_objects
  7  where
  8  rownum <= 10000
  9  ;
10000 rows created.
 
SQL 10G>commit;
Commit complete.
 
创建索引,并限制pctfree为99,模拟大索引的产生
SQL 10G>create index ind_t1 on t1(id) pctfree 99;
Index created.
 
使用analyze分析索引
SQL 10G>ANALYZE INDEX IND_T1 COMPUTE STATISTICS;
Index analyzed.
 
SQL 10G>SELECT INDEX_NAME,BLEVEL,LEAF_BLOCKS FROM  user_indexes where table_name='T1';
INDEX_NAME                         BLEVEL LEAF_BLOCKS
------------------------------ ---------- -----------
IND_T1                                  2       10000
 
再使用dbms_stats分析,可以看到在这个时候基本统计数据是相同的
SQL 10G>EXEC DBMS_STATS.GATHER_INDEX_STATS('TEST','IND_T1');
PL/SQL procedure successfully completed.
 
SQL 10G>SELECT INDEX_NAME,BLEVEL,LEAF_BLOCKS FROM  user_indexes where table_name='T1';
INDEX_NAME                         BLEVEL LEAF_BLOCKS
------------------------------ ---------- -----------
IND_T1                                  2       10010
 
删除数据使表中只保留一条记录
SQL 10G>delete from t1 where rownum<10000;
9999 rows deleted.
 
SQL 10G>commit;
Commit complete.
 
再用analyze分析索引,可以发现leaf_blocks依然是10000
SQL 10G>ANALYZE INDEX IND_T1 COMPUTE STATISTICS;
Index analyzed.
 
SQL 10G>SELECT INDEX_NAME,BLEVEL,LEAF_BLOCKS FROM  user_indexes where table_name='T1';
INDEX_NAME                         BLEVEL LEAF_BLOCKS
------------------------------ ---------- -----------
IND_T1                                  2       10000
 
看cost这一项显示index fast full scan的成本为2679,这是正确的
SQL 10G>set autotrace trace exp;

SQL 10G>select/*+ index_ffs(t1,ind_t1)*/ count(*) from t1;
Execution Plan
-------------------------------------------------------------
| Id  | Operation             | Name   | Rows  | Cost (%CPU)|
-------------------------------------------------------------
|   0 | SELECT STATEMENT      |        |     1 |  2679  (19)|
|   1 |  SORT AGGREGATE       |        |     1 |            |
|   2 |   INDEX FAST FULL SCAN| IND_T1 |     1 |  2679  (19)|
-------------------------------------------------------------
 
使用dbms_stats分析索引,leaf_blocks被统计为1,只统计了当前在用的leaf block
SQL 10G>EXEC DBMS_STATS.GATHER_INDEX_STATS('TEST','IND_T1');
PL/SQL procedure successfully completed.
 
SQL 10G>set autotrace off;

SQL 10G>SELECT INDEX_NAME,BLEVEL,LEAF_BLOCKS FROM  user_indexes where table_name='T1';
INDEX_NAME                         BLEVEL LEAF_BLOCKS
------------------------------ ---------- -----------
IND_T1                                  2           1
 
看cost这一项显示index fast full scan的成本为1,这显然是出现了错误
SQL 10G>set autotrace trace;
SQL 10G>select/*+ index_ffs(t1,ind_t1)*/ count(*) from t1;
Execution Plan
-------------------------------------------------------------
| Id  | Operation             | Name   | Rows  | Cost (%CPU)|
-------------------------------------------------------------
|   0 | SELECT STATEMENT      |        |     1 |     1   (0)|
|   1 |  SORT AGGREGATE       |        |     1 |            |
|   2 |   INDEX FAST FULL SCAN| IND_T1 |     1 |     1   (0)|
-------------------------------------------------------------
 
再来看看它究竟需要读取多少个块,是不是cost=1就够了
 
SQL 10G>   ALTER SESSION SET EVENTS 'immediate trace name flush_cache';
Session altered.
SQL 10G>select/*+ index_ffs(t1,ind_t1)*/ count(*) from t1;

Execution Plan
----------------------------------------------------------
-------------------------------------------------------------
| Id  | Operation             | Name   | Rows  | Cost (%CPU)|
-------------------------------------------------------------
|   0 | SELECT STATEMENT      |        |     1 |     1   (0)|
|   1 |  SORT AGGREGATE       |        |     1 |            |
|   2 |   INDEX FAST FULL SCAN| IND_T1 |     1 |     1   (0)|
-------------------------------------------------------------
 

Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
      10035  consistent gets
      10016  physical reads
          0  redo size
        411  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
显然,这里发生了10016个physical reads,cost=1是远远不够的。不知道oracle会不会就这个问题有改进方案,大家拭目以待。
 
 

Commenti (25)

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

28 Ago.
Senza nomeha scritto:
When the <a href="http://www.game4power.com/">Wow Gold </a> wolf finally found the <a href="http://www.game4power.com/">Buy Wow Gold</a>hole in the chimney he crawled <a href="http://www.game4power.com/buy-gold/">wow gold cheap </a> down and KERSPLASH right into that kettle of water and that was <a href="http://www.wowgoldone.com/"> cheapest wow gold </a> the end of his troubles with the big bad wolf.

The next day the <a href="http://www.wowgoldone.com/"><strong> cheap wow gold </strong></a><a href="http://www.wowgoldone.com/"> cheapest wow gold </a> little pig invited his mother over . She said "You see it is just as I told you. The way to <a href="http://www.gdpchina.org/">gdpchina</a>get along in the world is to do <a href="http://www.itemchannel.com/">world of warcraft gold</a> things as well as you can." Fortunately for that little pig, he <a href="http://www.meinwowgold.com/">meinwowgold</a> learned that lesson. And he just lived happily ever after!
19 Mar.
27 Set.
27 Set.
Senza nomeha scritto:
wOW Gold Site supply WOW GOld cheats, Wow goldtips in Wow goldgame,so you can find more thing about wOw Gold cheat guide. For more information of WOw gold, please visit a the super Wow GOld   website specialized in selling wow gold,We will serve you with cheap WoW gold , woW golD , wow goLd , WOW gold , wow gold .
27 Set.
Senza nomeha scritto:

Amberdigital Branch,Southern Stars Enterprises Co is specializing in the development and manufacturing of ad players, advertisement player and LCD advertisings. Established in 1996, we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.

amberdigital Contact Us
Southern Stars Enterprises Co (Hong Kong Office)
Add:3 Fl, No.2, Lane 2, Kam Tsin Tsuen, Sheung Shui, Hong Kong
Tel:+852 2681 4099
Fax:+852 2681 4586

Southern Stars Enterprises Co (Shenzhen Office)
Add:DE, 16/F, Building 2, Nanguo Tower, Sungang Road, Shenzhen, China
Tel:+86 755 2592 9100
Fax:+86 755 2592 7171

E-mail:sstar@netvigator.com
website:www.amberdigital.com.hk
alibaba:amberdigital.en.alibaba.com[cibgffaiadgbb]

28 Ago.
Immagine di Anonimo
阿泰 ha scritto:

Hello, come and wow gold kaufen here, you can find wow gold tips and wow gold cheats on this website, you also can buy gold for wow after wow gold reviews.wow po and free wow gold are always on the stock! we supply wow gold guide to your power leveler and free wow gold,free wow gold guide to wow players. free wow gold,runescape gold and lots of wow po are on sales, if you play many games, you may find mmorpg news from now on. but you should teeth whitening and fast lose weight at home. that means you may have a pet, like dog or cat, so you may interesting in pet insurance,and also if you have more money, you may Tibet tour 

21 Ago.
9 Ago.
Senza nomeha scritto:

Unless you're wow gold and wow gold a Warlock or a Paladin, purchasing a mount at level 40 can be cheap wow gold and cheap wow gold a near impossible thing to buy wow gold and buy wow gold afford. Without world of warcraft gold and world of warcraft gold the honored faction discount, the cost cheapest wow gold,cheap world of warcraft gold is 100gp; 20gp to pay buy world of warcraft gold for the training fast wow gold and 80 to fast wow gold pay for the mount buy cheap wow gold itself. Even cheapest world of warcraft gold with the 10% discount, the wow gold for sale cost gold for wow of 90gp is staggering to players at sell wow gold such low levels. This is aoc gold on-top of the heavy training costs aoc gold,cheap aoc gold for level 40 spells and abilities cheap aoc gold,buy aoc gold which easily cost over buy aoc gold 1gp each to learn! The level 40 ffxi gil mark in the game is easily one ffxi gil of the most expensive levels in buy ffxi gil the game. At level 40, Hunters buy ffxi gil and Shamans learn to wear cheap ffxi gil chainmail armor. Thus, on top cheap ffxi gil of the wide range of wow power leveling,wow powerleveling spells and abilities wow power leveling earned at that level, and the ability wow powerleveling to ride a mount, they have power leveling to purchase a powerleveling whole new world of warcraft power leveling set of armor. Warriors and Paladins world of warcraft powerleveling go through the world of warcraft powerleveling same ordeal, upgrading wow power level from chainmail to platemail. For other wow power level classes like Priests, Mages and Rogues, level wow powerlevel,power leveling 40 represents a whole new selection of skills and spells which ffxi power leveling can cost over 20gp to afford them aoc power leveling all. All these expenditures while the player is rs power leveling still getting 5-10 silver pieces per kill! The costs wow powerlevel only keep piling up as you progress in levels, making gold world of warcraft power leveling farming one of the most arduous and boring tasks a player is challenged with.

5 Ago.
Senza nomeha scritto:

Druids are rs gold the blessed servants of buy rs gold Cenarion and cheap rs gold protectors of the natural order swg credits of the Azeroth. Their powers swg gold spring from the buy swg credits very energy of the cheap swg credits world itself and allow Druid lotro gold characters buy lotro gold to tap into nature's raw cheap lotro gold power to silkroad gold transform themselves buy silkroad gold into fearsome cheap silkroad gold creatures, attack guild wars gold opponents with buy guild wars gold mystic cheap guild wars gold energy, or heal gw gold and buff their anarchy gold allies. Druids buy anarchy gold are welcome cheap anarchy gold in almost any ao gold group, able buy ao gold to perform cheap ao gold multiple roles gaiaonline gold as the need gaia gold arises. For gold on gaia the Alliance, cheap gaia gold only Night gaia gold fast Elves buy gaia gold may become gaia online gold Druids. Knightonline gold Having abandoned ko gold the practices tibia gold of arcane magic buy tibia gold which caused the cheap tibia gold downfall rf gold of their brethren, the buy rf gold Blood cheap rf gold Elves, the Night vanguard gold Elves cheap vanguard gold have become buy vanguard gold masters vanguard soh gold of nature. For the soh gold Horde, only buy soh gold the shamanistic cheap soh gold Tauren have cov infamy the capacity buy cov infamy of becoming cheap cov infamy Druids. The difference cov gold between the cabal alz two races is buy cabal alz slight; a Night Elf cheap cabal alz transforms into a cabal gold Black Panther for shaiya gold their buy shaiya gold combat form, while cheap shaiya gold as a Tauren becomes ddo plat a Lion. No matter buy ddo plat which side your cheap ddo plat character ddo gold may be on, you will buy ddo gold find Druids to cheap ddo gold be one of the 2moons dil most capable 2 moons dil classes in PVP buy 2moons dil and PVE. Shrugging cheap 2moons dil off 2moons gold polymorphs, removing 2 moons gold curses and breaking buy 2moons gold any movement cheap 2moons gold afflictions, Druids dofus kamas are a buy dofus kamas terror on any cheap dofus kamas PVP buying dofus kamas battlefield. At dofus gold higher levels, Druids are buy dofus gold primarily healers, becoming cheap dofus gold an essential part archlord gold to 40-man raid groups archlord online gold seeking to buy archlord gold kill dragons cheap archlord gold and gods ultima online gold in the depths of uo gold Azeroth's most buy ultima online gold dangerous uogold dungeons. No buy uo gold guild looking to sof gold kill Ragnaros, the soldier of fortune gold Lord of Fire, or sof 2 gold Nefarion, ruler of Black sof ii gold Rock Mountain, is buy sof gold complete without Druids cheap sof gold in their ranks. We can help you get there.

5 Ago.
30 Lug.
Senza nomeha scritto:
ffxi gil Maple Story Mesos wow gold wow gold age of conan gold age of conan age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold age of conan power leveling age of conan gold aoc gold age of conan power leveling aoc power leveling Runescape Money Runescape Gold Runescape Items Runescape Money Runescape Gold Runescape Power leveling Runescape Money Runescape Gold Runescape gold runescape money Runescape Money Runescape Runescape Money Runescape Power leveling Runescape Items runescape money money runescape Runescape Gold age of conan gold archlord gold anarchy online credits cabal alz city of heroes influence coh influence city of heroes city of villains infamy cov infamy city of villains dofus kamas kamas dofus dofus daoc gold daoc plat eve isk eve online isk eve online everquest 2 gold eq2 plat Ever Quest 2 final fantasy xi gil Final Fantasy XI gaia online gold gaia gold guild wars gold gw gold guild wars hellgate london palladium Hellgate London dofus kamas dofus gold dofus dofus kamas dofus eq2 plat EverQuest 2 gold wow gold world of warcraft gold buy wow gold cheap wow gold wow power leveling eq plat EverQuest gold Maple Story Mesos MapleStory mesos MapleStory Meso Final Fantasy XI gil ffxi gil dofus kamas kamas dofus lotro gold lotr gold lord of the ring gold Lineage adena Lineage 1 adena Silkroad gold buy silkroad gold flyff penya buy flyff gold flyff money eve online isk eve isk 2moons dil 2moons gold maplestory Mesos
16 Lug.
Immagine di Anonimo
17 Giu.
Immagine di Anonimo
ssqt ha scritto:
wow gold wow gold wow gold cheap wow gold to our loyal reliable customers
17 Giu.
16 Giu.
Senza nomeha scritto:
wow gold wow power leveling wow power leveling wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow gold wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling wow power leveling -44252751248285
13 Giu.
14 Mag.
Li Sevenha scritto:
各有利弊吧。
有一点不可否认啊:
"oracle 9里面的External Table,Analyze不能使用,只能使用DBMS_STATS来收集信息"
28 Feb.
jh chenha scritto:
有人居然说你像个音乐家
16 Ago.
banky1 wang1ha scritto:
你好象每次都用金甲.什么时候用隐刀干掉你
8 Ago.

Riferimenti

L'URL di riferimento per questo intervento è:
http://wzwanghai.spaces.live.com/blog/cns!56626E237AFBD116!328.trak
Blog che fanno riferimento a questo intervento
  • Nessuno