Re: BUG #14032: trigram index is not used for '=' operator

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: ruslan(dot)zakirov(at)gmail(dot)com, Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14032: trigram index is not used for '=' operator
Date: 2016-03-20 01:06:26
Message-ID: CAMkU=1wCVDDgwxKstHEQ_d5075FnDWXJpM0LxqhQsDD-vvg3mw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Mar 18, 2016 at 3:37 PM, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru> wrote:
> Hello,
>
> Unfortunately, pg_trgm can not support '=' operator. If I am not mistaken it
> is GiST and GIN limitation.

I think it is actually quite trivial to support '='. In fact I think
that all you have to do is tap into the same code that LIKE already
uses, and let the recheck remove things which match on the LIKE
interpretation of the query string but not the equality
interpretation.

Attached is a crude patch I put together which seems to do the job,
but I haven't thoroughly tested it.

The main problem is likely to be that there is already a really good
index type for speeding up equality queries (btree), and adding
another (generally much worse) alternative is likely to confuse the
planner more than anything. Is it really worth taking the performance
hit on executing the equality query in order to avoid just keeping a
second btree index?

If I could somehow turn this into an extension module that installed
with pg_trgm as a dependency, rather than reaching into pg_trgm's
internals, then it might be worthwhile putting something like this on
PGXN. But I don't know how to do that. And it doesn't seem
worthwhile to change pg_trgm itself in this way.

But in any case, it isn't a bug that pg_trgm doesn't do everything it
theoretically could do.

Cheers,

Jeff

Attachment Content-Type Size
trgm_gin_equality.patch application/octet-stream 1.8 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Christian Ullrich 2016-03-20 15:45:08 Re: [HACKERS] BUG #13854: SSPI authentication failure: wrong realm name used
Previous Message Alvaro Herrera 2016-03-19 22:38:26 Re: BUG #14033: cross-compilation to ARM fails