Re: Slow query with sub-select - Mailing list pgsql-general

From Rick Genter
Subject Re: Slow query with sub-select
Date
Msg-id EEAAD9C0-81B6-4B63-8AAB-00D3AD1B7388@gmail.com
Whole thread Raw
In response to Re: Slow query with sub-select  (- - <loh.law@hotmail.com>)
List pgsql-general

On Jul 16, 2011, at 4:14 PM, - - wrote:

I would like to count rows in q whose mid does not exist in t.

I would write such a query like this:

SELECT COUNT(*)
   FROM q
      LEFT OUTER JOIN t
         ON (t.mid = q.mid)
WHERE t.mid IS NULL;

And I would make sure there was an index on t.mid. (And for 9.2, as I understand it, q.mid as well, since I believe in 9.2 PostgreSQL will be able to compute the result strictly from the indexes without hitting the base tables.)


pgsql-general by date:

Previous
From: - -
Date:
Subject: Re: Slow query with sub-select
Next
From: AI Rumman
Date:
Subject: "FATAL: role "postgres" does not exist" after recover