{"id":6939,"date":"2016-01-21T10:33:06","date_gmt":"2016-01-21T09:33:06","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/"},"modified":"2016-01-21T10:33:06","modified_gmt":"2016-01-21T09:33:06","slug":"execution-plan-with-ash","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/","title":{"rendered":"Execution Plan with ASH"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nHere is a query I use when I&#8217;m on a system that has Diagnostic Pack (ASH) but no tuning Pack (SQL Monitor).<br \/>\nIt displays the execution plan with dbms_xplan.display_cursor and adds the % of ASH samples in front of each plan operation.<br \/>\nHere is a small output example. Usual dbms_xplan output but showing the most active operation:<br \/>\n<a href=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH.jpg\" alt=\"CaptureXplanASH\" width=\"1240\" height=\"264\" class=\"alignnone size-full wp-image-6706\" \/><\/a><br \/>\n<!--more--><br \/>\nAs you see, you can quickly focus on the important part of a 3 pages execution plan. The part that is responsible for most of the response time.<\/p>\n<p>Query is here. Customize the first line to filter the statements you want.<\/p>\n<pre><code>\nwith \n \"sql\" as (select SQL_ID,CHILD_NUMBER,PLAN_HASH_VALUE,'' FORMAT from v$sql where sql_id='&amp;1'),\n \"ash\" as (\n          select sql_id,sql_plan_line_id,child_number,sql_plan_hash_value\n          ,round(count(*)\/\"samples\",2) load \n          ,nvl(round(sum(case when session_state='ON CPU' then 1 end)\/\"samples\",2),0) load_cpu\n          ,nvl(round(sum(case when session_state='WAITING' and wait_class='User I\/O' then 1 end)\/\"samples\",2),0) load_io\n          from \"sql\" join\n          (\n            select sql_id,sql_plan_line_id,sql_child_number child_number,sql_plan_hash_value,session_state,wait_class,count(*) over (partition by sql_id,sql_plan_hash_value) \"samples\" \n            FROM V$ACTIVE_SESSION_HISTORY \n          ) using(sql_id,child_number) group by sql_id,sql_plan_line_id,child_number,sql_plan_hash_value,\"samples\"\n ),\n \"plan\" as (\n        -- get dbms_xplan result\n        select \n         sql_id,child_number,n,plan_table_output\n         -- get plan line id from plan_table output\n         ,case when regexp_like (plan_table_output,'^[|][*]? *([0-9]+) *[|].*[|]$') then\n          regexp_replace(plan_table_output,'^[|][*]? *([0-9]+) *[|].*[|]$','\\1') \n          END SQL_PLAN_LINE_ID\n         from (select rownum n,plan_table_output,SQL_ID,CHILD_NUMBER from \"sql\", table(dbms_xplan.display_cursor(\"sql\".SQL_ID,\"sql\".CHILD_NUMBER,\"sql\".FORMAT)))\n )\nselect PLAN_TABLE_OUTPUT||CASE \n       -- ASH load to be displayed\n       WHEN LOAD &gt;0 THEN TO_CHAR(100*LOAD,'999')||'% (' || TO_CHAR(100*LOAD_CPU,'999')||'% CPU'|| TO_CHAR(100*LOAD_IO,'999')||'% I\/O)'\n       -- header\n       WHEN REGEXP_LIKE (PLAN_TABLE_OUTPUT,'^[|] *Id *[|]')  THEN ' %ASH SAMPLES' \n       end plan_table_output\nfrom \"plan\" left outer join \"ash\" using(sql_id,child_number,sql_plan_line_id) order by sql_id,child_number,n \n<\/code><\/pre>\n<p>The idea is to simply parse the PLAN_TABLE_OUTPUT to get the LINE_ID and match that with the ASH SQL_PLAN_LINE_ID which by itself worth the price to buy Diagnostic Pack. Don&#8217;t hesitate to comment for improvement.<br \/>\nOriginally shared on <a href=\"http:\/\/www.dba-village.com\/village\/dvp_scripts.ScriptDetails?ScriptIdA=6108\">dba-village<\/a> as a view to create so it seems that I use it for about 5 years.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . Here is a query I use when I&#8217;m on a system that has Diagnostic Pack (ASH) but no tuning Pack (SQL Monitor). It displays the execution plan with dbms_xplan.display_cursor and adds the % of ASH samples in front of each plan operation. Here is a small output example. Usual dbms_xplan output [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":6941,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[699,451,96],"type_dbi":[],"class_list":["post-6939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database-administration-monitoring","tag-ash","tag-dbms_xplan","tag-oracle"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Execution Plan with ASH - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Execution Plan with ASH\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . Here is a query I use when I&#8217;m on a system that has Diagnostic Pack (ASH) but no tuning Pack (SQL Monitor). It displays the execution plan with dbms_xplan.display_cursor and adds the % of ASH samples in front of each plan operation. Here is a small output example. Usual dbms_xplan output [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-21T09:33:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1240\" \/>\n\t<meta property=\"og:image:height\" content=\"264\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Execution Plan with ASH\",\"datePublished\":\"2016-01-21T09:33:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\"},\"wordCount\":169,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg\",\"keywords\":[\"ASH\",\"dbms_xplan\",\"Oracle\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\",\"name\":\"Execution Plan with ASH - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg\",\"datePublished\":\"2016-01-21T09:33:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg\",\"width\":1240,\"height\":264},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Execution Plan with ASH\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Execution Plan with ASH - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/","og_locale":"en_US","og_type":"article","og_title":"Execution Plan with ASH","og_description":"By Franck Pachot . Here is a query I use when I&#8217;m on a system that has Diagnostic Pack (ASH) but no tuning Pack (SQL Monitor). It displays the execution plan with dbms_xplan.display_cursor and adds the % of ASH samples in front of each plan operation. Here is a small output example. Usual dbms_xplan output [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/","og_site_name":"dbi Blog","article_published_time":"2016-01-21T09:33:06+00:00","og_image":[{"width":1240,"height":264,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg","type":"image\/jpeg"}],"author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Execution Plan with ASH","datePublished":"2016-01-21T09:33:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/"},"wordCount":169,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg","keywords":["ASH","dbms_xplan","Oracle"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/","url":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/","name":"Execution Plan with ASH - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg","datePublished":"2016-01-21T09:33:06+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/CaptureXplanASH-1.jpg","width":1240,"height":264},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/execution-plan-with-ash\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Execution Plan with ASH"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6939","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=6939"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/6939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/6941"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=6939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=6939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=6939"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=6939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}