乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      【轉(zhuǎn)】簡單試驗(yàn)一下BulkBinds對性能的提高

       汲取者 2010-05-24

      簡單試驗(yàn)一下Bulk Binds對性能的提高

      http://www./130636.html

      當(dāng)Oracle運(yùn)行PL/SQL時會使用兩套引擎,所有procedural code由PL/SQL engine 完成,所有SQL由SQL engine處理。所以如果Oracle從一個collection中循環(huán)執(zhí)行相同的DML操作,那么為了避免兩套engine切換所消耗的系統(tǒng)資源,可 以使用bulk binds來把所有的DML操作binding到一次操作中完成。這將極大提高PL/SQL的執(zhí)行效率。
      以下是簡單的測試,用兩 種方式插入100000條數(shù)據(jù),可以看到效率提高了7倍左右。

      PHP code:



      SQL
      CREATE TABLE test1(

        
      2    id           NUMBER(10),

        
      3    description  VARCHAR2(50));



      Table created



      SQL
      ALTER TABLE test1 ADD (

        
      2    CONSTRAINT test1_pk PRIMARY KEY (id));



      Table altered



      SQL
      SET TIMING ON;



      SQL> DECLARE

        
      2    TYPE id_type          IS TABLE OF test1.id%TYPE;

        
      3    TYPE description_type IS TABLE OF test1.description%TYPE;

        
      4  

        5    t_id           id_type          
      := id_type();

        
      6    t_description  description_type := description_type();

        
      7  BEGIN

        8    
      FOR i IN 1 .. 100000 LOOP

        9      t_id
      .extend;

       
      10      t_description.extend;

       
      11  

       12      t_id
      (t_id.last)                   := i;

       
      13      t_description(t_description.last) := 'Description: ' || To_Char(i);

       
      14    END LOOP;

       
      15  

       16    
      FOR i IN t_id.first .. t_id.last LOOP

       17      INSERT INTO test1 
      (iddescription)

       
      18      VALUES (t_id(i), t_description(i));

       
      19    END LOOP;

       
      20  

       21    COMMIT
      ;

       
      22  END;

       
      23  /



      PL/SQL procedure successfully completed



      Executed in 141.233 seconds



      SQL
      truncate table test1;



      Table truncated



      Executed in 0.631 seconds



      SQL


      SQL> DECLARE

        
      2    TYPE id_type          IS TABLE OF test1.id%TYPE;

        
      3    TYPE description_type IS TABLE OF test1.description%TYPE;

        
      4  

        5    t_id           id_type          
      := id_type();

        
      6    t_description  description_type := description_type();

        
      7  BEGIN

        8    
      FOR i IN 1 .. 100000 LOOP

        9      t_id
      .extend;

       
      10      t_description.extend;

       
      11  

       12      t_id
      (t_id.last)                   := i;

       
      13      t_description(t_description.last) := 'Description: ' || To_Char(i);

       
      14    END LOOP;

       
      15  

       16    FORALL i IN t_id
      .first .. t_id.last

       17      INSERT INTO test1 
      (iddescription)

       
      18      VALUES (t_id(i), t_description(i));

       
      19  

       20    COMMIT
      ;

       
      21  END;

       
      22  /



      PL/SQL procedure successfully completed



      Executed in 27.52 seconds



      SQL
      select count(*) from test1;



        
      COUNT(*)

      ----------

          
      100000



      Executed in 0.04 seconds



      SQL
      >
      下面我們使用上面那個例子中插入的100000條數(shù)據(jù),來測試一 下BULK COLLECT的威力。
      PHP code:


      SQL
      SET TIMING ON;

      SQL

      SQL> DECLARE

        
      2    TYPE id_type          IS TABLE OF test1.id%TYPE;

        
      3    TYPE description_type IS TABLE OF test1.description%TYPE;

        
      4  

        5    t_id           id_type          
      := id_type();

        
      6    t_description  description_type := description_type();

        
      7  

        8    CURSOR c_data IS

        9      SELECT 
      *

       
      10      FROM   test1;

       
      11  BEGIN

       12    
      FOR cur_rec IN c_data LOOP

       13      t_id
      .extend;

       
      14      t_description.extend;

       
      15  

       16      t_id
      (t_id.last)                   := cur_rec.id;

       
      17      t_description(t_description.last) := cur_rec.description;

       
      18    END LOOP;

       
      19  END;

       
      20  /



      PL/SQL procedure successfully completed



      Executed in 2.974 seconds



      SQL


      SQL> DECLARE

        
      2    TYPE id_type          IS TABLE OF test1.id%TYPE;

        
      3    TYPE description_type IS TABLE OF test1.description%TYPE;

        
      4  

        5    t_id           id_type
      ;

        
      6    t_description  description_type;

        
      7  BEGIN

        8    SELECT id
      description

        9    BULK COLLECT INTO t_id
      t_description FROM test1;

       
      10  END;

       
      11  /



      PL/SQL procedure successfully completed



      Executed in 0.371 seconds



      SQL
      >

      結(jié)論:當(dāng)我們需要將大量的檢索結(jié)果放入一個collection的時候,使用bulking將比直接使用cursor循環(huán)有效的多。

      關(guān)于Bulk Binds中LIMIT的使用,請看TOM的解說

      http://asktom.oracle.com/pls/ask ... 8_B:5918938803188,Y

      do something like this:
      PHP code:


      open cursor
      ;

         
      loop

             fetch c bulk collect into l_c1
      l_c2, ....... LIMIT 1000;

             for 
      i in 1 .. l_c1.count

             loop

                  process
      ....

             
      end loop;

             
      forall i in 1 .. l_c1.count

                  insert into 
      ..... values L_c1(i), .... );

             
      end loop;

             exit 
      when c%notfound;

         
      end loop;



         
      c

      1000 would be extreme, 100 is reasonable.
      Oracle10g中對于forall的增強(qiáng)

      http://www./showthread.php?s=&threadid=184794

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多