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 1fgXIu-0004kc-D7 for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jul 2018 15:26: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 1fgXIr-0002LS-MM for pgsql-hackers@arkaria.postgresql.org; Fri, 20 Jul 2018 15:26: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 1fgXIr-0002LL-94 for pgsql-hackers@lists.postgresql.org; Fri, 20 Jul 2018 15:26:45 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fgXIo-0005FM-2F for pgsql-hackers@postgresql.org; Fri, 20 Jul 2018 15:26:44 +0000 Received: by mail-lf1-x144.google.com with SMTP id a4-v6so2072834lff.5 for ; Fri, 20 Jul 2018 08:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fFFnmy6Z6q4RwZLdacqgsey1UCKtbHgmsJphn9HKbcs=; b=Mrtq9+HIDjhP/D4eSKwc+RWfKTn65Sf3QoCii3oNFIlxpkYnqHzEjvgrlUkaq4KpVo GhglQ6haMzOYoA4pxLTblakeIiCbfGyENY7SQgkwOB5yBi9p8I0vI72I9+1A5eZiaZ6e nY11I1+IuZ35iGUooEZLSymO6GIw2zlVukMCh7AC8dYUfHe7pX+acYVcxjgxEK09nVmC PrtZOJPXVGYL1Gu4Dj78Iq1RrxU0ZAOIFlhjezwFWWP78u6+3TiTBOVJKERNFSYZMw+Q LNHrRDlRAfdRQMcF+eWyBdshxOtegufSHgkZkSYi/cSADWpPBF+0uHFRXlpLGXfyD6qy N96g== 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=fFFnmy6Z6q4RwZLdacqgsey1UCKtbHgmsJphn9HKbcs=; b=VQpULAoH+zB76QG1FDNkTN+x+h1aAQe5nfR/cwU60NMhWZZ4ZHTpVgdSlRwgVgdcGf qAsvmgYKm9gFo3/nTYeP2cZZMUZsjahxTpmrI0yRH0Lg7cDZmE/P0hQReXyQx2l0CoOh t8/ne6/Ea6EkpVAMfpNrB0nwCBnfIrZkv7hK6uGZ05PPjjQEszyFdAPdARppVPlqlPcr mbjaC9gOzLxnVhvzXDGAdiuKq9xs4XxIQDLsALBIRQnGKDgIRoJmpxNh4R27vI/4OiDR /Zf/vXwkUkSIEFBtE3kO7qvti9omrsxlZB5yUtbHeTjjo2pk+fSb8mGrymDUPh8JAWYt /ynA== X-Gm-Message-State: AOUpUlFpijkGJLaViUIe2PmtMRzMk0C3gapFCQkRCFkkpu9uu7qkg59D TSZzWcafbSK2gJ+QEN+xYqaaUBnsXKkB+nYNl0s= X-Google-Smtp-Source: AAOMgpcQivppkz3v6tOhlUUwh13PX9Mmr14H7PV9/TeQ0zoO/t5s1rrlCAkFMc8a8jsuqgIP7xQ87DaWYjdts0HrCqI= X-Received: by 2002:a19:238d:: with SMTP id j135-v6mr1788807lfj.58.1532100400117; Fri, 20 Jul 2018 08:26:40 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:e508:0:0:0:0:0 with HTTP; Fri, 20 Jul 2018 08:26:39 -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: Robert Haas Date: Fri, 20 Jul 2018 11:26:39 -0400 Message-ID: Subject: Re: Expression errors with "FOR UPDATE" and postgres_fdw with partition wise join enabled. To: Etsuro Fujita Cc: Andres Freund , Ashutosh Bapat , 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:38 AM, Robert Haas wrote: > This looks like a terrible design to me. If somebody in future > invents a new plan type that is not projection-capable, then this > could fail an assertion here and there won't be any simple fix. And > if you reach here and the child targetlists somehow haven't been > adjusted, then you won't even fail an assertion, you'll just crash (or > maybe return wrong answers). To elaborate on this thought a bit, it is currently the case that all scan and join types are projection-capable, and most likely we would make any such node types added in the future projection-capable as well, but it still doesn't seem like a good idea to me to have tangentially-related parts of the system depend on that in subtle ways. Also, even today, this would fail if the subplan happened to be a Sort, and it's not very obvious why that couldn't happen. If it can't happen today, it's not obvious why a future code change couldn't introduce cases where it can happen. More broadly, the central idea of this patch is that we can set the target list for a child rel to something other than the target list that we expect it will eventually produce, and then at plan creation time fix it. I think that's a bad idea. The target list affects lots of things, like costing. If we don't insert a ConvertRowTypeExpr into the child's target list, the costing will be wrong to the extent that ConvertRowTypeExpr has any cost, which it does. Any other current or future property that is computed based on the target list -- parallel-safety, width, security-level, whatever -- could also potentially end up with a wrong value if the target list as written does not match the target list as will actually be produced. It's true that, in all of these areas, the ConvertRowTypeExpr isn't likely to have a lot of impact; it probably won't have a big effect on costing and may not actually cause a problem for the other things that I mentioned. On the other hand, if it does cause a serious problem, what options would we have for fixing it other than to back out your entire patch and solve the problem some other way? The idea that derived properties won't be correct unless they are based on the real target list is pretty fundamental, and I think deviating from the idea that we get the correct target list first and then compute the derived properties afterward is likely to cause real headaches for future developers. 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. 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. 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. 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 don't see anything in Ashutosh's patch that is so ugly that we can't live with it for the time being. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company