Home » RDBMS Server » Performance Tuning » How to reduce nested loops in a big query?
How to reduce nested loops in a big query? [message #178559] Wed, 21 June 2006 09:21 Go to next message
Jaime Stuardo
Messages: 57
Registered: March 2004
Member
Hi all..

I have a query that is very heavy and takes very long time to execute.

By watching its explain plan, I see a lot of nested loops, some unique scans and some range scans. I show you this :

SELECT STATEMENT Optimizer Mode=RULE
SORT UNIQUE
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
NESTED LOOPS
TABLE ACCESS BY ROWID ACSEL.POLIZA
INDEX RANGE SCAN ACSEL.POLIZA_KEY
TABLE ACCESS BY ROWID ACSEL.EMPLEADOR
INDEX UNIQUE SCAN ACSEL.IND_EMPLEADOR
INDEX UNIQUE SCAN ACSEL.PK_TERCERO
TABLE ACCESS BY ROWID ACSEL.ASEGURADO
INDEX RANGE SCAN ACSEL.IDX_ASEGURADO_01
TABLE ACCESS BY ROWID ACSEL.CLIENTE
INDEX UNIQUE SCAN ACSEL.PK_CLIENTE
TABLE ACCESS BY ROWID ACSEL.TERCERO
INDEX UNIQUE SCAN ACSEL.PK_TERCERO

Is there a way to reduce the number of nested loops?

One thing I never have cleared is how to arrange conditions in WHERE clause. The condition that filters most of the records must be placed at the end of the query or at just after the WHERE keyword? what about table order in FROM clause? all that affects nested loops? I have tested rearranging tables, but explain plan doesn't vary.

Any hint would be greatly appretiated

Thanks
Jaime
Re: How to reduce nested loops in a big query? [message #178561 is a reply to message #178559] Wed, 21 June 2006 09:27 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Quote:

Optimizer Mode=RULE

Are you using Oracle 7.3 or lesser version?
Else you are supposed to use CBO.
Did you also collect statistics on tables/indexes?
Re: How to reduce nested loops in a big query? [message #178563 is a reply to message #178559] Wed, 21 June 2006 09:32 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
What you need to do is stop using the Rule Based Optimiser (RBO) and move to the Cost Based Optimizer (CBO).

The RBO follows a set of rules to determine how to process a query, and one of those runes is 'If there's an index, use it' (I exaggerate, but not much)

The CBO will look at the amount and distribution of data in the queries, estimate how many rows it will get from each table, and decide the access routes to each table based on this data.

If you can't go CBO, then you might want to try this:

Look at the explain plan, and try to work out how many rows each step will be returning, starting at the innermost one.
Any step that's returning more than 5-10% of the table, add a FULL(table alias) hint to the query to disuade the RBO from trying to step through too many rows using an index.

AFAIK, the table ordr and where clause order don't matter.
Re: How to reduce nested loops in a big query? [message #178565 is a reply to message #178561] Wed, 21 June 2006 09:33 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
'Supposed to' is a bit strong.
You're supposed to use the CBO in 10g, because the RBO was desupported, but until then they're both valid options - it's just that the CBO is better. Cool
Re: How to reduce nested loops in a big query? [message #178566 is a reply to message #178561] Wed, 21 June 2006 09:34 Go to previous messageGo to next message
Jaime Stuardo
Messages: 57
Registered: March 2004
Member
Sorry, I didn't tell about what version I'm using. I have Oracle 7.3.4.

Sorry, but what is CBO?

Thanks
Jaime
Re: How to reduce nested loops in a big query? [message #178571 is a reply to message #178566] Wed, 21 June 2006 09:49 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Go here, and read chapter 13

http://download-uk.oracle.com/docs/pdf/A32534_1.pdf

Then give serious consideration to upgrading to supported version of Oracle. Cool
icon7.gif  Re: How to reduce nested loops in a big query? [message #178572 is a reply to message #178571] Wed, 21 June 2006 09:52 Go to previous message
Jaime Stuardo
Messages: 57
Registered: March 2004
Member
We are in progress to upgrade to 8i, but finally reach 9i Razz

We were said that we cannot upgrade to 9i at once. We have to go through 8i first, and then 9i.

Jaime
Previous Topic: capture users & statements causing archive log full
Next Topic: Can I use Pragma Autonomous Transactions for Performance Improvement?
Goto Forum:
  


Current Time: Thu May 02 14:00:49 CDT 2024