|
EXPLAIN PLAN À̶õ »ç¿ëÀÚµéÀÌ SQL ¹®ÀÇ ¾×¼¼½º °æ·Î¸¦ È®ÀÎÇÏ°í
Æ©´×À» ÇÒ ¼ö ÀÖµµ·Ï SQL ¹®À» ºÐ¼®ÇÏ°í Çؼ®ÇÏ¿© ½ÇÇà °èȹÀ» ¼ö¸³ÇÑ ÈÄ
½ÇÇà °èȹÀ» Å×À̺í(plan_table) ¿¡ ÀúÀåÇϵµ·Ï ÇØÁÖ´Â ¸í·ÉÀÌ´Ù.
1. Plan_table »ý¼º
Explain plan À» sql ¿¡ Æ÷ÇÔÇؼ ¼öÇàÇÏ¸é ¿ÉƼ¸¶ÀÌÀú°¡ ½ÇÇà °èȹ±îÁö¸¸
¼ö¸³ÇÏ¿© plan_table¿¡ ÀúÀåÇØ µÐ´Ù.
ÀÌ tableÀ» »ý¼ºÇϱâ À§ÇÑ script´Â ?/rdbms/admin/utlxplan.sql ÀÌ´Ù.
2. Index »ý¼º
Å×ÀÌºí »ý¼º ÈÄ ¼öÇà ¼Óµµ Çâ»ó°ú µ¿ÀÏÇÑ statement_id°¡ »ý¼ºµÇ´Â °ÍÀ»
¹æÁöÇϱâ À§ÇØ index¸¦ »ý¼ºÇÑ´Ù.
SQL> create unique index plan_index on plan_table(statement_id,id);
3. SQL ¹® »ç¿ë
for µÞºÎºÐ¿¡ È®ÀÎÇÏ°íÀÚ ÇÏ´Â sqlÀ» ´ëÄ¡ÇÑ´Ù.
EXPLAIN PLAN SET STATEMENT_ID='a1' FOR
SELECT /*+ index(free_idx free) */ * from free;
4. Plan_table À» select ÇÏ´Â SQL ¹® (plan.sqlÀ̶ó°í ÀÛ¼º)
Select lpad(operation,length(operation)+ 2*(level-1)) ||decode(id,0,'cost
estimate:' ||
decode(position,'0','N/A',position),null) || ' ' ||options || decode(object_name,null,null,':') ||
rpad(object_owner, length(object_name)+1,',') || object_name ||
decode (object_type,'UNIQUE' ,'(U) ','NON_UNIQUE','(NU)',null) ||
decode(object_instance,null,null,'('||object_instance||')')
FROM PLAN_TABLE
START WITH ID= 0 and STATEMENT_ID = '&&id'
CONNECT by prior ID=PARENT_ID and STATEMENT_ID='&&id'
5. Explain plan ¹®ÀÇ 'statement_id =' ¿¡¼ ºÎ¿©ÇÑ Á¦¸ñÀ» 'id'¿¡ ÁöÁ¤ÇÏ°í ´ÙÀ½Ã³·³
½ÇÇàÇÑ´Ù.
sql> def id = a1
sql> @plan
6. ´ÙÀ½Àº SQL*Plus ¿¡¼ ÀÚµ¿À¸·Î Explain PlanÀ» CreationÇÏ´Â ¹æ¹ýÀÌ´Ù.
ÀÌ ¹æ¹ýÀº ExplainÀ» ½ÇÇàÇÏ´Â ±¸¹®À» ±â¾ïÇÒ ÇÊ¿ä ¾øÀÌ ÇöÀç ¼öÇàÇÏ´Â
SQL ¹®ÀåÀ» ½±°Ô üũÇØ º¼ ¼ö ÀÖ´Ù.
ÀÌ°ÍÀ» ¼öÇàÇϱâ Àü¿¡ plan_tableÀÌ »ý¼ºµÇ¾î ÀÖÁö ¾Ê´Ù¸é »ç¿ëÇÏ°íÀÚ ÇÏ´Â
user·Î sqlplus loginÇÑ ÈÄ $ORACLE_HOME/rdbms/admin/utlxplan.sqlÀ» ¼öÇàÇÏ¿© plan_tableÀ» »ý¼ºÇÑ´Ù.
´ÙÀ½ÀÌ script ÀÇ ³»¿ëÀÌ´Ù.
´Ü, À̶§ --·Î ½ÃÀÛÇÏ´Â comment·Î ÀÎÇØ error°¡ ¹ß»ýÇÏ´Â ¼öµµ ÀÖÀ¸¹Ç·Î,
¿À·ù°¡ ¹ß»ýÇϸé --·Î ½ÃÀÛÇÏ´Â comment¸¦ ¸ðµÎ Á¦°ÅÇÏ°í ¼öÇàÇÏ¸é µÈ´Ù.
save toto repl -- Save current script
truncate table plan_table; -- Clean Plan Table
get toto nolist -- Restore script
1 -- setup explain statement
-- ¿µ¹®ÀÚ lÀÌ ¾Æ´Ï°í ¼ýÀÚ 1ÀÌ´Ù.
ch //explain plan set statement_id='MyTest' for /
/
-- Go!
select lpad(' ',2*(level-1))|| operation||' '||
options||' '||object_name||
' '||object_type||' '||object_instance||' '||
decode(id,0,'Cost = '||position) "Query Plan"
from plan_table
start with id = 0 -- start with statement_id = 'MyTest'
connect by prior id = parent_id;
get toto nolist -- Restore script
EXAMPLE:
À§ÀÇ script ¸¦ 'plan.sql' À̶ó´Â ÈÀÏ·Î ÀúÀåÇÑ ÈÄ SQL*Plus¸¦ login ÇÑ´Ù.
SQL) select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL) @plan
Wrote file toto
Table truncated.
|