{
  "date": "2014-10-29T10:06:09",
  "slug": "oracle-cloud-control-sql-details-statistics",
  "link": "https://www.dbi-services.com/blog/oracle-cloud-control-sql-details-statistics/",
  "title": {
    "rendered": "Oracle cloud control / SQL Details / Statistics"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nA question that I had several times: in Enterprise Manager, in the screen about one SQL statement, the &#8216;statistics&#8217; tab shows the number of executions, elapsed time, etc. Question is: which time window does it cover? There is a one hour chart above, and two timestamps displayed as &#8216;First Load Time&#8217; and &#8216;Last load Time&#8217;, and we don&#8217;t know which one is related with the execution statistics numbers. I&#8217;ll explain it clearly on an example.</p>\n<p>I&#8217;ll check a query I have on my system which has several cursors, with two different execution plans. And I check from V$SQL because here is where is the most detailed information, and columns are well documented.</p>\n<p>From the <a href=\"http://docs.oracle.com/database/121/REFRN/refrn30246.htm#REFRN30246\">documentation</a>:</p>\n<ul>\n<li>FIRST_LOAD_TIME is the Timestamp of the parent creation time</li>\n<li>LAST_LOAD_TIME is the Time at which the query plan was loaded into the library cache</li>\n</ul>\n<p>It&#8217;s clear that because V$SQL show information about child cursors, the FIRST_LOAD_TIME will be the same for all children.</p>\n<pre class=\"brush: sql; gutter: true; first-line: 1\">SQL&gt; select sql_id,plan_hash_value,executions,first_load_time,last_load_time,last_active_time from v$sql where sql_id='dcstr36r0vz0d' order by child_number\n\nSQL_ID        PLAN_HASH_VALUE EXECUTIONS FIRST_LOAD_TIME     LAST_LOAD_TIME      LAST_ACTIVE_TIME\n------------- --------------- ---------- ------------------- ------------------- -------------------\ndcstr36r0vz0d        17720163         60 2014-10-29/07:01:59 2014-10-29/07:01:59 2014-10-29/13:01:25\ndcstr36r0vz0d      3798950322        102 2014-10-29/07:01:59 2014-10-29/07:03:49 2014-10-29/13:05:54\ndcstr36r0vz0d      3798950322         24 2014-10-29/07:01:59 2014-10-29/07:05:55 2014-10-29/13:05:54\ndcstr36r0vz0d      3798950322          1 2014-10-29/07:01:59 2014-10-29/08:11:19 2014-10-29/08:11:19\ndcstr36r0vz0d      3798950322          1 2014-10-29/07:01:59 2014-10-29/08:29:34 2014-10-29/08:29:34\n</pre>\n<p>The plan with hash value 17720163 has been executed 60 times since 07:01:59. It was the first child cursor (child_number=0) for that parent, so this is why FIRST_LOAD_TIME=LAST_LOAD_TIME</p>\n<p>And, the plan with hash value 3798950322 has been executed 128 times since 07:03:49 by cursors that are not shared but have come to the same plan anyway</p>\n<p>Two remarks:</p>\n<ul>\n<li>FIRST_LOAD_TIME is the same for all children because it is a parent information</li>\n<li>LAST_LOAD_TIME is different for each child and that&#8217;s important because Enterprise Manager don&#8217;t show that detail, aggregating together the children with same execution plan.</li>\n</ul>\n<div>Time to look at the Enterprise Manager screen.</div>\n<div></div>\n<div>I&#8217;m talking about the &#8216;Real Time&#8217;  statistics:</div>\n<div></div>\n<div><a class=\"easyblog-thumb-preview\" title=\"EMLastLoadTime1.png\" href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime1.png\"><img decoding=\"async\" title=\"EMLastLoadTime1.png\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime1.png\" alt=\"EMLastLoadTime1.png\" /></a></div>\n<div></div>\n<div>and I&#8217;ve selected the plan hash value 17720163:</div>\n<div></div>\n<div><a class=\"easyblog-thumb-preview\" title=\"EMLastLoadTime2.png\" href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime2.png\"><img decoding=\"async\" title=\"EMLastLoadTime2.png\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime2.png\" alt=\"EMLastLoadTime2.png\" /></a></div>\n<div></div>\n<div>Ok. So we have 60 executions here. This matches the line in V$SQL. And we know that is it 60 executions since 07:01:59 because both timestamps are the same. No doubt here.</div>\n<div></div>\n<div>Then, let&#8217;s select the other plan hash value from the popup:</div>\n<div></div>\n<div><a class=\"easyblog-thumb-preview\" title=\"EMLastLoadTime3.png\" href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime3.png\"><img decoding=\"async\" title=\"EMLastLoadTime3.png\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime3.png\" alt=\"EMLastLoadTime3.png\" /></a></div>\n<div></div>\n<div>128 executions for this plan. This is what we had when summing the lines from V$SQL. And look at the Shared Cursor Statistics. The number of &#8216;Child Cursors&#8217; is 4 which is what we know. The &#8216;First Load Time&#8217; is the one of the parent.</div>\n<div></div>\n<div>However, what is the &#8216;Last Load Time&#8217; when we know that there are 4 different values in V$SQL for it? Look, they choose the latest one, 08:29:34, and that&#8217;s a good choice according to the name. It&#8217;s the last load time.</div>\n<div></div>\n<div>But what I want to know is the time from which the 128 executions are counted. And that should be the earliest one. In my example, we know from V$SQL what we had 128 executions since 07:03:49 but that timestamp is not displayed here.</div>\n<div></div>\n<div>If you want a date, you should take the &#8216;First Load time&#8217; because it&#8217;s true that there were 128 executions of cursors with that plan hash value since 07:01:59</div>\n<div></div>\n<div>Sometimes the first load time is very old and it would be better to have the MIN(LAST_LOAD_TIME). But anyway if we want better time detail, we can choose the &#8216;Historical&#8217; view instead of the &#8216;Real Time&#8217; one and we have the numbers related with the AWR snapshots.</div>\n<div></div>\n<div>Here is an example for the cursor with plan hash value 17720163:</div>\n<div></div>\n<div><a class=\"easyblog-thumb-preview\" title=\"EMLastLoadTime4.png\" href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime4.png\"><img decoding=\"async\" title=\"EMLastLoadTime4.png\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/EMLastLoadTime4.png\" alt=\"EMLastLoadTime4.png\" /></a></div>\n<div></div>\n<div>From the historical view, we select a timestamp, we see the begin and end timestamps. Here I have 10 executions per hour.</div>\n<div></div>\n<div>Everything looks good there, except that &#8216;Child Cursors&#8217; is 5, which is for the whole statement and not only for the cursors selected by the plan hash value.</div>\n<div></div>\n<div>Then I&#8217;ve two conclusions:</div>\n<div>\n<ul>\n<li>&#8216;Last Load Time&#8217; is not useful to know the time window covered by the Real Time statistics. Use First &#8216;Load time instead&#8217;</li>\n<li>In case of any doubt, fall back to V$ views which are much more documented, and give more detail.</li>\n</ul>\n</div>\n",
    "protected": false
  }
}
