{"id":5751,"date":"2015-10-04T19:24:41","date_gmt":"2015-10-04T17:24:41","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/"},"modified":"2015-10-04T19:24:41","modified_gmt":"2015-10-04T17:24:41","slug":"result-cache-and-12c-fetch-first-n-rows","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/","title":{"rendered":"Result Cache and 12c &#8216;fetch first n rows&#8217;"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"float:right\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51.jpg\" alt=\"2015-10-02 16.45.51\" width=\"300\" height=\"149\" class=\"alignnone size-medium wp-image-4169\" \/> At our bi-annual dbiXchange I was talking with <a href=\"http:\/\/dbi-services.com\/blog\/author\/nicolas-jardot\/\">Nicolas Jardot<\/a> about his presentation on Result Cache (don&#8217;t forget <a href=\"http:\/\/dbi-services.com\/blog\/author\/jerome-witt\/\">J\u00e9rome witt<\/a> session about RC at <a href=\"https:\/\/www.doag.org\/konferenz\/konferenzplaner\/b.php?id=473721&amp;locS=1&amp;q=jerome\">DOAG<\/a>) where he has shown an unexpected behavior on &#8216;fetch first n rows queries&#8217;.<br \/>\nThat behavior &#8211; if it is not a bug &#8211; can also be a good thing when using offset queries.<br \/>\n<!--more--><\/p>\n<h3>The case<\/h3>\n<p>Everything is in the execution plan:<\/p>\n<pre><code>\nPLAN_TABLE_OUTPUT\n---------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  799vsxdg75sm6, child number 0\n-------------------------------------\nselect \/*+ result_cache *\/ * from DEMO order by n fetch first 5 rows only\n&nbsp;\nPlan hash value: 896528075\n&nbsp;\n--------------------------------------------------------------------------------------------------------------------------------\n| Id  | Operation                      | Name                       | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |\n--------------------------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT               |                            |      1 |        |      5 |00:00:02.49 |     376 |    207 |\n|*  1 |  VIEW                          |                            |      1 |    100K|      5 |00:00:02.49 |     376 |    207 |\n|   2 |   RESULT CACHE                 | aanuwt05phj34078f253ht7x0x |      1 |        |    100K|00:00:02.25 |     376 |    207 |\n|   3 |    WINDOW NOSORT               |                            |      1 |    100K|    100K|00:00:01.72 |     376 |    207 |\n|   4 |     TABLE ACCESS BY INDEX ROWID| DEMO                       |      1 |    100K|    100K|00:00:00.99 |     376 |    207 |\n|   5 |      INDEX FULL SCAN           | DEMO_PK                    |      1 |    100K|    100K|00:00:00.25 |     210 |    207 |\n--------------------------------------------------------------------------------------------------------------------------------\n&nbsp;\nPredicate Information (identified by operation id):\n---------------------------------------------------\n   1 - filter(\"from$_subquery$_002\".\"rowlimit_$$_rownumber\"&lt;=5)\n&nbsp;\nResult Cache Information (identified by operation id):\n------------------------------------------------------\n   2 - column-count=4; dependencies=(DEMO.DEMO); attributes=(ordered); name=&quot;select \/*+ result_cache *\/ * from DEMO &quot;\n<\/code><\/pre>\n<p>I want to fetch only the first 5 rows, I access through an index scan so that I don&#8217;t need a sort. Then I expect to read only the 5 first entrie in the index &#8211; only a few blocks.<br \/>\nI want to use the result cache in case I run my query again. That should increase the performance of subsequent runs, but should not decrease the performance of the first run &#8211; except the small overhead to put 5 rows into the result cache.<\/p>\n<p>But look at it again: I&#8217;ve read 100000 rows. The whole table. And 100000 have gone to the result cache:<\/p>\n<pre><code>\nSQL&gt; select id,type,status,cache_id,row_count,name from v$result_cache_objects;\n&nbsp;\n        ID TYPE       STATUS    CACHE_ID                        ROW_COUNT NAME\n---------- ---------- --------- ------------------------------ ---------- ----------------------\n         0 Dependency Published DEMO.DEMO                               0 DEMO.DEMO\n         1 Result     Published a46rp35xsfhzg6ukq622ax96xh         100000 select \/*+ result_cach\n<\/code><\/pre>\n<h3>Good or bad?<\/h3>\n<p>My first idea is that it is a bug. When I put a &#8216;result_cache&#8217; hint, I expect the final result to go to result cache. Not an intermediate one. If I want an intermediate one, I can put the hint in a subquery. Of course, it&#8217;s bad to read all table rows when I explicitly want only 5 ones.<\/p>\n<p>I addition to that, I expected that the behavior here would be the same as when forcing the table result cache mode. But it&#8217;s not the case. Setting &#8216;result_cache (mode force)&#8217; instead of using the result_cache hint caches the final result &#8211; the 5 rows.<br \/>\nLook, when setting both, I&#8217;ve two results going to the cache:<\/p>\n<pre><code>\nSQL&gt; alter table DEMO result_cache (mode force);\nTable altered.\n&nbsp;\nSQL&gt; select \/*+ result_cache *\/ * from DEMO order by n fetch first 5 rows only;\n&nbsp;\n         N          X\n---------- ----------\n         1          1\n         2         .5\n         3         .3\n         4         .3\n         5         .2\n&nbsp;\nSQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  799vsxdg75sm6, child number 0\n-------------------------------------\nselect \/*+ result_cache *\/ * from DEMO order by n fetch first 5 rows only\n&nbsp;\nPlan hash value: 896528075\n&nbsp;\n------------------------------------------------------------------------------------------------------------------------\n| Id  | Operation                       | Name                       | Starts | E-Rows | A-Rows |   A-Time   | Buffers |\n------------------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                |                            |      1 |        |      5 |00:00:02.46 |     376 |\n|   1 |  RESULT CACHE                   | 2j3s6quuam85248yh8458tcprb |      1 |        |      5 |00:00:02.46 |     376 |\n|*  2 |   VIEW                          |                            |      1 |    100K|      5 |00:00:02.46 |     376 |\n|   3 |    RESULT CACHE                 | ch5d2dt62d5n485utqj03pftw2 |      1 |        |    100K|00:00:02.22 |     376 |\n|   4 |     WINDOW NOSORT               |                            |      1 |    100K|    100K|00:00:01.70 |     376 |\n|   5 |      TABLE ACCESS BY INDEX ROWID| DEMO                       |      1 |    100K|    100K|00:00:00.97 |     376 |\n|   6 |       INDEX FULL SCAN           | DEMO_PK                    |      1 |    100K|    100K|00:00:00.24 |     210 |\n------------------------------------------------------------------------------------------------------------------------\n&nbsp;\nPredicate Information (identified by operation id):\n---------------------------------------------------\n   2 - filter(\"from$_subquery$_002\".\"rowlimit_$$_rownumber\" select id,type,status,cache_id,row_count,name from v$result_cache_objects;\n&nbsp;\n        ID TYPE       STATUS    CACHE_ID                        ROW_COUNT NAME\n---------- ---------- --------- ------------------------------ ---------- ----------------------\n         0 Dependency Published DEMO.DEMO                               0 DEMO.DEMO\n      1769 Result     Published 9jdwtku77k9ap60x1anfqsd2ny         100000 select \/*+ result_cach\n      1768 Result     Published b4aa0hncfmd7bcdxnwf4mdyyj0              5 select \/*+ result_cach\n<\/code><\/pre>\n<p>It think it&#8217;s bad. I&#8217;ll open a SR about it.<\/p>\n<h3>Pagination queries and Offset<\/h3>\n<p>When you have hundreds of lines to display to the user, you use pagination: display the first 15 lines with a &#8216;next&#8217; button. Then the user can display the 15 next lines with the &#8216;next&#8217; button, etc.<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"float:left;margin-right:20px\" src=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/Terminal-ibm3486.jpg\" alt=\"Terminal-ibm3486\" width=\"150\" height=\"150\" class=\"alignnone size-thumbnail wp-image-4182\" \/><br \/>\nIn the days where a user had only one screen, that was easy. You run the query, get a cursor, fetch 15 lines from it. When the user press &#8216;next&#8217; function we fetch 15 more lines. Exactly as when you use &#8216;set pause on&#8217; in sqlplus.<br \/>\nThat was perfect. But that changed. Still in client\/server but on Windows, the users were able to run several applications at a time. They can open a cursor, and let it open for hours or even days. Then a new requirement came: a transaction must match the user interaction, or we leave too many resources idle.<br \/>\nIt was even worse with web applications where you can start a use case and never finish it. Or use the &#8216;back&#8217; button the the browser and break the flow of the application. The solution is stateless sessions. But then you can leave the cursor open. Or timeouts, but the user don&#8217;t like to re-start from begining because he has an urgent phone call.<br \/>\n<a href=\"http:\/\/use-the-index-luke.com\/no-offset\" target=\"use-the-index-luke.com\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" style=\"float:left;margin-right:20px\" src=\"http:\/\/dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2015\/10\/no-offset-banner.white_.png\" alt=\"Do not use offset for pagination. Learn why.\" width=\"180\" height=\"150\" class=\"alignnone size-full wp-image-4176\" \/><\/a><br \/>\nWith stateless sessions, you have to re-run the query. Whether you use rownum, row_number() or &#8216;fetch first &#8230; rows&#8217; (see when you need the first_rows() hint in a <a href=\"http:\/\/dbi-services.com\/blog\/oracle-rownum-vs-rownumber-and-12c-fetch-first\/\">previous blog post<\/a>) the problem is that the query for the second fetch will need to read 30 lines and skip the first 15 ones. This is not optimal. More info from Markups Winand at <a href=\"http:\/\/use-the-index-luke.com\/no-offset\" target=\"use-the-index-luke.com\" rel=\"noopener noreferrer\">http:\/\/use-the-index-luke.com\/no-offset<\/a>.<br \/>\nSo the basic advice is: don&#8217;t use offset.<\/p>\n<h3>Result Cache<\/h3>\n<p>However, we can take an advantage of the fact that result cache stores all the rows. The first run will put all rows in result cache and display only the first page. The second run will get the next rows from the result set without the need to re-run the query.<br \/>\nHere is the first page:<\/p>\n<pre><code>\nSQL&gt; variable next number\nSQL&gt; variable offset number\nSQL&gt; exec :offset := 0 ; :next:=5\n&nbsp;\nPL\/SQL procedure successfully completed.\n&nbsp;\nSQL&gt; select \/*+ result_cache *\/ * from DEMO order by n offset :offset rows fetch next :next rows only;\n&nbsp;\n         N          X\n---------- ----------\n         1          1\n         2         .5\n         3         .3\n         4         .3\n         5         .2\n&nbsp;\nSQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  36gjax1bq229s, child number 0\n-------------------------------------\nselect \/*+ result_cache *\/ * from DEMO order by n offset :offset rows\nfetch next :next rows only\n&nbsp;\nPlan hash value: 1397896352\n&nbsp;\n---------------------------------------------------------------------------------------------------------------------------------\n| Id  | Operation                       | Name                       | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |\n---------------------------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                |                            |      1 |        |      5 |00:00:02.51 |     376 |    208 |\n|*  1 |  FILTER                         |                            |      1 |        |      5 |00:00:02.51 |     376 |    208 |\n|*  2 |   VIEW                          |                            |      1 |    100K|      5 |00:00:02.51 |     376 |    208 |\n|   3 |    RESULT CACHE                 | 18fnpv7tfn444bghaxs5mb20kk |      1 |        |    100K|00:00:02.26 |     376 |    208 |\n|   4 |     WINDOW NOSORT               |                            |      1 |    100K|    100K|00:00:01.74 |     376 |    208 |\n|   5 |      TABLE ACCESS BY INDEX ROWID| DEMO                       |      1 |    100K|    100K|00:00:01.00 |     376 |    208 |\n|   6 |       INDEX FULL SCAN           | DEMO_PK                    |      1 |    100K|    100K|00:00:00.25 |     210 |    208 |\n---------------------------------------------------------------------------------------------------------------------------------\n&nbsp;\nPredicate Information (identified by operation id):\n---------------------------------------------------\n&nbsp;\n   1 - filter(:OFFSET=0) THEN FLOOR(TO_NUMBER(TO_CHAR(:OFFSET))) ELSE 0 END +:NEXT)\n   2 - filter((\"from$_subquery$_002\".\"rowlimit_$$_rownumber\"=0) THEN\n              FLOOR(TO_NUMBER(TO_CHAR(:OFFSET))) ELSE 0 END +:NEXT AND \"from$_subquery$_002\".\"rowlimit_$$_rownumber\"&gt;:OFFSET))\n<\/code><\/pre>\n<p>Here is the second page:<\/p>\n<pre><code>\nSQL&gt; exec :offset := 5 ; :next:=5\n&nbsp;\nPL\/SQL procedure successfully completed.\n&nbsp;\nSQL&gt; select \/*+ result_cache *\/ * from DEMO order by n offset :offset rows fetch next :next rows only;\n&nbsp;\n         N          X\n---------- ----------\n         6         .2\n         7         .1\n         8         .1\n         9         .1\n        10         .1\n&nbsp;\nSQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  36gjax1bq229s, child number 0\n-------------------------------------\nselect \/*+ result_cache *\/ * from DEMO order by n offset :offset rows\nfetch next :next rows only\n&nbsp;\nPlan hash value: 1397896352\n&nbsp;\n--------------------------------------------------------------------------------------------------------------\n| Id  | Operation                       | Name                       | Starts | E-Rows | A-Rows |   A-Time   |\n--------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                |                            |      1 |        |      5 |00:00:00.48 |\n|*  1 |  FILTER                         |                            |      1 |        |      5 |00:00:00.48 |\n|*  2 |   VIEW                          |                            |      1 |    100K|      5 |00:00:00.48 |\n|   3 |    RESULT CACHE                 | 18fnpv7tfn444bghaxs5mb20kk |      1 |        |    100K|00:00:00.24 |\n|   4 |     WINDOW NOSORT               |                            |      0 |    100K|      0 |00:00:00.01 |\n|   5 |      TABLE ACCESS BY INDEX ROWID| DEMO                       |      0 |    100K|      0 |00:00:00.01 |\n|   6 |       INDEX FULL SCAN           | DEMO_PK                    |      0 |    100K|      0 |00:00:00.01 |\n--------------------------------------------------------------------------------------------------------------\n&nbsp;\nPredicate Information (identified by operation id):\n---------------------------------------------------\n&nbsp;\n   1 - filter(:OFFSET=0) THEN FLOOR(TO_NUMBER(TO_CHAR(:OFFSET))) ELSE 0 END +:NEXT)\n   2 - filter((\"from$_subquery$_002\".\"rowlimit_$$_rownumber\"=0) THEN\n              FLOOR(TO_NUMBER(TO_CHAR(:OFFSET))) ELSE 0 END +:NEXT AND\n              \"from$_subquery$_002\".\"rowlimit_$$_rownumber\"&gt;:OFFSET))\n<\/code><\/pre>\n<p>The second run had no rows to read from the table.<\/p>\n<p>If we know that the user will never go further than a few pages, the we can add a subquery with rownum.<\/p>\n<p>Here is a pagination query that get at maximum 30 rows paged 5 by 5:<\/p>\n<pre><code>\nSQL&gt; variable next number\nSQL&gt; variable offset number\nSQL&gt; exec :offset := 0 ; :next:=5\nPL\/SQL procedure successfully completed.\n&nbsp;\nSQL&gt; select * from (\n  2   select \/*+ result_cache *\/ * from (\n  3    select * from DEMO order by n fetch first 30 rows only\n  4   ) order by n offset :offset rows fetch next :next rows only\n  5  )\n  6  \/\n         N          X\n---------- ----------\n         1          1\n         2         .5\n         3         .3\n         4         .3\n         5         .2\n&nbsp;\nSQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  1yubnzwpd2z2g, child number 0\n-------------------------------------\nselect * from (  select \/*+ result_cache *\/ * from (   select * from\nDEMO order by n fetch first 30 rows only  ) order by n offset :offset\nrows fetch next :next rows only )\n&nbsp;\n------------------------------------------------------------------------------------------------------------------------------------\n| Id  | Operation                          | Name                       | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |\n------------------------------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                   |                            |      1 |        |      5 |00:00:00.01 |       5 |      1 |\n|*  1 |  FILTER                            |                            |      1 |        |      5 |00:00:00.01 |       5 |      1 |\n|*  2 |   VIEW                             |                            |      1 |     30 |      5 |00:00:00.01 |       5 |      1 |\n|   3 |    RESULT CACHE                    | gbwdtyz67n3kk0qkgw86s4jk67 |      1 |        |     30 |00:00:00.01 |       5 |      1 |\n|   4 |     WINDOW NOSORT                  |                            |      1 |     30 |     30 |00:00:00.01 |       5 |      1 |\n|   5 |      VIEW                          |                            |      1 |     30 |     30 |00:00:00.01 |       5 |      1 |\n|*  6 |       VIEW                         |                            |      1 |     30 |     30 |00:00:00.01 |       5 |      1 |\n|*  7 |        WINDOW NOSORT STOPKEY       |                            |      1 |    100K|     30 |00:00:00.01 |       5 |      1 |\n|   8 |         TABLE ACCESS BY INDEX ROWID| DEMO                       |      1 |    100K|     31 |00:00:00.01 |       5 |      1 |\n|   9 |          INDEX FULL SCAN           | DEMO_PK                    |      1 |    100K|     31 |00:00:00.01 |       3 |      1 |\n------------------------------------------------------------------------------------------------------------------------------------\n&nbsp;\nSQL&gt; exec :offset := 5 ; :next:=5\nPL\/SQL procedure successfully completed.\n&nbsp;\nSQL&gt; select * from (\n  2   select \/*+ result_cache *\/ * from (\n  3    select * from DEMO order by n fetch first 30 rows only\n  4   ) order by n offset :offset rows fetch next :next rows only\n  5  )\n  6  \/\n         N          X\n---------- ----------\n         6         .2\n         7         .1\n         8         .1\n         9         .1\n        10         .1\n&nbsp;\nSQL&gt; select * from table(dbms_xplan.display_cursor(format=&gt;'allstats last'));\n&nbsp;\nPLAN_TABLE_OUTPUT\n------------------------------------------------------------------------------------------------------------------------------------\nSQL_ID  1yubnzwpd2z2g, child number 0\n-------------------------------------\nselect * from (  select \/*+ result_cache *\/ * from (   select * from\nDEMO order by n fetch first 30 rows only  ) order by n offset :offset\nrows fetch next :next rows only )\n&nbsp;\n-----------------------------------------------------------------------------------------------------------------\n| Id  | Operation                          | Name                       | Starts | E-Rows | A-Rows |   A-Time   |\n-----------------------------------------------------------------------------------------------------------------\n|   0 | SELECT STATEMENT                   |                            |      1 |        |      5 |00:00:00.01 |\n|*  1 |  FILTER                            |                            |      1 |        |      5 |00:00:00.01 |\n|*  2 |   VIEW                             |                            |      1 |     30 |      5 |00:00:00.01 |\n|   3 |    RESULT CACHE                    | gbwdtyz67n3kk0qkgw86s4jk67 |      1 |        |     30 |00:00:00.01 |\n|   4 |     WINDOW NOSORT                  |                            |      0 |     30 |      0 |00:00:00.01 |\n|   5 |      VIEW                          |                            |      0 |     30 |      0 |00:00:00.01 |\n|*  6 |       VIEW                         |                            |      0 |     30 |      0 |00:00:00.01 |\n|*  7 |        WINDOW NOSORT STOPKEY       |                            |      0 |    100K|      0 |00:00:00.01 |\n|   8 |         TABLE ACCESS BY INDEX ROWID| DEMO                       |      0 |    100K|      0 |00:00:00.01 |\n|   9 |          INDEX FULL SCAN           | DEMO_PK                    |      0 |    100K|      0 |00:00:00.01 |\n-----------------------------------------------------------------------------------------------------------------\n<\/code><\/pre>\n<p>The first run reads 30 rows, put them into the result cache and returns the first 5. The second run get the first 10 rows from result cache, skips the first 5 and returns next 5 ones.<\/p>\n<h3>So what?<\/h3>\n<p>We have a solution to use offset in an optimal way, but I don&#8217;t know if is an expected behavior, bug or side effect. The same idea can be done with rownum and subqueries. You have also to think about how static the base tables are. the &#8216;snapshot&#8217; hint may be use to allow stale results (see <a href=\"http:\/\/dbi-services.com\/blog\/resultcache-hint-expiration-options\/\">previous blog post<\/a>) but not documented yet.<\/p>\n<p>We know a lot of bugs and side effects about result cache. We know a lot of unexpected behavior and performance issue about first rows. Search &#8220;first rows&#8221; or &#8220;result cache&#8221; on this blog, or Jonathan Lewis blog, or on MOS and you will see that you can use it only when you have tested the cases where you use it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . At our bi-annual dbiXchange I was talking with Nicolas Jardot about his presentation on Result Cache (don&#8217;t forget J\u00e9rome witt session about RC at DOAG) where he has shown an unexpected behavior on &#8216;fetch first n rows queries&#8217;. That behavior &#8211; if it is not a bug &#8211; can also be [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":5754,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,59],"tags":[670,209,671,303],"type_dbi":[],"class_list":["post-5751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database-administration-monitoring","category-oracle","tag-first-rows","tag-oracle-12c","tag-pagination","tag-result-cache"],"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>Result Cache and 12c &#039;fetch first n rows&#039; - 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\/result-cache-and-12c-fetch-first-n-rows\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Result Cache and 12c &#039;fetch first n rows&#039;\" \/>\n<meta property=\"og:description\" content=\"By Franck Pachot . At our bi-annual dbiXchange I was talking with Nicolas Jardot about his presentation on Result Cache (don&#8217;t forget J\u00e9rome witt session about RC at DOAG) where he has shown an unexpected behavior on &#8216;fetch first n rows queries&#8217;. That behavior &#8211; if it is not a bug &#8211; can also be [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-04T17:24:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2372\" \/>\n\t<meta property=\"og:image:height\" content=\"1176\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\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=\"9 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\/result-cache-and-12c-fetch-first-n-rows\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Result Cache and 12c &#8216;fetch first n rows&#8217;\",\"datePublished\":\"2015-10-04T17:24:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\"},\"wordCount\":863,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg\",\"keywords\":[\"first rows\",\"Oracle 12c\",\"pagination\",\"Result cache\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\",\"name\":\"Result Cache and 12c 'fetch first n rows' - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg\",\"datePublished\":\"2015-10-04T17:24:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg\",\"contentUrl\":\"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg\",\"width\":2372,\"height\":1176},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Result Cache and 12c &#8216;fetch first n rows&#8217;\"}]},{\"@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":"Result Cache and 12c 'fetch first n rows' - 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\/result-cache-and-12c-fetch-first-n-rows\/","og_locale":"en_US","og_type":"article","og_title":"Result Cache and 12c 'fetch first n rows'","og_description":"By Franck Pachot . At our bi-annual dbiXchange I was talking with Nicolas Jardot about his presentation on Result Cache (don&#8217;t forget J\u00e9rome witt session about RC at DOAG) where he has shown an unexpected behavior on &#8216;fetch first n rows queries&#8217;. That behavior &#8211; if it is not a bug &#8211; can also be [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/","og_site_name":"dbi Blog","article_published_time":"2015-10-04T17:24:41+00:00","og_image":[{"width":2372,"height":1176,"url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg","type":"image\/jpeg"}],"author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Result Cache and 12c &#8216;fetch first n rows&#8217;","datePublished":"2015-10-04T17:24:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/"},"wordCount":863,"commentCount":0,"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg","keywords":["first rows","Oracle 12c","pagination","Result cache"],"articleSection":["Database Administration &amp; Monitoring","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/","url":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/","name":"Result Cache and 12c 'fetch first n rows' - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage"},"image":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage"},"thumbnailUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg","datePublished":"2015-10-04T17:24:41+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#primaryimage","url":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg","contentUrl":"https:\/\/www.dbi-services.com\/blog\/wp-content\/uploads\/sites\/2\/2022\/04\/2015-10-02-16.45.51-1.jpg","width":2372,"height":1176},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/result-cache-and-12c-fetch-first-n-rows\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Result Cache and 12c &#8216;fetch first n rows&#8217;"}]},{"@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\/5751","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=5751"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/5751\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media\/5754"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=5751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=5751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=5751"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=5751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}