Re: [pg_trgm] Making similarity(?, ?) < ? use an index

From: Greg Navis <contact(at)gregnavis(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [pg_trgm] Making similarity(?, ?) < ? use an index
Date: 2016-06-11 10:47:28
Message-ID: CAA6WWt95ohn9vo1Nv-mxALd=jhUpG7K+iyJsdNogwrviFE89pw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I made some progress but I'm stuck. I'm focused on GiST for now. Please
ignore sloppy naming for now.

I made the following changes to pg_trgm--1.2.sql:

CREATE TYPE pg_trgm_match AS (match TEXT, threshold REAL);

CREATE OR REPLACE FUNCTION trgm_check_match(string TEXT, match
pg_trgm_match) RETURNS bool AS $$
BEGIN
RETURN match.match <-> string <= 1 - match.threshold;
END;
$$ LANGUAGE plpgsql;

CREATE OPERATOR %%(leftarg = text, rightarg = pg_trgm_match,
procedure=trgm_check_match);

ALTER OPERATOR FAMILY gist_trgm_ops USING gist ADD
OPERATOR 9 %% (text,
pg_trgm_match);

It does indeed make PostgreSQL complain about undefined strategy 9. I added
the following define to trgm.h:

#define ThresholdStrategyNumber 9

It seems StrategyNumber is used in gtrgm_consistent and gtrgm_distance.

In gtrgm_consistent, I need change the way `nlimit` is obtained:

nlimit = (strategy == SimilarityStrategyNumber) ?
similarity_threshold : word_similarity_threshold;

I need to add a case for ThresholdStrategyNumber and extract `nlimit` from
the argument of `pg_trgm_match`. I'm not sure what to do in
`gtrgm_distance`.

My questions:

1a. Is it possible to make `gtrgm_consistent` accept `text` or
`pg_trgm_match` as the second argument?
1b. What's the equivalent of `match.match` and `match.threshold` (where
`match` is a `pg_trgm_match`) in C?
2. What to do with `gtrgm_distance`?

Thanks for help.
--
Greg Navis
I help tech companies to scale Heroku-hosted Rails apps.
Free, biweekly scalability newsletter for SaaS CEOs
<http://www.gregnavis.com/newsletter/>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2016-06-11 14:12:45 Re: pgAdmin 4 beta not working on Windows 10
Previous Message Daniel Migowski 2016-06-11 09:29:44 Re: Why are no NEGATORS defined in the standard operators