Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1HDV-0003pG-4L for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2019 21:03:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h1HDR-00088z-TT for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2019 21:03:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1HDR-00088V-Jo for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2019 21:03:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1HDK-0005PX-9V for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2019 21:03:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x25L2ujC020478; Tue, 5 Mar 2019 16:02:56 -0500 From: Tom Lane To: Julien Rouhaud cc: thibaut.madelaine@dalibo.com, Robert Haas , PostgreSQL mailing lists Subject: Re: BUG #15669: Error with unnest in PG 11 (ERROR: 0A000) In-reply-to: References: <15669-02fb3296cca26203@postgresql.org> <19353.1551800347@sss.pgh.pa.us> <21482.1551806937@sss.pgh.pa.us> Comments: In-reply-to Julien Rouhaud message dated "Tue, 05 Mar 2019 19:22:32 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20476.1551819776.1@sss.pgh.pa.us> Date: Tue, 05 Mar 2019 16:02:56 -0500 Message-ID: <20477.1551819776@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk So actually, there are more things wrong here than I thought. 1. This logic is pretty stupid, if not outright wrong, for partitioned relations. It fixes all the existing paths to have new outputs, and then goes and generates all-new Append paths which it just adds on to the existing paths. There isn't any situation where that makes sense; we may as well just throw away the existing paths and then generate the new ones. Aside from being wasteful, I wonder whether it's even correct --- if any of the existing paths have dependencies on the old reltargets of the children, there'll be trouble, assuming they survive the cost comparisons. 2. If we have a dummy relation, and we stick a ProjectionPath atop the existing dummy path, it stops looking like a dummy relation, as indeed noted in the existing comment. It's possible that nothing after this point cares, but I would not exactly bet on that --- I think it's more likely that we just don't have test cases exercising combinations where there are nontrivial processing steps remaining. The most obvious fix for #2 is to change IS_DUMMY_REL() so that it can still return true once we've inserted SRF path steps. In HEAD I'd be inclined to do that by backing off the premature optimization of equating a dummy rel with something that has a dummy path, and instead adding a separate bool is_dummy_rel flag to RelOptInfo. That doesn't seem real safe to back-patch into v11 unfortunately. To make matters worse, since IS_DUMMY_REL() is a macro, it could be that this broken test is actually compiled into some third-party extensions. There's probably little we can do about that except hope that those extensions are not dealing with SRF-with-dummy-input cases. What I suggest we do in v11 is change IS_DUMMY_REL() to be a subroutine that drills down through any ProjectionPaths to see if it can find a dummy path. (Having done that, possibly apply_scanjoin_target_to_paths could be simplified --- I think it might not need to have a separate code path for dummy rels anymore.) Thoughts? regards, tom lane