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

From: Hursh Jain <hurshj(at)gmail(dot)com>
To: 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 00:54:47
Message-ID: 587C19D7.5080008@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

As a followup:

I noticed that there isn't any "pid" column in the reward table. So that
was an error and maybe that's why a sequential scan was being forced. To
recap, the query was:

SELECT
*
FROM
property p
LEFT OUTER JOIN users ON (p.current_owner = users.uid)
WHERE
p.pid in
(SELECT pid FROM reward WHERE reward_type = 'daily'
ORDER BY reward_date DESC LIMIT 30)

But weirdly, the query still runs without any errors. Why ?

===

I tried this (a simpler version of the above):

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)? In fact, because there was no error, I
didn't notice my typo (no pid in reward table) until right now...

Best,
--J

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message David G. Johnston 2017-01-16 01:41:48 Re: Queries with Joins before filtering taking too much time! Filter (where clause) *first* -- suggestions ?
Previous Message Hursh Jain 2017-01-15 23:46:09 Queries with Joins before filtering taking too much time! Filter (where clause) *first* -- suggestions ?