Oracle view performance with rownum

前端 未结 4 1300
故里飘歌
故里飘歌 2021-01-03 02:15

I am using Oracle 10g, and I have a view that joins two large tables (millions of records). I am trying to select a limited \"sample\" of the data for the user like this:

相关标签:
4条回答
  • 2021-01-03 02:30

    You can also try:

    select * FROM 
    (SELECT rownum ROW_NUMBER, YOUR_VIEW.* FROM  YOUR_VIEW) 
    WHERE ROW_NUMBER> 2
    
    0 讨论(0)
  • 2021-01-03 02:31

    I'd see what the /*+ NOPARALLEL */ hint does as per GuiGi's answer. Another thing to try is look at the plan generated for this:

    select /*+ FIRST_ROWS(10)*/ * from VIEW_NAME where ROWNUM < 5;
    
    0 讨论(0)
  • 2021-01-03 02:37

    Do you have join index (indexed nested loops should be the access path chosen by optimizer)? Try disabling hash_join (together with sort_merge_join) to see what is the cost of alternative plane, if you see ordinary nested loops, then optimizer ignored index for some reason.

    When tuning queries with views inline the view definition, then try hinting the access path that you want. When you find magic hints (e.g.cardinality) sometimes they can be moved into outside query block (this is especially true for later oracle versions).

    0 讨论(0)
  • 2021-01-03 02:42

    You can try adding a NOPARALLEL hint to the query.

    select /*+ NOPARALLEL */ * from VIEW_NAME where ROWNUM < 5; 
    

    This is a situation where parallel execution is chosen but it might be bad for performance, as it would use more CPU and I/O.

    0 讨论(0)
提交回复
热议问题