Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 3568163336F for ; Mon, 29 Mar 2010 14:19:30 -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 89348-07 for ; Mon, 29 Mar 2010 17:19:19 +0000 (UTC) X-Greylist: from auto-whitelisted 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 62F456324E2 for ; Mon, 29 Mar 2010 14:19:19 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.local (Postfix) with ESMTP id 520D2328002; Mon, 29 Mar 2010 10:23:37 -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 4O6i7wPB0+zJ; Mon, 29 Mar 2010 10:23:33 -0700 (PDT) Received: from mail.local (mail.local [10.0.0.200]) by mail.local (Postfix) with ESMTP id 35A9E328001; Mon, 29 Mar 2010 10:23:33 -0700 (PDT) Date: Mon, 29 Mar 2010 09:23:33 -0800 (PST) From: randalls@bioinfo.wsu.edu To: Tom Lane Cc: pgsql-performance@postgresql.org Message-ID: <2002514254.8941269883413114.JavaMail.root@mail> In-Reply-To: <16513.1269882003@sss.pgh.pa.us> Subject: Re: Performance regarding LIKE searches MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [134.121.88.59] X-Mailer: Zimbra 6.0.0_GA_1802.UBUNTU8_64 (ZimbraWebClient - IE8 (Win)/6.0.0_GA_1802.UBUNTU8_64) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/374 X-Sequence-Number: 38199 Tom, We are using perl 5.10 with postgresql DBD. Can you point me in the right direction in terms of unamed and named prepared statements? Thanks, Randall Svancara Systems Administrator/DBA/Developer Main Bioinformatics Laboratory ----- Original Message ----- From: "Tom Lane" To: randalls@bioinfo.wsu.edu Cc: pgsql-performance@postgresql.org Sent: Monday, March 29, 2010 10:00:03 AM Subject: Re: [PERFORM] Performance regarding LIKE searches randalls@bioinfo.wsu.edu writes: > 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? You're not going to get an index optimization when the LIKE pattern isn't a constant (and left-anchored, but this is). It is possible to get the planner to treat a query parameter as a constant (implying a re-plan on each execution instead of having a cached plan). I believe what you have to do at the moment is use unnamed rather than named prepared statements. The practicality of this would depend a lot on your client-side software stack, which you didn't mention. regards, tom lane