Vous êtes sur la page 1sur 4

(//docs.oracle.

com/en/)

SignIn(http://www.oracle.com/webapps/redirect/signon?nexturl=http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9010.htm)

Home(/)/Database(/en/database/database.html)/OracleDatabaseOnlineDocumentation,10gRelease2(10.2)
(../../index.htm)/Administration(../../nav/portal_3.htm)

DatabaseSQLReference
EXPLAINPLAN
Purpose
UsetheEXPLAINPLANstatementtodeterminetheexecutionplanOracleDatabasefollowstoexecutea
specifiedSQLstatement.Thisstatementinsertsarowdescribingeachstepoftheexecutionplanintoa
specifiedtable.YoucanalsoissuetheEXPLAINPLANstatementaspartoftheSQLtracefacility.
Thisstatementalsodeterminesthecostofexecutingthestatement.Ifanydomainindexesaredefined
onthetable,thenuserdefinedCPUandI/Ocostswillalsobeinserted.
ThedefinitionofasampleoutputtablePLAN_TABLEisavailableinaSQLscriptonyourdistribution
media.Youroutputtablemusthavethesamecolumnnamesanddatatypesasthistable.Thecommon
nameofthisscriptisUTLXPLAN.SQL.Theexactnameandlocationdependonyouroperatingsystem.
OracleDatabaseprovidesinformationoncachedcursorsthroughseveraldynamicperformanceviews:

ForinformationontheworkareasusedbySQLcursors,queryV$SQL_WORKAREA.
Forinformationontheexecutionplanforacachedcursor,queryV$SQL_PLAN.
Forexecutionstatisticsateachsteporoperationofanexecutionplanofcachedcursors(for
example,numberofproducedrows,numberofblocksread),queryV$SQL_PLAN_STATISTICS.
Foraselectiveprecomputedjoinoftheprecedingthreeviews,queryV$SQL_PLAN_STATISTICS_ALL.

SeeAlso:
OracleDatabasePerformanceTuningGuide(../../server.102/b14211/ex_plan.htm#PFGRF009)for
informationontheoutputofEXPLAINPLAN,howtousetheSQLtracefacility,andhowto
generateandinterpretexecutionplans
OracleDatabaseReference(../../server.102/b14237/dynviews_part.htm#REFRN003)forinformationon
dynamicperformanceviews

Prerequisites
ToissueanEXPLAINPLANstatement,youmusthavetheprivilegesnecessarytoinsertrowsintoan
existingoutputtablethatyouspecifytoholdtheexecutionplan.
YoumustalsohavetheprivilegesnecessarytoexecutetheSQLstatementforwhichyouare
determiningtheexecutionplan.IftheSQLstatementaccessesaview,thenyoumusthaveprivilegesto
accessanytablesandviewsonwhichtheviewisbased.Iftheviewisbasedonanotherviewthatis
basedonatable,thenyoumusthaveprivilegestoaccessboththeotherviewanditsunderlyingtable.
ToexaminetheexecutionplanproducedbyanEXPLAINPLANstatement,youmusthavetheprivileges
necessarytoquerytheoutputtable.
TheEXPLAINPLANstatementisadatamanipulationlanguage(DML)statement,ratherthanadata
definitionlanguage(DDL)statement.Therefore,OracleDatabasedoesnotimplicitlycommitthe
changesmadebyanEXPLAINPLANstatement.IfyouwanttokeeptherowsgeneratedbyanEXPLAIN
PLANstatementintheoutputtable,thenyoumustcommitthetransactioncontainingthestatement.

SeeAlso:
INSERT (statements_9014.htm#i2163698)andSELECT (statements_10002.htm#i2065646)forinformationonthe
privilegesyouneedtopopulateandquerytheplantable

Syntax
explain_plan::=

Descriptionoftheillustrationexplain_plan.gif(img_text/explain_plan.htm)

Semantics

SETSTATEMENT_IDClause
SpecifyavaluefortheSTATEMENT_IDcolumnfortherowsoftheexecutionplanintheoutputtable.You
canthenusethisvaluetoidentifytheserowsamongothersintheoutputtable.Besuretospecifya
STATEMENT_IDvalueifyouroutputtablecontainsrowsfrommanyexecutionplans.Ifyouomitthis
clause,thentheSTATEMENT_IDvaluedefaultstonull.

INTOtableClause

Specifythenameoftheoutputtable,andoptionallyitsschemaanddatabase.Thistablemustexist
beforeyouusetheEXPLAINPLANstatement.
Ifyouomitschema,thenthedatabaseassumesthetableisinyourownschema.
ThedblinkcanbeacompleteorpartialnameofadatabaselinktoaremoteOracleDatabasewhere
theoutputtableislocated.YoucanspecifyaremoteoutputtableonlyifyouareusingOracleDatabase
distributedfunctionality.Ifyouomitdblink,thenthedatabaseassumesthetableisonyourlocal
database.See"ReferringtoObjectsinRemoteDatabases"(sql_elements009.htm#i27761)forinformationon
referringtodatabaselinks.
IfyouomitINTOaltogether,thenthedatabaseassumesanoutputtablenamedPLAN_TABLEinyour
ownschemaonyourlocaldatabase.

FORstatementClause
SpecifyaSELECT,INSERT,UPDATE,DELETE,CREATETABLE,CREATEINDEX,orALTERINDEX...
REBUILDstatementforwhichtheexecutionplanisgenerated.
NotesonEXPLAINPLAN
ThefollowingnotesapplytoEXPLAINPLAN:

Ifstatementincludestheparallel_clause,thentheresultingexecutionplanwillindicateparallel
execution.However,EXPLAINPLANactuallyinsertsthestatementintotheplantable,sothatthe
parallelDMLstatementyousubmitisnolongerthefirstDMLstatementinthetransaction.This
violatestheOracleDatabaserestrictionofoneparallelDMLstatementinasingletransaction,and
thestatementwillbeexecutedserially.Tomaintainparallelexecutionofthestatements,youmust
commitorrollbacktheEXPLAINPLANstatement,andthensubmittheparallelDMLstatement.
Todeterminetheexecutionplanforanoperationonatemporarytable,EXPLAINPLANmustberun
fromthesamesession,becausethedataintemporarytablesissessionspecific.

Examples
EXPLAINPLANExamples
ThefollowingstatementdeterminestheexecutionplanandcostforanUPDATEstatementandinserts
rowsdescribingtheexecutionplanintothespecifiedplan_tabletablewiththeSTATEMENT_IDvalueof
'RaiseinTokyo':
EXPLAINPLANSETSTATEMENT_ID='RaiseinTokyo'INTOplan_tableFORUPDATE
employeesSETsalary=salary*1.10WHEREdepartment_id=(SELECT
department_idFROMdepartmentsWHERElocation_id=1200)

ThefollowingSELECTstatementqueriestheplan_tabletableandreturnstheexecutionplanandthe
cost:

SELECTLPAD('',2*(LEVEL1))||operationoperation,options,object_name,
positionFROMplan_tableSTARTWITHid=0ANDstatement_id='RaiseinTokyo'
CONNECTBYPRIORid=parent_idANDstatement_id='RaiseinTokyo'

Thequeryreturnsthisexecutionplan:
OPERATIONOPTIONSOBJECT_NAMEPOSITION
UPDATESTATEMENT2UPDATEEMPLOYEES1TABLEACCESSFULL
EMPLOYEES1VIEWindex$_join$_0012HASHJOIN1INDEXRANGESCAN
DEPT_LOCATION_I1XINDEXFASTFULLSCANDEPT_ID_PK2

ThevalueinthePOSITIONcolumnofthefirstrowshowsthatthestatementhasacostof2.
EXPLAINPLAN:PartitionedExample
Thesampletablesh.salesispartitionedonthetime_idcolumn.Partitionsales_q3_2000contains
timevalueslessthanOct.1,2000,andthereisalocalindexsales_time_bixonthetime_idcolumn.
Considerthequery:
EXPLAINPLANFORSELECT*FROMsalesWHEREtime_idBETWEEN:hAND'01OCT
2000'

where:hrepresentsanalreadydeclaredbindvariable.EXPLAINPLANexecutesthisquerywith
PLAN_TABLEastheoutputtable.Thebasicexecutionplan,includingpartitioninginformation,is
obtainedwiththefollowingquery:
SELECToperation,options,partition_start,partition_stop,partition_idFROM
plan_table

Page436of479

(http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9011.htm)
(http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9009.htm)

(http://www.oracle.com/us/legal/index.html)

ContactUs (http://www.oracle.com/us/corporate/contact/index.html)

TermsofUse(http://www.oracle.com/us/legal/terms/index.html)

(http://www.oracle.com/us/legal/privacy/index.html)

Copyright2015,Oracleand/oritsaffiliates.Allrightsreserved.

LegalNotices

YourPrivacyRights

AboutOracle(http://www.oracle.com/corporate/index.html)

(#)

Vous aimerez peut-être aussi