Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A0223B5DBE6 for ; Fri, 17 Jun 2011 05:55:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 98753-08 for ; Fri, 17 Jun 2011 08:54:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og111.obsmtp.com (exprod7og111.obsmtp.com [64.18.2.175]) by mail.postgresql.org (Postfix) with ESMTP id 6B84DB5DBC0 for ; Fri, 17 Jun 2011 05:54:56 -0300 (ADT) Received: from mail-ey0-f181.google.com ([209.85.215.181]) (using TLSv1) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTfsWX3tc7l7rvXa73XRdBQ8vRyLW6d+s@postini.com; Fri, 17 Jun 2011 01:54:57 PDT Received: by mail-ey0-f181.google.com with SMTP id 5so35317eyh.26 for ; Fri, 17 Jun 2011 01:54:55 -0700 (PDT) Received: by 10.14.48.75 with SMTP id u51mr768615eeb.154.1308300895281; Fri, 17 Jun 2011 01:54:55 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id z1sm2030592eeb.20.2011.06.17.01.54.52 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 17 Jun 2011 01:54:53 -0700 (PDT) Message-ID: <4DFB165B.4000004@enterprisedb.com> Date: Fri, 17 Jun 2011 11:54:51 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.17) Gecko/20110510 Icedove/3.1.10 MIME-Version: 1.0 To: Tom Lane CC: PostgreSQL-development Subject: Re: Nested CASE-WHEN scoping References: <4DDCEEB8.50602@enterprisedb.com> <5487.1306334876@sss.pgh.pa.us> <4DDD35B6.2050203@enterprisedb.com> <27772.1306359110@sss.pgh.pa.us> <4DE38CCD.80702@enterprisedb.com> <23055.1306765290@sss.pgh.pa.us> <4DE512FC.9070707@enterprisedb.com> <4DE93A08.90309@enterprisedb.com> <25826.1308257790@sss.pgh.pa.us> In-Reply-To: <25826.1308257790@sss.pgh.pa.us> 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=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/1491 X-Sequence-Number: 190204 On 16.06.2011 23:56, Tom Lane wrote: > Heikki Linnakangas writes: >> The complicated part is to ensure that levelsup is always set correctly. >> At parse time, levelsup is always set to 0, as the syntax doesn't allow >> referencing upper levels directly. When an SQL function is inlined, any >> ExpressionParams in the expressions that are substituted for Params need >> to have their levelsup adjusted, so that it still refers to the right >> value if there's CASE expressions in the inlined function. Also, when an >> ExpressionParam is replaced with a Const, the levelsup fields of any >> other ExpressionParams within the CaseExpr referring to higher levels >> need to have their levelsup decremented to account for the fact that the >> CaseExpr doesn't push the expression parameter anymore. > > I believe this is an unworkably complex, and almost certainly buggy > Rube Goldberg device. Even if it manages to work today, it's going to > be impossible to maintain those levelsup values correctly during > any sort of expression rearrangement or optimization. > > Please take another look at just assigning a PARAM_EXEC parameter per > Case expression. I've added this to the TODO list, hopefully someone more skilled with the planner than me will pick this up... -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com