X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C7FBAD90E3 for ; Mon, 10 Oct 2005 11:58:18 -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 09183-10 for ; Mon, 10 Oct 2005 14:58:12 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 61A66D905E for ; Mon, 10 Oct 2005 11:58:14 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j9AEwF6x020805; Mon, 10 Oct 2005 10:58:16 -0400 (EDT) To: "Federico Simonetti (Liveye)" Cc: pgsql-performance@postgresql.org Subject: Re: Query performance on ILIKE with AND operator... In-reply-to: <434A6C2D.9070207@liveye.net> References: <434A6C2D.9070207@liveye.net> Comments: In-reply-to "Federico Simonetti (Liveye)" message dated "Mon, 10 Oct 2005 15:27:09 +0200" Date: Mon, 10 Oct 2005 10:58:15 -0400 Message-ID: <20804.1128956295@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200510/170 X-Sequence-Number: 14938 "Federico Simonetti (Liveye)" writes: > I'm encountering a quite strange performance problem. The problem stems from the horrid misestimation of the number of rows fetched from detail0009: > " -> Seq Scan on detail0009 (cost=0.00..20500.11 > rows=26 width=1005) (actual time=453.000..5983.000 rows=53588 loops=1)" > " Filter: ((txcontenttype ~~* '%html%'::text) > AND ((vchost)::text ~~* '%www.%'::text))" When the planner is off by a factor of two thousand about the number of rows involved, it's not very likely to produce a good plan :-( In the OR case the rowcount estimate is 6334, which is somewhat closer to reality (only about a factor of 10 off, looks like), and that changes the plan to something that works acceptably well. Assuming that this is web-log data, the prevalence of www and html together is hardly surprising, but PG's statistical mechanisms will never realize it. Not sure about a good workaround. Does it make sense to combine the two conditions into one? (vchost || txcontenttype) ilike '%www.%html%' regards, tom lane