Click here to load reader

Execution plans

  • View
    29

  • Download
    0

Embed Size (px)

DESCRIPTION

Execution plans. Lubom ír Andrle lubomir.andrle @ unicorn.eu 6 . přednáška 11 .1 1 .201 3. Agenda. Shrnutí předchozích poznatků … Jak získat exe cution plan Jak umět číst execution plan Metody joinů. Opakování ;). Shrnutí z minulých přednášek - PowerPoint PPT Presentation

Text of Execution plans

Indexy

Execution plansLubomr [email protected]

6. pednka11.11.2013AgendaShrnut pedchozch poznatk Jak zskat execution planJak umt st execution planMetody joinOpakovn ;)Shrnut z minulch pednekExecution plny vznikaj v rmci hard parsuVznikaj na zklad statistikVyslenm nejvhodnjho costuJsou uloeny v library cache (shared pool)pozor: jedno sql me mt nkolik execution plans child cursoryJeden execution plan me bt sdlen rznmi sqlZskn execution planZskn execution planOracle poskytuje 4 metody pro zskn execution planSQL pkazem EXPLAIN PLANDynamick dotaz do performance viewPouze z library cacheAutomatic Workload Repository (AWR)Pomoc aktivace tracing podporyPkaz EXPLAIN PLANStatement SELECT, INSERT, UPDATE, MERGE, DELETE, CREATE TABLE, CREATE INDEX, ALTER INDEXIDNepovinn, identifikuje pkaz v plan tableTablePlan table

Pkaz EXPLAIN PLAN - vstupEXPLAIN PLAN FOR SELECT * FROM T1 WHERE col1 = 10 ORDER BY col2;SELECT * FROM table(dbms_xplan.display);

---------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |---------------------------------------------------------------------------| 0 | SELECT STATEMENT || 5 | 185 | 4 (25) | 00:00:01 || 1 | SORT ORDER BY | | 5 | 185 | 4 (25) | 00:00:01 ||* 2 | TABLE ACCESS FULL| T1 | 5 | 185 | 3 (0) | 00:00:01 |---------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - filter(COL1"=10)Dotaz do performance viewDotaz do library cacheDleit viewv$sql_planPodobn informace jako v plan table v$sql_plan_statisticsInformace o sputn pkazu (Doba bhu, poet dk, )v$sql_workareaPamov nroky dotazuv$sql_plan_statistics_allSlouen pedelch viewPerformance view a display cursor Pro jednodu interpretaci plnPouit package dbms_xplanSELECT * FROM table(dbms_xplan.display_cursor('1hqjydsjbvmwq',0));PLAN_TABLE_OUTPUT------------------------------------------------------------------------------------SQL_ID 1hqjydsjbvmwq, child number 0-------------------------------------SELECT SUM(AMOUNT_SOLD) FROM SALES S, PROMOTIONS P WHERE S.PROMO_ID =P.PROMO_ID AND PROMO_SUBCATEGORY = 'online discount'------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 517 (100)| || 1 | SORT AGGREGATE | | 1 | 30 | | ||* 2 | HASH JOIN | | 913K| 26M| 517 (4)| 00:00:07 ||* 3 | TABLE ACCESS FULL | PROMOTIONS | 23 | 483 | 17 (0)| 00:00:01 || 4 | PARTITION RANGE ALL| | 918K| 8075K| 494 (3)| 00:00:06 || 5 | TABLE ACCESS FULL | SALES | 918K| 8075K| 494 (3)| 00:00:06 |------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - access("S"."PROMO_ID"="P"."PROMO_ID")3 - filter("PROMO_SUBCATEGORY"='online discount')AWRloit zodpovdn za sbr informac souvisejcch s vkonemSlou pro ely self-tuninguPi vytven snmku (snapshot) me AWR sbrat plnyAWR - ukzkaSELECT * FROM table(dbms_xplan.display_awr('1hqjydsjbvmwq'));PLAN_TABLE_OUTPUT------------------------------------------------------------------------------SELECT SUM(AMOUNT_SOLD) FROM SALES S, PROMOTIONS P WHERE S.PROMO_ID =P.PROMO_ID AND PROMO_SUBCATEGORY = 'online discount'------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 517 (100)| || 1 | SORT AGGREGATE | | 1 | 30 | | || 2 | HASH JOIN | | 913K| 26M| 517 (4)| 00:00:07 || 3 | TABLE ACCESS FULL | PROMOTIONS | 23 | 483 | 17 (0)| 00:00:01 || 4 | PARTITION RANGE ALL| | 918K| 8075K| 494 (3)| 00:00:06 || 5 | TABLE ACCESS FULL | SALES | 918K| 8075K| 494 (3)| 00:00:06 |------------------------------------------------------------------------------------Monosti trasovnUdlosti Event 10053Ideln monost pochopen CBO ;)ALTER SESSION SET events '10053 trace name context forever'Pozor ten trace files nen jednoduchEvent 10132Vhodn pro historii vech execution plan vztaench k njakmu moduluAktivovat pouze v opodstatnnch ppadechUdlosti nejsou oficiln podporovny!ten execution planPackage dbms_xplan 1. sekceVstup - prvn sekce

sql_id Pouze v ppad generovn pomoc funkc display_cursor a display_awrchild numberSpolu se sql_id identifikuje child cursorSoust pouze pi pouit display_cursorSQL pkazSQL_ID cmm8zrzv2v2s5, child number 0-------------------------------------SELECT t2.* FROM t t1, t t2 WHERE t1.n = t2.n AND t1.id > 6 AND t2.idBETWEEN 6 AND 19Package dbms_xplan 2. sekceVstup druh sekce

Plan hash value: 1338433605------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 49 (100)| ||* 1 | HASH JOIN | | 14 | 7756 | 49 (3)| 00:00:01 || 2 | TABLE ACCESS BY INDEX ROWID| T | 14 | 7392 | 4 (0)| 00:00:01 ||* 3 | INDEX RANGE SCAN | T_PK | 14 | | 2 (0)| 00:00:01 ||* 4 | TABLE ACCESS FULL | T | 994 | 25844 | 44 (0)| 00:00:01 |------------------------------------------------------------------------------------Package dbms_xplan 2. sekceSloupce (vdy zobrazeny)Id operaceOperationName objektuSloupce (Oracle odhaduje)Rows odhad potu vrcench dk operaceBytes - odhad velikosti dat operaceCost (%CPU) odhad ceny operaceTime odhad dlky trvn operaceA dal Package dbms_xplan 3. sekcePrediktyPredicate Information (identified by operation id):---------------------------------------------------1 - access("T1"."N"="T2"."N")3 - access("T2"."ID">=6 AND "T2"."ID"6)Vztahy Parent - ChildExecution plan je stromov strukturaZachycuje poad sputn operacPlus vztahy mezi operacemiPravidla vztah mezi operacemiRodi m jednoho nebo vce potomkPotomek m prv jednoho rodieOperace bez rodie je vdy koen stromuRodi je vdy ped svmi dtmi (IDparent < IDchild)Ukzka vztahVztahy operac v execution plan---------------------------------------| Id | Operation |---------------------------------------| 1 | UPDATE || 2 | NESTED LOOPS ||* 3 | TABLE ACCESS FULL ||* 4 | INDEX UNIQUE SCAN || 5 | SORT AGGREGATE || 6 | TABLE ACCESS BY INDEX ROWID||* 7 | INDEX RANGE SCAN || 8 | TABLE ACCESS BY INDEX ROWID ||* 9 | INDEX UNIQUE SCAN |---------------------------------------

Optimalizan operace ICOUNT STOPKEYM za kol jakmile je to mon ukonit vykonvnOperace m uren limit

Pozor nap. v ppad Order by klauzuleSELECT * FROM emp WHERE rownum