Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 62CEE9FB33B for ; Mon, 23 Oct 2006 16:54:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 95332-09 for ; Mon, 23 Oct 2006 16:54:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by postgresql.org (Postfix) with ESMTP id 52F679FB229 for ; Mon, 23 Oct 2006 16:54:02 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id k27so797286nfc for ; Mon, 23 Oct 2006 12:54:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:sender:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition:x-google-sender-auth; b=fO9cGbLUs5eB9HasEJW5Owxf7uGczawoOVpqjseroZw/JNhzO7wtKmZHm90WdJly5YrMvi9+Nhul5QDSV+pX/1TUjXvsO01z1GLBOEZxqcCHWfATADrXIrQveSQEY7H4uSlqOtXbLRfJK9x6tkGALUhyeNEHrlAJ4MpKMiG4+aQ= Received: by 10.49.8.10 with SMTP id l10mr7265239nfi; Mon, 23 Oct 2006 12:54:00 -0700 (PDT) Received: by 10.48.219.7 with HTTP; Mon, 23 Oct 2006 12:54:00 -0700 (PDT) Message-ID: <52cedf850610231254y11c036d4g436fa54370690689@mail.gmail.com> Date: Mon, 23 Oct 2006 16:54:00 -0300 From: "Mara Dalponte" Reply-To: dalponte@sol.info.unlp.edu.ar To: pgsql-performance@postgresql.org Subject: Problems using a function in a where clause MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: e5355aa9e4120c26 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.816 tagged_above=0 required=5 tests=SPF_HELO_SOFTFAIL, SPF_SOFTFAIL X-Spam-Level: *** X-Archive-Number: 200610/495 X-Sequence-Number: 21624 Hello, I have a query with several join operations and applying the same filter condition over each involved table. This condition is a complex predicate over an indexed timestamp field, depending on some parameters. To factorize code, I wrote the filter into a plpgsql function, but the resulting query is much more slower than the first one! The explain command over the original query gives the following info for the WHERE clause that uses the filter: ... Index Cond: ((_timestamp >= '2006-02-23 03:00:00'::timestamp without time zone) AND (_timestamp <= '2006-02-27 20:00:00.989999'::timestamp without time zone)) ... The explain command for the WHERE clause using the filtering function is: ... Filter: include_time_date('2006-02-23'::date, '2006-02-27'::date, '03:00:00'::time without time zone, '20:00:00'::time without time zone, (_timestamp)::timestamp without time zone) ... It seems to not be using the index, and I think this is the reason of the performance gap between both solutions. How can I explicitly use this index? which type of functions shall I use (VOLATILE | INMUTABLE | STABLE)? Thanks in advance Mara