Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 312D19FBB0F for ; Thu, 29 Mar 2007 20:13:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 37201-05 for ; Thu, 29 Mar 2007 20:13:01 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from globalrelay.com (mail1.globalrelay.com [204.92.49.200]) by postgresql.org (Postfix) with ESMTP id BDC489FB58B for ; Thu, 29 Mar 2007 20:13:01 -0300 (ADT) X-Virus-Scanned: Scanned by GRC-AntiVirus Gateway X-GR-Acctd: YES X-Real-To: pgsql-performance@postgresql.org, vincenzo.romano@gmail.com Received: from [63.226.156.118] (HELO DaveEMachine) by globalrelay.com (CommuniGate Pro SMTP 4.2.3) with ESMTP id 134193547; Thu, 29 Mar 2007 16:12:59 -0700 From: "Dave Dutcher" To: "'Vincenzo Romano'" , Subject: Re: Weird performance drop Date: Thu, 29 Mar 2007 18:12:58 -0500 Message-ID: <018c01c77257$cb0bd520$2e00a8c0@tridecap.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6822 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 Thread-Index: AcdyOWLSggCYqGnnRqy7EcFsnqarIgAHPTrw In-Reply-To: <200703292056.08459.Vincenzo.Romano@gmail.com> Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/425 X-Sequence-Number: 23830 > From: pgsql-performance-owner@postgresql.org=20 > [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of=20 > Vincenzo Romano > > I thought that the query planner usually did a bad job on=20 > function bodies > because they'd appear opaque to it. > In this case it seems to me that the body is opaque only if I=20 > use the "like" > operator. If you run explain on a query that looks like "select * from a_table = where a_column like 'foo%'" (and you have the appropriate index) you will see = that postgres rewrites the where clause as "a_column >=3D 'foo' and a_column = < 'fop'". I think your problem is that the query is planned when the = function is created, and at that time postgres doesn't know the value you are comparing against when you use the like operator, so postgres can't = rewrite the query using >=3D and <. The problem doesn't happen for plain = equality because postgres doesn't need to know anything about what you are = comparing against in order to use equality. Somebody else can correct me if I'm wrong. Dave