From: Jan de Visser <jdevisser@digitalfairway.com>
To: pgsql-performance@postgresql.org
Cc: s d <s.d.sauron@gmail.com>
Subject: Re: Beginner Question
Date: Mon, 9 Apr 2007 07:51:53 -0400
Message-ID: <200704090751.53347.jdevisser@digitalfairway.com> (raw)
In-Reply-To: <24b53fa00704090209pcdd2c6cof487d6388c1743b8@mail.gmail.com>
References: <24b53fa00704090209pcdd2c6cof487d6388c1743b8@mail.gmail.com>
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 choses.
>
>
> # explain select * FROM word_association WHERE (word1 = 'bdss' OR
> word2 = 'bdss') AND count >= 10;
> QUERY PLAN
> ---------------------------------------------------------------------------
>--------------------- Bitmap Heap Scan on word_association
> (cost=11.53..1192.09 rows=155 width=22) Recheck Cond: (((word1)::text =
> 'bdss'::text) OR ((word2)::text = 'bdss'::text))
> Filter: (count >= 10)
> -> BitmapOr (cost=11.53..11.53 rows=364 width=0)
> -> Bitmap Index Scan on word_association_index1_1
> (cost=0.00..5.79 rows=190 width=0)
> Index Cond: ((word1)::text = 'bdss'::text)
> -> Bitmap Index Scan on word_association_index2_1
> (cost=0.00..5.67 rows=174 width=0)
> Index Cond: ((word2)::text = 'bdss'::text)
> (8 rows)
>
> The questions:
> 1. i can undestand where the cost=11.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 have
to scan all rows that satisfy word1 and word2 to see if count >= 10.
jan
--
--------------------------------------------------------------
Jan de Visser jdevisser@digitalfairway.com
Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------
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: jdevisser@digitalfairway.com, s.d.sauron@gmail.com
Subject: Re: Beginner Question
In-Reply-To: <200704090751.53347.jdevisser@digitalfairway.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