Why cannot avoid the sort ORDER BY STOPKEY function index

 

SQL> alter session set nls_language=american;

Session altered.

SQL> create table test_sort(name,object_name) as select 'select',object_name from 
  2  dba_objects;

Table created.

SQL> create index i_test_sort_1 on test_sort(substr(name,0,3),object_name);

Index created.

SQL> exec dbms_stats.gather_table_stats(user,'TEST_SORT');

PL/SQL procedure successfully completed.

SQL> set autot trace
SQL> select * from (select * from test_sort where substr(name,0,3)='sel' order by 
  2  object_name) where rownum<11;

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 4202652051

--------------------------------------------------------------------------------
-------------

| Id  | Operation               | Name      | Rows  | Bytes |TempSpc| Cost (%CPU
)| Time     |

--------------------------------------------------------------------------------
-------------

|   0 | SELECT STATEMENT        |           |    10 |   740 |       |   504   (3
)| 00:00:07 |

|*  1 |  COUNT STOPKEY          |           |       |       |       |
 |          |

|   2 |   VIEW                  |           | 49902 |  3606K|       |   504   (3
)| 00:00:07 |

|*  3 |    SORT ORDER BY STOPKEY|           | 49902 |  1559K|  3928K|   504   (3
)| 00:00:07 |

|*  4 |     TABLE ACCESS FULL   | TEST_SORT | 49902 |  1559K|       |    60   (5
)| 00:00:01 |

--------------------------------------------------------------------------------
-------------


Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM<11)
   3 - filter(ROWNUM<11)
   4 - filter(SUBSTR("NAME",0,3)='sel')


Statistics
----------------------------------------------------------
        139  recursive calls
          0  db block gets
        279  consistent gets
          0  physical reads
          0  redo size
        695  bytes sent via SQL*Net to client
        400  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          5  sorts (memory)
          0  sorts (disk)
         10  rows processed 

sql doesn't choose index ,so I use hint to force oracle choose index

SQL> select * from (select /*+ index(test_sort) */ * from test_sort where substr(name,0,3)='sel'
  2  order by object_name) where rownum<11;

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1978014138

--------------------------------------------------------------------------------
------------------------

| Id  | Operation                      | Name          | Rows  | Bytes |TempSpc|
 Cost (%CPU)| Time     |

--------------------------------------------------------------------------------
------------------------

|   0 | SELECT STATEMENT               |               |    10 |   740 |       |
 22869   (1)| 00:04:35 |

|*  1 |  COUNT STOPKEY                 |               |       |       |       |
            |          |

|   2 |   VIEW                         |               | 49902 |  3606K|       |
 22869   (1)| 00:04:35 |

|*  3 |    SORT ORDER BY STOPKEY       |               | 49902 |  1559K|  3928K|
 22869   (1)| 00:04:35 |

|   4 |     TABLE ACCESS BY INDEX ROWID| TEST_SORT     | 49902 |  1559K|       |
 22424   (1)| 00:04:30 |

|*  5 |      INDEX RANGE SCAN          | I_TEST_SORT_1 | 49902 |       |       |
   278   (1)| 00:00:04 |

--------------------------------------------------------------------------------
------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM<11)
   3 - filter(ROWNUM<11)
   5 - access(SUBSTR("NAME",0,3)='sel')


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
      22393  consistent gets
          0  physical reads
          0  redo size
        695  bytes sent via SQL*Net to client
        400  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
         10  rows processed

From the explain ,the sql chooses the index,but SORT ORDER BY STOPKEY  doesn't avoid,so oracle
must read all rows satisfy substr(name,0,3)='sel' ,the I rewrite the sql as the following,we can see 
that sort ORDER BY STOPKEY does't happen,so oracle return 10 rows fast. 

SQL> select * from (select /*+ index(test_sort) */ * from test_sort where substr(name,0,3)='sel'
  2  order by substr(name,0,3),object_name) where rownum<11;

10 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 4154852915

--------------------------------------------------------------------------------
---------------

| Id  | Operation                     | Name          | Rows  | Bytes | Cost (%C
PU)| Time     |

--------------------------------------------------------------------------------
---------------

|   0 | SELECT STATEMENT              |               |    10 |   740 |     8
(0)| 00:00:01 |

|*  1 |  COUNT STOPKEY                |               |       |       |
   |          |

|   2 |   VIEW                        |               |    10 |   740 |     8
(0)| 00:00:01 |

|   3 |    TABLE ACCESS BY INDEX ROWID| TEST_SORT     | 49902 |  1559K|     8
(0)| 00:00:01 |

|*  4 |     INDEX RANGE SCAN          | I_TEST_SORT_1 |    10 |       |     3
(0)| 00:00:01 |

--------------------------------------------------------------------------------
---------------


Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(ROWNUM<11)
   4 - access(SUBSTR("NAME",0,3)='sel')
       filter(SUBSTR("NAME",0,3)='sel')


Statistics
----------------------------------------------------------
          1  recursive calls
          0  db block gets
         11  consistent gets
          0  physical reads
          0  redo size
        695  bytes sent via SQL*Net to client
        400  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         10  rows processed

Jinyu wrote:
Hi, I think that this may be an optimizer bug 10g or flaw optimizer 10 g, although substr (name, 0, 3) = 'salt' is not selective, but oracle can also use indexes to find the top 10 by object_name result order

Jinyu,

Indeed, it seems to be a gap in the mode of optimization 10.2 FIRST_ROWS_n. I could reproduce your problem in 10.2.0.4 and watching the 10053 trace, it looks like that the optimizer does not consider the option "Recost for ORDER (with the HELP of indexes)" where you have a composite index based function. It does when using a 'normal' composite index, and it does - as you mentioned - when using the main column in the ORDER BY expression as well. You don't need to use INDEX indicator in this case, moreover, the recosting for ORDER BY then works very well and chooses the index without specified indicators.

11 g the "recalculate for ORDER BY" appears again in the first place it looks like an obvious limitation / bug of 10.2.0.3/4 at least.

Kind regards
Randolf

Oracle related blog stuff:
http://Oracle-Randolf.blogspot.com/

SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/

Tags: Database

Similar Questions

  • Why Lightroom arbitrarily changing the sort order?

    As I can't reach the cat, nor can I phone, nor there at - it a way to send an email, I have only a possibility and this is to publish this error on the forum.

    Lightroom CC arbitrarily changes the sort order. Sometimes after generating a panorama or modification outside of Lightroom, for example in Photoshop app ranges from the sort order 'moment of creation' to 'user defined' (I don't know the English article for this sorting options).

    This behavior of the application has been boring since Lightroom 4 and I am baffled that this still does not work. However, professionals in their workflow and it can't be so hard to fix.

    Thank you.

    Hi pentido,

    Please try to reset the preferences of LR CC

    Retrieve the catalog and images after resetting preferences

    Concerning

    Rohit

  • What is the sort order used Finder?

    I did a little research on this issue and found that (unless I'm missing something), the sort order of the Finder is not what it is supposed to be.

    The only requirement that I found is this note archived tech how Finder lists items that are sorted by name (Mac OS X) from 2012.

    In fact, almost everything what he described how Finder behaves, with the exception of the note at the bottom:

    Technically speaking, the Finder sort is based on the Unicode snack Algorithm, defined by the Unicode Consortium. This standard provides an order for all characters in Unicode sorting complete and unambiguous

    And that complicates matters, since (for example) the underscore character (officially called "bass line"), which sorts upwards and so before all alphanumeric value Unicode of U005F, which lies between the uppercase and lowercase Latin letters: 'Z' is U005A and 'a' corresponds to U0061.

    The reason I ask is because I would like to find a character that sorts after all Latin characters.  Many sort to before, including < space >, stress / < low line > and (my favorite for folders) < pointing right angle double quote > (i.e. "'").

    If it was really sort by Unicode, then it would be simple to use the selector of characters to insert a Unicode character value, such as U25B9, which is "▹.  "But we sort after space <>, < low line >, and" ' ", but before all Latin characters.

    I found an abstract character who works here for this, but I am helpless about the why.  U1400 is the Unicode section called "Unified Canadian Aboriginal syllable", and U1433, the "Canadian syllable Po", is a character who appears in the Finder as a very big plus of symbol: "ᐳ." (More than the symbol is ' > ' for comparison.)

    Yes WHY?

    Why think the Finder that's good (partial) order:

    U0020 "" (space)

    U005F '_' (bass line) < underscore >

    "U00BB '" ' (pointing to the right angle double quote)

    U005C "------" (Reverse Solidus) < backslash >

    U25B7 "▷" (white triangle pointing to the right)

    U0041 "A".

    U007A 'z '.

    U1433 "ᐳ" (Canadian syllable Po)

    Note: I see that note technical I linked to refers to the "Unicode snack Algorithm", which could indicate the answer somewhere in its depths.  If this is the case, then I guess this raises the question of why the Unicode coalition choose such an unexpected algorithm.

    Your "Note" has the answer.  Sorting of Unicode is not determined by the values of code as such point, it is determined by the algorithm.  This can be quite complex, but I think an easy way of having things to sort after Latin is to use a Greek character as µ (m option).

    http://Unicode.org/charts/collation/

  • How can I change the sort order in the finder / media / photos?

    When I want to open a photo in an application I can access photos via the media / photos. The sort order is ascending. I want that the descending sort order. Where can I do this? Thanks for the reply! Christian

    You can click right in the grid of thumbnails and choose to display it as a list. You can then sort the columns by clicking on them.

    I don't know of a way to get to another level by default.

  • How to change the sort order of the items sought for the last element of this research first. I DON'T want to say the order search engines, but the existing research by arrow down

    I want to be able to change the sort order of the items, I already looked in the search box. I want to be able to hit the arrow key down and see my previous searches in order of last search showing the first. For the moment, I don't know how it is sorting and it is very annoying to have to re - enter a query that I typed 5 minutes earlier, but because I typed in another 10 since it's lost somewhere in the list. Is it possible, I Googled, but did not find the topic anywhere. Just to clarify, I DON'T mean of the order of the search engines (which is what appears in google), I mean that the text typed into which has been registered in the drop-down list.

    Thank you

    'Form filling' uses a "frecency" algorithm, frequency + recency, similar to the list of AutoComplete address bar.

    I found an extension that seems relevant, but critics are old, so I'm not sure it's still working: Searchbar Autocomplete Order.

    But... is the AutoComplete does not? I expect that typing a few characters of the previous query would be to filter the list so that you can easily select? Or is the problem that the list does not remember quite who looking for?

  • How can I change the sort order of the emails?

    iPhone SE 64 GB iOS 9.3.1

    When I opened my mailbox (Mail-> all inboxes) mail is currently sorted from most recent email on top, then retreating.
    How can I correct the sort order so that the oldest email is on top then go ahead?

    You have not, not in the stock email app.  Perhaps a 3rd party app offers this, but not the stock iOS app.

  • How can I change the sort order in the Photos?

    How can I change the sort order in the Photos? I would like to have more recent photos at the top of the screen instead of at the bottom.

    The view of Photos with moments and collections will be sorted always growing by date, also the album «All the Photos»

    But you can sort any other album descending by date.  Create your own album custom as smart album 'My Pictures' and the descending sort.

    File > new Smart Album

    and use the rules:

    CTRL-click the smart album in the sidebar and in this way it as you want:

    These sorting options available in Photos on MacOS X 10.11. El Capitan, but not in Yosemite.

  • Is it possible to change the sort order of the Windows Explorer?

    When you use windows Explorer to search for files I find things I named by date are sorted incorrectly.
    Here is an example of how that fate (sorted by name, having consulted the details page): names of files in the following order

    Tidbits200710001b
    Tidbits200710001a
    Tidbits20100207a
    Tidbits20100201a
    tidbits20080300s
    tidbits20080300r

    I would like to than years (at least) to be in order.  Is it possible to change the sort order in windows Explorer?

    http://support.microsoft.com/kb/319827 :

    1. Click Start, click run, type regedit, and then click OK.
    2. Use one of the following methods, depending on your situation:
      • To configure the policy for all users of the computer, locate and then click the following registry key:

        HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer
      • To configure the policy for the current user, locate and then click the following registry key:
        HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Currentversion\Policies\Explorer
    3. On the Edit menu, point to newand then click DWORD value
    4. Type NoStrCmpLogical, and press ENTER.
    5. On the Edit menu, click modify.
    6. To set the order of sort that you want to use for files and folders whose names contain numerals, use one of the following methods, depending on your situation:
      • To configure Windows XP or Windows Server 2003 to use the method used by Windows 2000 for sorting files and folders, in the value data box, type 1, and then click OK.
      • To configure the default Windows XP or Windows Server 2003 method for sorting files and folders, in the value data box, type 0, and then click OK.

        Note When the NoStrCmpLogical value does not exist or it is set to 0 (zero), the Windows XP default sort order is used.

    7. Exit the registry editor and restart the computer.

    You want the first option 6.

    Noel

  • Windows Mail seems to change the sort order of the mail every now and then.

    Windows Mail seems to change the sort order of the mail every now and then.  I want that it in the order received, desending and back to this sometimes.

    Hi rondebmar,

    You can check out the following link and try the suggestions posted by t-4-2 on Thursday, January 7, 2010 08:57 PMand check if this may help.

    http://social.answers.Microsoft.com/forums/en-us/vistanetworking/thread/d9aa1297-1124-43e5-b463-5441f3922388

    For more information, please visit the following links:

    http://Windows.Microsoft.com/en-us/Windows-Vista/view-e-mail-messages-in-Windows-Mail

    http://Windows.Microsoft.com/en-us/Windows-Vista/check-for-new-e-mail

    Hope this information is useful.

    Boumediene. K.
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How to keep the sort order when you rename a collection?

    I renamed a manually sorted Collection, but the sort order changes. Is it possible to maintain the order of the files when a Collection is renamed?

    In my view, the bridge works correctly implemented. Kinds of collection seem to be kept in a directory UserSort that contains an index and sort sequence list files. In win 7, it's . Entries in the file index.xml include the name of the collection and point to the xml file UserSort containing manually sorted sequences.

    A workaround solution you could try: go to the UserSort/Index.xml file find your former name of collection (.filelist) and change it to your new collection name.

  • Change the sort order for symbol/button.

    I have a line of buttons (which are near eachother). When you click them they step up big.

    Problem is that the button clicked is not arranged / sorting forward and what lies behind

    other buttons next to him.

    How can I change the sort order (inside the button symbol /) when clicked?

    Hi Claursen,

    This is what I did to reproduce your scenario: -.

    1. on stage, I create a symbol, I created another symbol inside, and inside the nested symbol, I created 3 symbols and names them "btn1", 'btn2', 'btn3.

    2. now, I open the actions of the "btn1" symbol and for the click event, I wrote the following code

    var El = sym.getSymbol("btn1").getSymbolElement ();

    El.CSS ("Transform","Scale (4,4)");

    El.CSS("z-index","1");

    Similarly, I put the code for the click event handler for 'btn2' and 'btn3.

    3.now when I published the file and clicked on one of the three symols, he scaled and was visible in the foreground the other symbols.

    Correct me if this is not the scenario that you call.

    Thank you

    Sliman

  • Why cannot create the table partitioned successfully?

    Why cannot create the table partitioned successfully?
    SQL> create table hr.gps_log_his
    (id number,
    name varchar2(10),
    time date)
    tablespace ts_log_his
    PARTITION BY RANGE (TIME)
    (PARTITION udp_part09110707 VALUES LESS THAN (TO_DATE('09110708','yymmddhh24')),
    PARTITION udp_part09110708 VALUES LESS THAN (TO_DATE('09110709','yymmddhh24')),
    PARTITION udp_part09110709 VALUES LESS THAN (TO_DATE('09110710','yymmddhh24')),
    PARTITION udp_part09110710 VALUES LESS THAN (maxvalue)
    );
    
    (PARTITION udp_part09110707 VALUES LESS THAN (TO_DATE('09110708','yymmddhh24')),
    Error on line 7: 
    ORA-14120: DATE columns did not specify the complete partitioning limits.

    The detailed error message is as follows:

    ORA-14120: incompletely specified partition bound for a DATE column
    
    Cause: An attempt was made to use a date expression whose format does not fully
    (i.e. day, month, and year (including century)) specify a date as a partition bound
    for a DATE column. The format may have been specified explicitly (using TO_DATE()
    function) or implicitly (NLS_DATE_FORMAT).
    
    Action: Ensure that date format used in a partition bound for a DATE column supports
    complete specification of a date (i.e. day, month, and year (including century)). If
    NLS_DATE_FORMAT does not support complete (i.e. including the century) specification
    of the year, use TO_DATE() (e.g. TO_DATE('01-01-1999', 'MM-DD-YYYY') to fully
    express the desired date. 
    

    Action: Change to_date('09110708','yymmddhh24') to
    to_date('2009110708','yyyymmddhh24')

  • How to avoid the SORT operation.

    Hi gurus,

    Oracle version is 11.1.0.7

    I have a select query that has Row_number() over (Partition of col1, col2 order by col1, col2 desc nulls last) function to eliminate the DUP on these two passes.

    Here it costs 4639 for sorting. Now, I added a two other columns in the query Select (has not changed the Row_number analytic function).

    COST of sorting is now 555635.

    This sort operation may use Temp table space. How to avoid the cost of SORTING.

    Note: I use the function analytical only to eliminate duplicates on Col1 and Col2 only.

    How to sort takes a large part of the COSTS by adding only two columns in the select list.


    Any Suggestions...?


    Thank you
    Mike

    I would say:
    1 don't worry unnecessarily about the cost of sorting - do you know if you have a problem.

    2. in general, eliminate from the beginning, sort late (i.e. After you have eliminated all you can)

    3. If you are concerned by the outpouring sort on the disc then you could go to manual management of pga (assuming that you are currently using automatic) for this particular operation and override sort_area_size.

  • change the sort order in the photo gallery

    I'm changing the sort that photo gallery displays my photos.  Right now, it appears it's their date/time display.  I want that they appear in the order of file name.  I changed the file names in the image library and selected "sort by", "name", "Crescent" and is sorts them properly in image library list, but when I opened the Gallery of pictures, it is always showing them by date/time order.  They show in a different order in the Gallery how they appear in the list of image library.  Can you help me?

    Unfortunately, this is just one of the many shortcomings of the Photos app we
    really has no options to change the sort criteria.
     
     
    Barb
     
    MVP - Windows/entertainment and connected home
     
     
    Please mark as answer if that answers your question
     
     
     
     
  • Change the sort order on film

    For some reason any my sort order in my film is mixed up.  It allows to sort by oldest date to last date.  Is there a way to change this?

    Thanks for any help in advance!

    Scott

    Switch to grid mode in the library module. If the toolbar under the grid does not appear, type "T". When you have a toolbar, make sure that it has a tool of "Spell" on this subject. (If she is not there, click the triangle at the right end of the toolbar and choose "Sort" from the list).

    Now click on the text to the right of "sort:" on the toolbar, then choose "capture time. Make sure the a / z has 'a' high on, or your fate will be in the reverse order.

    HAL

Maybe you are looking for

  • What I really join the music Apple to listen to the music I want to listen to?

    What I really join the music Apple to listen to the music I want to hear?

  • PRS 950 frozen

    I downloaded a file PDF from Google Book Search. The guy was small and I did XL without any positive result. I then 'zoom', and as I tried to adjust it, it went from portrait to landscape and froze for about an hour. I can't turn off - it is just fro

  • compatibility with Google onhub

    Airports can be used to extend the range of a network of Google OnHub? If so, how?

  • 2.0.22: where is Google Sync?

    I want to manually sync my contacts and calendar, am I missing something? I thought it was in the accounts, but there is nothing there now. Thanks in advance!

  • Photosmart 7520 printing in black and white?

    I have a photosmart 7520. I want to print a black and white text form, but since there is no ink in the photo to the left cartridge, I can't print anything. Is it not possible to print only black and white stuff, whith this printer? Thank you Thomas