Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 60D9D1337B68 for ; Wed, 23 Mar 2011 04:25:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 14938-03 for ; Wed, 23 Mar 2011 07:25:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 200DE13364DE for ; Wed, 23 Mar 2011 04:25:16 -0300 (ADT) Received: by fxm17 with SMTP id 17so7080382fxm.19 for ; Wed, 23 Mar 2011 00:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=m8wgGTXoJOA/dBI+i7Hb3DR7I4SnBzsssxi+Yu4YRBY=; b=EUF6SN7Nhbh3hRg/smGIMMzbar6v9u7qxcS7mJO/nrIzSiBxHBo6RDExbYeNl78KJT RqVgoM5b9eucPf7fsbFMj0et+TLURmqbVMvtc7vRSQF7Lkmr88truzaT8BVbKK7YvYiW 9lQ7sJYax37SDmAC4nW3qQt5GWNF2AVa8jutE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; b=ERC+Ik9DFo2aUkuwaXcEfNesEmgTOH/W+bt/Np4P65NrahaC71eL4+n7XGLqgRlCSF l5BGQKWAUQFjE6uH0hJWubSMPsSoZyTGjTrrGor0joscj6cdWJq8Jb2V2tI0l3BdOABy A2nbfPZhuyMbi/ARqMxf9Rj4XEPpUANlz6WAM= Received: by 10.223.15.141 with SMTP id k13mr2639186faa.30.1300865116100; Wed, 23 Mar 2011 00:25:16 -0700 (PDT) Received: from [10.1.1.57] (skuns.zoral.com.ua [91.193.166.194]) by mx.google.com with ESMTPS id f15sm3276052fax.34.2011.03.23.00.25.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 23 Mar 2011 00:25:15 -0700 (PDT) Message-ID: <4D89A06E.2020202@gmail.com> Date: Wed, 23 Mar 2011 09:25:34 +0200 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Reason of Slowness of query References: <4D899301.7070301@orkash.com> In-Reply-To: <4D899301.7070301@orkash.com> Content-Type: multipart/alternative; boundary="------------000001010109050006030700" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.035 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=1.553, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201103/256 X-Sequence-Number: 42935 This is a multi-part message in MIME format. --------------000001010109050006030700 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 23.03.11 08:28, Adarsh Sharma ???????(??): > * > *I perform a join query on it as : > > * explain analyze select distinct(p.crawled_page_id) from page_content > p , clause2 c where p.crawled_page_id != c.source_id ;* Your query is wrong. This query will return every *crawled_page_id* if clause2 has more then 1 source_id. This is because DB will be able to find clause with source_id different from crawled_page_id. You need to use "not exists" or "not in". Best regards, Vitalii Tymchyshyn. --------------000001010109050006030700 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 23.03.11 08:28, Adarsh Sharma написав(ла):

I perform a join query on it as :

 explain analyze select distinct(p.crawled_page_id) from page_content p , clause2  c where p.crawled_page_id != c.source_id ;
Your query is wrong. This query will return every crawled_page_id if clause2 has more then 1 source_id. This is because DB will be able to find clause with source_id different from crawled_page_id. You need to use "not exists" or "not in".

Best regards, Vitalii Tymchyshyn.
--------------000001010109050006030700--