Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 8BEF49F9640 for ; Wed, 22 Aug 2007 18:09:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 68050-01 for ; Wed, 22 Aug 2007 18:09:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from tomts20-srv.bellnexxia.net (tomts20.bellnexxia.net [209.226.175.74]) by postgresql.org (Postfix) with ESMTP id A2E659FA05F for ; Wed, 22 Aug 2007 18:09:13 -0300 (ADT) Received: from serenity ([70.55.72.134]) by tomts20-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20070822210912.ZWAF8273.tomts20-srv.bellnexxia.net@serenity>; Wed, 22 Aug 2007 17:09:12 -0400 From: "Carlo Stonebanks" To: "'Oleg Bartunov'" Cc: References: In-Reply-To: Subject: Re: Fast tsearch2, trigram matching on short phrases Date: Wed, 22 Aug 2007 17:09:52 -0400 Message-ID: <0BC8501AC4E64C528432FBE619AA59AD@serenity> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480 Thread-Index: Acfk/RaTftE05G+0RPGmh1ExljHndwAAL9IQ X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/252 X-Sequence-Number: 26382 >> The problem is in idea, not in performance. Oh, I think we both agree on that! ;-D This is why I didn't post any EXPLAINs or anything like that. I thought the problem was in the entire method of how to best zero in on the set of records best suited for closer analysis by my phrase-matching function. Since you asked about an EXPLAIN ANALYZE, I put together some results for for you. I added a pg_trgm index to the table to show the performance of GiST indexes, and did another based on exclusively on similarity(). But I don't think that you will be surprised by what you see. As you say, the problem is in the idea - but no matter what, I need to be able to match phrases that will have all sorts of erratic abbreviations and misspellings - and I have to do it at very high speeds. I would appreciate any suggestions you might have. Carlo select similarity('veterans''s affairs', name) as sim, name from institution where name % 'veterans''s affairs' order by sim desc Sort (cost=4068.21..4071.83 rows=1446 width=23) (actual time=4154.962..4155.006 rows=228 loops=1) Sort Key: similarity('veterans''s affairs'::text, (name)::text) -> Bitmap Heap Scan on institution (cost=75.07..3992.31 rows=1446 width=23) (actual time=4152.825..4154.754 rows=228 loops=1) Recheck Cond: ((name)::text % 'veterans''s affairs'::text) -> Bitmap Index Scan on institution_name_trgm_idx (cost=0.00..74.71 rows=1446 width=0) (actual time=4152.761..4152.761 rows=228 loops=1) Index Cond: ((name)::text % 'veterans''s affairs'::text) Total runtime: 4155.127 ms select name from institution where similarity('veterans''s affairs', name) > 0.5 order by similarity('veterans''s affairs', name) > 0.5 Sort (cost=142850.08..144055.17 rows=482036 width=23) (actual time=12603.745..12603.760 rows=77 loops=1) Sort Key: (similarity('veterans''s affairs'::text, (name)::text) > 0.5::double precision) -> Seq Scan on institution (cost=0.00..97348.81 rows=482036 width=23) (actual time=2032.439..12603.370 rows=77 loops=1) Filter: (similarity('veterans''s affairs'::text, (name)::text) > 0.5::double precision) Total runtime: 12603.818 ms