RE: [GENERAL] Subselect question - Mailing list pgsql-general

From Jackson, DeJuan
Subject RE: [GENERAL] Subselect question
Date
Msg-id F10BB1FAF801D111829B0060971D839F5B06C4@cpsmail
Whole thread Raw
List pgsql-general
> Hi,
>
> I have some trouble with subselects. (Version 6.3).
>
> If I try
>
> Select name, address from costumers where cod_costumer  in (
> Select cod_costumer from logins where total_usage > 0);
>
> It take lots of time (really I din't wait till the end).
>
> But if I manualy split in
> Select cod_costumer from logins where total_usage > 0;
> getting
> ( 1,  9, 15, 18 , 40)
> and then use
> Select name, address from costumers where cod_costumer  in ( 1,  9,
> 15, 18 , 40);
>
> All is OK.
>
> Is this type of subselect suported ?
>
> Thanks
>  Giovanni Floridia
>

Yes it's supported, but the subselect will be executed for each row of
the main select.
This should be a faster select (but not as fast as your second one).
Select name, address from costumers where EXISTS(Select 1 from logins
where total_usage > 0 AND logins.cod_customer = customers.cod_customer);
    -DEJ

pgsql-general by date:

Previous
From: Anand Surelia
Date:
Subject: Regress test failing on Sparc Solaris 2.5.1
Next
From: Clark Evans
Date:
Subject: Re: [GENERAL] 88, CREATE FUNCTION ON TABLE