課程實踐(二)
使用不同的訪問路徑
案例一
結論:當資料量大,而檢索的資料又比較少時,使用索引的效率會更好。
案例一
點選(此處)摺疊或開啟
-
--執行ap_setup.sh指令碼搭建環境
-
# ap_setup.sh指令碼
-
# !/bin/bash
-
sqlplus / as sysdba <<EOF
-
-
alter user sh identified by sh account unlock;
-
grant dba to sh;
-
exit;
-
EOF
-
-
--以SH登入,執行指令碼idx_setup.sql
-
sh@TESTDB11>@idx_setup.sql
-
-- idx_setup.sql
-
DROP TABLE mysales PURGE;
-
CREATE TABLE mysales AS SELECT * FROM sh.sales;
-
INSERT INTO mysales SELECT * FROM mysales;
-
COMMIT;
-
INSERT INTO mysales SELECT * FROM mysales;
-
COMMIT;
-
INSERT INTO mysales SELECT * FROM mysales;
-
COMMIT;
-
INSERT INTO mysales SELECT * FROM mysales;
-
COMMIT;
-
INSERT INTO mysales SELECT * FROM mysales;
-
COMMIT;
-
INSERT INTO mysales VALUES (0, 0, SYSDATE, 0, 0, 0, 0);
-
COMMIT;
-
-
EXEC dbms_stats.gather_schema_stats(\'SH\');
-
-
--with_and_without_index.sql
-
SET ECHO ON
-
SET TIMING ON
-
SET AUTOTRACE TRACE ONLY
-
SET PAGESIZE 1000
-
-
ALTER SYSTEM FLUSH SHARED_POOL;
-
ALTER SYSTEM FLUSH BUFFER_CACHE;
-
-
select * from mysales where prod_id = 0;
-
-
SET TIMING OFF;
-
SET AUTOTRACE OFF;
-
-
--執行with_and_without_index.sql指令碼
-
sh@TESTDB11>@with_and_without_index.sql
-
-
Elapsed: 00:00:41.19
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 3597614299
-
-
-----------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
-----------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 402K| 11M| 40161 (1)| 00:08:02 |
-
|* 1 | TABLE ACCESS FULL| MYSALES | 402K| 11M| 40161 (1)| 00:08:02 |
-
-----------------------------------------------------------------------------
-
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
-
1 - filter(\"PROD_ID\"=0)
-
-
-
Statistics
-
----------------------------------------------------------
-
45 recursive calls
-
1 db block gets
-
142137 consistent gets
-
142055 physical reads
-
0 redo size
-
970 bytes sent via SQL*Net to client
-
523 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
5 sorts (memory)
-
0 sorts (disk)
-
1 rows processed
-
-
-
-- create_mysales_index.sql
-
-
SET ECHO ON
-
CREATE INDEX idx_mysales_prodid on mysales(prod_id) nologging compute statistics;
-
-
--再次執行with_and_without_index.sql指令碼
-
sh@TESTDB11>@with_and_without_index.sql
-
-
Elapsed: 00:00:00.49
-
-
Execution Plan
-
----------------------------------------------------------
-
Plan hash value: 2732191377
-
-
--------------------------------------------------------------------------------------------------
-
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-
--------------------------------------------------------------------------------------------------
-
| 0 | SELECT STATEMENT | | 402K| 11M| 6003 (1)| 00:01:13 |
-
| 1 | TABLE ACCESS BY INDEX ROWID| MYSALES | 402K| 11M| 6003 (1)| 00:01:13 |
-
|* 2 | INDEX RANGE SCAN | IDX_MYSALES_PRODID | 402K| | 821 (1)| 00:00:10 |
-
--------------------------------------------------------------------------------------------------
-
-
Predicate Information (identified by operation id):
-
---------------------------------------------------
-
-
2 - access(\"PROD_ID\"=0)
-
-
-
Statistics
-
----------------------------------------------------------
-
51 recursive calls
-
0 db block gets
-
110 consistent gets
-
21 physical reads
-
0 redo size
-
974 bytes sent via SQL*Net to client
-
523 bytes received via SQL*Net from client
-
2 SQL*Net roundtrips to/from client
-
6 sorts (memory)
-
0 sorts (disk)
-
-
--建立idx_cleanup.sql指令碼,清理環境
-
--idx_cleanup.sql
-
SET ECHO ON
-
DROP TABLE mysales purge;
-
-
--執行idx_cleanup.sql
- sh@TESTDB11>@idx_cleanup.sql
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1072456/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 課程實踐(二)續
- 課程實踐(一)
- 課程實踐(一)續
- 實踐JavaWeb課程專案JavaWeb
- 課程實踐(一)續1
- 作業系統課程實踐報告作業系統
- 武漢專場|第二期《資料安全實踐專題培訓》課程即將開課
- 企業級實戰大資料課程(二)-尹成-專題視訊課程大資料
- 機器學習業務實踐之路-李博-專題視訊課程機器學習
- 軟體工程的實踐專案課程的自我目標軟體工程
- DevOps企業實踐和價值-CSDN公開課-專題視訊課程dev
- 課程報名丨“重大活動”網路安全保障中的攻守實踐
- C#課外實踐——校園二手平臺(心得篇)C#
- 資料採集與融合技術實驗課程作業二
- 我的慕課實戰課程上線了
- 微信小程式前置課程:flex佈局(二)微信小程式Flex
- 大資料公開課系列課程第二季-趙強老師-專題視訊課程大資料
- TDD 實踐-FizzFuzzWhizz(二)
- DHCP最佳實踐(二)
- Python課程程式碼實現Python
- 線上課程|儲存與計算分離,京東在Elasticsearch上的實踐分享Elasticsearch
- [Strata Data Conference培訓課程] Apache Spark高階實踐和原理解析ApacheSpark
- 【課程筆記】中科大凸優化(二)筆記優化
- 北航OS課程筆記--二、系統引導筆記
- C#課外實踐——校園二手平臺(技術篇2)C#
- C#課外實踐——校園二手平臺(技術篇3)C#
- C#課外實踐——校園二手平臺(技術篇1)C#
- Modern PHP(二)良好實踐PHP
- Nginx入門實踐(二)Nginx
- Node with React: Fullstack Web Development 課程手記(二)——Google OAuthReactWebdevGoOAuth
- 企業級實戰大資料課程(一)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(三)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(四)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(五)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(六)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(七)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(八)-尹成-專題視訊課程大資料
- 企業級實戰大資料課程(九)-尹成-專題視訊課程大資料