Re: Query process is very slow

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Kalai R <softlinne(dot)kv(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Query process is very slow
Date: 2010-06-08 18:12:49
Message-ID: AANLkTilLtEe7AyEkNeHDPm--QBX3r5GYE7Ha0ijZKXNm@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/6/8 Kalai R <softlinne(dot)kv(at)gmail(dot)com>

> Sir,
>
> I am using the following psql query with union and subqueries in my
> project.
>
>
> select a.areaname,f.fmno,fm.mno,f.aliasno as falias,f.salutation as
> fsal,f.headname, fm.aliasno as fmalias,fm.salutation as fmsal,fm.membername,
> extract (year from age(now(), to_date(fm.dob,'yyyy-MM-dd'))) as age,
> fr1.year,sum(fr2.amount) as amt from fmember fm left outer join fmreceipt2
> fr2 on fm.mno=fr2.mno, fmreceipt1 fr1,prayerarea a,family f where fr2.mno in
> (select fm2.mno from fmreceipt1 fm1,fmreceipt2 fm2 where fm1.refno =
> fm2.refno and fr1.edate>='01-06-2010' and fr1.edate<='08-06-2010' group by
> fm2.mno,fm1.year having (sum(fm2.amount)>=0 and sum(fm2.amount)<=1000))and a.areano=f.areano and fm.fmno=f.fmno and fm.dob<>'' and
> fr2.refno=fr1.refno group by
> a.areaname,f.fmno,fm.mno,f.aliasno,f.salutation,f.headname,fm.aliasno,
> fm.salutation,fm.membername,fm.dob,fr1.year,fr1.edate having extract (year
> from age(now(), to_date(fm.dob,'yyyy-MM-dd')))>0 and fr1.edate>='01-06-2010'
> and fr1.edate<='08-06-2010' union select
> a.areaname,f.fmno,fm.mno,f.aliasno as falias,f.salutation as fsal,
> f.headname,fm.aliasno as fmalias,fm.salutation as fmsal,fm.membername,
> extract (year from age(now(), to_date(fm.dob,'yyyy-MM-dd'))) as age,0,0 from
> fmember fm,family f,prayerarea a where fm.mno not in (select fm2.mno from
> fmreceipt2 fm2) and f.fmno=fm.fmno and a.areano=f.areano and fm.dob<>''
> group by a.areaname,f.fmno,fm.mno,f.aliasno,f.salutation,f.headname,
> fm.aliasno,fm.salutation,fm.membername,fm.dob having extract (year from
> age(now(), to_date(fm.dob,'yyyy-MM-dd')))>0 order by 1,2,3,11
>
>
> When I run this query it takes 1 minute to give result but in the receipt1
> table contains 4000 records only.
> I want to know what is the problem? Is there any mistake in the query?
>
> Kindly clarify.
>
> Thanks
> Gloier
>
>

Sorry, the query in this form is totally unreadable. First of all run
explain analyze and then paste the output here or use
http://explain.depesz.com/ and give us the link to the much
more readable version.

regards
Szymon Guz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jaime Casanova 2010-06-08 18:15:41 Re: 3rd time is a charm.....right sibling is not next child crash.
Previous Message Kalai R 2010-06-08 18:08:50 Query process is very slow