Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UNPi4-00030V-7J for pgsql-performance@arkaria.postgresql.org; Wed, 03 Apr 2013 15:34:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UNPi3-00006O-K3 for pgsql-performance@arkaria.postgresql.org; Wed, 03 Apr 2013 15:34:47 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UNPi2-00006H-EB for pgsql-performance@postgresql.org; Wed, 03 Apr 2013 15:34:46 +0000 Received: from nm13-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.79]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UNPhr-00027L-JT for pgsql-performance@postgresql.org; Wed, 03 Apr 2013 15:34:45 +0000 Received: from [98.139.215.140] by nm13.bullet.mail.bf1.yahoo.com with NNFMP; 03 Apr 2013 15:34:33 -0000 Received: from [98.139.212.199] by tm11.bullet.mail.bf1.yahoo.com with NNFMP; 03 Apr 2013 15:34:33 -0000 Received: from [127.0.0.1] by omp1008.mail.bf1.yahoo.com with NNFMP; 03 Apr 2013 15:34:33 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 876629.76068.bm@omp1008.mail.bf1.yahoo.com Received: (qmail 89270 invoked by uid 60001); 3 Apr 2013 15:34:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1365003273; bh=5T9D8rsCATa46jbD2QKegr1lhwhrftP4SdHoM+nkC3c=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=qJ8GvhJ5mYSmEf7I5eZgh9b28Z45akjhFowY1gYzSKBQ7+OodQV/E/dOqrf8WT0MK5xZjG9qCUizUQDIPrcvHR/zQPXyIlx/TMyiInla8oQO5tF1Ouz01R2FtYbVqlGtDt0sYM3B+Ezi/oSqoQBklrh3BXWy6cx/muEg0ZAWvdU= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=1+wN9z3+M9WnNpXNRYe2rVIzLXAQfOygF+Qk/ZLXcY4hxtQFtJYuYnGWstcszrS6QbX1cukF+Bfdyecb9oPdyJoEHF5yeTs8rCwKQcXFAJEGe2m7ii9YjV/4cFHqWnRrBsEhGuE4PThVEVwt45d8llbCHSwf7nFF6509krcN08I=; X-YMail-OSG: 2UEz5AIVM1nslNCri0Ovz7mkegZOMMan2Q0wrdaDgTSaweJ AB0WArOwohLxkHwxpoxFGTyUydHKSQMZb7LCiGp4Uwdx8_AtswJFgStkA_we th6Y0zqNcJuJPwC9sk_j0EN74kfWZHufNV2VjSSc6EPBlkxCwpuGZzHpFLU4 cH063Es9wSSDfhdtkZvty2Z6f6NRrqWYZml0k56NonDUA5c651YwWt3Wk4nr LUFdivEnUwBPyUT3xR.7T_4d9krpNec0dKCSt_yjeqNthtCi6IJwxDLsxjfD TRsREeR_UJQQb4t1GW.fLa2xlEOl3UYJq.1TaHxt5MRuomgGuacAYqdBq3Ye 9WYfbarfnlNR0ErYNQ0c34WL76ef9P9W.fLOrfc1uaFwN8e4cWLBeGeY0HcN 2sEGJ6n9c0dRIJovZrcPsSCytOIGhgg5HArdY.ume1jpIuh7Z.62Dzhq6P0c C39XEI2PQEWY7Sy7NK7dqRrZ6a2ITfIxGeDtrJmk3ITVG8NLWlpoqQ5ULqSs ljoJJpwVQ07k3Aa8_qU.9KEve.Gb7S1HwpxmDhLKKwaMttJWgKFWe2sC4nGu x4KeUc3G06403VpIK Received: from [76.255.18.237] by web162905.mail.bf1.yahoo.com via HTTP; Wed, 03 Apr 2013 08:34:33 PDT X-Rocket-MIMEInfo: 002.001, QUkgUnVtbWFuIDxydW1tYW5kYmFAZ21haWwuY29tPiB3cm90ZToKCj4gV2h5IGlzIHRoZSBmb2xsb3dpbmcgcXVlcnkgZ2V0dGluZyB3cm9uZyBlc3RpbWF0aW9uIG9mIHJvd3M_Cj4gSSBhbSB1c2luZyBQb3N0Z3Jlc3FsIDkuMi4xIHdpdGggZGVmYXVsdF9zdGF0aXN0aWNzX3RhcmdldCA9IDEwMC4KPiBJIGV4ZWN1dGUgdmFjdXVtIGFuYWx5emUgZWFjaCBuaWdodC4KCj4gSGFzaCBKb2luwqAgKGNvc3Q9MTQwNjcuOTAuLjI4MDY2LjUzIHJvd3M9OTAzNzkgd2lkdGg9MjYpIChhY3R1YWwgdGltZT01MzYuMDABMAEBAQE- X-Mailer: YahooMailWebService/0.8.140.532 References: Message-ID: <1365003273.32054.YahooMailNeo@web162905.mail.bf1.yahoo.com> Date: Wed, 3 Apr 2013 08:34:33 -0700 (PDT) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Planner is getting wrong row count To: AI Rumman , postgres performance list In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org AI Rumman wrote: > Why is the following query getting wrong estimation of rows? > I am using Postgresql 9.2.1 with default_statistics_target =3D 100. > I execute vacuum analyze each night. > Hash Join=A0 (cost=3D14067.90..28066.53 rows=3D90379 width=3D26) (actual = time=3D536.009..1772.910 rows=3D337139 loops=3D1) >=A0=A0=A0 Hash Cond: (leads.leadid =3D entity.id) >=A0=A0=A0 ->=A0 Seq Scan on leads=A0 (cost=3D0.00..7764.83 rows=3D533002 w= idth=3D18) (actual time=3D0.008..429.576 rows=3D532960 loops=3D1) >=A0=A0=A0=A0=A0=A0=A0=A0=A0 Filter: (converted =3D 0) >=A0=A0=A0 ->=A0 Hash=A0 (cost=3D9406.25..9406.25 rows=3D372932 width=3D16)= (actual time=3D535.800..535.800 rows=3D342369 loops=3D1) >=A0=A0=A0=A0=A0=A0=A0=A0=A0 Buckets: 65536=A0 Batches: 1=A0 Memory Usage: = 16049kB >=A0=A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Index Scan using entity_type_idx on enti= ty=A0 (cost=3D0.00..9406.25 rows=3D372932 width=3D16) (actual time=3D0.030.= .305.250 rows=3D342369 loops=3D1) >=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Index Cond: ((type)::text = =3D 'Leads'::text) The estimates match up well with actual until the hash join.=A0 That suggests that there is a correlation between the join conditions and the other selection criteria which the planner doesn't know about.=A0 Right now PostgreSQL has no way to adjust estimates based on such correlations.=A0 If an inefficient plan is being chosen due to this, there are a few tricks to coerce the plan. -- Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance