데이터 베이스 MySQL 튜토리얼 如何快速得到真实的执行计划

如何快速得到真实的执行计划

Jun 07, 2016 pm 04:04 PM
create 준비 어떻게 빠른 구현하다 현실 계획

准备工作: create table zbdba as select * from dba_objects;create table zbdba1 as select * from dba_objects;create index zbdba_owner on zbdba(owner);create index zbdba1_owner on zbdba1(owner);exec dbms_stats.gather_table_stats(user, ZBDBA,

准备工作:
create table zbdba as select * from dba_objects;

create table zbdba1 as select * from dba_objects;

create index zbdba_owner on zbdba(owner);

create index zbdba1_owner on zbdba1(owner);

exec dbms_stats.gather_table_stats(user, 'ZBDBA', method_opt => 'FOR ALL COLUMNS SIZE 1');

exec dbms_stats.gather_table_stats(user, 'ZBDBA1', method_opt => 'FOR ALL COLUMNS SIZE 1');
로그인 후 복사
通常我们对于执行时间很长的sql查看执行计划:
explain plan for select zbdba.object_name from zbdba,zbdba1 where zbdba.owner=zbdba1.owner

SCOTT@orcl11g>select plan_table_output from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1287183320

----------------------------------------------------------------------------------------------
| Id  | Operation             | Name         | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |              |   207M|  7330M|       |  1198  (55)| 00:00:15 |
|*  1 |  HASH JOIN            |              |   207M|  7330M|  1272K|  1198  (55)| 00:00:15 |
|   2 |   INDEX FAST FULL SCAN| ZBDBA1_OWNER | 72068 |   422K|       |    48   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL   | ZBDBA        | 72067 |  2181K|       |   288   (1)| 00:00:04 |
----------------------------------------------------------------------------------------------

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

   1 - access("ZBDBA"."OWNER"="ZBDBA1"."OWNER")

15 rows selected.
로그인 후 복사

但是这种执行计划不一定是准确的。那我们怎么能才能快速的得到准确的执行计划呢?

真实的执行计划就是已经执行的sql

那么

select zbdba.object_name from zbdba,zbdba1 where zbdba.owner=zbdba1.owner;

你不需要一直等,ctrl+c中断即可

SCOTT@orcl11g>select sql_text,sql_id,hash_value,child_number from v$sql where sql_text like 'select zbdba.object_name from zbdba,zbdba1 where zbdba.owner=zbdba1.owner%';
SQL_TEXT                                                     SQL_ID                     HASH_VALUE CHILD_NUMBER
------------------------------------------------------------ -------------------------- ---------- ------------
select zbdba.object_name from zbdba,zbdba1 where zbdba.owner fr4g7ypwx5krq              2043857654            0
=zbdba1.owner


SCOTT@orcl11g>select * from table(dbms_xplan.display_cursor('fr4g7ypwx5krq',0,'ALLSTATS LAST'));
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
SQL_ID  fr4g7ypwx5krq, child number 0
-------------------------------------
select zbdba.object_name from zbdba,zbdba1 where
zbdba.owner=zbdba1.owner

Plan hash value: 1287183320

----------------------------------------------------------------------------------
| Id  | Operation             | Name         | E-Rows |  OMem |  1Mem | Used-Mem |
----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT      |              |        |       |       |          |
|*  1 |  HASH JOIN            |              |    207M|  3024K|  1862K| 7066K (0)|
|   2 |   INDEX FAST FULL SCAN| ZBDBA1_OWNER |  72068 |       |       |          |
|   3 |   TABLE ACCESS FULL   | ZBDBA        |  72067 |       |       |          |
----------------------------------------------------------------------------------

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

   1 - access("ZBDBA"."OWNER"="ZBDBA1"."OWNER")

Note
-----
   - Warning: basic plan statistics not available. These are only collected when:
       * hint 'gather_plan_statistics' is used for the statement or
       * parameter 'statistics_level' is set to 'ALL', at session or system level

27 rows selected.
로그인 후 복사
这样就快速从内存中到了真实的执行计划

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

뜨거운 기사 태그

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

5분마다 실행되는 Python 스크립트 5분마다 실행되는 Python 스크립트 Sep 10, 2023 pm 03:33 PM

5분마다 실행되는 Python 스크립트

Linux에서 스크립팅 및 실행을 위해 Python을 사용하는 방법 Linux에서 스크립팅 및 실행을 위해 Python을 사용하는 방법 Oct 05, 2023 am 11:45 AM

Linux에서 스크립팅 및 실행을 위해 Python을 사용하는 방법

SpringBoot와 SpringMVC의 차이점과 비교 이해 SpringBoot와 SpringMVC의 차이점과 비교 이해 Dec 29, 2023 am 09:20 AM

SpringBoot와 SpringMVC의 차이점과 비교 이해

Vue3의 라이프사이클 기능: Vue3의 라이프사이클을 빠르게 마스터하세요 Vue3의 라이프사이클 기능: Vue3의 라이프사이클을 빠르게 마스터하세요 Jun 18, 2023 am 08:20 AM

Vue3의 라이프사이클 기능: Vue3의 라이프사이클을 빠르게 마스터하세요

WordPress 웹사이트 구축 가이드: 개인 웹사이트를 빠르게 구축하기 WordPress 웹사이트 구축 가이드: 개인 웹사이트를 빠르게 구축하기 Mar 04, 2024 pm 04:39 PM

WordPress 웹사이트 구축 가이드: 개인 웹사이트를 빠르게 구축하기

Win11에서 '내 컴퓨터' 경로의 차이점은 무엇입니까? 빨리 찾는 방법! Win11에서 '내 컴퓨터' 경로의 차이점은 무엇입니까? 빨리 찾는 방법! Mar 29, 2024 pm 12:33 PM

Win11에서 '내 컴퓨터' 경로의 차이점은 무엇입니까? 빨리 찾는 방법!

win11 미리보기 프로그램을 종료할 수 없습니다. win11 미리보기 프로그램을 종료할 수 없습니다. Jun 29, 2023 pm 12:04 PM

win11 미리보기 프로그램을 종료할 수 없습니다.

브라우저에서 PHP 코드를 작성하고 코드가 실행되지 않도록 하는 방법은 무엇입니까? 브라우저에서 PHP 코드를 작성하고 코드가 실행되지 않도록 하는 방법은 무엇입니까? Mar 10, 2024 pm 02:27 PM

브라우저에서 PHP 코드를 작성하고 코드가 실행되지 않도록 하는 방법은 무엇입니까?

See all articles