X-Original-To: pgsql-admin@postgresql.org Received: from mail.virginia.edu (mail.Virginia.EDU [128.143.2.9]) by postgresql.org (Postfix) with SMTP id 30E63474E44 for ; Fri, 21 Mar 2003 10:35:43 -0500 (EST) Received: from smtp.mail.virginia.edu by mail.virginia.edu id aa26162; 21 Mar 2003 10:35 EST Received: from jlk3xpc (d-128-19-222.bootp.Virginia.EDU [128.143.19.222]) by smtp.mail.Virginia.EDU (8.11.6p/8.11.6) with SMTP id h2LFZhh15148 for ; Fri, 21 Mar 2003 10:35:43 -0500 Message-ID: <004101c2efc0$65e6d0a0$de138f80@virginia.edu> From: Jodi Kanter To: Postgres Admin List Subject: indexes not being used! Date: Fri, 21 Mar 2003 10:41:53 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_003E_01C2EF96.7CEDB040" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Archive-Number: 200303/341 X-Sequence-Number: 7981 This is a multi-part message in MIME format. ------=_NextPart_000_003E_01C2EF96.7CEDB040 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable We have a query that is causing performance problems. The indexes do not ap= pear to be used despite the fact that they exist. I dropped the table and r= ecreated from scratch. I reindexed as well and still no luck. We vacuum ana= lyze 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=3D# \d groupref=20 Table "groupref" Column | Type | Modifiers=20 -------------+---------+----------- us_fk | integer | not null gs_fk | integer | not null ref_fk | integer | not null permissions | integer |=20 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=3D# explain select am_pk, smp_fk, am_comments, hybridization_name fr= om arraymeasurement, groupref, grouplink where (groupref.ref_fk=3Darraymeas= urement.am_pk and ((groupref.us_fk=3D1 and groupref.us_fk=3Dgrouplink.us_f= k and grouplink.gs_fk=3Dgroupref.gs_fk and (groupref.permissions&128)>0) or= (groupref.gs_fk=3Dgrouplink.gs_fk and grouplink.us_fk=3D1 and (groupref.pe= rmissions&16)>0 ))); NOTICE: QUERY PLAN: Nested Loop (cost=3D5.88..350.58 rows=3D1 width=3D55) -> Hash Join (cost=3D5.88..47.57 rows=3D42 width=3D47) -> Seq Scan on groupref (cost=3D0.00..38.83 rows=3D313 width=3D16) -> Hash (cost=3D5.50..5.50 rows=3D150 width=3D31) -> Seq Scan on arraymeasurement (cost=3D0.00..5.50 rows=3D1= 50 width=3D31) -> Seq Scan on grouplink (cost=3D0.00..1.78 rows=3D78 width=3D8) Why is it ignoring indexes? There is a double join between groupref and gro= uplink. I thought this could be the trouble but you'll se below that I star= ted to simplify the query below and still have trouble. Next I eliminated a join to the main data table and got this: genex=3D# explain select ref_fk from groupref, grouplink where ((groupref.u= s_fk=3D1 and groupref.us_fk=3Dgrouplink.us_fk and grouplink.gs_fk=3Dgroupre= f.gs_fk and (groupref.permissions&128)>0) or (groupref.gs_fk=3Dgrouplink.gs= _fk and grouplink.us_fk=3D1 and (groupref.permissions&16)>0 )); NOTICE: QUERY PLAN: Nested Loop (cost=3D0.00..2303.34 rows=3D1 width=3D24) -> Seq Scan on groupref (cost=3D0.00..38.83 rows=3D313 width=3D16) -> Seq Scan on grouplink (cost=3D0.00..1.78 rows=3D78 width=3D8) I thought that the OR part of the statement might be causing trouble so I e= liminated it and got: genex=3D# explain select ref_fk from groupref, grouplink where (groupref.us= _fk=3D1 and groupref.us_fk=3Dgrouplink.us_fk and grouplink.gs_fk=3Dgroupref= .gs_fk and (groupref.permissions&128)>0); NOTICE: QUERY PLAN: Hash Join (cost=3D18.71..20.89 rows=3D1 width=3D20) -> Seq Scan on grouplink (cost=3D0.00..1.78 rows=3D78 width=3D8) -> Hash (cost=3D18.71..18.71 rows=3D2 width=3D12) -> Index Scan using groupref_us_fk_ind on groupref (cost=3D0.00..= 18.71 rows=3D2 width=3D12) Now an index is being used?? I did a vaccum analyze again and ran the same query. The explain results ch= anged to this: Merge Join (cost=3D34.96..35.86 rows=3D32 width=3D20) -> Sort (cost=3D30.72..30.72 rows=3D95 width=3D12) -> Seq Scan on groupref (cost=3D0.00..27.62 rows=3D95 width=3D12) -> Sort (cost=3D4.23..4.23 rows=3D78 width=3D8) -> Seq Scan on grouplink (cost=3D0.00..1.78 rows=3D78 width=3D8) I backed off to a very simple query and still cannot get the indexes workin= g.=20 genex=3D# explain select ref_fk from groupref where (groupref.us_fk=3D1 and= (groupref.permissions&128)>0); NOTICE: QUERY PLAN: Seq Scan on groupref (cost=3D0.00..27.62 rows=3D95 width=3D4) EXPLAIN genex=3D# explain select ref_fk from groupref where (groupref.us_fk=3D1); NOTICE: QUERY PLAN: Seq Scan on groupref (cost=3D0.00..22.01 rows=3D284 width=3D4) _______________________________ Jodi L Kanter BioInformatics Database Administrator University of Virginia (434) 924-2846 jkanter@virginia.edu =20 =20 =20 ------=_NextPart_000_003E_01C2EF96.7CEDB040 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
We have a query that is causing perform= ance=20 problems. The indexes do not appear to be used despite the fact that they e= xist.=20 I dropped the table and recreated from scratch. I reindexed = as=20 well and still no luck. We vacuum analyze the system often. I will do my be= st to=20 list all that is happening. Any assistance would be greatly appreciated. If= you=20 can offer some insight as to what the explains are telling me that would be= so=20 helpful. Is there some documentation somewhere that discusses such=20 results?
Thanks a lot!
Jodi Kanter
 
This is the=20 table:
genex=3D# \d groupref=20
         Table=20 "groupref"
   Column    |  Type  = ; |=20 Modifiers=20
-------------+---------+-----------
 us_fk   &nb= sp;  =20 | integer | not null
 gs_fk       |= =20 integer | not null
 ref_fk      | integer = | not=20 null
 permissions | integer |
Indexes:=20 groupref_gs_fk_ind,
        =20 groupref_permissions,
        = =20 groupref_us_fk_ind
Unique keys: groupref_ref_fk_ind
 
This is the original query and = it's=20 explain results:
genex=3D# explain select am_pk, smp_fk,= =20 am_comments, hybridization_name  from arraymeasurement, groupref, grou= plink=20 where (groupref.ref_fk=3Darraymeasurement.am_pk and  ((groupref.us_fk= =3D1 and=20 groupref.us_fk=3Dgrouplink.us_fk and grouplink.gs_fk=3Dgroupref.gs_fk and= =20 (groupref.permissions&128)>0) or (groupref.gs_fk=3Dgrouplink.gs_fk a= nd=20 grouplink.us_fk=3D1 and (groupref.permissions&16)>0 )));
NOTICE:&= nbsp;=20 QUERY PLAN:
 
Nested Loop  (cost=3D5.88..350.58 = rows=3D1=20 width=3D55)
  ->  Hash Join  (cost=3D5.88..47.57 rows= =3D42=20 width=3D47)
        ->  Seq S= can on=20 groupref  (cost=3D0.00..38.83 rows=3D313=20 width=3D16)
        ->  Hash&= nbsp;=20 (cost=3D5.50..5.50 rows=3D150=20 width=3D31)
          =    =20 ->  Seq Scan on arraymeasurement  (cost=3D0.00..5.50 rows=3D15= 0=20 width=3D31)
  ->  Seq Scan on grouplink  (cost=3D0.00.= .1.78=20 rows=3D78 width=3D8)
 
Why is it ignoring indexes? The= re is a=20 double join between groupref and grouplink. I thought this could be the tro= uble=20 but you'll se below that I started to simplify the query below and still ha= ve=20 trouble.
 
Next I eliminated a join to the= main=20 data table and got this:
genex=3D# explain select ref_fk from gr= oupref,=20 grouplink where ((groupref.us_fk=3D1 and groupref.us_fk=3Dgrouplink.us_fk a= nd=20 grouplink.gs_fk=3Dgroupref.gs_fk and (groupref.permissions&128)>0) o= r=20 (groupref.gs_fk=3Dgrouplink.gs_fk and grouplink.us_fk=3D1 and=20 (groupref.permissions&16)>0 ));
NOTICE:  QUERY PLAN:
<= /DIV>
 
Nested Loop  (cost=3D0.00..2303.34= rows=3D1=20 width=3D24)
  ->  Seq Scan on groupref  (cost=3D0.00..= 38.83=20 rows=3D313 width=3D16)
  ->  Seq Scan on grouplink =20 (cost=3D0.00..1.78 rows=3D78 width=3D8)
 
I thought that the OR part of t= he=20 statement might be causing trouble so I eliminated it and=20 got:
genex=3D# explain select ref_fk from gr= oupref,=20 grouplink where (groupref.us_fk=3D1 and groupref.us_fk=3Dgrouplink.us_fk an= d=20 grouplink.gs_fk=3Dgroupref.gs_fk and=20 (groupref.permissions&128)>0);
NOTICE:  QUERY PLAN:
 
Hash Join  (cost=3D18.71..20.89 ro= ws=3D1=20 width=3D20)
  ->  Seq Scan on grouplink  (cost=3D0.00.= .1.78=20 rows=3D78 width=3D8)
  ->  Hash  (cost=3D18.71..18.71 = rows=3D2=20 width=3D12)
        ->  Index= Scan=20 using groupref_us_fk_ind on groupref  (cost=3D0.00..18.71 rows=3D2=20 width=3D12)
Now an index is being=20 used??
 
I did a vaccum analyze again an= d ran=20 the same query. The explain results changed to this:
Merge Join  (cost=3D34.96..35.86 r= ows=3D32=20 width=3D20)
  ->  Sort  (cost=3D30.72..30.72 rows=3D95= =20 width=3D12)
        ->  Seq S= can on=20 groupref  (cost=3D0.00..27.62 rows=3D95 width=3D12)
  ->&nb= sp;=20 Sort  (cost=3D4.23..4.23 rows=3D78=20 width=3D8)
        ->  Seq Sc= an on=20 grouplink  (cost=3D0.00..1.78 rows=3D78 width=3D8)
 
I backed off to a very simple q= uery=20 and still cannot get the indexes working.
genex=3D# explain select ref_fk from gr= oupref=20 where (groupref.us_fk=3D1 and=20 (groupref.permissions&128)>0);
NOTICE:  QUERY PLAN:
 
Seq Scan on groupref  (cost=3D0.00= ..27.62=20 rows=3D95 width=3D4)
 
EXPLAIN
genex=3D# explain select ref= _fk from=20 groupref where (groupref.us_fk=3D1);
NOTICE:  QUERY PLAN:
 
Seq Scan on groupref  (cost=3D0.00= ..22.01=20 rows=3D284 width=3D4)

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

 

 

 

<= /DIV> ------=_NextPart_000_003E_01C2EF96.7CEDB040--