【SQL】查詢資料的方式 (二)
如果表查詢中所有的列都包括在了索引中,就有可能使用FFS,當然也可以使用hint來選擇FFS。下面看看使用不同方式訪問索引的例子:
SQL> create index idx_un_tset_ownid_dataid on un_test (owner,data_object_id);
Index created.
Elapsed: 00:00:00.96
SQL> select owner ,data_object_id from un_test
2 where data_object_id >5;
6891 rows selected.
Elapsed: 00:00:00.06
Execution Plan
----------------------------------------------------------
Plan hash value: 287826149
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6913 | 55304 | 32 (4)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| IDX_UN_TSET_OWNID_DATAID | 6913 | 55304 | 32 (4)| 00:00:01 |
------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("DATA_OBJECT_ID">5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
602 consistent gets
135 physical reads
0 redo size
..........
0 sorts (memory)
0 sorts (disk)
6891 rows processed
SQL> select owner ,data_object_id from un_test
2 where data_object_id =5;
no rows selected
Elapsed: 00:00:00.00
Execution Plan
----------------------------------------------------------
Plan hash value: 1786681723
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 21 (0)| 00:00:01 |
|* 1 | INDEX SKIP SCAN | IDX_UN_TSET_OWNID_DATAID | 1 | 8 | 21 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("DATA_OBJECT_ID"=5)
filter("DATA_OBJECT_ID"=5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
15 consistent gets
0 physical reads
。。。。。。
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> select object_id from un_test where object_id = 5;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 333614268
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
|* 1 | INDEX UNIQUE SCAN| I_TEST_UNI | 1 | 5 | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
-------------------------------------------------
1 - access("OBJECT_ID"=5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
2 consistent gets
0 physical reads
。。。。。
0 sorts (disk)
1 rows processed
SQL> select /*+ index_ffs(a)*/ owner,data_object_id from un_test a
2 where wner = 'SYS';
23021 rows selected.
Elapsed: 00:00:00.12
Execution Plan
----------------------------------------------------------
Plan hash value: 287826149
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2668 | 21344 | 32 (4)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| IDX_UN_TSET_OWNID_DATAID | 2668 | 21344 | 32 (4)| 00:00:01 |
-------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OWNER"='SYS')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1674 consistent gets
0 physical reads
。。。。。。。
0 sorts (memory)
0 sorts (disk)
23021 rows processed
----------------
SQL> SELECT /* INDEX(A)*/ OWNER,DATA_OBJECT_ID FROM UN_TEST A
2 WHERE WNER ='SYS';
23021 rows selected.
Elapsed: 00:00:00.12
Execution Plan
----------------------------------------------------------
Plan hash value: 3998526102
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2668 | 21344 | 8 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IDX_UN_TSET_OWNID_DATAID | 2668 | 21344 | 8 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("OWNER"='SYS')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
1586 consistent gets
0 physical reads
。。。。。
0 sorts (disk)
23021 rows processed
----------------------------
SQL> select /*+ index (a idx_un_test_ownid_dataid)*/ count(*) from un_test a
2 where data_object_id = 5;
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 1636324484
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 21 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 2 | | |
|* 2 | INDEX SKIP SCAN| IDX_UN_TSET_OWNID_DATAID | 1 | 2 | 21 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("DATA_OBJECT_ID"=5)
filter("DATA_OBJECT_ID"=5)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
15 consistent gets
0 physical reads
。。。。。
0 sorts (disk)
1 rows processed
---點陣圖索引。。
SQL> select /*+ index(a idx_type_bit)*/ * from un_test a
2 where a.object_type ='TABLE';
2921 rows selected.
Elapsed: 00:00:00.05
Execution Plan
----------------------------------------------------------
Plan hash value: 4191918535
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1779 | 161K| 194 (0)| 00:00:03 |
| 1 | TABLE ACCESS BY INDEX ROWID | UN_TEST | 1779 | 161K| 194 (0)| 00:00:03 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
|* 3 | BITMAP INDEX SINGLE VALUE | IDX_TYPE_BIT | | | | |
---------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("A"."OBJECT_TYPE"='TABLE')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
347 consistent gets
1 physical reads
0 sorts (memory)
0 sorts (disk)
2921 rows processed
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-673844/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【SQL】查詢資料的方式 (一)SQL
- oracle資料庫sql查詢檢視第二次查詢很慢Oracle資料庫SQL
- 查詢所有資料字典的SQLSQL
- 【資料結構】折半查詢(二分查詢)資料結構
- SQL Server 跨資料庫查詢SQLServer資料庫
- 【資料庫】sql連表查詢資料庫SQL
- SQL Server實戰四:查詢資料庫的資料SQLServer資料庫
- 資料庫資料的查詢----連線查詢資料庫
- 查詢 JSON 資料結構的 8 種方式JSON資料結構
- 查詢json資料結構的8種方式JSON資料結構
- sql查詢一張表的重複資料SQL
- SQL Server:基於WEB的資料庫查詢SQLServerWeb資料庫
- SQL總結(二)連表查詢SQL
- SQL查詢的:子查詢和多表查詢SQL
- Android SQL資料庫查詢方法 query( )AndroidSQL資料庫
- 優化SQL Server資料庫查詢方法優化SQLServer資料庫
- SQL的資料庫操作:新增、更新、刪除、查詢SQL資料庫
- SQL Server中基於WEB的資料庫查詢SQLServerWeb資料庫
- SQL Server中Table字典資料的查詢SQL示例程式碼SQLServer
- ElasticSearch - 分頁查詢方式二 【scroll】滾動查詢(kibana、Java示例)ElasticsearchJava
- SQL Server 查詢資料庫中所有表資料條數SQLServer資料庫
- 樹狀資料結構儲存方式——查詢篇資料結構
- SSH_hibernate---六種查詢資料庫方式資料庫
- 透過shell指令碼生成查詢表資料的sql指令碼SQL
- 通過shell指令碼生成查詢表資料的sql指令碼SQL
- SQL Server資料庫查詢優化的方法總結SQLServer資料庫優化
- 查詢資料庫隱含引數的sql語句資料庫SQL
- 關於SQL Server資料查詢基本方法的總結SQLServer
- MySQL資料庫:7、SQL常用查詢語句MySql資料庫
- 改進資料庫效能-SQL查詢優化資料庫SQL優化
- 回閃查詢查詢刪除的資料
- Flask——資料的查詢Flask
- 利用資料泵匯出查詢結果(二)
- MySQL - 資料查詢 - 簡單查詢MySql
- B樹查詢,磁碟查詢資料
- 關係型資料庫查詢語言 SQL 和圖資料庫查詢語言 nGQL 對比資料庫SQL
- [SQL Server玩轉Python] 二.T-SQL查詢表格值及Python實現資料分析SQLServerPython
- MySql、SqlServer、Oracle 三種資料庫查詢分頁方式MySqlServerOracle資料庫