Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 0E46A9FBACC for ; Thu, 12 Apr 2007 01:16:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 85611-01-5 for ; Thu, 12 Apr 2007 01:16:38 -0300 (ADT) X-Greylist: delayed 01:15:03.881675 by SQLgrey-1.7.4 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 595009FA305 for ; Thu, 12 Apr 2007 01:16:28 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from smtpauth00.csee.siteprotect.com (smtpauth00.csee.siteprotect.com [64.41.126.131]) by svr4.postgresql.org (Postfix) with ESMTP id 093305B01D3 for ; Mon, 9 Apr 2007 11:52:01 +0000 (GMT) Received: from waterloo (CPE00119557f5ec-CM000f9faa78f6.cpe.net.cable.rogers.com [74.100.133.105]) by smtpauth00.csee.siteprotect.com (Postfix) with ESMTP id 2430232C032; Mon, 9 Apr 2007 06:51:59 -0500 (CDT) Received: by waterloo (sSMTP sendmail emulation); Mon, 09 Apr 2007 07:51:53 -0400 From: "Jan de Visser" To: pgsql-performance@postgresql.org Subject: Re: Beginner Question Date: Mon, 9 Apr 2007 07:51:53 -0400 User-Agent: KMail/1.9.6 Cc: "s d" References: <24b53fa00704090209pcdd2c6cof487d6388c1743b8@mail.gmail.com> In-Reply-To: <24b53fa00704090209pcdd2c6cof487d6388c1743b8@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200704090751.53347.jdevisser@digitalfairway.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200704/244 X-Sequence-Number: 24121 On Monday 09 April 2007 05:09:53 s d wrote: > Hi, > I am trying to figure out how to debug a performance problem / use psql > explain. The table in question is: > # \d word_association; > Table "public.word_association" > Column | Type | Modifiers > --------+------------------------+-------------------- > word1 | character varying(128) | not null > word2 | character varying(128) | not null > count | integer | not null default 0 > Indexes: > "word1_word2_comb_unique" unique, btree (word1, word2) > "word1_hash_index" hash (word1) > "word2_hash_index" hash (word2) > "word_association_count_index" btree (count) > "word_association_index1_1" btree (word1) > "word_association_index2_1" btree (word2) > > It has multiple indices since i wanted to see which one the planner chose= s. > > > # explain select * FROM word_association WHERE (word1 =3D 'bdss' OR > word2 =3D 'bdss') AND count >=3D 10; > QUERY PLAN > -------------------------------------------------------------------------= =2D- >--------------------- Bitmap Heap Scan on word_association=20 > (cost=3D11.53..1192.09 rows=3D155 width=3D22) Recheck Cond: (((word1)::te= xt =3D > 'bdss'::text) OR ((word2)::text =3D 'bdss'::text)) > Filter: (count >=3D 10) > -> BitmapOr (cost=3D11.53..11.53 rows=3D364 width=3D0) > -> Bitmap Index Scan on word_association_index1_1 > (cost=3D0.00..5.79 rows=3D190 width=3D0) > Index Cond: ((word1)::text =3D 'bdss'::text) > -> Bitmap Index Scan on word_association_index2_1 > (cost=3D0.00..5.67 rows=3D174 width=3D0) > Index Cond: ((word2)::text =3D 'bdss'::text) > (8 rows) > > The questions: > 1. i can undestand where the cost=3D11.53 came from but where did the > 1192.09 come form? The values are in milli right ? > 2. the query takes in reality much longer than 1 second. > > In short, it feels like something is very wrong here (i tried vacuum > analyze and it didn't do much diff). > any ideas ? You need an index on (word1, word2, count). In your current setup it will h= ave=20 to scan all rows that satisfy word1 and word2 to see if count >=3D 10. jan =2D-=20 =2D------------------------------------------------------------- Jan de Visser =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 jdevisser@digitalfair= way.com =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Baruk Khazad! Khazad ai-menu! =2D-------------------------------------------------------------