Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGUc-0006eQ-0p for pgsql-docs@arkaria.postgresql.org; Thu, 27 Dec 2012 16:39:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1ToGUb-0002IQ-DO for pgsql-docs@arkaria.postgresql.org; Thu, 27 Dec 2012 16:39:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGUa-0002Hh-Eq for pgsql-docs@postgresql.org; Thu, 27 Dec 2012 16:39:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1ToGUY-0000TE-CR for pgsql-docs@postgresql.org; Thu, 27 Dec 2012 16:39:36 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qBRGdUnX014130; Thu, 27 Dec 2012 11:39:31 -0500 (EST) From: Tom Lane To: Peter Eisentraut cc: pgsql-docs@postgresql.org Subject: Re: pattern matching indexing In-reply-to: <1356615259.13340.4.camel@vanquo.pezone.net> References: <1356360300.5854.2.camel@vanquo.pezone.net> <4603.1356361965@sss.pgh.pa.us> <1356615259.13340.4.camel@vanquo.pezone.net> Comments: In-reply-to Peter Eisentraut message dated "Thu, 27 Dec 2012 08:34:19 -0500" Date: Thu, 27 Dec 2012 11:39:30 -0500 Message-ID: <14129.1356626370@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-docs Precedence: bulk Sender: pgsql-docs-owner@postgresql.org Peter Eisentraut writes: > On Mon, 2012-12-24 at 10:12 -0500, Tom Lane wrote: >> It is stated at >> http://www.postgresql.org/docs/devel/static/indexes-opclass.html >> that you don't need the special pattern opclasses in C locale. >> Feel free to rephrase or document elsewhere if you find that too >> obscure. > What it doesn't make very clear is that you can also override the locale > in the index definition itself. So instead of the recommended > CREATE INDEX test_index ON test_table (col varchar_pattern_ops); > you can write nearly equivalently > CREATE INDEX test_index ON test_table (col COLLATE "C"); Ah, now I see what you're getting at. That's not equivalent though: IIRC, an index defined in that way will not match to a plain old WHERE col = 'constant' query, unless the prevailing locale is C anyway. The pattern_ops index will match, because varchar_pattern_ops and regular varchar_ops share the same equality operator. > I'm also wondering whether the latter wouldn't be a preferable > recommendation going forward. Because of the above, it is most definitely not a preferable recommendation. I don't mind if it's documented more explicitly, but the pattern_ops approach is the one to recommend in most cases, I believe. regards, tom lane -- Sent via pgsql-docs mailing list (pgsql-docs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-docs