Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fhXIm-0008EP-GU for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Jul 2018 09:38:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fhXIj-0006dv-Ua for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Jul 2018 09:38:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fhXIj-0006do-K5 for pgsql-hackers@lists.postgresql.org; Mon, 23 Jul 2018 09:38:45 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fhXIh-0007Lw-0B for pgsql-hackers@postgresql.org; Mon, 23 Jul 2018 09:38:43 +0000 Received: by mail-pg1-x543.google.com with SMTP id y5-v6so6456pgv.1 for ; Mon, 23 Jul 2018 02:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CDPvEvoCIalZt/FpWUsAastEFbsSVxeAylMsNT4F6cU=; b=ly4hmJzzT7Wql82rgFE6XErnfDziJ8ujap05MurUh/4iRHJZ/RzlPNjwR8Kdx65SHc g5z/s2B2Ats+mS3G0jDopDB1y76fo5GTZb83blO80AC//rCW6U2J0qKyKyB2IZzyzBdp LobUIiTadb26LQYvhujeuinQ9iOl9Zb2EpiuEZWchU4eKsvym97NORuAy6AQw+5X/Tp6 HTefqt7JQ5IT5XUr18BF69mWwWCzVxa6a7BMgjRohUcmK0ULec4seFDCDjZAcarURNtg GvTAGV9ngMBRdXkaefw9rlZwUldJVUCfX6zKLL1LfCV7llBTuQsmPYd7h5i1oJjhs5XE PWEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CDPvEvoCIalZt/FpWUsAastEFbsSVxeAylMsNT4F6cU=; b=p6pGaTwsG0M7BGWGeq/e6uGee3WeA5FjUPtnRYcH0bzztHq4R6oDXCYlTlxURVsCEv +d/cnJ7G5RWlePm2wrYf9Vsfw8M09bDZSAPdYkk0nXtDhPIVXFlBXVGLWn8FibOVef5p vayNwCGnp0vwe0f1b7UI+/Pn+ZR6M50uGJjTexbxhAHMuPy4BmowAkhApedRREsMuEBS VPXaGT7nsprz3O5BGBxMx1eYclv9j2HHtoUHxwWWUzBCZeYr3RjXkRcD6iDtcJhsScb9 zf9BwyQyc4Mp1yS24C07pAAR2iGPgJhH38kxUiDexfUCyNfls9+0pmdMTNCiiQuK2QRm R3tg== X-Gm-Message-State: AOUpUlHhFba1KLW08d3JxcTeUkun3bmrhFN+Z5C+SNsdMPnaslf79e2H qExhUT689L10dwuhOf7VgYn+99OlTolfdGlodj1i7Jhh X-Google-Smtp-Source: AAOMgpf/mSYYhhjwgX1TzOUKZM+FVcaFmZ0tC8PVtcptqkRnPOYV4V0pE6TB1jmOAIKx9xMvPan6k6/JctmL1XLY64M= X-Received: by 2002:a62:b612:: with SMTP id j18-v6mr12575805pff.199.1532338722035; Mon, 23 Jul 2018 02:38:42 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:3c8f:0:0:0:0 with HTTP; Mon, 23 Jul 2018 02:38:41 -0700 (PDT) In-Reply-To: References: <5AFC0865.8050802@lab.ntt.co.jp> <5AFD6580.5090308@lab.ntt.co.jp> <5AFE81CC.8000508@lab.ntt.co.jp> <5B17C5EC.1090602@lab.ntt.co.jp> <5B1E5071.1000704@lab.ntt.co.jp> <5B23A964.9020800@lab.ntt.co.jp> <5B28FB19.3090809@lab.ntt.co.jp> <20180703163519.tsigyic5xefunv74@alap3.anarazel.de> <5B3C2A4E.5030901@lab.ntt.co.jp> <5B4F2BE9.3000304@lab.ntt.co.jp> From: Ashutosh Bapat Date: Mon, 23 Jul 2018 15:08:41 +0530 Message-ID: Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled. To: Robert Haas Cc: Etsuro Fujita , Andres Freund , Rajkumar Raghuwanshi , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jul 20, 2018 at 8:56 PM, Robert Haas wrote: [ ... clipped portion ...] > > In short, plan creation time is just the wrong time to change the > plan. It's just a time to translate the plan from the form needed by > the planner to the form needed by the executor. It would be fine if > the change you were making were only cosmetic, but it's not. > Agree with all that, including the clipped paras. > After looking over both patches, I think Ashutosh Bapat has basically > the right idea. What he is proposing is a localized fix that doesn't > seem to make any changes to the way things work overall. I do think > his patches need to be fixed up a bit to avoid conflating > ConvertRowtypeExpr with "converted whole-row reference." The two are > certainly not equivalent; the latter is a narrow special case. Some > of the comments could use some more wordsmithing, too, I think. Apart > from those gripes, though, I think it's solving the problem the > correct way: don't build the wrong plan and try to fix it, just build > the right plan from the beginning. I will work on that if everyone agrees that that's the right way to go. Fujita-san seems to have some arguments still. I have argued on the same lines as yours but your explanation is better. I don't have anything more to add. I will wait for that to be resolved. > > There are definitely some things not to like about this approach. In > particular, I definitely agree that treating a converted whole-row > reference specially is not very nice. It feels like it might be > substantially cleaner to be able to represent this idea as a single > node rather than a combination of ConvertRowtypeExpr and var with > varattno = 0. Perhaps in the future we ought to consider either (a) > trying to use a RowExpr for this rather than ConvertRowtypeExpr or (b) > inventing a new WholeRowExpr node that stores two RTIs, one for the > relation that's generating the whole-row reference and the other for > the relation that is controlling the column ordering of the result or > (c) allowing a Var to represent a whole-row expression that has to > produce its outputs according to the ordering of some other RTE. I never liked representing a whole-row expression as a Var worst with varattno = 0. We should have always casted it as RowExpr(set of vars, one var per column). This problem wouldn't arise then. Many other problems wouldn't arise then, I think. I think we do that so that we can convert a tuple from buffer into a datum and put it in place of Var with varattno = 0. Given that I prefer (a) or (b) in all the cases. If not that, then c. But I agree that we have to avoid ConvertRowtypeExpr being used in this case. > But > I don't think it's wise or necessary to whack that around just to fix > this bug; it is refactoring or improvement work best left to a future > release. > > Also, it is definitely a real shame that we have to build attr_needed > data for each child separately. Right now, we've got to build a whole > lot of things for each child individually, and that's slow and > inefficient. We're not going to scale nicely to large partitioning > hierarchies unless we can figure out some way of minimizing the work > we do for each partition. So, the fact that Fujii-san's approach > avoids needing to compute attr_needed in some cases is very appealing. > However, in my opinion, it's nowhere near appealing enough to justify > trying to do surgery on the target list at plan-creation time. I > think we need to leave optimizing this to a future effort. > Partition-wise join/aggregate, and partitioning in general, need a lot > of optimization in a lot of places, and fortunately there are people > working on that, but our goal here should just be to fix things up > well enough that we can ship it. I agree. > I don't see anything in Ashutosh's > patch that is so ugly that we can't live with it for the time being. Thanks. -- Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company