Re: Postgres doesn't use indexes for prefix matching? - Mailing list pgsql-general

From Stephan Szabo
Subject Re: Postgres doesn't use indexes for prefix matching?
Date
Msg-id 20040708104125.N97290@megazone.bigpanda.com
Whole thread Raw
In response to Postgres doesn't use indexes for prefix matching?  (Jon Valvatne <jon@valvatne.com>)
List pgsql-general
On Fri, 2 Jul 2004, Jon Valvatne wrote:

> Pasted below, I demonstrate two queries which both produce the same two
> records in their result set (the two objects which have my full name in
> their name field). Based on my experiences with other DBMS, I would have
> thought Postgres could do a simple index scan for both queries and thus
> produce the results equally fast in both cases, but not so. In the
> second case it fails to use the index, falling back to filtering a slow
> sequential scan.
>
> I can't seem to find anything in the manual about this, but I'm sure
> I've read several places that Postgres can do what I want here. The only
> place I can dig up right now is in contrib/fulltextindex/README.fti,
> which mentions: "If a ~ search starts with a ^ (match start of string),
> btree indices can be used by PostgreSQL."
>
> Is there something I am doing wrong?

Prefix matching using indexes is available in "C" locale or if you have
an index in a special opclass (<something>_pattern_ops -- I think the
operator class part of the docs describe them).

pgsql-general by date:

Previous
From: "B.W.H. van Beest"
Date:
Subject: How to filter on timestamps?
Next
From:
Date:
Subject: Re: enable thready safety on Mac OS X 10.3.4