一個查詢不走索引的例子
-- 查詢不走索引的例子,因為不能對NULL進行索引,所有存在null的情況下,查詢不走索引。當指定了索引的欄位為not null的時候,查詢才會走索引。
-- 建立測試用表,並建立索引
SYS@test>create table t11 as select * from dba_objects where object_id is not null;
Table created.
SYS@test>create index idx_object_id11 on t11(object_id);
Index created.
-- 檢視執行計劃,發現是全表掃描,雖然有索引
SYS@test>set autotrace traceonly
SYS@test>select count(*) from t11;
Execution Plan
----------------------------------------------------------
Plan hash value: 4132580237
-------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 340 (1)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| T11 | 98612 | 340 (1)| 00:00:01 |
-------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
- SQL plan baseline "SQL_PLAN_5b92zmgvh38s16d6f1a89" used for this statement
Statistics
----------------------------------------------------------
6 recursive calls
0 db block gets
1329 consistent gets
1245 physical reads
0 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
將索引所在的列,修改為not null。 這樣執行計劃就走索引了。
SYS@test>alter table t11 modify object_id not null;
Table altered.
SYS@test>select count(*) from t11;
Execution Plan
----------------------------------------------------------
Plan hash value: 767390840
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 54 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | INDEX FAST FULL SCAN| IDX_OBJECT_ID11 | 98612 | 54 (0)| 00:00:01 |
---------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
31 recursive calls
4 db block gets
298 consistent gets
193 physical reads
712 redo size
528 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
1 rows processed
SYS@test>
END。 相關文章
- mybatis like 查詢的例子MyBatis
- MySQL 唯一索引範圍查詢鎖下一個記錄的理解MySql索引
- Laravel 關聯查詢 ——一對一 簡單例子Laravel單例
- Oracle 查詢行數很少,為什麼不走索引?Oracle索引
- PMM Query Analytics的查詢分析器怎麼用?典型教學例子一個
- Elasticsearch(三):索引查詢Elasticsearch索引
- elasticsearch之多索引查詢Elasticsearch索引
- Laravel 5 關聯查詢 ——一對 N 簡單例子Laravel單例
- [20180926]查詢相似索引.txt索引
- MongoDB慢查詢與索引MongoDB索引
- MYSQL DQL in 到底會不會走索引&in 範圍查詢引發的思考。MySql索引
- 關於聯合索引,範圍查詢,時間列索引的幾個問題索引
- 不要再問我 in,exists 走不走索引了索引
- SSM框架實現分頁查詢例子SSM框架
- Mysql 巢狀查詢100例子MySql巢狀
- MySQL索引與查詢優化MySql索引優化
- IndexPatternService 模糊查詢索引 fuzzyQuery分析Index索引
- 理解索引(中):MySQL查詢過程和高階查詢索引MySql
- 一個MySQL多表查詢的問題MySql
- TableStore多元索引,大資料查詢的利器索引大資料
- ElasticSearch分片互動過程(建立索引、刪除索引、查詢索引)Elasticsearch索引
- MySQL 覆蓋索引、回表查詢MySql索引
- indexedDB 通過索引查詢資料Index索引
- 一文讀懂MySQL的索引結構及查詢優化MySql索引優化
- AppBoxFuture: 二級索引及索引掃描查詢資料APP索引
- expdp一個例子
- 談談MYSQL索引是如何提高查詢效率的MySql索引
- MyBatis-maven-User例子-根據id查詢UserMyBatisMaven
- Sqlserver自動查詢缺失索引及拼出建立索引的語句的指令碼SQLServer索引指令碼
- MySQL 學習之索引篇和查詢MySql索引
- MySQL 索引及查詢優化總結MySql索引優化
- SnapshotService 查詢快照下所有索引 queryIndicesByRepoAndSnapshotWithIndices分析索引
- 【最佳化】模糊查詢索引問題索引
- SQLServer查詢哪些索引利用率低SQLServer索引
- 索引為什麼能提供查詢效能...索引
- 一個複雜的json例子JSON
- 一個簡單的「IOC」例子
- MySQL 合併查詢union 查詢出的行合併到一個表中MySql