🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: how can I speed up this query

#10990
From: Arno Brinkman
Date: Sat, 21 Dec 2002 10:33
32 lines
2095 bytes
Hi,

> I have one table which has 90.000 records and it has all accounts to
receive
> Each record has a Contract_ID and the same Contract can have up to 20
> Accounts to receive
> But, I want to show only the first record of each Contract which was not
> paid yet or if it was paid between two dates.
>
> Select P.Name R.* from Receive R inner join Customer P on
> R.Customer_ID = P.Customer_ID where R.Receive_ID = (select min(Receive_ID)
> from Receive
> where (PayDate is Null or PayDate between '12/01/02' and '12/31/02') and
> Contract_ID=R.Contract_ID group by Contract_ID ) and R.DueDate between
> '12/01/02' and '12/31/02'

<..snip..>

> It takes up to 11 seconds to return using IBConsole.
> and, if I use:
> select * from Receive where DueDate between '12/01/02' and '12/31/02'
> It takes just 0.006 Seconds to return
>
> Then, What do need I do to run that first query faster, like this last one
?

Do you have an index on PayDate and one at DueDate ?

And give us also the PLAN from query, so we can see more.

Regards,
Arno
Technical Details
Message-ID: <3e044201@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!gestalt.direcpc.com!telocity-west!DIRECTV!203.109.225.2!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3e03bb4d@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 114a0e,bdd368e2d37d69d2
X-Google-Attributes: gid114a0e,public
X-Google-ArrivalTime: 2002-12-21 02:39:40 PST
From: "Arno Brinkman" <bnewsgroups @ abvisie.nl>
Newsgroups: borland.public.interbase.sql
References: <3e03bb4d@newsgroups.borland.com>
Subject: Re: how can I speed up this query
Date: Sat, 21 Dec 2002 11:33:45 +0100
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 213.116.166.201
Message-ID: <3e044201@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1040466433 213.116.166.201 (21 Dec 2002 02:27:13 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!64.152.100.70.MISMATCH!sjc70.webusenet.com!news.webusenet.com!gestalt.direcpc.com!telocity-west!DIRECTV!203.109.225.2!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail