• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    Oracle數據庫中分區表的操作方法

    發布: 2008-9-05 13:58 | 作者: 網絡轉載 | 來源: blog | 查看: 70次 | 進入軟件測試論壇討論

    領測軟件測試網

    1.2.3. 更新分區表的記錄:

    SQL> update dinya_test partition(part_01) t set t.item_description=’DESK’ where
    t.transaction_id=1;
    1 row updated.
    SQL> commit;
    Commit complete.
    SQL>

      這里將第一個分區中的交易ID=1的記錄中的item_description字段更新為“DESK”,可以看到已經成功更新了一條記錄。但是當更新的時候指定了分區,而根據查詢的記錄不在該分區中時,將不會更新數據,請看下面的例子:

    SQL> update dinya_test partition(part_01) t set t.item_description=’DESK’ where
    t.transaction_id=6;
    0 rows updated.
    SQL> commit;
    Commit complete.
    SQL>

      指定了在第一個分區中更新記錄,但是條件中限制交易ID為6,而查詢全表,交易ID為6的記錄在第三個分區中,這樣該條語句將不會更新記錄。

      1.2.4. 刪除分區表記錄:

    SQL> delete from dinya_test partition(part_02) t where t.transaction_id=4;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL>

      上面例子刪除了第二個分區part_02中的交易記錄ID為4的一條記錄,和更新數據相同,如果指定了分區,而條件中的數據又不在該分區中時,將不會刪除任何數據。

      1.3. 分區表索引的使用:

      分區表和一般表一樣可以建立索引,分區表可以創建局部索引和全局索引。當分區中出現許多事務并且要保證所有分區中的數據記錄的唯一性時采用全局索引。

      1.3.1. 局部索引分區的建立:

    SQL> create index dinya_idx_t on dinya_test(item_id)
    2 local
    3 (
    4 partition idx_1 tablespace dinya_space01,
    5 partition idx_2 tablespace dinya_space02,
    6 partition idx_3 tablespace dinya_space03
    7 );
    Index created.
    SQL>

      看查詢的執行計劃,從下面的執行計劃可以看出,系統已經使用了索引:

    SQL> select * from dinya_test partition(part_01) t where t.item_id=12;
    Execution Plan
    ----------------------------------------------------------
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=1 Bytes=187)
    1 0 TABLE ACCESS (BY LOCAL INDEX ROWID) OF ’DINYA_TEST’ (Cost=
    2 Card=1 Bytes=187)
    2 1 INDEX (RANGE SCAN) OF ’DINYA_IDX_T’ (NON-UNIQUE) (Cost=1
    Card=1)
    Statistics
    ----------------------------------------------------------
    0 recursive calls
    0 db block gets
    4 consistent gets
    0 physical reads
    0 redo size
    334 bytes sent via SQL*Net to client
    309 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client

    1 sorts (memory)
    0 sorts (disk)
    2 rows processed
    SQL>

      1.3.2. 全局索引分區的建立

      全局索引建立時global 子句允許指定索引的范圍值,這個范圍值為索引字段的范圍值:

    SQL> create index dinya_idx_t on dinya_test(item_id)
    2 global partition by range(item_id)
    3 (
    4 partition idx_1 values less than (1000) tablespace dinya_space01,
    5 partition idx_2 values less than (10000) tablespace dinya_space02,
    6 partition idx_3 values less than (maxvalue) tablespace dinya_space03
    7 );
    Index created.
    SQL>

      本例中對表的item_id字段建立索引分區,當然也可以不指定索引分區名直接對整個表建立索引,如:

    SQL> create index dinya_idx_t on dinya_test(item_id);
    Index created.
    SQL>

      同樣的,對全局索引根據執行計劃可以看出索引已經可以使用:

    SQL> select * from dinya_test t where t.item_id=12;
    Execution Plan
    ----------------------------------------------------------
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=3 Bytes=561)
    1 0 TABLE ACCESS (BY GLOBAL INDEX ROWID) OF ’DINYA_TEST’ (Cost
    =2 Card=3 Bytes=561)
    2 1 INDEX (RANGE SCAN) OF ’DINYA_IDX_T’ (NON-UNIQUE) (Cost=1
    Card=3)
    Statistics
    ----------------------------------------------------------
    5 recursive calls
    0 db block gets
    10 consistent gets
    0 physical reads

    0 redo size
    420 bytes sent via SQL*Net to client
    309 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    3 sorts (memory)
    0 sorts (disk)
    5 rows processed
    SQL>

      1.4. 分區表的維護:

      了解了分區表的建立、索引的建立、表和索引的使用后,在應用的還要經常對分區進行維護和管理。日常維護和管理的內容包括:增加一個分區,合并一個分區及刪除分區等等。下面以范圍分區為例說明增加、合并、刪除分區的一般操作:

      1.4.1. 增加一個分區:

    SQL> alter table dinya_test
    2 add partition part_04 values less than(to_date(’2012-01-01’,’yyyy-mm-dd’))
    tablespace dinya_spa
    ce03;
    Table altered.
    SQL>

      增加一個分區的時候,增加的分區的條件必須大于現有分區的最大值,否則系統將提示ORA-14074 partition bound must collate higher than that of the last partition 錯誤。

      1.4.2. 合并一個分區:

    SQL> alter table dinya_test merge partitions part_01,part_02 into partition part_02;
    Table altered.
    SQL>

      在本例中將原有的表的part_01分區和part_02分區進行了合并,合并后的分區為part_02,如果在合并的時候把合并后的分區定為part_01的時候,系統將提示ORA-14275 cannot reuse lower-bound partition as resulting partition 錯誤。

      1.4.3. 刪除分區:

    SQL> alter table dinya_test drop partition part_01;
    Table altered.
    SQL>

      刪除分區表的一個分區后,查詢該表的數據時顯示,該分區中的數據已全部丟失,所以執行刪除分區動作時要慎重,確保先備份數據后再執行,或將分區合并。

      1.5. 總結:

      需要說明的是,本文在舉例說名分區表事務操作的時候,都指定了分區,因為指定了分區,系統在執行的時候則只操作該分區的記錄,提高了數據處理的速度。不要指定分區直接操作數據也是可以的。在分區表上建索引及多索引的使用和非分區表一樣。此外,因為在維護分區的時候可能對分區的索引會產生一定的影響,可能需要在維護之后重建索引,相關內容請參考分區表索引部分的文檔。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    22/2<12

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>