Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnTsb-0002pJ-Ta for pgsql-admin@arkaria.postgresql.org; Tue, 25 Dec 2012 12:45:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TnTsa-0002FX-Eu for pgsql-admin@arkaria.postgresql.org; Tue, 25 Dec 2012 12:45:08 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnTsZ-0002El-36 for pgsql-admin@postgresql.org; Tue, 25 Dec 2012 12:45:07 +0000 Received: from 30.55.colo.spiretech.net ([69.168.55.30] helo=lists.commandprompt.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnTsT-0004dv-Ju for pgsql-admin@postgresql.org; Tue, 25 Dec 2012 12:45:05 +0000 Received: from [10.0.1.11] (spinlock.commandprompt.com [69.168.55.30]) by lists.commandprompt.com (Postfix) with ESMTPA id 7574B3B6; Tue, 25 Dec 2012 04:44:59 -0800 (PST) Received: from [10.0.1.11] ([91.222.51.43] helo=[10.0.1.11]) by assp.commandprompt.com with ESMTPS(AES128-SHA) (2.1.1); 25 Dec 2012 04:44:58 -0800 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Does index based on text with 'en_US.utf8' collation support like query? From: Alexey Klyukin In-Reply-To: Date: Tue, 25 Dec 2012 14:44:58 +0200 Cc: "pgsql-admin@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Haifeng Liu X-Mailer: Apple Mail (2.1499) X-Assp-Version: 2.1.1(11364) on assp.commandprompt.com X-Assp-Client-SSL: yes X-Assp-ID: assp.commandprompt.com m1-39499-05128 X-Assp-Envelope-From: alexk@commandprompt.com X-Assp-Intended-For: liuhaifeng@live.com X-Assp-Original-Subject: Re: [ADMIN] Does index based on text with 'en_US.utf8' collation support like query? X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Hello, On Dec 25, 2012, at 1:37 PM, Haifeng Liu wrote: >=20 > Hi, >=20 > I found that queries like "select * from tbl where col1 like 'abc%'" will= use index only when the col1(and the index) use 'C' collation. If I use 'd= efault' which is 'en_US.utf8' in my database, the equation condition will u= se the index but like query will not. This is a documented behavior, LIKE with a default operator class only work= s with C locale. >=20 > I also tried to specify the collation explicitly: like ('abc%' collate 'e= n_US.utf8'), not work too. >=20 > Is that only 'C' collation support 'like' query or I missed something in = my sql? Or do I need to install something additional to support index on ot= her collation? You need to add a new index with a special operator class called 'text_patt= ern_ops' (or 'varchar_pattern_ops), i.e: CREATE INDEX col1_pattern_idx ON tbl(col1 text_pattern_ops); =20 This index will be used in LIKE queries under non-C locale. You also need t= o preserve your existing default (aka text_ops) indexes if you want compari= son or inequality operations on the col1 column to be indexed.=20 Refer to http://www.postgresql.org/docs/current/static/indexes-opclass.html= for more details. -- Alexey Klyukin http://www.commandprompt.com The PostgreSQL Company =96 Command Prompt, Inc. --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin