X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C1AD2D1B437 for ; Tue, 25 Nov 2003 20:02:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 27088-01 for ; Tue, 25 Nov 2003 16:01:56 -0400 (AST) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id C03E6D1B431 for ; Tue, 25 Nov 2003 16:01:55 -0400 (AST) Received: from [66.219.92.2] (HELO temoku) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3977322; Tue, 25 Nov 2003 12:02:44 -0800 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: LIANHE SHAO , pgsql-performance@postgresql.org Subject: Re: why index scan not working when using 'like'? Date: Tue, 25 Nov 2003 11:51:40 -0800 User-Agent: KMail/1.4.3 References: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu> In-Reply-To: <3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200311251151.40781.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/251 X-Sequence-Number: 4811 Lianhe, > I want to use index on the gene_symbol column in my > query and gene_symbol is indexed. but when I use > lower (gene_symbol) like lower('%mif%'), the index > is not used. While when I change to > lower(gene_symbol) =3D lower('mif'), the index is used > and index scan works, but this is not what I like. I > want all the gene_symbols containing substring > 'mif' are pulled out, and not necessarily exactly match. LIKE '%mif%' is what's called an "unanchored text search" and it cannot use= an=20 index. The database *has* to scan the full text looking for the substring= .=20=20 This is true of all database platforms I know of. In regular text fields containing words, your problem is solvable with full= =20 text indexing (FTI). Unfortunately, FTI is not designed for arbitrary=20 non-language strings. It could be adapted, but would require a lot of=20 hacking. So you will need to find a way to restructure you data to avoid needing=20 unanchored text searches. One way would be to break down the gene_symbol= =20 field into its smallest atomic components and store those in an indexed chi= ld=20 table. Or if you're searching on the same values all the time, you can=20 create a partial index. --=20 -Josh Berkus Aglio Database Solutions San Francisco