/*+ full(table name)*/ optimization details in oracle

hint keyword: / + full (table name) /

  • Generally speaking, when sql is optimized, try to use index, but not absolutely
  • Sometimes, a full table scan is more efficient than an index
'索引''全表扫描' 的区别:
1. '索引' 就是 '目录',一本词典使用 '目录' 查字会块些
2. 但是若只有两页还是一眼扫过去更快些

如果玩过 LOL 这种游戏,也可以理解为
如果你距离血池就 5 码的距离,你还会选择回城吗?肯定是走过去更快些啦~

Actual application:

  • When the query sql time range is long
  • When the index (execution plan) is used in sql, the query is still very slow

Description:

表名
	(1) 若表有 '别名',则是 '别名'
	(2) 若表没有 '别名',则是 '表名' 全称

Example:

SELECT /*+ full(t)*/
       *
  FROM scott.emp t
 WHERE t.empno >= 1

Insert picture description here

Possible problems

Aliased as "@SELxx"

SQL> select * from table(dbms_xplan.display_cursor(sql_id => 'bsdw1ur9qw6mv',cursor_child_no => 0,format => 'advanced'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
SQL_ID  bsdw1ur9qw6mv, child number 0
-------------------------------------
SELECT *   FROM scott.emp t  WHERE t.empno >= 1
Plan hash value: 169057108
--------------------------------------------------------------------------------
| Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |        |       |       |     2 (100)|
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |    14 |   532 |     2   (0)| 00:0
|*  2 |   INDEX RANGE SCAN          | PK_EMP |    14 |       |     1   (0)| 00:0
--------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / T@SEL$1
   2 - SEL$1 / T@SEL$1
PLAN_TABLE_OUTPUT

Explanation:

1. T : 表别名
2. @SETL$1 数据块别名

说明:我们一般只需要关注 '表别名' 即可。
	 '数据块别名' Oracle 系统自行维护

Guess you like

Origin blog.csdn.net/qq_34745941/article/details/97259853