The AskTOM team is taking a break over the holiday season, so we're not taking questions or responding to comments. Please have a happy and safe festive season and as always, thanks for being a member of the AskTOM community.
Thanks for the question, Ionut.
Asked: March 20, 2018 - 3:38 pm UTC
Last updated: March 21, 2018 - 11:36 am UTC
Version: 12c
Viewed 10K+ times! This question is
FIRST_ROWS EXPMA 851.120.01
(n)
SQL> create table t as select * from dba_Objects; Table created. SQL> create index ix on t ( owner ); Index created. SQL> exec dbms_stats.gather_table_stats('','T',method_opt=>'for all columns size 200'); PL/SQL procedure successfully completed. SQL> SQL> set autotrace traceonly explain SQL> select * from t where owner = 'SYS'; Execution Plan ---------------------------------------------------------- Plan hash value: 1601196873 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 51685 | 6662K| 427 (1)| 00:00:01 | |* 1 | TABLE ACCESS FULL| T | 51685 | 6662K| 427 (1)| 00:00:01 | -------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("OWNER"='SYS') SQL> select /*+ first_rows(1) */ * from t where owner = 'SYS'; Execution Plan ---------------------------------------------------------- Plan hash value: 3947747388 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 132 | 2 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 132 | 2 (0)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IX | | | 1 (0)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OWNER"='SYS') SQL> select /*+ first_rows */ * from t where owner = 'SYS'; Execution Plan ---------------------------------------------------------- Plan hash value: 3947747388 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 51685 | 6662K| 1522 (1)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 51685 | 6662K| 1522 (1)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IX | 51685 | | 119 (1)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OWNER"='SYS') SQL> select /*+ first_rows other comments */ * from t where owner = 'SYS'; Execution Plan ---------------------------------------------------------- Plan hash value: 3947747388 -------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 51685 | 6662K| 1522 (1)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 51685 | 6662K| 1522 (1)| 00:00:01 | |* 2 | INDEX RANGE SCAN | IX | 51685 | | 119 (1)| 00:00:01 | -------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OWNER"='SYS') SQL> SQL> SQL>
The Oracle documentation contains a complete SQL reference.