{"id":1416,"date":"2017-02-20T15:14:52","date_gmt":"2017-02-20T13:14:52","guid":{"rendered":"http:\/\/www.ora-solutions.net\/web\/?p=1416"},"modified":"2017-02-20T15:22:04","modified_gmt":"2017-02-20T13:22:04","slug":"oracle-database-result-cache-troubleshooting","status":"publish","type":"post","link":"https:\/\/www.ora-solutions.net\/web\/2017\/02\/20\/oracle-database-result-cache-troubleshooting\/","title":{"rendered":"Oracle Database Result Cache Troubleshooting"},"content":{"rendered":"<p>I was troubleshooting an issue where the Oracle Database Result Cache did not get used when the RESULT_CACHE hint was specified inside a subquery. As the main query has a sysdate inside, the RESULT_CACHE Hint can not be specified for the main query, but only for the subquery.<\/p>\n<pre lang=\"SQL\" line=\"1\">\r\nselect SQ.*, sysdate from\r\n(select * from tableX, ....) SQ;\r\n<\/pre>\n<p>When using &#8220;\/*+ RESULT_CACHE *\/ inside of Subquery, result cache was not enabled.<\/p>\n<pre lang=\"SQL\" line=\"1\">\r\n\r\nselect SQ.*, sysdate from\r\n(select \/*+ RESULT_CACHE *\/ * from tableX, ....) SQ;\r\n<\/pre>\n<p>I found out that there is a trace event which can be set for diagnostics.<\/p>\n<pre lang=\"SQL\" line=\"1\">\r\nALTER SESSION SET EVENTS '43905 trace name context forever, level 1';\r\n<\/pre>\n<p>This generated a trace file containing a clue to the reason:<\/p>\n<pre lang=\"SQL\" line=\"1\">\r\nQKSRC: ViewText[ecode=942] = SELECT  \/*+ RESULT_CACHE *\/ ......<\/pre>\n<p>So, it seemed that there was an internal<strong> ORA-942<\/strong> somewhere that prevented result caching from being used. The solution was to qualify the objects inside the subquery. Now the result cache was used correctly:<\/p>\n<pre lang=\"SQL\" line=\"1\">\r\nselect SQ.*, sysdate from\r\n(select \/*+ RESULT_CACHE *\/ * from ownerY.tableX, ....)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was troubleshooting an issue where the Oracle Database Result Cache did not get used when the RESULT_CACHE hint was specified inside a subquery. As the main query has a sysdate inside, the RESULT_CACHE Hint can not be specified for the main query, but only for the subquery. select SQ.*, sysdate from (select * from [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[58,5],"tags":[],"class_list":["post-1416","post","type-post","status-publish","format-standard","hentry","category-12c","category-oracle-database"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/posts\/1416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/comments?post=1416"}],"version-history":[{"count":10,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/posts\/1416\/revisions"}],"predecessor-version":[{"id":1426,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/posts\/1416\/revisions\/1426"}],"wp:attachment":[{"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/media?parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/categories?post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ora-solutions.net\/web\/wp-json\/wp\/v2\/tags?post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}