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 1grDd8-00081v-ID for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Feb 2019 03:12:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1grDd4-00083Z-R3 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Feb 2019 03:12:02 +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 1grDd4-00083S-B3 for pgsql-hackers@lists.postgresql.org; Wed, 06 Feb 2019 03:12:02 +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 1grDcz-0006R4-Li for pgsql-hackers@lists.postgresql.org; Wed, 06 Feb 2019 03:11:59 +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 x163Br1d020002; Tue, 5 Feb 2019 22:11:53 -0500 From: Tom Lane To: David Rowley cc: PostgreSQL Hackers Subject: Re: Bogus lateral-reference-propagation logic in create_lateral_join_info In-reply-to: References: <3951.1549403812@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Wed, 06 Feb 2019 14:26:30 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20000.1549422713.1@sss.pgh.pa.us> Date: Tue, 05 Feb 2019 22:11:53 -0500 Message-ID: <20001.1549422713@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley writes: > On Wed, 6 Feb 2019 at 10:57, Tom Lane wrote: >> Also, I'd really like to know why I had to put in the exception seen >> in the loop for AppendRelInfos that do not point to a valid parent. >> It seems to me that that is almost certainly working around a bug in >> the partitioning logic. (Without it, the partition_prune regression test >> crashes.) Or would somebody like to own up to having created that state >> of affairs intentionally? If so why? > Sounds pretty strange to me. What exactly do you mean by not > pointing to a valid parent? Do you mean the parent_relid index is not > a valid RelOptInfo? Exactly --- the parent_relid index does not have a RelOptInfo in simple_rel_array[]. > Can you point to the regression test that's doing this? Yeah, I misspoke above, it's in partition_join not partition_prune, specifically DELETE FROM prt1_l WHERE EXISTS ( SELECT 1 FROM int4_tbl, LATERAL (SELECT int4_tbl.f1 FROM int8_tbl LIMIT 2) ss WHERE prt1_l.c IS NULL); I didn't run this totally to bottom yet, but what seems to be happening is that inheritance_planner is creating a partition-specific subplan for the DELETE, and it's allowing AppendRelInfos from the parent query to propagate into the subquery even though they have nothing to do with that subquery. We could just decide that it's okay for code dealing with the subquery to ignore the irrelevant AppendRelInfos (which is basically what my draft patch did), but I find that to be an uncomfortable answer: it seems *way* too likely to result in code that can mask real bugs. I'd be happier fixing things so that inheritance_planner doesn't propagate anything into the subquery that doesn't make sense in the subquery's context. But perhaps that's unreasonably hard? Not enough data yet. regards, tom lane