Re: How to enable partial matching on a GIN index

From: Chris Spencer <chrisspen(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: How to enable partial matching on a GIN index
Date: 2016-01-11 20:14:04
Message-ID: CANe40g+-+OQ85X_y62ea9DbKhtVNQGma17A8bqpT2GR8Fm8KcA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>What's your grounds for claiming that?

It returns no results whenever I use partial search terms. If I search for,
say, "hospital" it returns results containing the exact word "hospital",
but if I search for "hosp" it returns nothing. The doc page explaining that
PG "can" do partial matches, and not that it "does" do partial matches, led
me to believe this is the expected default behaviour. Is this not the case?

Here's code to reproduce the problem:

ALTER TABLE mytable ADD COLUMN search_index tsvector;
CREATE INDEX mytable_search_index_gin ON mytable USING gin(search_index);

INSERT INTO mytable (name, search_index) VALUES ('hospital',
plainto_tsquery('pg_catalog.english', 'hospital'));

SELECT * FROM mytable WHERE (search_index) @@
(plainto_tsquery('pg_catalog.english', 'hospital')); -- returns results
SELECT * FROM mytable WHERE (search_index) @@
(plainto_tsquery('pg_catalog.english', 'hosp')); -- returns nothing

Am I using the index correctly?

On Mon, Jan 11, 2016 at 12:58 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Chris Spencer <chrisspen(at)gmail(dot)com> writes:
> > I recently setup a GIN index on a large database, and it's performance is
> > spectacular. However, I noticed by default it doesn't allow searching by
> > partial matches.
>
> What's your grounds for claiming that?
>
> We recently fixed a bug whereby the planner overestimated the cost of
> partial-match index scans, which might discourage it from choosing an
> index scan versus other plans, but that's a lot different from "doesn't
> allow". In any case, the bug only manifests if you've never vacuumed the
> table since creating the index ...
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2016-01-11 20:33:37 Re: How to enable partial matching on a GIN index
Previous Message Tom Lane 2016-01-11 17:58:01 Re: How to enable partial matching on a GIN index