举例一个比较好的表连接的执行计划

WBOY
풀어 주다: 2016-06-07 15:57:30
원래의
1117명이 탐색했습니다.

SQL var loc varchar2(30)SQL exec :loc:=South San FranciscoPL/SQL procedure successfully completed.SQL SELECT 2 emp.last_name,emp.first_name,j.job_title,d.department_name,l.city,l.state_province,l.postal_code,l.street_address, 3 emp.email,e

SQL> var loc varchar2(30)
SQL> exec :loc:='South San Francisco'

PL/SQL procedure successfully completed.

SQL> SELECT 
  2  emp.last_name,emp.first_name,j.job_title,d.department_name,l.city,l.state_province,l.postal_code,l.street_address,
  3  emp.email,emp.phone_number,emp.hire_date,emp.salary,mgr.last_name
  4  from hr.employees emp,hr.employees mgr,hr.departments d,hr.locations
  5  l,hr.jobs j
  6  where l.city =:loc
  7  and emp.manager_id=mgr.employee_id
  8  and emp.department_id=d.department_id
  9  and d.location_id=l.location_id
 10  and emp.job_id=j.job_id;
--每次都是以嵌套循环来完成整个的查询流程,这就是一个最好的执行计划
45 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 4121168346

<span style="font-size:10px;">-----------------------------------------------------------------------------------------------------
| Id  | Operation                       | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                |                   |    15 |  2580 |     8   (0)| 00:00:01 |
|   1 |  NESTED LOOPS                   |                   |    15 |  2580 |     8   (0)| 00:00:01 |
|   2 |   NESTED LOOPS                  |                   |    15 |  2400 |     6   (0)| 00:00:01 |
|   3 |    NESTED LOOPS                 |                   |    15 |  1995 |     5   (0)| 00:00:01 |
|   4 |     NESTED LOOPS                |                   |     4 |   268 |     3   (0)| 00:00:01 |
|   5 |      TABLE ACCESS BY INDEX ROWID| LOCATIONS         |     1 |    48 |     2   (0)| 00:00:01 |
|*  6 |       INDEX RANGE SCAN          | LOC_CITY_IX       |     1 |       |     1   (0)| 00:00:01 |
|   7 |      TABLE ACCESS BY INDEX ROWID| DEPARTMENTS       |     4 |    76 |     1   (0)| 00:00:01 |
|*  8 |       INDEX RANGE SCAN          | DEPT_LOCATION_IX  |     4 |       |     0   (0)| 00:00:01 |
|   9 |     TABLE ACCESS BY INDEX ROWID | EMPLOYEES         |     4 |   264 |     1   (0)| 00:00:01 |
|* 10 |      INDEX RANGE SCAN           | EMP_DEPARTMENT_IX |    10 |       |     0   (0)| 00:00:01 |
|  11 |    TABLE ACCESS BY INDEX ROWID  | JOBS              |     1 |    27 |     1   (0)| 00:00:01 |
|* 12 |     INDEX UNIQUE SCAN           | JOB_ID_PK         |     1 |       |     0   (0)| 00:00:01 |
|  13 |   TABLE ACCESS BY INDEX ROWID   | EMPLOYEES         |     1 |    12 |     1   (0)| 00:00:01 |
|* 14 |    INDEX UNIQUE SCAN            | EMP_EMP_ID_PK     |     1 |       |     0   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------</span>

Predicate Information (identified by operation id):
---------------------------------------------------

   6 - access("L"."CITY"=:LOC)
   8 - access("D"."LOCATION_ID"="L"."LOCATION_ID")
  10 - access("EMP"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
  12 - access("EMP"."JOB_ID"="J"."JOB_ID")
  14 - access("EMP"."MANAGER_ID"="MGR"."EMPLOYEE_ID")


Statistics
----------------------------------------------------------
       2035  recursive calls
          0  db block gets
        669  consistent gets
         19  physical reads
          0  redo size
       3923  bytes sent via SQL*Net to client
        407  bytes received via SQL*Net from client
          4  SQL*Net roundtrips to/from client
         24  sorts (memory)
          0  sorts (disk)
         45  rows processed
로그인 후 복사

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿