系統優化之---分割槽表加速查詢速度和刪除速度
1、刪除表裡的資料最用下面語句
alter table t_name drop partition p_name;
alter table t_name truncate partition p_name;
delete 方式弊端:消耗大量的系統資源和無法釋放空間
SQL> create user test identified by test account unlock;
User created.
SQL> grant dba to test;
Grant succeeded.
SQL> grant resource,connect to test;
Grant succeeded.
SQL> conn test/test as sysdba
Connected.
SQL> create table t as select object_id,object_name from dba_objects;
create table t as select object_id,object_name from dba_objects
Table created.
SQL> exec dbms_stats.gather_table_stats(user,'t');
PL/SQL procedure successfully completed.
SQL> set autotrace trace exp stat;
SQL> delete from t where object_id <10000;
9708 rows deleted.
Execution Plan
----------------------------------------------------------
Plan hash value: 3335594643
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 9715 | 48575 | 96 (2)| 00:00:02 |
| 1 | DELETE | T | | | | |
|* 2 | TABLE ACCESS FULL| T | 9715 | 48575 | 96 (2)| 00:00:02 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("OBJECT_ID"<10000)
Statistics
----------------------------------------------------------
200 recursive calls
10106 db block gets
373 consistent gets
0 physical reads
2609544 redo size
678 bytes sent via SQL*Net to client
608 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
5 sorts (memory)
0 sorts (disk)
9708 rows processed
這種情況下,delete操作產生了10106+373條資料塊(db block gets+consistent gets)同是產生了2.6M的redo日誌。
即使用建立索引的方法也無法避免資源消耗
SQL> rollback;
Rollback complete.
SQL> create index ind_t on t(object_id);
Index created.
SQL> exec dbms_stats.gather_index_stats(user,'ind_t')
PL/SQL procedure successfully completed.
SQL> delete from t where object_id <10000;
9708 rows deleted.
Execution Plan
----------------------------------------------------------
Plan hash value: 3974964266
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | DELETE STATEMENT | | 9715 | 48575 | 23 (0)| 00:00:01 |
| 1 | DELETE | T | | | | |
|* 2 | INDEX RANGE SCAN| IND_T | 9715 | 48575 | 23 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<10000)
Statistics
----------------------------------------------------------
282 recursive calls
10370 db block gets
90 consistent gets
0 physical reads
2777076 redo size
680 bytes sent via SQL*Net to client
609 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
8 sorts (memory)
0 sorts (disk)
9708 rows processed
上面兩種情況消耗的資源差不多都是1000多個資料塊,相反使用truncate和drop 消耗的資源小的多。
create table t1(object_id int,object_name varchar2(1000)) partition by range(object_id)
(partition p1 values less than(10000),
partition p2 values less than(20000),
partition p3 values less than(30000),
partition p4 values less than(40000)
,partition pm values less than(maxvalue));
create table t1(object_id int,object_name varchar2(1000)) partition by range(object_id) (partition p1 values less than(10000),partition p2 values less than(20000),partition p3 values less than(30000),partition p4 values less than(40000),partition pm values less than(maxvalue));
SQL> insert into t1 select * from t;
62751 rows created.
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time
|
--------------------------------------------------------------------------------
-
| 0 | INSERT STATEMENT | | 72459 | 2052K| 95 (0)| 00:00:02
|
| 1 | LOAD TABLE CONVENTIONAL | T1 | | | |
|
| 2 | TABLE ACCESS FULL | T | 72459 | 2052K| 95 (0)| 00:00:02
|
--------------------------------------------------------------------------------
-
Statistics
----------------------------------------------------------
1170 recursive calls
39860 db block gets
38041 consistent gets
0 physical reads
10866864 redo size
680 bytes sent via SQL*Net to client
602 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
62751 rows processed
SQL> commit;
啟動SQL TRACE實用工具
對會話啟動SQL TRACE
對會話啟動SQL TRACE
SQL> alter session set sql_trace=true;
Session altered.
SQL> alter table t1 truncate partition p1;
SQL> truncate table t1;
Table truncated.
SQL> insert into t1 select * from t;
62751 rows created.
SQL> commit;
Commit complete.
SQL> alter session set sql_trace=true;
Session altered.
SQL> alter table t1 drop partition p1;
Table altered.
關閉SQL TRACE實用工具
對會話關閉SQL TRACE
對會話關閉SQL TRACE
SQL> alter session set sql_trace=false;
Session altered.
獲得程式資訊,選擇需要跟蹤的程式:
select s.USERNAME,s.SID,s.SERIAL#,s.COMMAND from v$session s where s.USERNAME='TEST';
USERNAME SID SERIAL# COMMAND
------------------------------ ---------- ---------- ----------
TEST 33 52 2
SQL> show user
USER is "SYS"
設定跟蹤:
SQL> exec sys.dbms_system.set_sql_trace_in_session(33,52,true)
PL/SQL procedure successfully completed.
可以等候片刻,跟蹤session執行任務,捕獲sql操作…
停止跟蹤:
SQL> exec sys.dbms_system.set_sql_trace_in_session(33,52,false);
PL/SQL procedure successfully completed.
tkorof工具 分析ORACLE跟蹤檔案並且產生一個更加人性化清晰的輸出結果的可執行工具
[oracle@haoxy trace]$ pwd
/u01/app/diag/rdbms/hxy/hxy/trace
[oracle@haoxy trace]$ tkprof hxy_ora_10283.trc tra.txt print=600 record=sql.txt sys=no
vi tra.txt
alter table t1 truncate partition p1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.06 0 4 1 0
Execute 1 0.03 0.11 5 1 82 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.04 0.18 5 5 83 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 91
alter table t1 drop partition p1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.02 0.12 0 0 1 0
Execute 1 0.04 0.11 1 1 35 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.06 0.23 1 1 36 0
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 91
由此實驗可以看出DDL消耗資源遠小於DML資源,DDl消耗的資源是對資料字典的修改,這個值基本是不變的,DML是隨著資料量的增大消耗的資源也隨之增大。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24492954/viewspace-765656/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE刪除-表分割槽和資料Oracle
- 優化sql查詢速度優化SQL
- Oracle分割槽表基礎運維-09刪除分割槽Oracle運維
- win10刪除系統保留分割槽如何操作_win10刪除系統保留分割槽怎麼處理Win10
- webpack--效能優化之打包構建速度和程式碼除錯優化Web優化除錯
- SQL Server表分割槽刪除詳情DSCCSQLServer
- windows10分割槽無法刪除怎麼辦_win10系統磁碟刪除分割槽的方法WindowsWin10
- oracle分割槽表和分割槽表exchangeOracle
- oracle分割槽表和非分割槽表exchangeOracle
- win10 oem分割槽怎麼刪除_win10 oem分割槽可以刪除嗎Win10
- win10系統OEM分割槽怎麼合併或刪除Win10
- App啟動速度優化APP優化
- npm下載速度優化NPM優化
- win10系統硬碟分割槽無法格式化也刪除不了如何解決Win10硬碟
- [Hive]Hive中表連線的優化,加快查詢速度Hive優化
- 刪除雙系統誤修改Win11 EFI分割槽的解決方案
- 電腦刪除檔案速度很慢怎麼辦?電腦刪除檔案速度慢的解決方法
- oracle 分割槽表move和包含分割槽表的lob moveOracle
- 移動分割槽表和分割槽索引的表空間索引
- MySQL調優之分割槽表MySql
- win10分割槽好了怎麼刪除_win10分割槽完後如何刪除Win10
- mysql千萬級資料量根據索引優化查詢速度MySql索引優化
- PostgreSQL:傳統分割槽表SQL
- Android Note - 構建速度優化Android優化
- 刪除EFI系統分割槽(ESP)後Windows無法啟動,重建引導分割槽並修復啟動的過程Windows
- 分割槽表之自動增加分割槽(11G)
- Oracle SQL調優之分割槽表OracleSQL
- 電腦硬碟分割槽要注意什麼,刪除硬碟分割槽的注意事項硬碟
- Oracle 效能優化-expdp備份速度優化02Oracle優化
- Oracle 效能優化-expdp備份速度優化03Oracle優化
- SQL優化案例-分割槽索引之無字首索引(六)SQL優化索引
- Oracle優化案例-分割槽索引之無字首索引(六)Oracle優化索引
- win10系統怎麼優化ssd硬碟提高固態硬碟速度Win10優化硬碟
- Oracle 12.2之後ALTER TABLE .. MODIFY轉換非分割槽表為分割槽表Oracle
- iOS 啟動速度優化和安裝包優化簡單總結iOS優化
- 優化 SPA 首屏載入速度優化
- 優酷 Android 構建速度優化實踐Android優化
- win10優化開機速度怎麼設定 win10如何優化開機速度Win10優化
- hpz420系統盤安裝win10無法刪除分割槽表解決方法Win10