{"id":1714,"date":"2018-02-25T17:47:37","date_gmt":"2018-02-25T17:47:37","guid":{"rendered":"http:\/\/nenadnoveljic.com\/blog\/?p=1714"},"modified":"2022-02-16T19:53:23","modified_gmt":"2022-02-16T19:53:23","slug":"corruption-alter-table-move-oracle-12-2","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/","title":{"rendered":"Corruption after &#8220;alter table move&#8221; in Oracle 12.2"},"content":{"rendered":"<p>The purpose of this blog post is to warn of a possible data corruption in 12.2. In particular, it occurs when &#8220;alter table move&#8221; command is issued against a table having the following characteristics:<\/p>\n<ul>\n<li>The table contains a user defined type which is declared as NOT INSTANTIABLE and NOT FINAL.<\/li>\n<li>There are at least three classes which inherit from this user defined type.<\/li>\n<\/ul>\n<p>Just in case that such boundary conditions seem non-realistic to you, simply think of how many software vendors out there are using all kinds of OR-mappers and tools for automated data model creation. More often than not, this approach results in way to complex schemes. For instance, you might be left with something like this:<\/p>\n<pre><code>CREATE OR REPLACE TYPE ty_parent AS OBJECT(\n   n1_parent   NUMBER\n)\nNOT INSTANTIABLE NOT FINAL ; \n\nCREATE OR REPLACE TYPE ty_child_1 UNDER ty_parent(\n   VALUE   varchar2(300) \n) FINAL ;\n\nCREATE OR REPLACE TYPE ty_child_2 UNDER ty_parent(\n   VALUE   TIMESTAMP\n) FINAL ;\n\nCREATE OR REPLACE TYPE ty_child_3 UNDER ty_parent(\n   VALUE   number\n) FINAL ;\n\ncreate table t1 ( ty1 ty_parent , n1 number ) ;<\/code><\/pre>\n<p>As a matter of fact, that&#8217;s just an oversimplified model of something I indeed saw in one of our databases.<\/p>\n<p>Anyway, Oracle database stores the object attributes in invisible columns. As you can see below, there is one invisible column for each attribute:<\/p>\n<pre><code>select segment_column_id-1 col, data_type,qualified_col_name \n  from dba_tab_cols where table_name='T1' order by segment_column_id ;\n\nCOL DATA_TYPE    QUALIFIED_COL_NAME\n0   TY_PARENT    TY1\n1   RAW          SYS_TYPEID(\"TY1\")\n<span style=\"color: #ff0000;\">2   NUMBER       \"TY1\".\"N1_PARENT\"\n3   VARCHAR2     TREAT(\"TY1\" AS \"TY_CHILD_1\").\"VALUE\"\n4   TIMESTAMP(0) TREAT(\"TY1\" AS \"TY_CHILD_2\").\"VALUE\"\n5   NUMBER       TREAT(\"TY1\" AS \"TY_CHILD_3\").\"VALUE\"<\/span>\n6   NUMBER       N1<\/code><\/pre>\n<p>Next, I&#8217;ll create a ty_child_1 object and insert it into the table:<\/p>\n<pre><code>insert into t1 values ( <span style=\"color: #ff0000;\">ty_child_1<\/span>( 1, 'AAAAAAAAAAAAAAAA' ) , 1 ) ;\ncommit ;<\/code><\/pre>\n<p>As expected, only the ty_child_1 attribute is initialized:<\/p>\n<pre><code>select \n    dump(TREAT(ty1 AS ty_child_1).VALUE,16),\n    dump(TREAT(ty1 AS ty_child_2).VALUE,16), \n    dump(TREAT(ty1 AS ty_child_3).VALUE,16)\n  from t1 ;\n  \nDUMP(TREAT(TY1ASTY_<span style=\"color: #ff0000;\">CHILD_1<\/span>).VALUE)\n----------------------------------\nDUMP(TREAT(TY1ASTY_CHILD_2).VALUE)\n----------------------------------\nDUMP(TREAT(TY1ASTY_CHILD_3).VALUE)\n----------------------------------\n<span style=\"color: #ff0000;\">Typ=1 Len=16: 41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41<\/span>\nNULL\nNULL\n<\/code><\/pre>\n<p>At this point, I&#8217;ll introduce some turmoil into the database:<\/p>\n<pre><code>alter table t1 move ;<\/code><\/pre>\n<p>Shockingly, the bytes representing the &#8216;AAAAAAAAAAAAAAAA&#8217; string simply wandered from the invisible column ty_child_1 to ty_child_2, even though both of the columns have different data types. (The data type of ty_child_2 is timestamp.)<\/p>\n<pre><code>select \n    dump(TREAT(ty1 AS ty_child_1).VALUE,16),\n    dump(TREAT(ty1 AS <span style=\"color: #ff0000;\">ty_child_2<\/span>).VALUE,16), \n    dump(TREAT(ty1 AS ty_child_3).VALUE,16)\n  from t1 ;\n  \nDUMP(TREAT(TY1ASTY_CHILD_1).VALUE)\n----------------------------------\nDUMP(TREAT(TY1ASTY_CHILD_2).VALUE)\n----------------------------------\nDUMP(TREAT(TY1ASTY_CHILD_3).VALUE)\n----------------------------------\nNULL\n<span style=\"color: #ff0000;\">Typ=180 Len=16: 41,41,41,41,41,41,41,41,41,41,41,41,41,41,41,41<\/span>\nNULL<\/code><\/pre>\n<p>By the way, symbolic block dump also confirms the difference before and after the move:<\/p>\n<p>Before:<\/p>\n<pre><code>col  <span style=\"color: #ff0000;\">3<\/span>: [16]  41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41\ncol  4: *NULL*\ncol  5: *NULL*<\/code><\/pre>\n<p>After:<\/p>\n<pre><code>col  3: *NULL*\ncol  <span style=\"color: #ff0000;\">4<\/span>: [16]  41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41\ncol  5: *NULL*<\/code><\/pre>\n<p>From now on, all kind of weird staff can start happening in the database, like the following ORA-00600 error while performing a hash join:<\/p>\n<pre><code>create table t2 (n1 number) ;\ninsert into t2 values (1) ;\ncommit ;\n\nselect  t1.* from t1,t2 where t1.n1 = t2.n1 ;\nERROR at line 1:\nORA-00600: internal error code, arguments: [rworupo.1], [16], [11], [], [], [], [], [], [], [], [], []\n<\/code><\/pre>\n<p>Or &#8220;ORA-12899: value too large for column&#8221;, like in this case:<\/p>\n<pre><code>create table t3 as select * from t1\n*\nERROR at line 1:\nORA-12899: value too large for column ??? (actual: 16, maximum: 11)<\/code><\/pre>\n<p>In conclusion, this corruption is really nasty. To begin with, it is extremely difficult to associate a symptom with its root cause. And then, database validate wouldn&#8217;t notice anything.<\/p>\n<p>So, better check for any user defined objects and invisible columns in the database before upgrading to 12.2.<\/p>\n<h1>Update August 21st, 2018 &#8211; Affected Tables<\/h1>\n<p>The following query shows the tables that could be corrupted with the &#8220;alter table move&#8221; command:<\/p>\n<pre><code>select c.owner, c.table_name, \n  substr(qualified_col_name,1,instr(qualified_col_name,'\"',1,2)) parent_type\n  from dba_tab_cols c, dba_tables t \n  where hidden_column = 'YES' and virtual_column='NO'\n    and t.owner = c.owner and t.table_name = c.table_name \n    and tablespace_name is not null\n    and qualified_col_name like 'TREAT(%' \n  group by c.owner,c.table_name,\n    substr(qualified_col_name,1,instr(qualified_col_name,'\"',1,2))\n  having count(*) &gt; 2 ;\n  \nOWNER  TABLE_NAME           PARENT_TYPE\n------ -------------------- --------------------\nSYS    KUPC$DATAPUMP_QUETAB TREAT(\"USER_DATA\"\nU      T1                   TREAT(\"TY1\"<\/code><\/pre>\n<p>I recommend running the query above not only before the upgrades but also including it in your routine database checks.<\/p>\n<h1>Update August 28th, 2018 &#8211; Move Online<\/h1>\n<p>Online move causes the corruption too:<\/p>\n<pre><code>alter table t1 move online ;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Alter table move&#8221; might cause a corruption in an Oracle 12.2 databases if user defined types are used. <a href=\"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[22,25,51,5],"tags":[],"class_list":["post-1714","post","type-post","status-publish","format-standard","hentry","category-12-2","category-corruption","category-ora-00600","category-oracle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Corruption after &quot;alter table move&quot; in Oracle 12.2 - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"&quot;Alter table move&quot; might cause a corruption in an Oracle 12.2 databases if user defined types are used.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Corruption after &quot;alter table move&quot; in Oracle 12.2 - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"&quot;Alter table move&quot; might cause a corruption in an Oracle 12.2 databases if user defined types are used.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-25T17:47:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-16T19:53:23+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Corruption after &#8220;alter table move&#8221; in Oracle 12.2\",\"datePublished\":\"2018-02-25T17:47:37+00:00\",\"dateModified\":\"2022-02-16T19:53:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/\"},\"wordCount\":391,\"commentCount\":4,\"articleSection\":[\"12.2\",\"corruption\",\"ORA-00600\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/\",\"name\":\"Corruption after \\\"alter table move\\\" in Oracle 12.2 - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2018-02-25T17:47:37+00:00\",\"dateModified\":\"2022-02-16T19:53:23+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"\\\"Alter table move\\\" might cause a corruption in an Oracle 12.2 databases if user defined types are used.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/corruption-alter-table-move-oracle-12-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Corruption after &#8220;alter table move&#8221; in Oracle 12.2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Corruption after \"alter table move\" in Oracle 12.2 - All-round Database Topics","description":"\"Alter table move\" might cause a corruption in an Oracle 12.2 databases if user defined types are used.","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:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/","og_locale":"en_US","og_type":"article","og_title":"Corruption after \"alter table move\" in Oracle 12.2 - All-round Database Topics","og_description":"\"Alter table move\" might cause a corruption in an Oracle 12.2 databases if user defined types are used.","og_url":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/","og_site_name":"All-round Database Topics","article_published_time":"2018-02-25T17:47:37+00:00","article_modified_time":"2022-02-16T19:53:23+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Corruption after &#8220;alter table move&#8221; in Oracle 12.2","datePublished":"2018-02-25T17:47:37+00:00","dateModified":"2022-02-16T19:53:23+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/"},"wordCount":391,"commentCount":4,"articleSection":["12.2","corruption","ORA-00600","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/","url":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/","name":"Corruption after \"alter table move\" in Oracle 12.2 - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2018-02-25T17:47:37+00:00","dateModified":"2022-02-16T19:53:23+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"\"Alter table move\" might cause a corruption in an Oracle 12.2 databases if user defined types are used.","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/corruption-alter-table-move-oracle-12-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Corruption after &#8220;alter table move&#8221; in Oracle 12.2"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=1714"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1714\/revisions"}],"predecessor-version":[{"id":4169,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1714\/revisions\/4169"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=1714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=1714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=1714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}