pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: LIANHE SHAO <lshao2@jhmi.edu>
To: pgsql-performance@postgresql.org
Subject: why index scan not working when using 'like'?
Date: Tue, 25 Nov 2003 19:48:49 +0000 (GMT)
Message-ID: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu> (raw)

Hi all,

I want to use index on the gene_symbol column in my
query and gene_symbol is indexed. but when I use
lower (gene_symbol) like lower('%mif%'), the index
is not used. While when I change to
lower(gene_symbol) = lower('mif'), the index is used
and index scan works, but this is not what I like. I
want all the gene_symbols  containing substring
'mif' are pulled out, and not necessarily exactly match.

could anybody give me some hints how to deal with 
this. If I do not used index, it take too long for
the query.

   
PGA> explain select distinct probeset_id, chip,
gene_symbol, title, sequence_description, pfam from
affy_array_annotation where lower(gene_symbol) like
upper('%mif%');
                                       QUERY PLAN
-----------------------------------------------------------------------------------------
 Unique  (cost=29576.44..29591.44 rows=86 width=265)
   ->  Sort  (cost=29576.44..29578.59 rows=857
width=265)
         Sort Key: probeset_id, chip, gene_symbol,
title, sequence_description, pfam
         ->  Seq Scan on affy_array_annotation 
(cost=0.00..29534.70 rows=857 width=265)
               Filter: (lower((gene_symbol)::text)
~~ 'MIF%'::text)
(5 rows)


PGA=> explain select distinct probeset_id, chip,
gene_symbol, title, sequence_description, pfam from
affy_array_annotation where lower(gene_symbol) =
upper('%mif%');
                                                   
 QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
 Unique  (cost=3433.44..3448.44 rows=86 width=265)
   ->  Sort  (cost=3433.44..3435.58 rows=857 width=265)
         Sort Key: probeset_id, chip, gene_symbol,
title, sequence_description, pfam
         ->  Index Scan using gene_symbol_idx_fun1
on affy_array_annotation  (cost=0.00..3391.70
rows=857 width=265)
               Index Cond:
(lower((gene_symbol)::text) = '%MIF%'::text)
(5 rows)





Regards,
William




view thread (5+ messages)  latest in thread

Message-ID: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu>
Permalink:  ../3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu/
Also on:    postgresql.org/message-id/3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.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-performance@postgresql.org
  Cc: lshao2@jhmi.edu
  Subject: Re: why index scan not working when using 'like'?
  In-Reply-To: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu>
  References: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.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