От: Pierre-Frédéric Caillaud
Тема: Re: Poor Query
Дата: ,
Msg-id: opsilkfkrucq72hf@musicbox
(см: обсуждение, исходный текст)
Ответ на: Re: Poor Query  (Pallav Kalva)
Ответы: Re: Poor Query  (Pallav Kalva)
Список: pgsql-performance

Скрыть дерево обсуждения

Poor Query  (Pallav Kalva, )
 Re: Poor Query  (Pierre-Frédéric Caillaud<>, )
  Re: Poor Query  (Pallav Kalva, )
   Re: Poor Query  (Pierre-Frédéric Caillaud<>, )
    Re: Poor Query  (Pallav Kalva, )
     Re: Poor Query  (Pierre-Frédéric Caillaud<>, )
      Re: Poor Query  (Pallav Kalva, )
       Re: Poor Query  (Pierre-Frédéric Caillaud<>, )
        Re: Poor Query  (Pallav Kalva, )


> Just One, user can i have only one bankaccount.

    Ah well, in that case :
    This is your query :

select userID, fname, lname, email, phone, dateEntered, dateCanceled,
dateSuspended, billAmount, billDate, dateBilled, datePaid, '?' as searches
 from Users u
where 1=1 AND exists (select userID
            from bankaccount ba
            where ba.bankaccountID = u.bankaccountID
            and   ba.accountnumber = '12345678')
AND exists (select userID
         from bankaccount ba
         where ba.bankaccountID = u.bankaccountID
         and ba.routingNumber = '12345678')
order by UserID desc
limit 500

    What it does is scan all users, and for each user, test if it has the
accountnumber or the routingNumber you seek. You're reversing the problem
: you should first look for accountnumber and routingNumber, THEN look for
the user :


SELECT * FROM Users WHERE bankaccountID IN
(SELECT bankaccountID FROM bankaccount WHERE accountnumber = '12345678'
OR/AND routingNumber = '12345678')

or :

SELECT * FROM Users WHERE userID IN
(SELECT userID FROM bankaccount WHERE accountnumber = '12345678' OR/AND
routingNumber = '12345678')

There is something very strange in your query, it seems that bankaccount
and Users both have a UserID column and a bankaccountID column. Is this
normal ? It looks denormalized to me...


В списке pgsql-performance по дате сообщения:

От: Pallav Kalva
Дата:
Сообщение: Re: Poor Query
От: "Rosny"
Дата:
Сообщение: Re: TableSpace Design issues on Postgres 8.0 beta 5