Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 678A3633660 for ; Mon, 29 Mar 2010 13:50:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 83765-05-2 for ; Mon, 29 Mar 2010 16:50:03 +0000 (UTC) X-Greylist: delayed 00:08:23.237579 by SQLgrey-1.7.6 Received: from mail.local (mail.bioinfo.wsu.edu [134.121.5.141]) by mail.postgresql.org (Postfix) with ESMTP id 5B4436338E4 for ; Mon, 29 Mar 2010 13:46:59 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.local (Postfix) with ESMTP id B4A95328002 for ; Mon, 29 Mar 2010 09:42:52 -0700 (PDT) X-Virus-Scanned: amavisd-new at mail.local Received: from mail.local ([127.0.0.1]) by localhost (mail.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YPJ9HSm-yy0u for ; Mon, 29 Mar 2010 09:42:48 -0700 (PDT) Received: from mail.local (mail.local [10.0.0.200]) by mail.local (Postfix) with ESMTP id CA310328001 for ; Mon, 29 Mar 2010 09:42:48 -0700 (PDT) Date: Mon, 29 Mar 2010 08:42:48 -0800 (PST) From: randalls@bioinfo.wsu.edu To: pgsql-performance@postgresql.org Message-ID: <2071262140.8761269880968618.JavaMail.root@mail> Subject: Performance regarding LIKE searches MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [134.121.89.19] X-Mailer: Zimbra 6.0.0_GA_1802.UBUNTU8_64 (ZimbraWebClient - SAF3 (Linux)/6.0.0_GA_1802.UBUNTU8_64) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.185 tagged_above=-10 required=5 tests=BAYES_40=-0.185 X-Spam-Level: X-Archive-Number: 201003/371 X-Sequence-Number: 38196 Hi, I am querying a Postgresql 8.3 database table that has approximately 22 million records. The (explain analyze) query is listed below: gdr_gbrowse_live=> explain analyze SELECT f.id,f.object,f.typeid,f.seqid,f.start,f.end,f.strand FROM feature as f, name as n WHERE (n.id=f.id AND lower(n.name) LIKE 'Scaffold:scaffold_163:1000..1199%' AND n.display_name>0); QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------ Nested Loop (cost=0.01..5899.93 rows=734 width=884) (actual time=0.033..0.033 rows=0 loops=1) -> Index Scan using name_name_lower_pattern_ops_idx on name n (cost=0.01..9.53 rows=734 width=4) (actual time=0.032..0.032 rows=0 loops=1) Index Cond: ((lower((name)::text) ~>=~ 'Scaffold:scaffold'::text) AND (lower((name)::text) ~<~ 'Scaffold:scaffole'::text)) Filter: ((display_name > 0) AND (lower((name)::text) ~~ 'Scaffold:scaffold_163:1000..1199%'::text)) -> Index Scan using feature_pkey on feature f (cost=0.00..8.01 rows=1 width=884) (never executed) Index Cond: (f.id = n.id) Total runtime: 0.119 ms (7 rows) I can see I am hitting an index using an index that I created using the varchar_pattern_ops setting. This is very fast and performs like I would expect. However, when my application, GBrowse, access the database, I see in my slow query log this: 2010-03-29 09:34:38.083 PDT,"gdr_gbrowse_live","gdr_gbrowse_live",11649,"10.0.0.235:59043",4bb0399d.2d81,8,"SELECT",2010-03-28 22:24:45 PDT,4/118607,0,LOG,00000,"duration: 21467.467 ms execute dbdpg_p25965_9: SELECT f.id,f.object,f.typeid,f.seqid,f.start,f.end,f.strand FROM feature as f, name as n WHERE (n.id=f.id AND lower(n.name) LIKE $1) ","parameters: $1 = 'Scaffold:scaffold\_163:1000..1199%'",,,,,,, GBrowse is a perl based application. Looking at the duration for this query is around 21 seconds. That is a bit long. Does anyone have any ideas why the query duration is so different? Randall Svancara Systems Administrator/DBA/Developer Main Bioinformatics Laboratory