Вы находитесь на странице: 1из 3

SQL> create table scott.

test as select * from dba_objects;

Table created.

SQL>

SQL> select count(*) from test where object_type='JAVA CLASS';

COUNT(*)
----------
30816

SQL> select count(*) from test where object_type='TEST';

COUNT(*)
----------
0

SQL> explain plan for select count(*) from test where object_type='JAVA CLASS';

Explained.

SQL> select * from table (dbms_xplan.display());

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
Plan hash value: 1950795681

---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 429 (1)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | TABLE ACCESS FULL| TEST | 1995 | 17955 | 429 (1)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
---------------------------------------------------

2 - filter("OBJECT_TYPE"='JAVA CLASS')

14 rows selected.

SQL>
SQL> explain plan for select count(*) from test where object_type='TABLE';

Explained.

SQL> select * from table (dbms_xplan.display());

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
Plan hash value: 1950795681

---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 429 (1)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | TABLE ACCESS FULL| TEST | 1995 | 17955 | 429 (1)| 00:00:01 |
---------------------------------------------------------------------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
---------------------------------------------------

2 - filter("OBJECT_TYPE"='TABLE')

14 rows selected.

SQL>

-> Create index

SQL> select * from table (dbms_xplan.display());

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
Plan hash value: 3434671059

-----------------------------------------------------------------------------------
------------
| Id | Operation | Name | Rows | Bytes | Cost
(%CPU)| Time |
-----------------------------------------------------------------------------------
------------
| 0 | SELECT STATEMENT | | 1995 | 224K| 98
(0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| TEST | 1995 | 224K| 98
(0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | TEST_IN | 1995 | | 6
(0)| 00:00:01 |
-----------------------------------------------------------------------------------
------------

Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------------------------------------
---------------------------------------------------

2 - access("OBJECT_TYPE"='JAVA CLASS')

14 rows selected.