473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Order By Performance Problem on View

I have a view that contains the following SQL1 and it takes about 500ms
to run with Explain Plan EXP1. However, if I add an order by
clause(e.g. select * from view1 order by ID desc), it will then take
about 3 mins to return. The explain plan for the query with the order
by clause is as follows (EXP2).

The explain plan 2 shows that there is no changes to the index
selection except adding the "Sort Order by" step. The total number of
rows in proposal is 7000, owner is 7000 and routing is 7000 and the
joined result should be around 7000 rows. I suspect that in order to
process an order by clause, Oracle has to wait for every row to return
before sorting. I tried the materialized view but since it is complex
query, I cannot use on commit or fast refresh which then makes the MV
useless in this scenario. (can't update every few seconds :-) ). I
tried partial MV (joining two simple MVs and order by the result), but
still doesn't work. I have seen someone posting similar question, but
no response. Any suggestions are welcome! Thanks!

SORT_AREA_SIZE = 1MB
SORT_AREA_RETAINER_SIZE = 1MB

SQL 1:
SELECT p.proposal_id AS ID, p.proposal_title,
p.status AS status, o.common_name,
fcn_submit_date (p.proposal_id),
fcn_last_decision (p.proposal_id),
(CASE
WHEN r.review_channel_list_id = 0
THEN fcn_decode_sequence (r.segment_id_one, 'segment')
WHEN r.review_channel_list_id = 1
THEN 'Multi Segment'
WHEN r.review_channel_list_id = 2
THEN 'Research'
WHEN r.review_channel_list_id = 3
THEN 'Other'
END
),
fcn_decode_primary_value (r.segment_id_two),
fcn_last_proposal_log_date (p.proposal_id),
fcn_calculate_slip (fcn_last_proposal_log_date (p.proposal_id)),
fcn_user_group (p.proposal_id, 0),
fcn_last_routing (p.proposal_id),
fcn_submitter_name (fcn_user_group (p.proposal_id, 0)),
p.review_level,
o.ldap_alias,
p.priority
FROM PROPOSAL p,
OWNER o,
(SELECT proposal_id, routing_id, segment_id_one,
segment_id_two,review_channel_list_id FROM ROUTING WHERE routing_id IN
(SELECT MAX (routing_id) FROM ROUTING GROUP BY proposal_id)) r
WHERE p.status IN (1, 2) AND p.owner_id = o.owner_id(+)
AND r.proposal_id = p.proposal_id

== EXPLAIN PLAN (EXP1) ==
Operation Object Name
SELECT STATEMENT Optimizer Mode=CHOOSE
NESTED LOOPS OUTER
NESTED LOOPS
HASH JOIN SEMI
INDEX FAST FULL SCAN MARINER.IDX_ROUTING_MULTI1
VIEW SYS.VW_NSO_1
SORT GROUP BY
INDEX FULL SCAN MARINER.IDX_ROUTING_MULTI2
TABLE ACCESS BY INDEX ROWID MARINER.PROPOSAL
INDEX UNIQUE SCAN MARINER.SYS_C004829
TABLE ACCESS BY INDEX ROWID MARINER.OWNER
INDEX UNIQUE SCAN MARINER.OWNER_PK11090439533640
================================================== ==============

== EXPLAIN (EXP2) ==
SELECT STATEMENT Optimizer Mode=CHOOSE
SORT ORDER BY
NESTED LOOPS OUTER
NESTED LOOPS
HASH JOIN SEMI
INDEX FAST FULL SCAN MARINER.IDX_ROUTING_MULTI1
VIEW SYS.VW_NSO_1
SORT GROUP BY
INDEX FULL SCAN MARINER.IDX_ROUTING_MULTI2
TABLE ACCESS BY INDEX ROWID MARINER.PROPOSAL
INDEX UNIQUE SCAN MARINER.SYS_C004829
TABLE ACCESS BY INDEX ROWID MARINER.OWNER
INDEX UNIQUE SCAN MARINER.OWNER_PK11090439533640
================================================== ==============

Jul 19 '05 #1
1 13554
I notice that the two plans appear to be the same expect for the second
plan having the sort operation. When you add an order by you force
Oracle to find all the data and sort it prior to returning any data to
the application. The first query can start returning data as soon as
it finds any even though the query is still running on the db.

So how are you measuring the run time? You should be measuring it for
the last row being returned, not the first to get the true difference.
The difference is the cost of the sort.

Tuning the query or eliminating the sort are your only performance
options. What is the hash area size set to? If less than what you
calculate for the size of the hash set then you could try to bump it
up. You could also force the use of nested loops instead of a hash and
see it that is better or worse.

That is the only general advice I can think of without really trying to
figure out your query but without more knowledge of the data, the
available indexes etc... I do not want to make any specific query
rewrite recommendations.

HTH -- Mark D Powell --

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Xenophobe | last post by:
I have successfully converted the ASP code included in the following article to PHP: http://www.4guysfromrolla.com/webtech/040100-1.shtml As described the high and low latitudes and longitudes...
5
by: Steve_CA | last post by:
Hello all, I've been recruited to assist in diagnosing and fixing a performance problem on an application we have running on SQL Server 7. The application itself is third party software, so we...
4
by: CK | last post by:
Hi all, I know this question is stupid. But i need some advice for this. I am trying to develop a website, which will allow the user send to order form to the admin email. I am planning to use the...
5
by: Scott | last post by:
I have a customer that had developed an Access97 application to track their business information. The application grew significantly and they used the Upsizing Wizard to move the tables to SQL...
2
by: elein | last post by:
Yes, I vacuumed. Reproduced on both 7.3.2 and 7.5. Brain dead java beans want order by clauses in views that they use. my view is: select .... from bigtable b left join lookuptable l order...
3
by: Mary | last post by:
MemberID VID 1002 1001 1003 1002 1004 1003 1005 1003 1007 1001...
104
by: Beowulf | last post by:
I have the view below and if I use vwRouteReference as the rowsource for a combo box in an MS Access form or run "SELECT * FROM vwRouteReference" in SQL Query Analyzer, the rows don't come through...
24
by: Hurricane | last post by:
When I create a view in SQL and include an ORDER BY clause i can see it in Management Studio. However, when I call the same view from an ASP page the order goes completely haywire. Any ideas?
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.