From: Pallav Kalva <pkalva@deg.cc>
To: Pierre-Frédéric Caillaud <lists@boutiquenumerique.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Poor Query
Date: Mon, 06 Dec 2004 15:44:04 -0500
Message-ID: <41B4C494.5090304@deg.cc> (raw)
In-Reply-To: <opsilr02qxcq72hf@musicbox>
References: <41B47A97.1090708@deg.cc>
<opsilfifducq72hf@musicbox>
<41B48053.7090805@deg.cc>
<opsilgs8b4cq72hf@musicbox>
<41B48ADB.7000100@deg.cc>
<opsilkfkrucq72hf@musicbox>
<41B49E3B.7030407@deg.cc>
<opsilr02qxcq72hf@musicbox>
Pierre-Frédéric Caillaud wrote:
>
> Your suffering comes from the "where ba.bankaccountID =
> u.bankaccountID" in the subselect. It means postgres has to run the
> subselect once for each row in Users. You want the subselect to run
> only once, and return one (or more?) bankaccountid's, then fetch the
> users from Users.
>
> Just remove the "where ba.bankaccountID = u.bankaccountID" !
>
>> select userID, fname, lname, email, phone, dateEntered, dateCanceled,
>> dateSuspended, billAmount, billDate, dateBilled, datePaid, '?' as
>> searches
>> from Users u
>> where bankaccountid in (select bankaccountid
>> from bankaccount ba
>> where ba.bankaccountID = u.bankaccountID
>> and ba.accountnumber = '12345678'
>> and ba.routingNumber = '12345678')
>> order by UserID desc
>> limit 500
>
>
> New version :
>
> select userID, fname, lname, email, phone, dateEntered, dateCanceled,
> dateSuspended, billAmount, billDate, dateBilled, datePaid, '?' as
> searches
> from Users u
> where bankaccountid in (select bankaccountid
> from bankaccount ba
> WHERE ba.accountnumber = '12345678'
> and ba.routingNumber = '12345678')
>
> You could also do this :
>
> select u.* from Users u, bankaccount ba
> where u.bankaccountid = ba.bankaccountid
> and ba.accountnumber = '12345678'
> and ba.routingNumber = '12345678')
>
>
>
Thanks! a lot that was it , it is way much better now.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: pkalva@deg.cc, lists@boutiquenumerique.com
Subject: Re: Poor Query
In-Reply-To: <41B4C494.5090304@deg.cc>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox