X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 086B39FB36D for ; Tue, 8 Aug 2006 14:49:12 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 47889-07 for ; Tue, 8 Aug 2006 17:49:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.avior.ca (mail.avior.ca [209.47.34.36]) by postgresql.org (Postfix) with SMTP id 7E12D9FB218 for ; Tue, 8 Aug 2006 14:49:08 -0300 (ADT) Received: (qmail 10564 invoked by uid 0); 8 Aug 2006 17:49:07 -0000 Received: from pbeliveau@avior.ca by mail by uid 510 with qmail-scanner-1.16 (clamscan: 0.60. Clear:. Processed in 0.864485 secs); 08 Aug 2006 17:49:07 -0000 Received: from mis-07.avior.ca (HELO ?10.1.1.7?) (10.1.1.7) by mail.avior.ca with SMTP; 8 Aug 2006 17:49:06 -0000 Message-ID: <44D8CE92.1080407@avior.ca> Date: Tue, 08 Aug 2006 13:49:06 -0400 From: Patrice Beliveau User-Agent: Thunderbird 1.5.0.4 (X11/20060614) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Optimizing queries Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200608/106 X-Sequence-Number: 20291 Hi, I have a query that use a function and some column test to select row. It's in the form of: SELECT * FROM TABLE WHERE TABLE.COLUMN1=something AND TABLE.COLUMN2=somethingelse AND function(TABLE.COLUMN3,TABLE.COLUMN4) > 0; The result of the function does NOT depend only from the table, but also from some other tables. Since it's long to process, I've add some output to see what's going on. I find out that the function process every row even if the row should be rejected as per the first or the second condition. Then , my question is: Is there a way to formulate a query that wont do all the check if it does not need to do it ? Meaning that, if condition1 is false then it wont check condition2 and that way the function will only be called when it's really necessary. Thanks