Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 963339FA2D0 for ; Wed, 13 Jun 2007 08:41:33 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 49984-04 for ; Wed, 13 Jun 2007 08:41:25 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by postgresql.org (Postfix) with ESMTP id 1B9E99FA21F for ; Wed, 13 Jun 2007 08:41:29 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id u2so419324uge for ; Wed, 13 Jun 2007 04:41:28 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=mZ8O4JggIenNqBcIffD2i8q9MfOE+hgrbqxo8OlBVh/7uj+Hq8Z1rdQ6OBlsUw+4PVnkZNfBM9lTXpadALMIcMsbPOHd7xYpJhLOdjdJ1Wrh+88ppkUL/LJidcXPTeVl2dzlanb+/ZCWST9xcNDHnLQqdXvvRMz8ST1baI3/oco= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=iJ5OWWuMY3K2V7THCnyWeWNpLJc4Ib/Kn/03gAEnhhy8te76APhEoa/4wV6sQVyXUJPJ3G7JY0OBZM+fZ4aMzSkMPBIbbDRg06Q86LzQy0cxm1eMvcZe/oY4VktV6wF/eUi+LIak23GDHuaxvKfn+8kgV6trcsXTmusaO92g220= Received: by 10.78.200.20 with SMTP id x20mr151296huf.1181734887426; Wed, 13 Jun 2007 04:41:27 -0700 (PDT) Received: by 10.78.172.7 with HTTP; Wed, 13 Jun 2007 04:41:27 -0700 (PDT) Message-ID: Date: Wed, 13 Jun 2007 12:41:27 +0100 From: "Tyler Durden" To: pgsql-performance@postgresql.org Subject: Optimize slow query MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.316 tagged_above=0 required=5 tests=AWL=0.315, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200706/230 X-Sequence-Number: 25263 Hi, I've a table with 300 000 records and I'm trying to do a search: SELECT * FROM addresses WHERE address ILIKE '%Jean Paul%' AND (l_pc='4250' or r_pc='4250') AND (l_struc='O' or r_struc='O') AND (prenm ILIKE 'Street') It performs in 2 seconds in a dual Xeon 2.4mhz with 2Gb of RAM. I'm using Postgresql 8.1 on ubuntu. I've indexes on l_pc, r_pc, l_struc,r_struc and prenm (all btrees) What I'm doing wrong to have such a slow query? Thanks, Nuno Mariz