X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6E12C5388B for ; Sun, 8 May 2005 23:06:45 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 43417-04 for ; Mon, 9 May 2005 02:06:44 +0000 (GMT) Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by svr1.postgresql.org (Postfix) with ESMTP id 06DC15385B for ; Sun, 8 May 2005 23:06:43 -0300 (ADT) X-EthosMedia-Virus-Scanned: no infections found Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 7337879; Sun, 08 May 2005 19:08:46 -0700 From: Josh Berkus Organization: Aglio Database Solutions To: Dan Harris Subject: Re: Query tuning help Date: Sun, 8 May 2005 19:06:47 -0700 User-Agent: KMail/1.8 Cc: pgsql-performance@postgresql.org References: <924ac6c029f5453c442eacdda06b132c@drivefaster.net> <200505091051.14689.mr-russ@pws.com.au> <6f4a543a2fbd348c7e82876b8e477600@drivefaster.net> In-Reply-To: <6f4a543a2fbd348c7e82876b8e477600@drivefaster.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200505081906.47731.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.013 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/92 X-Sequence-Number: 12256 Dan, > While I believe you, I'm confused by this line in my original EXPLAIN > > ANALYZE: > >> -> Index Scan using ea1 on ea (cost=0.00..2736.43 rows=42 width=47) > >> (actual time=2.085..2.309 rows=2 loops=473) > >> Index Cond: > >> ((ea.incidentid)::text = ("outer".incidentid)::text) > >> Filter: (((recordtext)::text > >> ~~ '%RED%'::text) OR ((recordtext)::text ~~ '%CORVETTE%'::text)) The index named is matching based on incidentid -- the join condition. The "filter" is applied against the table rows, i.e. a scan. > If I were to use tsearch2 for full-text indexing, would I need to > create another table that merges all of my recordtext rows into a > single 'text' field type? No. Read the OpenFTS docs, they are fairly clear on how to set up a simple FTS index. (TSearch2 ~~ OpenFTS) > If so, this is where I run into problems, as > my logic also needs to match multiple words in their original order. You do that by doubling up ... that is, use the FTS index to pick all rows that contain "RED" and "CORVETTE", and then check the order. I'll also note that your current query is not checking word order. Example: WHERE recordtext_fti @@ to_tsquery ('default', 'RED && CORVETTE') AND recordtext LIKE '%RED%CORVETTE%' I'm doing something fairly similar on one of my projects and it works very well. The limitations on TSearch2 indexes are: 1) they are expensive to update, so your data loads would be noticably slower. 2) they are only fast when cached in RAM (and when cached, are *very* fast). So if you have a variety of other processes that tend to fill up RAM between searches, you may find them less useful. 3) You have to create a materialized index column next to recordtext, which will increase the size of the table. -- Josh Berkus Aglio Database Solutions San Francisco