{"id":9416,"date":"2016-11-24T20:53:29","date_gmt":"2016-11-24T19:53:29","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/"},"modified":"2016-11-24T20:53:29","modified_gmt":"2016-11-24T19:53:29","slug":"observing-dml-restarts-caused-by-invalidations","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/","title":{"rendered":"Observing DML restarts caused by invalidations"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nUsually, cursor invalidations do not interrupt the current execution of the cursor. You can even drop a table while a query on it is running and the query may end successfully. However some invalidations will throw internal errors that are catch and the cursor execution restarts transparently. I&#8217;ve reproduced one here to show the symptoms: it&#8217;s a different EXEC_SQL_ID so the restarts are not accounted within the same SQL Monitoring.<br \/>\n<!--more--><br \/>\nI had that question because I encountered a SQL Monitoring report where the &#8216;executions&#8217; count of the INSERT operation was more than one. I wondered if it can be a case of DML restart or if DML restart should be accounted in different EXEC_SQL_ID. I got the quick answer from a very reliable source:<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"und\" dir=\"ltr\">Yep!<\/p>\n<p>&mdash; Stefan Koehler (@OracleSK) <a href=\"https:\/\/twitter.com\/OracleSK\/status\/800693437876027392?ref_src=twsrc%5Etfw\">November 21, 2016<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>However for my better understanding, I&#8217;m now reproducing a case of DML restart to show the symptoms on V$SQL and SQL Monitor.<\/p>\n<p>I need a table with some rows:<\/p>\n<pre><code>\nSQL&gt; create table DEMO as select rownum n from xmltable('1 to 3');\nTable created.\n<\/code><\/pre>\n<p>Initially my problem was with an insert into a GTT but now I&#8217;m reproducing the case with a partitioned table:<\/p>\n<pre><code>\nSQL&gt; create table DEMOGTT (n number) partition by hash(n);\nTable created.\n<\/code><\/pre>\n<p>For internal reasons, when a cursor is invalidated after it has acquired a lock on a partition, a DML restart occurs. If you have a doubt, &#8220;oerr ora 14403&#8221; explains that.<\/p>\n<p>The easiest way to invalidate while the cursor is running is to call a function that does it for each row. And as you will see that it can be restarted to infinity I set a timeout timestamp after 30 seconds.<\/p>\n<pre><code>\nSQL&gt; column limit new_value limit\nSQL&gt; select to_char(sysdate+30\/24\/60\/60,'yyyymmddhh24miss') limit from dual;\n&nbsp;\nLIMIT\n--------------\n20161124212154\n&nbsp;\nSQL&gt; create function DEMOSLOW(n number) return number as\n  2    pragma autonomous_transaction;\n  3  begin\n  4   if sysdate &gt; to_date('&amp;limit','yyyymmddhh24miss')\n  5   then\n  6    dbms_stats.gather_table_stats(user,'DEMOGTT',no_invalidate=&gt;false);\n  7   end if;\n  8   return n;\n  9  end;\n 10  \/\nold   4:  if sysdate &lt; to_date(&#039;&amp;limit&#039;,&#039;yyyymmddhh24miss&#039;)\nnew   4:  if sysdate &lt; to_date(&#039;20161124212154&#039;,&#039;yyyymmddhh24miss&#039;)\n&nbsp;\nFunction created.\n<\/code><\/pre>\n<p>Time to run the insert, calling the function for each row:<\/p>\n<pre><code>\nSQL&gt; alter session set statistics_level=all;\nSession altered.\n&nbsp;\nSQL&gt; set timing on time on\n21:21:24 SQL&gt; insert \/*+ monitor *\/ into DEMOGTT select n from DEMO where n=DEMOSLOW(n);\n3 rows created.\n&nbsp;\nElapsed: 00:00:29.30\n21:21:54 SQL&gt; \n<\/code><\/pre>\n<p>This has taken 30 seconds. Without the timeout, it never stops.<\/p>\n<p>Execution plan for last run shows only one &#8216;Start&#8217;:<\/p>\n<pre><code>\n21:21:54 SQL&gt; select * from table(dbms_xplan.display_cursor('','','allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n------------------------------------------------------------------------------------------------------------------------\nSQL_ID  3fk1hyq9vnuzx, child number 0\n-------------------------------------\ninsert \/*+ monitor *\/ into DEMOGTT select n from DEMO where\nn=DEMOSLOW(n)\n&nbsp;\nPlan hash value: 4000794843\n&nbsp;\n----------------------------------------------------------------------------------------------\n| Id  | Operation                | Name    | Starts | E-Rows | A-Rows |   A-Time   | Buffers |\n----------------------------------------------------------------------------------------------\n|   0 | INSERT STATEMENT         |         |      1 |        |      0 |00:00:00.01 |     138 |\n|   1 |  LOAD TABLE CONVENTIONAL | DEMOGTT |      1 |        |      0 |00:00:00.01 |     138 |\n|*  2 |   TABLE ACCESS FULL      | DEMO    |      1 |      1 |      3 |00:00:00.01 |       9 |\n----------------------------------------------------------------------------------------------\n&nbsp;\nPredicate Information (identified by operation id):\n---------------------------------------------------\n&nbsp;\n   2 - filter(\"N\"=\"DEMOSLOW\"(\"N\"))\n<\/code><\/pre>\n<p>This is a proof that DML restarts are not accounted within the same execution. the &#8216;last&#8217; statistics are only from the last restart.<\/p>\n<p>V$SQL accounts only one execution but thousands of invalidations:<\/p>\n<pre><code>\n21:21:54 SQL&gt; select executions,invalidations from v$sql where sql_id='3fk1hyq9vnuzx';\n&nbsp;\nEXECUTIONS INVALIDATIONS\n---------- -------------\n         1          1571\n<\/code><\/pre>\n<p>ASH shows the different SQL_EXEC_ID:<\/p>\n<pre><code>\n21:21:54 SQL&gt; select sample_time,sql_id,sql_exec_id from v$active_session_history where sql_id='3fk1hyq9vnuzx' and sample_time&gt;sysdate-10\/24\/60\/60 order by sample_time desc;\n&nbsp;\nSAMPLE_TIME                                                                 SQL_ID        SQL_EXEC_ID\n--------------------------------------------------------------------------- ------------- -----------\n24-NOV-16 09.21.53.773 PM                                                   3fk1hyq9vnuzx    16778774\n24-NOV-16 09.21.51.773 PM                                                   3fk1hyq9vnuzx\n24-NOV-16 09.21.48.773 PM                                                   3fk1hyq9vnuzx    16778501\n24-NOV-16 09.21.46.773 PM                                                   3fk1hyq9vnuzx    16778396\n24-NOV-16 09.21.45.773 PM                                                   3fk1hyq9vnuzx    16778341\n<\/code><\/pre>\n<p>and SQL Monitoring see different executions:<\/p>\n<pre><code>\n21:21:54 SQL&gt; select sql_id,sql_exec_id,status,last_refresh_time,plan_operation,starts from v$sql_plan_monitor where sql_id='3fk1hyq9vnuzx' and plan_line_id=0 order by last_refresh_time desc fetch first 10 rows only;\n&nbsp;\nSQL_ID        SQL_EXEC_ID STATUS              LAST_REFRESH_TI PLAN_OPERATION                     STARTS\n------------- ----------- ------------------- --------------- ------------------------------ ----------\n3fk1hyq9vnuzx    16778762 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778765 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778767 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778766 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778771 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778769 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778764 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778770 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778763 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n3fk1hyq9vnuzx    16778768 DONE                24-nov 21:21:53 INSERT STATEMENT                        1\n<\/code><\/pre>\n<p>So those are the symptoms of DML restart. And my initial problem is still there:<\/p>\n<ul>\n<li>This test case does not reproduce the issue on a GTT<\/li>\n<li>My issue on the GTT had only one SQL_EXEC_ID with multiple &#8216;starts&#8217; of the plan operations.<\/li>\n<\/ul>\n<blockquote class=\"twitter-tweet\" data-width=\"500\" data-dnt=\"true\">\n<p lang=\"en\" dir=\"ltr\"><a href=\"https:\/\/twitter.com\/hashtag\/sqlmon?src=hash&amp;ref_src=twsrc%5Etfw\">#sqlmon<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/puzzled?src=hash&amp;ref_src=twsrc%5Etfw\">#puzzled<\/a><br \/>I expected to see &#39;1&#39; as &#39;executions for the first line of a plan,<br \/>Here I have executions with 1,12,19,64&#8230; ?!? <a href=\"https:\/\/t.co\/yHPZXDprgX\">pic.twitter.com\/yHPZXDprgX<\/a><\/p>\n<p>&mdash; Franck Pachot (@FranckPachot) <a href=\"https:\/\/twitter.com\/FranckPachot\/status\/800678031908110336?ref_src=twsrc%5Etfw\">November 21, 2016<\/a><\/p><\/blockquote>\n<p><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n<p>Any comments greatly appreciated \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . Usually, cursor invalidations do not interrupt the current execution of the cursor. You can even drop a table while a query on it is running and the query may end successfully. However some invalidations will throw internal errors that are catch and the cursor execution restarts transparently. I&#8217;ve reproduced one here [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229],"tags":[96,44],"type_dbi":[],"class_list":["post-9416","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","tag-oracle","tag-troubleshooting"],"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>Observing DML restarts caused by invalidations - 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\/observing-dml-restarts-caused-by-invalidations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Observing DML restarts caused by invalidations\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . Usually, cursor invalidations do not interrupt the current execution of the cursor. You can even drop a table while a query on it is running and the query may end successfully. However some invalidations will throw internal errors that are catch and the cursor execution restarts transparently. I&#8217;ve reproduced one here [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-24T19:53:29+00:00\" \/>\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=\"4 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\/observing-dml-restarts-caused-by-invalidations\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Observing DML restarts caused by invalidations\",\"datePublished\":\"2016-11-24T19:53:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\"},\"wordCount\":395,\"commentCount\":0,\"keywords\":[\"Oracle\",\"Troubleshooting\"],\"articleSection\":[\"Database Administration &amp; Monitoring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\",\"name\":\"Observing DML restarts caused by invalidations - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2016-11-24T19:53:29+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Observing DML restarts caused by invalidations\"}]},{\"@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":"Observing DML restarts caused by invalidations - 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\/observing-dml-restarts-caused-by-invalidations\/","og_locale":"en_US","og_type":"article","og_title":"Observing DML restarts caused by invalidations","og_description":"By Franck Pachot . Usually, cursor invalidations do not interrupt the current execution of the cursor. You can even drop a table while a query on it is running and the query may end successfully. However some invalidations will throw internal errors that are catch and the cursor execution restarts transparently. I&#8217;ve reproduced one here [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/","og_site_name":"dbi Blog","article_published_time":"2016-11-24T19:53:29+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Observing DML restarts caused by invalidations","datePublished":"2016-11-24T19:53:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/"},"wordCount":395,"commentCount":0,"keywords":["Oracle","Troubleshooting"],"articleSection":["Database Administration &amp; Monitoring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/","url":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/","name":"Observing DML restarts caused by invalidations - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2016-11-24T19:53:29+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/observing-dml-restarts-caused-by-invalidations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Observing DML restarts caused by invalidations"}]},{"@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\/9416","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=9416"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/9416\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=9416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=9416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=9416"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=9416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}