X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6621B3A55D4 for ; Tue, 25 Jan 2005 10:10:14 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37695-03 for ; Tue, 25 Jan 2005 10:09:57 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.201]) by svr1.postgresql.org (Postfix) with ESMTP id 788433A5552 for ; Tue, 25 Jan 2005 10:09:58 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 71so39922wra for ; Tue, 25 Jan 2005 02:09:56 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=EhyNoKX29PQoydbes9nDE93R248MmtxFIT54kNdk1YJBppoLM/lQ4yDSaWIF4RX1P6rIuz3EQtjb4XO5xl578Lsb5jQY47bWZAbn5u2xPuPc/FiQw2+Y7xAQdlpXU9MYCCI4y4oDAvEUitP1CE7g67MXYFZKjFmd2dw5zt+pyNE= Received: by 10.54.32.22 with SMTP id f22mr19074wrf; Tue, 25 Jan 2005 02:09:56 -0800 (PST) Received: by 10.54.31.32 with HTTP; Tue, 25 Jan 2005 02:09:56 -0800 (PST) Message-ID: <2989532e05012502092288a062@mail.gmail.com> Date: Tue, 25 Jan 2005 15:39:56 +0530 From: Antony Paul Reply-To: Antony Paul To: Russell Smith Subject: Re: How to boost performance of ilike queries ? Cc: pgsql-performance@postgresql.org In-Reply-To: <200501251949.12874.mr-russ@pws.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <2989532e05012401184b0c3ef9@mail.gmail.com> <200501242058.54670.mr-russ@pws.com.au> <2989532e05012500235c78fd47@mail.gmail.com> <200501251949.12874.mr-russ@pws.com.au> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.54 tagged_above=0 required=5 tests=AWL, FROM_ENDS_IN_NUMS, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200501/456 X-Sequence-Number: 10146 Actually the query is created like this. User enters the query in a user interface. User can type any character in the query criteria. ie. % and _ can be at any place. User have the freedom to choose query columns as well. The query is agianst a single table . rgds Antony Paul On Tue, 25 Jan 2005 19:49:12 +1100, Russell Smith wrote: > On Tue, 25 Jan 2005 07:23 pm, Antony Paul wrote: > > Creating an index and using lower(column) does not change the explain > > plan estimates. > > It seems that it is not using index for like or ilike queries > > irrespective of whether it have a pattern matching character in it or > > not. (using PostgreSQL 7.3.3) > > > > On googling I found this thread > > > > http://archives.postgresql.org/pgsql-sql/2004-11/msg00285.php > > > > It says that index is not used if the search string begins with a % symbol. > > What exactly are the type of like queries you are going? there is a solution > for having the % at the start, but you can win everyway. > > > > > rgds > > Antony Paul > > > > On Mon, 24 Jan 2005 20:58:54 +1100, Russell Smith wrote: > > > On Mon, 24 Jan 2005 08:18 pm, Antony Paul wrote: > > > > Hi, > > > > I have a query which is executed using ilike. The query values are > > > > received from user and it is executed using PreparedStatement. > > > > Currently all queries are executed as it is using iilike irrespective > > > > of whether it have a pattern matching character or not. Can using = > > > > instead of ilike boot performance ?. If creating index can help then > > > > how the index should be created on lower case or uppercase ?. > > > > > > > It depends on the type of queries you are doing. > > > > > > changing it to something like lower(column) like lower('text%'), and > > > creating an index on lower(column) will give you much better performance. > > > > > > If you have % in the middle of the query, it will still be slow, but I assume that is not > > > the general case. > > > > > > I am not sure what the effect of it being prepared will be, however I've had much success > > > with the method above without the queries being prepared. Others may be able to offer advice > > > about if prepare will effect it. > > > > > > Regards > > > > > > Russell Smith > > > > > > > >