pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shaun Thomas <sthomas@peak6.com>
To: Adarsh Sharma <adarsh.sharma@orkash.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Re-Reason of Slowness of Query
Date: Wed, 23 Mar 2011 08:34:29 -0500
Message-ID: <4D89F6E5.7010803@peak6.com> (raw)
In-Reply-To: <4D89BABF.4080806@orkash.com>
References: <4D89BABF.4080806@orkash.com>

On 03/23/2011 04:17 AM, Adarsh Sharma wrote:

> explain analyze select distinct(p.crawled_page_id) from page_content
> p where NOT EXISTS (select 1 from clause2 c where c.source_id =
> p.crawled_page_id);

You know... I'm surprised nobody has mentioned this, but DISTINCT is 
very slow unless you have a fairly recent version of Postgres that 
replaces it with something faster. Try this:

EXPLAIN ANALYZE
SELECT p.crawled_page_id
   FROM page_content p
  WHERE NOT EXISTS (
          SELECT 1
            FROM clause2 c
           WHERE c.source_id = p.crawled_page_id
        )
  GROUP BY p.crawled_page_id;

Or if you like the cleaner query without a sub-select:

EXPLAIN ANALYZE
SELECT p.crawled_page_id
   FROM page_content p
   LEFT JOIN clause2 c ON (c.source_id = p.crawled_page_id)
  WHERE c.source_id IS NULL
  GROUP BY p.crawled_page_id;

-- 
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com

______________________________________________

See  http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email



view thread (19+ messages)  latest in thread

Message-ID: <4D89F6E5.7010803@peak6.com>
Permalink:  ../4D89F6E5.7010803@peak6.com/
Also on:    postgresql.org/message-id/4D89F6E5.7010803@peak6.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: sthomas@peak6.com, adarsh.sharma@orkash.com
  Subject: Re: Re-Reason of Slowness of Query
  In-Reply-To: <4D89F6E5.7010803@peak6.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox