X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 92A839DC833 for ; Wed, 11 Jan 2006 16:39:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79930-05 for ; Wed, 11 Jan 2006 16:39:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from opteron.random (217-133-42-200.b2b.tiscali.it [217.133.42.200]) by postgresql.org (Postfix) with ESMTP id 1BC999DC804 for ; Wed, 11 Jan 2006 16:39:47 -0400 (AST) Received: by opteron.random (Postfix, from userid 500) id C2C9C1C1421; Wed, 11 Jan 2006 21:39:47 +0100 (CET) Date: Wed, 11 Jan 2006 21:39:47 +0100 From: Andrea Arcangeli To: "Jim C. Nasby" Cc: pgsql-performance@postgresql.org Subject: Re: NOT LIKE much faster than LIKE? Message-ID: <20060111203947.GL15897@opteron.random> References: <20060110014447.GB18474@opteron.random> <20060111184032.GS3902@pervasive.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060111184032.GS3902@pervasive.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200601/123 X-Sequence-Number: 16601 On Wed, Jan 11, 2006 at 12:40:32PM -0600, Jim C. Nasby wrote: > On Tue, Jan 10, 2006 at 02:44:47AM +0100, Andrea Arcangeli wrote: > > "cooperative" runs "WHERE kernel_version NOT LIKE '%% PREEMPT %%'", while > > "preempt" runs "WHERE kernel_version LIKE '%% PREEMPT %%'. The only difference > > One thing you could do is change the like to: > > WHERE position(' PREEMPT ' in kernel_version) != 0 That alone fixed it, with this I don't even need the index (yet). Thanks a lot. > And then create a functional index on that: > > CREATE INDEX indexname ON tablename ( position(' PREEMPT ' in kernel_version) ); The index only helps the above query with = 0 and not the one with != 0, but it seems not needed in practice.