Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BC352632343 for ; Thu, 18 Feb 2010 08:14:36 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 87860-04 for ; Thu, 18 Feb 2010 12:14:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f219.google.com (mail-fx0-f219.google.com [209.85.220.219]) by mail.postgresql.org (Postfix) with ESMTP id 56C376321F8 for ; Thu, 18 Feb 2010 08:14:25 -0400 (AST) Received: by fxm19 with SMTP id 19so1393588fxm.3 for ; Thu, 18 Feb 2010 04:14:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=TDNdTisRyqjVfglDXDVsk52jLZzVcuhlWsk07Wa97C8=; b=MTGNS2siiHvDekRjn9rQLvYLkk952cY4RU/x0X3IKaVM/uur229uwzc0Tea6a2OWbO uhkTr1bAGdqyED+sgJ1wlH9mbrGmu/1JdVcRuMikkK3LRGT/t9UQY0+HTZ6TSsftlezA ffCF94qzB3+jZcTJ7wwEePFavAlCFezVSbm18= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=H7j74CI1HSVAkhp+BbvSNkg3RdzrtO8X0kpRIkz7XlJf0bww0K5hGdlRkwq9lPA1rc w0NBBD2wxXncSMI47RyT/I+Enmd6hpbyX2j2EH8J3qaHzGwe0WhD0ht2+YFmjjcRIPLD 0MUo44634Ad0uJqfifIkSmidS3uxZj9k43RZ8= MIME-Version: 1.0 Received: by 10.102.209.7 with SMTP id h7mr374502mug.33.1266495263395; Thu, 18 Feb 2010 04:14:23 -0800 (PST) In-Reply-To: <2a7905441002180406g571578admf467fd90f01420cd@mail.gmail.com> References: <2a7905441002180355w6dc89a87y8643c0a7f881072a@mail.gmail.com> <2a7905441002180406g571578admf467fd90f01420cd@mail.gmail.com> From: Thom Brown Date: Thu, 18 Feb 2010 12:14:03 +0000 Message-ID: Subject: Re: index usage in not like To: AI Rumman Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.421 tagged_above=-10 required=5 tests=AWL=-0.681, BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 201002/272 X-Sequence-Number: 37693 > On Thu, Feb 18, 2010 at 6:00 PM, Thom Brown wrote: >> >> On 18 February 2010 11:55, AI Rumman wrote: >> > "Not like" operation does not use index. >> > >> > select * from vtiger_contactscf where lower(cf_1253) not like >> > lower('Former%') >> > >> > I created index on lower(cf_1253). >> > >> > How can I ensure index usage in not like operation? >> > Anyone please help. >> > >> >> How many rows do you have in your table? =A0If there are relatively few, >> it probably guesses it to be cheaper to do a sequential scan and >> calculate lower values on-the-fly rather than bother with the index. >> >> Thom > On 18 February 2010 12:06, AI Rumman wrote: > vtigercrm504=3D# explain analyze select * from vtiger_contactscf where > lower(cf_1253) like 'customer'; > > QUERY > PLAN > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------- > Index Scan using vtiger_contactscf_cf_1253_idx on vtiger_contactscf > (cost=3D0.00..146.54 rows=3D6093 width=3D179) (actual time=3D0.083..29.86= 8 rows=3D5171 > loops=3D1) > Index Cond: (lower((cf_1253)::text) ~=3D~ 'customer'::character varyin= g) > Filter: (lower((cf_1253)::text) ~~ 'customer'::text) > Total runtime: 34.956 ms > (4 rows) > vtigercrm504=3D# explain analyze select * from vtiger_contactscf where > lower(cf_1253) like 'customer'; > > QUERY > PLAN > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= -------- > Index Scan using vtiger_contactscf_cf_1253_idx on vtiger_contactscf > (cost=3D0.00..146.54 rows=3D6093 width=3D179) (actual time=3D0.083..29.86= 8 rows=3D5171 > loops=3D1) > Index Cond: (lower((cf_1253)::text) ~=3D~ 'customer'::character varyin= g) > Filter: (lower((cf_1253)::text) ~~ 'customer'::text) > Total runtime: 34.956 ms > (4 rows) Could you do the same again for a "not like" query? Thom