pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jodi Kanter <jkanter@virginia.edu>
To: Postgres Admin List <pgsql-admin@postgresql.org>
Subject: indexes not being used!
Date: Fri, 21 Mar 2003 10:41:53 -0500
Message-ID: <004101c2efc0$65e6d0a0$de138f80@virginia.edu> (raw)

We have a query that is causing performance problems. The indexes do not appear to be used despite the fact that they exist. I dropped the table and recreated from scratch. I reindexed as well and still no luck. We vacuum analyze the system often. I will do my best to list all that is happening. Any assistance would be greatly appreciated. If you can offer some insight as to what the explains are telling me that would be so helpful. Is there some documentation somewhere that discusses such results?
Thanks a lot!
Jodi Kanter

This is the table:
genex=# \d groupref 
         Table "groupref"
   Column    |  Type   | Modifiers 
-------------+---------+-----------
 us_fk       | integer | not null
 gs_fk       | integer | not null
 ref_fk      | integer | not null
 permissions | integer | 
Indexes: groupref_gs_fk_ind,
         groupref_permissions,
         groupref_us_fk_ind
Unique keys: groupref_ref_fk_ind

This is the original query and it's explain results:
genex=# explain select am_pk, smp_fk, am_comments, hybridization_name  from arraymeasurement, groupref, grouplink where (groupref.ref_fk=arraymeasurement.am_pk and  ((groupref.us_fk=1 and groupref.us_fk=grouplink.us_fk and grouplink.gs_fk=groupref.gs_fk and (groupref.permissions&128)>0) or (groupref.gs_fk=grouplink.gs_fk and grouplink.us_fk=1 and (groupref.permissions&16)>0 )));
NOTICE:  QUERY PLAN:

Nested Loop  (cost=5.88..350.58 rows=1 width=55)
  ->  Hash Join  (cost=5.88..47.57 rows=42 width=47)
        ->  Seq Scan on groupref  (cost=0.00..38.83 rows=313 width=16)
        ->  Hash  (cost=5.50..5.50 rows=150 width=31)
              ->  Seq Scan on arraymeasurement  (cost=0.00..5.50 rows=150 width=31)
  ->  Seq Scan on grouplink  (cost=0.00..1.78 rows=78 width=8)

Why is it ignoring indexes? There is a double join between groupref and grouplink. I thought this could be the trouble but you'll se below that I started to simplify the query below and still have trouble.

Next I eliminated a join to the main data table and got this:
genex=# explain select ref_fk from groupref, grouplink where ((groupref.us_fk=1 and groupref.us_fk=grouplink.us_fk and grouplink.gs_fk=groupref.gs_fk and (groupref.permissions&128)>0) or (groupref.gs_fk=grouplink.gs_fk and grouplink.us_fk=1 and (groupref.permissions&16)>0 ));
NOTICE:  QUERY PLAN:

Nested Loop  (cost=0.00..2303.34 rows=1 width=24)
  ->  Seq Scan on groupref  (cost=0.00..38.83 rows=313 width=16)
  ->  Seq Scan on grouplink  (cost=0.00..1.78 rows=78 width=8)


I thought that the OR part of the statement might be causing trouble so I eliminated it and got:
genex=# explain select ref_fk from groupref, grouplink where (groupref.us_fk=1 and groupref.us_fk=grouplink.us_fk and grouplink.gs_fk=groupref.gs_fk and (groupref.permissions&128)>0);
NOTICE:  QUERY PLAN:

Hash Join  (cost=18.71..20.89 rows=1 width=20)
  ->  Seq Scan on grouplink  (cost=0.00..1.78 rows=78 width=8)
  ->  Hash  (cost=18.71..18.71 rows=2 width=12)
        ->  Index Scan using groupref_us_fk_ind on groupref  (cost=0.00..18.71 rows=2 width=12)

Now an index is being used??

I did a vaccum analyze again and ran the same query. The explain results changed to this:
Merge Join  (cost=34.96..35.86 rows=32 width=20)
  ->  Sort  (cost=30.72..30.72 rows=95 width=12)
        ->  Seq Scan on groupref  (cost=0.00..27.62 rows=95 width=12)
  ->  Sort  (cost=4.23..4.23 rows=78 width=8)
        ->  Seq Scan on grouplink  (cost=0.00..1.78 rows=78 width=8)

I backed off to a very simple query and still cannot get the indexes working. 
genex=# explain select ref_fk from groupref where (groupref.us_fk=1 and (groupref.permissions&128)>0);
NOTICE:  QUERY PLAN:

Seq Scan on groupref  (cost=0.00..27.62 rows=95 width=4)

EXPLAIN
genex=# explain select ref_fk from groupref where (groupref.us_fk=1);
NOTICE:  QUERY PLAN:

Seq Scan on groupref  (cost=0.00..22.01 rows=284 width=4)

_______________________________
Jodi L Kanter
BioInformatics Database Administrator
University of Virginia
(434) 924-2846
jkanter@virginia.edu



 

 

 

view thread (8+ messages)  latest in thread

Message-ID: <004101c2efc0$65e6d0a0$de138f80@virginia.edu>
Permalink:  ../004101c2efc0$65e6d0a0$de138f80@virginia.edu/
Also on:    postgresql.org/message-id/004101c2efc0$65e6d0a0$de138f80@virginia.edu

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: jkanter@virginia.edu
  Subject: Re: indexes not being used!
  In-Reply-To: <004101c2efc0$65e6d0a0$de138f80@virginia.edu>
  References: <004101c2efc0$65e6d0a0$de138f80@virginia.edu>

* 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