Re: Queries with Joins before filtering taking too much time! Filter (where clause) *first* -- suggestions ?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Hursh Jain <hurshj(at)gmail(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Queries with Joins before filtering taking too much time! Filter (where clause) *first* -- suggestions ?
Date: 2017-01-16 01:41:48
Message-ID: CAKFQuwYg5YgmKwVf1OGeEktO99yGPq_ed7_uSArciiBdR6tU6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sunday, January 15, 2017, Hursh Jain <hurshj(at)gmail(dot)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.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Piyush Katariya 2017-01-17 15:39:11 (Stateless and Distributed) Transaction in Event Driven Architecture
Previous Message Hursh Jain 2017-01-16 00:54:47 Re: Queries with Joins before filtering taking too much time! Filter (where clause) *first* -- suggestions ?