亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問板塊 發(fā)新帖
查看: 1971 | 回復(fù): 3
打印 上一主題 下一主題

奇怪。請(qǐng)幫忙分析一下為什么Rollup比簡(jiǎn)單SUM速度還快。 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2005-03-09 17:15 |只看該作者 |倒序?yàn)g覽
是Try幾個(gè)Oracle分析函數(shù)的時(shí)候發(fā)現(xiàn)使用rollup的語句比不使用的簡(jiǎn)單sum還要快些。搞不懂怎么回事,特別上來請(qǐng)教一下大家。

我用的是HPUX上架設(shè)的Oracle 8174
有一個(gè)比較大的Table,共170多萬行記錄。

使用如下語句RUN40次平均用時(shí)4.322525秒

  1. SELECT NVL(segment,'SUMMARY') AS segment,SUM(qty) FROM
  2. tablename
  3. GROUP BY ROLLUP(NVL(segment,SUMMARY))
  4. ---------------------------------------------------------------------------------
  5. FA        5314660
  6. Item 2        550
  7. PACKAGE        2606406
  8. PCBA        4980446
  9. SMT        3189386
  10.         16091448
  11. ---------------------------------------------------------------------------------
復(fù)制代碼


使用如下語句在DB Server 的 Loading非常低的時(shí)候,RUN40次平均用時(shí)6.3488秒
在正常Loading的時(shí)候在11秒到25秒之間

  1. SELECT segment,SUM(qty) FROM
  2. tablename
  3. GROUP BY segment
  4. ---------------------------------------------------------------------------------
  5. FA        5314660
  6. Item 2        550
  7. PACKAGE        2606406
  8. PCBA        4980446
  9. SMT        3189386
  10. ---------------------------------------------------------------------------------
復(fù)制代碼


我不明白相同的結(jié)果使用rollup還多做了運(yùn)算,為什么速度反而快這么多?

想請(qǐng)教一下看各位有什么看法。謝謝

附上執(zhí)行計(jì)劃如下:


  1. SQL>; set autot on
  2. SQL>; SELECT NVL(segment,'SUMMARY') AS segment,SUM(qty) FROM tablename
  3.   2  GROUP BY ROLLUP(NVL(segment,'SUMMARY'));

  4. SEGMENT         SUM(QTY)                                                      
  5. --------------- ----------                                                      
  6. FA                 5314660                                                      
  7. Item 2                 550                                                      
  8. PACKAGE            2606406                                                      
  9. PCBA               4980446                                                      
  10. SMT                3189386                                                      
  11.                   16091448                                                      

  12. 已選擇6行。


  13. Execution Plan
  14. ----------------------------------------------------------                     
  15.    0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=7817 Card=120559         
  16.           7 Bytes=26523134)                                                     
  17.                                                                                 
  18.    1    0   SORT (GROUP BY ROLLUP) (Cost=7817 Card=1205597 Bytes=26523         
  19.           134)                                                                  
  20.                                                                                 
  21.    2    1     TABLE ACCESS (FULL) OF 'TABLENAME' (Cost=2241 Card=1205597         
  22.            Bytes=26523134)                                                      
  23.                                                                                 




  24. Statistics
  25. ----------------------------------------------------------                     
  26.           0  recursive calls                                                   
  27.          12  db block gets                                                      
  28.       14760  consistent gets                                                   
  29.           0  physical reads                                                     
  30.           0  redo size                                                         
  31.         379  bytes sent via SQL*Net to client                                   
  32.          57  bytes received via SQL*Net from client                             
  33.           2  SQL*Net roundtrips to/from client                                 
  34.           2  sorts (memory)                                                     
  35.           0  sorts (disk)                                                      
  36.           6  rows processed                                                     

  37. SQL>; SELECT segment,SUM(qty) FROM tablename
  38.   2  GROUP BY segment;

  39. SEGMENT         SUM(QTY)                                                      
  40. --------------- ----------                                                      
  41. FA                 5314660                                                      
  42. Item 2                 550                                                      
  43. PACKAGE            2606406                                                      
  44. PCBA               4980446                                                      
  45. SMT                3189386                                                      


  46. Execution Plan
  47. ----------------------------------------------------------                     
  48.    0      SELECT STATEMENT Optimizer=FIRST_ROWS (Cost=826 Card=1205597         
  49.            Bytes=26523134)                                                      
  50.                                                                                 
  51.    1    0   SORT (GROUP BY NOSORT) (Cost=826 Card=1205597 Bytes=265231         
  52.           34)                                                                  
  53.                                                                                 
  54.    2    1     TABLE ACCESS (BY INDEX ROWID) OF 'TABLENAME' (Cost=826 Car         
  55.           d=1205597 Bytes=26523134)                                             
  56.                                                                                 
  57.    3    2       INDEX (FULL SCAN) OF 'IDX2_72QSY' (NON-UNIQUE) (Cost=2         
  58.           6 Card=1205597)                                                      
  59.                                                                                 




  60. Statistics
  61. ----------------------------------------------------------                     
  62.           0  recursive calls                                                   
  63.           0  db block gets                                                      
  64.      195228  consistent gets                                                   
  65.           0  physical reads                                                     
  66.           0  redo size                                                         
  67.         368  bytes sent via SQL*Net to client                                   
  68.         152  bytes received via SQL*Net from client                             
  69.           3  SQL*Net roundtrips to/from client                                 
  70.           1  sorts (memory)                                                     
  71.           0  sorts (disk)                                                      
  72.           5  rows processed                                                     

復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2005-03-10 02:45 |只看該作者

奇怪。請(qǐng)幫忙分析一下為什么Rollup比簡(jiǎn)單SUM速度還快。

The execution plans makes the difference.
One is full table scan + sort while the other is full index scan then table access by rowid + non sort.

From the output is looks that you have an index on the segment column, and it only has a few distinct values.
The ratio is 6/17000000.

This index is unselective and you should drop it.

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2005-03-10 09:26 |只看該作者

奇怪。請(qǐng)幫忙分析一下為什么Rollup比簡(jiǎn)單SUM速度還快。

謝謝sshd的解釋。不過是我沒有解釋清楚意思。執(zhí)行計(jì)劃我有看。
我疑惑的是如此相似的查詢?yōu)槭裁碠ra會(huì)采取這樣兩種執(zhí)行計(jì)劃。
Ora的選擇標(biāo)準(zhǔn)是什么?
為什么使用了rollup和不使用會(huì)關(guān)聯(lián)到Index的抉擇
謝謝。。。

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2005-03-10 14:48 |只看該作者

奇怪。請(qǐng)幫忙分析一下為什么Rollup比簡(jiǎn)單SUM速度還快。

In both SQLs, oracle need to sort on segment.

case1:
GROUP BY ROLLUP(NVL(segment,SUMMARY))
the index on segment will not be used because functions are applied to segment, thus oracle will do full table scan, then sort on segment

case 2)
GROUP BY segment
the index on segment will be used to access the table, and the results are in accending or decending order (since the leaf level of the index tree are sorted by segment ), no more sorts are needed

Since the index on tablename(segment ) is unselective, it's basically is useless, and you will need to drop it.
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP