Subject | Re: Subselect causes slow query |
---|---|
Author | Adam |
Post date | 2005-09-12T23:26:15Z |
--- In firebird-support@yahoogroups.com, "Rick Debay" <rdebay@r...>
wrote:
Firebird will take around
0.8 seconds + (0.5 seconds times the number of records in
mddb_drugitem).
So unless this table is very small, you would do better to rewrite
the query using either a more efficient subselect (you could most
likely use an exists which is much better), or by joining to itself.
I am pretty sure you can do this a lot quicker but I am not going to
spend time guessing at table structures.
Adam
wrote:
> Yes, I'm looking for duplicates in data sent by a third party.This is
> a one time analysis, so I just took the results from the IN queryand
> cut/paste them into the main query.to
>
> The reason for the original question was why FB would take so long
> execute the combined statement, if the individual statements wereBecause you are doing it a more efficient way than Firebird does.
> subsecond.
Firebird will take around
0.8 seconds + (0.5 seconds times the number of records in
mddb_drugitem).
So unless this table is very small, you would do better to rewrite
the query using either a more efficient subselect (you could most
likely use an exists which is much better), or by joining to itself.
I am pretty sure you can do this a lot quicker but I am not going to
spend time guessing at table structures.
Adam
>If I
> -----Original Message-----
> From: firebird-support@yahoogroups.com
> [mailto:firebird-support@yahoogroups.com] On Behalf Of Adam
> Sent: Friday, September 09, 2005 6:54 PM
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] Re: Subselect causes slow query
>
> --- In firebird-support@yahoogroups.com, "Rick Debay" <rdebay@r...>
> wrote:
> > The times listed are what it takes to run each query separately.
>of is
> > run it as one query, I kill it after several minutes.
> > The plan is natural for all querys. The only thing I can think
> > that FB is evaluating the IN statement for every row.di2.ID,di2.NDC,di2.FRMTD_NDC,di2.UPC_HRI,di2.FRMTD_MDDB_UPC_HRI,di2.GP
> >
> > -- 0.781s
> > select
> >
> >
> > I,this
> > di2.STATUS,di2.NAME,di2.LABELNAME
> > from
> > MDDB_DRUGITEM di2
> > where
> > di2.NDC in
> > (
> > -- 0.561s
> > select
> > d1.ndc
> > from
> > mddb_drugitem d1
> > where
> > d1.upc_hri is not null and d1.ndc is not null group by
> > d1.ndc
> > having
> > count(*) > 1
> > )
>
> The IN predicate means that the entire subselect must be run. In
> case, you should be able to change it to an EXISTS, which willreturn as
> soon as it has found a single record. If the subselect has a largeset,
> this could speed it up significantly.If
>
> If my brain was switched on, I could probably reverse engineer your
> table structure and the aim of your query and try and come up with
> something better, but sadly it is too early in the morning (here).
> you want to post the basic fields. Actually the subselect is usingthe
> same table, so I am guessing you are after duplicates or somethinglike
> that, but let us know if these tips didn't solve your problem andwe can
> take a deeper look.~-->
>
> Adam
>
>
>
>
>
>
> ------------------------ Yahoo! Groups Sponsor --------------------
> Fair play? Video games influencing politics. Click and talk back!~->
> http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/67folB/TM
> --------------------------------------------------------------------
>on
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Yahoo! Groups Links