Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 505302E004F for ; Wed, 27 Feb 2008 16:26:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 44770-03-5 for ; Wed, 27 Feb 2008 16:26:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C2CAD2E0051 for ; Wed, 27 Feb 2008 16:26:36 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m1RKQNCV007249; Wed, 27 Feb 2008 15:26:23 -0500 (EST) To: "Dan Kaplan" cc: pgsql-performance@postgresql.org Subject: Re: Optimizing t1.col like '%t2.col%' In-reply-to: <00c801c87979$9f3da480$1d00a8c0@dan> References: <00c801c87979$9f3da480$1d00a8c0@dan> Comments: In-reply-to "Dan Kaplan" message dated "Wed, 27 Feb 2008 11:47:43 -0800" Date: Wed, 27 Feb 2008 15:26:23 -0500 Message-ID: <7248.1204143983@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200802/382 X-Sequence-Number: 28924 "Dan Kaplan" writes: > I've got a lot of rows in one table and a lot of rows in another table. I > want to do a bunch of queries on their join column. One of these is like > this: t1.col like '%t2.col%' > I know that always sucks. I'm wondering how I can make it better. tsearch or pg_trgm could probably help. Are you really after exact substring-match semantics, or is this actually a poor man's substitute for full text search? If you just want substrings then see pg_trgm, if you want text search see tsearch. regards, tom lane