🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #288

Re: Store Procedure and IN

#288
From: Maxim Shiryaev
Date: Thu, 21 Feb 2008 09:45
72 lines
2870 bytes
The problem probably is that a view is just a syntactical substitution and
can use WHERE clause to limit records to return while the stored procedure
always executes from the first record to the last and only then the WHERE
conditions are checked.

I would change the procedure to accept some input arguments to limit records
inside the procedure. And I would try to split the query to two sections
combined with UNION ALL for both parts of your OR, like:

Select *
From MyStoreProcedure
Where foo1 = foo2
and foo3 = foo4
and foo5 = foo6

union all

Select *
From MyStoreProcedure
ID in (Select ID From MyTable Where f1 = f2);

If foo2..foo6 are parameters then the first section sould be like:

Select *
From MyStoreProcedure1(foo2, foo4, foo6)

and the procedure should be rewritten to take this parameters into account.

The second part should look like:

Select sp.*
From MyTable t
  left join MyStoreProcedure2(MyTable.ID) sp on 1=1
Where t.f1 = t.f2



Maxim.


"Safwan" <safwan_maswadeh@yahoo.com> �������/�������� � �������� ���������:
news:47bcbe87@newsgroups.borland.com...
> Hi
>
> Select *
> From MyView
> Where foo1 = foo2
> and foo3 = foo4
> and foo5 = foo6
> or ID in (Select ID From MyTable Where f1 = f2);
>
> With the above statement the speed is acceptable. But when changeing the
> same view (MyView) into a store procedure with  - for select .... from ...
> do suspend. - like this :
>
> Select *
> From MyStoreProcedure
> Where foo1 = foo2
> and foo3 = foo4
> and foo5 = foo6
> or ID in (Select ID From MyTable Where f1 = f2);
>
> The statement take a looooong time to fetch the records.
> I use the PLANalyzer to check the statement, I notice that the in clause
> cause slow.
>
> What should I do to speed up my query ??
>
> Your's
> Safwan.
>
>
Technical Details
Message-ID: <47bd47d7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder3.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!feeder.ecngs.de!ecngs!feeder2.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <47bcbe87@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,5e0810130fee05d6
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII
From: "Maxim Shiryaev" <MaximShiryaev@gmail.com>
Newsgroups: borland.public.interbase.sql
References: <47bcbe87@newsgroups.borland.com>
Subject: Re: Store Procedure and IN
Date: Thu, 21 Feb 2008 12:45:41 +0300
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 213.234.197.62
Message-ID: <47bd47d7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1203587031 213.234.197.62 (21 Feb 2008 01:43:51 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder3.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!feeder.ecngs.de!ecngs!feeder2.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail