{"id":1559,"date":"2017-08-23T19:51:44","date_gmt":"2017-08-23T19:51:44","guid":{"rendered":"http:\/\/nenadnoveljic.com\/blog\/?p=1559"},"modified":"2018-05-17T16:10:41","modified_gmt":"2018-05-17T16:10:41","slug":"large-tchk-allocations-shared-pool","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/","title":{"rendered":"Large TCHK Allocations in Shared Pool"},"content":{"rendered":"<p>I&#8217;ve noticed large shared pool memory allocations which were caused by a create table as select (CTAS) on a complex view on an Oracle 12.2 database:<\/p>\n<pre><code>create table t as select * from complex_view ;\r\n\r\ncolumn tchk format 999999\r\ncolumn sh format 999999\r\ncolumn pers format 999999\r\nselect typecheck_mem\/1024 TCHK, sharable_mem\/1024 SH, \r\n\tpersistent_mem\/1024 PERS \r\n\tfrom v$sql \r\n\twhere sql_text like '%complex%' ;\r\n\t\r\n   <span style=\"color: #ff0000;\">TCHK<\/span>      SH    PERS\r\n------- ------- -------\r\n <span style=\"color: #ff0000;\">384114<\/span>   67055    5408\r\n<\/code><\/pre>\n<p>The statement has occupied 384 MB just for the typecheck (TCHK) memory. The same allocations have been missing when the query runs standalone.<\/p>\n<pre><code>select \/*+ ALL_ROWS *\/ * from complex_view ;\r\n \r\n   TCHK      SH    PERS\r\n------- ------- -------\r\n      0    6855    4482\r\n<\/code><\/pre>\n<p>The TCHK allocations have also been observed when running a very simple test case:<\/p>\n<pre><code>create table test_table (a number) ;\r\n\r\ncreate table t as select * from test_table ;\r\n\r\n   TCHK      SH    PERS\r\n------- ------- -------\r\n    <span style=\"color: #ff0000;\">126<\/span>      37      71\r\n\r\nselect * from test_table ;\r\n\r\n  TCHK      SH    PERS\r\n------- ------- -------\r\n      0      19       6\r\n<\/code><\/pre>\n<p>Furthermore, the CHK allocations have been confirmed by a SGA heap dump processed by <a href=\"http:\/\/blog.tanelpoder.com\/about-2\/\" target=\"_blank\" rel=\"noopener\">Tanel Poder&#8217;s<\/a> <a href=\"http:\/\/blog.tanelpoder.com\/files\/scripts\/heapdump_analyzer\" target=\"_blank\" rel=\"noopener\">heapdump_analyzer<\/a>:<\/p>\n<pre><code>  Total_size #Chunks  Chunk_size,        From_heap,       Chunk_type,  Alloc_reason\r\n  ---------- ------- ------------ ----------------- ----------------- -----------------\r\n      <span style=\"color: #ff0000;\">101400<\/span>   25       4056 ,    SQLA^8012fc2a,         freeable,  <span style=\"color: #ff0000;\">TCHK<\/span>^8012fc2a  \r\n       <span style=\"color: #ff0000;\">25056<\/span>    6       4176 ,    SQLA^8012fc2a,         freeable,  <span style=\"color: #ff0000;\">TCHK<\/span>^8012fc2a  \r\n        8112    2       4056 ,    SQLA^8012fc2a,         freeable,  qbcqtcHTHeap   \r\n        <span style=\"color: #ff0000;\">4056<\/span>    1       4056 ,    SQLA^8012fc2a,         recreate,  <span style=\"color: #ff0000;\">TCHK<\/span>^8012fc2a  \r\n<\/code><\/pre>\n<p>By counting user stacks within the Oracle SGA memory allocation functions with DTrace we can find out functions which cause most memory allocation calls.<\/p>\n<pre><code>#pragma D option dynvarsize=64m\r\n\r\npid$target::kghalo:entry,\r\npid$target::kghalf:entry,\r\npid$target::kghalp:entry\r\n{\r\n  @ustacks[ustack(100)] = count();\r\n  @total = count() ;\r\n}\r\n<\/code><\/pre>\n<p>CTAS has made an order of magnitude more memory allocation calls than the query alone, 26&#8217;471 and 1&#8217;576 respectively, even for such a simple query, .<\/p>\n<p>The function <em>kksFullTypeCheck<\/em> stands out in the flame graph as a significant contributor to the sga memory allocation calls:<\/p>\n<p><em>Note: The flame graph is 1.41M large. It might take some time to open the file. Click <a href=\"http:\/\/nenadnoveljic.com\/blog\/wp-content\/uploads\/2017\/08\/ustacks_ctas.svg\" target=\"_blank\" rel=\"noopener\">here<\/a> to open the file in a new browser tab.<\/em><\/p>\n<p>This function has never been invoked when the select was executed.<\/p>\n<p>Finally, I measured the typecheck memory consumption in 11.2.0.3.7 for ctas. It allocated 86K compared to 126K in 12.2.<\/p>\n<p>Last but not least, if the problem becomes excesive, you can first create the table and then insert the rows with a <em>insert into table select &#8230;<\/em> as a workaround.<\/p>\n<p>Related articles:<\/p>\n<p><a href=\"http:\/\/nenadnoveljic.com\/blog\/ora-04036-parsing\/\" target=\"_blank\" rel=\"noopener\">Large Memory Allocations due to Query Parsing<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Large TCHK allocations in shared pool caused by create table as select <a href=\"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/\" 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":[11,24,5,20],"tags":[],"class_list":["post-1559","post","type-post","status-publish","format-standard","hentry","category-cost-based-optimizer","category-dtrace","category-oracle","category-slow-parsing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Large TCHK Allocations in Shared Pool - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"Large TCHK allocations in shared pool caused by create table as select\" \/>\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\/large-tchk-allocations-shared-pool\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Large TCHK Allocations in Shared Pool - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Large TCHK allocations in shared pool caused by create table as select\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-23T19:51:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-17T16:10:41+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Large TCHK Allocations in Shared Pool\",\"datePublished\":\"2017-08-23T19:51:44+00:00\",\"dateModified\":\"2018-05-17T16:10:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/\"},\"wordCount\":246,\"commentCount\":0,\"articleSection\":[\"cost based optimizer\",\"DTrace\",\"Oracle\",\"slow parsing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/\",\"name\":\"Large TCHK Allocations in Shared Pool - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2017-08-23T19:51:44+00:00\",\"dateModified\":\"2018-05-17T16:10:41+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"Large TCHK allocations in shared pool caused by create table as select\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/large-tchk-allocations-shared-pool\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Large TCHK Allocations in Shared Pool\"}]},{\"@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":"Large TCHK Allocations in Shared Pool - All-round Database Topics","description":"Large TCHK allocations in shared pool caused by create table as select","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\/large-tchk-allocations-shared-pool\/","og_locale":"en_US","og_type":"article","og_title":"Large TCHK Allocations in Shared Pool - All-round Database Topics","og_description":"Large TCHK allocations in shared pool caused by create table as select","og_url":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/","og_site_name":"All-round Database Topics","article_published_time":"2017-08-23T19:51:44+00:00","article_modified_time":"2018-05-17T16:10:41+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Large TCHK Allocations in Shared Pool","datePublished":"2017-08-23T19:51:44+00:00","dateModified":"2018-05-17T16:10:41+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/"},"wordCount":246,"commentCount":0,"articleSection":["cost based optimizer","DTrace","Oracle","slow parsing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/","url":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/","name":"Large TCHK Allocations in Shared Pool - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2017-08-23T19:51:44+00:00","dateModified":"2018-05-17T16:10:41+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"Large TCHK allocations in shared pool caused by create table as select","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/large-tchk-allocations-shared-pool\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Large TCHK Allocations in Shared Pool"}]},{"@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\/1559","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=1559"}],"version-history":[{"count":2,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1559\/revisions"}],"predecessor-version":[{"id":1568,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/1559\/revisions\/1568"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=1559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=1559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=1559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}