Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

How to force subquery being the first executed

 
   Database Help (Home) -> Oracle RSS
Next:  Oracle ODBC Linux 64bit Driver  
Author Message
Peter Kallweit

External


Since: Aug 27, 2008
Posts: 1



(Msg. 1) Posted: Wed Aug 27, 2008 2:51 pm
Post subject: How to force subquery being the first executed
Archived from groups: comp>databases>oracle>misc (more info?)

Hi %,

I've a question about 'leading' the optimizer. To make it not too
simple, it should work from 9.2.0.4 up to 11.1.0.6.

I'm selecting from a heavy view (many joins, big result set), using a
subquery to restrict the result:
select *
from heavyView
where keys in (select keys from simpleView);

In most cases the query starts with complete execution of the heavyView
and is then restricting the result using the subquery. This results in a
very bad performance.

However, from the application logic I know, that the subquery returns
only a few rows.
Therefore I want the query to start with the subquery, and then going
with the result rows into the main view.
Indexes to support accessing the main view in this way are available.

How can I enforce this execution order?

Sadly, changing the subquery into a join and using a 'leading' or
'ordered' hint is not possible.


Regards
Peter

 >> Stay informed about: How to force subquery being the first executed 
Back to top
Login to vote
Mark D Powell

External


Since: Dec 20, 2007
Posts: 289



(Msg. 2) Posted: Wed Aug 27, 2008 2:51 pm
Post subject: Re: How to force subquery being the first executed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Aug 27, 8:51 am, Peter Kallweit <p_kallw....DeleteThis@arcor.de> wrote:
> Hi %,
>
> I've a question about 'leading' the optimizer. To make it not too
> simple, it should work from 9.2.0.4 up to 11.1.0.6.
>
> I'm selecting from a heavy view (many joins, big result set), using a
> subquery to restrict the result:
>    select *
>      from heavyView
>     where keys in (select keys from simpleView);
>
> In most cases the query starts with complete execution of the heavyView
> and is then restricting the result using the subquery. This results in a
> very bad performance.
>
> However, from the application logic I know, that the subquery returns
> only a few rows.
> Therefore I want the query to start with the subquery, and then going
> with the result rows into the main view.
> Indexes to support accessing the main view in this way are available.
>
> How can I enforce this execution order?
>
> Sadly, changing the subquery into a join and using a 'leading' or
> 'ordered' hint is not possible.
>
> Regards
> Peter

Without the actual explain plan or any supporting detail for the
tables/indexes available there is no solid reliable way to answer your
question. The CBO is going to solve the query based on the statistics
for the referenced objects and the plan options available to it based
on how the query is written.

Run an explain plan and then look in your SQL manual to see if any of
the following hints might be of use in obtaining the plan you want:

NO_MERGE causes Oracle not to merge mergeable views.
PUSH_SUBQ causes non-merged subqueries to be evaluated at the earliest
possible step in the execution plan

But what you can do depends on how the SQL is written and what the
statistics tell the CBO. Rewriting the query so that the view code
and the query are one statement might provide more options.

HTH -- Mark D Powell --

 >> Stay informed about: How to force subquery being the first executed 
Back to top
Login to vote
Malcolm Dew-Jones

External


Since: Aug 05, 2003
Posts: 303



(Msg. 3) Posted: Wed Aug 27, 2008 2:51 pm
Post subject: Re: How to force subquery being the first executed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Peter Kallweit (p_kallweit@arcor.de) wrote:
: Hi %,

: I've a question about 'leading' the optimizer. To make it not too
: simple, it should work from 9.2.0.4 up to 11.1.0.6.

: I'm selecting from a heavy view (many joins, big result set), using a
: subquery to restrict the result:
: select *
: from heavyView
: where keys in (select keys from simpleView);

: In most cases the query starts with complete execution of the heavyView
: and is then restricting the result using the subquery. This results in a
: very bad performance.

: However, from the application logic I know, that the subquery returns
: only a few rows.
: Therefore I want the query to start with the subquery, and then going
: with the result rows into the main view.
: Indexes to support accessing the main view in this way are available.

: How can I enforce this execution order?

No idea, but there are various ways to structure your query. I would try
them all to see what works best.

syntax not correct

with simple as
( select ...
)
select * from heavy where clause using simple

select heavy.*
from heavy,simple
where heavy.key=simple.key

select
( select c1 from heavy h where h.k = s.k) C1 ,
( select c2 from heavy h where h.k = s.k) C2 ,
...
from
simple s


probably others, it may or may not make a difference.
 >> Stay informed about: How to force subquery being the first executed 
Back to top
Login to vote
sybrandb

External


Since: Dec 15, 2007
Posts: 172



(Msg. 4) Posted: Wed Aug 27, 2008 5:48 pm
Post subject: Re: How to force subquery being the first executed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 27 Aug 2008 08:33:23 -0700 (PDT), Barry Bulsara
<bbulsara23.TakeThisOut@hotmail.com> wrote:

>Most remaining subscribers
>to this group would like a lot more professionalism and technical
>input and a lot lot less ad hominem comment.

I assume by 'most' you mean basically 'I'?
Because you are the only one complaining, and as Usenet doesn't have
'subscribers' as far as I am concerned the subscribers you mention are
virtual.
Put it otherwise: it seems to me you speak only for yourself.
You should avoid to speak for others: you are the only one
complaining, just because in the past I've set you straight a few
times and rightly so.
I am amazed even after two or three years you couldn't forget this and
use this to campaign against me.
This forum assumes a basic willingness to resolve your own problems
and the willingness to 'learn to fish'.
If you don't want that, there are other forums where they are happy
to abstract the Oracle documentation ad nauseam for you.


--

Sybrand Bakker
Senior Oracle DBA
 >> Stay informed about: How to force subquery being the first executed 
Back to top
Login to vote
Aya the Vampire Slayer

External


Since: Aug 05, 2008
Posts: 17



(Msg. 5) Posted: Wed Aug 27, 2008 5:48 pm
Post subject: Re: How to force subquery being the first executed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

sybrandb DeleteThis @hccnet.nl wa:
>On Wed, 27 Aug 2008 08:33:23 -0700 (PDT), Barry Bulsara
><bbulsara23 DeleteThis @hotmail.com> wrote:

>>Most remaining subscribers
>>to this group would like a lot more professionalism and technical
>>input and a lot lot less ad hominem comment.

>I assume by 'most' you mean basically 'I'?

While I realize that you are a 10-year veteran of this group (at least,
so you've said) and probably get tired of answering the same questions
over and over again, it's still no excuse to be rude to people when
telling them to go use google instead of wasting your time. Especially
if you want to increase readership. Everyone has to start somewhere
before becoming an expert with something as complex as Oracle (DB,
AppServer, whatever), and being encouraging rather than derogatory is
more likely to get people to stick around after they stop being annoying
n00bs.


>Because you are the only one complaining, and as Usenet doesn't have
>'subscribers' as far as I am concerned the subscribers you mention are
>virtual.

Most people just don't want to get involved in an obviously impending
flamewar over something theoretically off-topic by showing support for
someone who is willing to step forward and call another person out on
their rude behavior. So yeah, I agree with Barry. Sorry.

I've been subbed to these oracle groups for about a year now but up
until about a month or two ago have done nothing but immediately
'catchup' the groups without even reading. I'm not sure what got me
actually reading them recently, but it has been enlightening so far,
random bouts of crankiness aside.

--
"Care must be exorcised when handring Opiticar System as it is apts to
be sticked by dusts and hand-fat." --Japanese Translators

"Keep your fingers off the lens." --Elton Byington, English Translator
 >> Stay informed about: How to force subquery being the first executed 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Oracle All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]