Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1544B632716 for ; Mon, 15 Feb 2010 05:50:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 54087-03 for ; Mon, 15 Feb 2010 09:50:15 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f214.google.com (mail-ew0-f214.google.com [209.85.219.214]) by mail.postgresql.org (Postfix) with ESMTP id 708FA63261E for ; Mon, 15 Feb 2010 05:50:15 -0400 (AST) Received: by ewy6 with SMTP id 6so2273319ewy.34 for ; Mon, 15 Feb 2010 01:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=sfNGsnLoE4IbZ1SLG9EEnaHvrBzltulNQZXNSrvlwUg=; b=xMI9cYJV5g1Gg5oZP9E5/FFxyVC4tReCMWwTTq6NAuC5JkfO3cCxVnhaZWmEuJnUTs +vIFXYhIXnV4DWnh/fmJxoy77P4NWdyEvKUMwYhR3bzSRgouOe6WTarNPqCXmpYDIbm/ 3YIW5qx22VRU+lqCnmyBCeQm7x1MP9AfMejng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Ig7sZ8X52/PzPHLUNLdGFreCk+1N+GZk3Y9jWL3IOs5ohGeOSAXQyRiVBudFEREHLX +oAlrDdKUJcwYmoZ7l5vK4zMZnN5W6tje6ef8BHcgn9lTGiKOm7OhcBsX0iAiQOYEgVk wZ2mK1tIuOMJc/JRWg31+/NQLns0KmJdXFnU4= MIME-Version: 1.0 Received: by 10.216.171.145 with SMTP id r17mr1316799wel.182.1266227413480; Mon, 15 Feb 2010 01:50:13 -0800 (PST) In-Reply-To: <2a7905441002150135x1ba61b19p89f3c3b94d252843@mail.gmail.com> References: <2a7905441002150135x1ba61b19p89f3c3b94d252843@mail.gmail.com> Date: Mon, 15 Feb 2010 02:50:13 -0700 Message-ID: Subject: Re: Why primary key index are not using in joining? From: Scott Marlowe To: AI Rumman Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.11 tagged_above=-10 required=5 tests=BAYES_05=-1.11 X-Spam-Level: X-Archive-Number: 201002/232 X-Sequence-Number: 37653 On Mon, Feb 15, 2010 at 2:35 AM, AI Rumman wrote: > > Please have a look at the following explain plan: > > explain analyze > select * > from vtiger_crmentity > inner JOIN vtiger_users > =A0=A0=A0=A0=A0=A0=A0=A0 ON vtiger_users.id =3D vtiger_crmentity.smowneri= d > where vtiger_crmentity.deleted =3D 0=A0 ; > > QUERY > PLAN > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------- > =A0Hash Join=A0 (cost=3D3665.17..40019.25 rows=3D640439 width=3D1603) (ac= tual > time=3D115.613..3288.436 rows=3D638081 loops=3D1) > =A0=A0 Hash Cond: ("outer".smownerid =3D "inner".id) > =A0=A0 ->=A0 Bitmap Heap Scan on vtiger_crmentity=A0 (cost=3D3646.54..303= 94.02 > rows=3D640439 width=3D258) (actual time=3D114.763..986.504 rows=3D638318 = loops=3D1) > =A0=A0=A0=A0=A0=A0=A0=A0 Recheck Cond: (deleted =3D 0) > =A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Bitmap Index Scan on vtiger_crmentity_dele= ted_idx > (cost=3D0.00..3646.54 rows=3D640439 width=3D0) (actual time=3D107.851..10= 7.851 > rows=3D638318 loops=3D1) > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 Index Cond: (deleted =3D 0) > =A0=A0 ->=A0 Hash=A0 (cost=3D18.11..18.11 rows=3D211 width=3D1345) (actua= l > time=3D0.823..0.823 rows=3D211 loops=3D1) > =A0=A0=A0=A0=A0=A0=A0=A0 ->=A0 Seq Scan on vtiger_users=A0 (cost=3D0.00..= 18.11 rows=3D211 > width=3D1345) (actual time=3D0.005..0.496 rows=3D211 loops=3D1) > =A0Total runtime: 3869.022 ms > > Sequential index is occuring on vtiger_users table while it has primary k= ey > index on id. > Could anyone please tell me why? Cause it's only 211 rows and only takes 0.5 milliseconds to scan?