Re: [NOVICE] Queries with Joins before filtering taking too muchtime! Filter (where clause) *first* -- suggestions ?

Поиск
Список
Период
Сортировка
От Hursh Jain
Тема Re: [NOVICE] Queries with Joins before filtering taking too muchtime! Filter (where clause) *first* -- suggestions ?
Дата
Msg-id 587E4238.1080203@gmail.com
обсуждение исходный текст
Ответ на Re: [NOVICE] Queries with Joins before filtering taking too muchtime! Filter (where clause) *first* -- suggestions ?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-novice
Thanks David.

I didn't realize that the column names in the subquery would be scoped
to the outer query table. I thought one *had* to use an alias for that
and by default the column names were always scoped to the inner query
(and would error out otherwise).

Definitely learnt something new today..thanks again for the reply!

Best,
--H

David G. Johnston wrote:
> On Sunday, January 15, 2017, Hursh Jain <hurshj@gmail.com
> <mailto:hurshj@gmail.com>> wrote:
>
>
>     SELECT * from property
>     WHERE pid in (
>        SELECT pid FROM reward WHERE reward_type = 'DAILYPROMO_WIN')
>     ;
>
>     And this also runs (again taking a long time) but without any
>     errors. How can this be ? (there is no pid in the reward table, so
>     why does the
>     subquery not throw an error)?
>
>
>
> The "pid" column is the one from the outer query property table - this
> is a correlated subquery that you've written.
>
> As long as one record with that reward_type exists your query devolves
> to "where true" thus making indexes useless and returning every row in
> property.
>
> David J.
>


В списке pgsql-novice по дате отправления:

Предыдущее
От: KARIN SUSANNE HILBERT
Дата:
Сообщение: [NOVICE] What's the best way to handle privileges when theapplication account needs to maintain the database objects?
Следующее
От: Kevin Grittner
Дата:
Сообщение: Re: [NOVICE] What's the best way to handle privileges when theapplication account needs to maintain the database objects?