pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Remove over-optimistic Assert. 4+ messages / 2 participants [nested] [flat]
* pgsql: Remove over-optimistic Assert. @ 2023-01-31 16:58 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 4+ messages in thread From: Tom Lane @ 2023-01-31 16:58 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Remove over-optimistic Assert. In commit 2489d76c4, I'd thought it'd be safe to assert that a PlaceHolderVar appearing in a scan-level expression has empty nullingrels. However this is not so, as when we determine that a join relation is certainly empty we'll put its targetlist into a Result-with-constant-false-qual node, and nothing is done to adjust the nullingrels of the Vars or PHVs therein. (Arguably, a Result used in this way isn't really a scan-level node, but it certainly isn't an upper node either ...) It's not clear this is worth any close analysis, so let's just take out the faulty Assert. Per report from Robins Tharakan. I added a test case based on his example, just in case somebody tries to tighten this up. Discussion: https://postgr.es/m/CAEP4nAz7Enq3+DEthGG7j27DpuwSRZnW0Nh6jtNh75yErQ_nbA@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/eae0e20deffb0a73f7cb0e94746f94a1347e71b1 Modified Files -------------- src/backend/optimizer/plan/setrefs.c | 2 +- src/test/regress/expected/join.out | 14 ++++++++++++++ src/test/regress/sql/join.sql | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Remove over-optimistic Assert. @ 2023-02-02 01:51 Richard Guo <guofenglinux@gmail.com> parent: Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 2 replies; 4+ messages in thread From: Richard Guo @ 2023-02-02 01:51 UTC (permalink / raw) To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-committers@lists.postgresql.org, PostgreSQL-development <pgsql-hackers@postgresql.org> On Thu, Feb 2, 2023 at 8:40 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Remove over-optimistic Assert. > > In commit 2489d76c4, I'd thought it'd be safe to assert that a > PlaceHolderVar appearing in a scan-level expression has empty > nullingrels. However this is not so, as when we determine that a > join relation is certainly empty we'll put its targetlist into a > Result-with-constant-false-qual node, and nothing is done to adjust > the nullingrels of the Vars or PHVs therein. (Arguably, a Result > used in this way isn't really a scan-level node, but it certainly > isn't an upper node either ...) It seems this is the only case we can have PlaceHolderVar with non-empty nullingrels at scan level. So I wonder if we can manually adjust the nullingrels of PHVs in this special case, and keep the assertion about phnullingrels being NULL in fix_scan_expr. I think that assertion is asserting the right thing in most cases. It's a pity to lose it. Currently for the tlist of a childless Result, we special-case ROWID_VAR Vars in set_plan_refs and thus keep assertions about varno != ROWID_VAR in fix_scan_expr. Do you think we can special-case PHVs at the same place by setting its phnullingrels to NULL? I'm imagining something like attached. Thanks Richard Attachments:^ permalink raw reply [nested|flat] 4+ messages in threadv1-0001-Adjust-phnullingrels-for-childless-Result.patch (application/octet-stream, 2.3K) download
From 41fc3b6855e5b6e525ec46a276a0892a321045e0 Mon Sep 17 00:00:00 2001 From: Richard Guo <guofenglinux@gmail.com> Date: Thu, 2 Feb 2023 09:06:53 +0800 Subject: [PATCH v1] Adjust phnullingrels for childless Result --- src/backend/optimizer/plan/setrefs.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 186fc8014b..f6d8eaf1df 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -1045,16 +1045,32 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) * expected to occur here, it seems safer to special-case * it here and keep the assertions that ROWID_VARs * shouldn't be seen by fix_scan_expr. + * + * The tlist of a childless Result could contain PHVs with + * non-empty phnullingrels, in case it's a dummy plan + * generated for empty join relation. Special-case it here + * by setting phnullingrels to NULL and keep the assertion + * about phnullingrels being NULL in fix_scan_expr. */ foreach(l, splan->plan.targetlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); - Var *var = (Var *) tle->expr; - if (var && IsA(var, Var) && var->varno == ROWID_VAR) - tle->expr = (Expr *) makeNullConst(var->vartype, - var->vartypmod, - var->varcollid); + if (tle->expr && IsA(tle->expr, Var)) + { + Var *var = (Var *) tle->expr; + + if (var->varno == ROWID_VAR) + tle->expr = (Expr *) makeNullConst(var->vartype, + var->vartypmod, + var->varcollid); + } + else if (tle->expr && IsA(tle->expr, PlaceHolderVar)) + { + PlaceHolderVar *phv = (PlaceHolderVar *) tle->expr; + + phv->phnullingrels = NULL; + } } splan->plan.targetlist = @@ -2205,7 +2221,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context) /* At scan level, we should always just evaluate the contained expr */ PlaceHolderVar *phv = (PlaceHolderVar *) node; - /* XXX can we assert something about phnullingrels? */ + Assert(phv->phnullingrels == NULL); return fix_scan_expr_mutator((Node *) phv->phexpr, context); } if (IsA(node, AlternativeSubPlan)) -- 2.31.0
* Fwd: pgsql: Remove over-optimistic Assert. @ 2023-02-02 02:01 Richard Guo <guofenglinux@gmail.com> parent: Richard Guo <guofenglinux@gmail.com> 1 sibling, 0 replies; 4+ messages in thread From: Richard Guo @ 2023-02-02 02:01 UTC (permalink / raw) To: PostgreSQL-development <pgsql-hackers@postgresql.org> Resend this email to -hackers. Sorry for the noise. Thanks Richard ---------- Forwarded message --------- From: Richard Guo <guofenglinux@gmail.com> Date: Thu, Feb 2, 2023 at 9:51 AM Subject: Re: pgsql: Remove over-optimistic Assert. To: Tom Lane <tgl@sss.pgh.pa.us> Cc: <pgsql-committers@lists.postgresql.org>, PostgreSQL-development < pgsql-hackers@postgresql.org> On Thu, Feb 2, 2023 at 8:40 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: > Remove over-optimistic Assert. > > In commit 2489d76c4, I'd thought it'd be safe to assert that a > PlaceHolderVar appearing in a scan-level expression has empty > nullingrels. However this is not so, as when we determine that a > join relation is certainly empty we'll put its targetlist into a > Result-with-constant-false-qual node, and nothing is done to adjust > the nullingrels of the Vars or PHVs therein. (Arguably, a Result > used in this way isn't really a scan-level node, but it certainly > isn't an upper node either ...) It seems this is the only case we can have PlaceHolderVar with non-empty nullingrels at scan level. So I wonder if we can manually adjust the nullingrels of PHVs in this special case, and keep the assertion about phnullingrels being NULL in fix_scan_expr. I think that assertion is asserting the right thing in most cases. It's a pity to lose it. Currently for the tlist of a childless Result, we special-case ROWID_VAR Vars in set_plan_refs and thus keep assertions about varno != ROWID_VAR in fix_scan_expr. Do you think we can special-case PHVs at the same place by setting its phnullingrels to NULL? I'm imagining something like attached. Thanks Richard Attachments:^ permalink raw reply [nested|flat] 4+ messages in threadv1-0001-Adjust-phnullingrels-for-childless-Result.patch (application/x-patch, 2.3K) download
From 41fc3b6855e5b6e525ec46a276a0892a321045e0 Mon Sep 17 00:00:00 2001 From: Richard Guo <guofenglinux@gmail.com> Date: Thu, 2 Feb 2023 09:06:53 +0800 Subject: [PATCH v1] Adjust phnullingrels for childless Result --- src/backend/optimizer/plan/setrefs.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 186fc8014b..f6d8eaf1df 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -1045,16 +1045,32 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset) * expected to occur here, it seems safer to special-case * it here and keep the assertions that ROWID_VARs * shouldn't be seen by fix_scan_expr. + * + * The tlist of a childless Result could contain PHVs with + * non-empty phnullingrels, in case it's a dummy plan + * generated for empty join relation. Special-case it here + * by setting phnullingrels to NULL and keep the assertion + * about phnullingrels being NULL in fix_scan_expr. */ foreach(l, splan->plan.targetlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); - Var *var = (Var *) tle->expr; - if (var && IsA(var, Var) && var->varno == ROWID_VAR) - tle->expr = (Expr *) makeNullConst(var->vartype, - var->vartypmod, - var->varcollid); + if (tle->expr && IsA(tle->expr, Var)) + { + Var *var = (Var *) tle->expr; + + if (var->varno == ROWID_VAR) + tle->expr = (Expr *) makeNullConst(var->vartype, + var->vartypmod, + var->varcollid); + } + else if (tle->expr && IsA(tle->expr, PlaceHolderVar)) + { + PlaceHolderVar *phv = (PlaceHolderVar *) tle->expr; + + phv->phnullingrels = NULL; + } } splan->plan.targetlist = @@ -2205,7 +2221,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context) /* At scan level, we should always just evaluate the contained expr */ PlaceHolderVar *phv = (PlaceHolderVar *) node; - /* XXX can we assert something about phnullingrels? */ + Assert(phv->phnullingrels == NULL); return fix_scan_expr_mutator((Node *) phv->phexpr, context); } if (IsA(node, AlternativeSubPlan)) -- 2.31.0
* Re: pgsql: Remove over-optimistic Assert. @ 2023-02-02 02:04 Tom Lane <tgl@sss.pgh.pa.us> parent: Richard Guo <guofenglinux@gmail.com> 1 sibling, 0 replies; 4+ messages in thread From: Tom Lane @ 2023-02-02 02:04 UTC (permalink / raw) To: Richard Guo <guofenglinux@gmail.com>; +Cc: pgsql-committers@lists.postgresql.org, PostgreSQL-development <pgsql-hackers@postgresql.org> Richard Guo <guofenglinux@gmail.com> writes: > On Thu, Feb 2, 2023 at 8:40 AM Tom Lane <tgl@sss.pgh.pa.us> wrote: >> In commit 2489d76c4, I'd thought it'd be safe to assert that a >> PlaceHolderVar appearing in a scan-level expression has empty >> nullingrels. However this is not so, as when we determine that a >> join relation is certainly empty we'll put its targetlist into a >> Result-with-constant-false-qual node, and nothing is done to adjust >> the nullingrels of the Vars or PHVs therein. (Arguably, a Result >> used in this way isn't really a scan-level node, but it certainly >> isn't an upper node either ...) > It seems this is the only case we can have PlaceHolderVar with non-empty > nullingrels at scan level. So I wonder if we can manually adjust the > nullingrels of PHVs in this special case, and keep the assertion about > phnullingrels being NULL in fix_scan_expr. I think that assertion is > asserting the right thing in most cases. It's a pity to lose it. Well, if we change the nullingrels of the PHV in the Result, then we will likely have to loosen the nullingrels cross-check in the next plan level up. That doesn't seem like much of an improvement. Keeping the Result's tlist the same as what we would have generated for a non-dummy join node seems right to me. We could perhaps use a weaker assert like "phv->phnullingrels == NULL || we-are-at-a-dummy-Result", but I didn't think it was worth passing down the extra flag needed to make that happen. (Also, it's fair to wonder whether setrefs.c actually knows whether a Result arose this way.) Also, there are other places in setrefs.c that are punting on checking phnullingrels. If we don't tighten all of them, I doubt we've moved the ball very far. regards, tom lane ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2023-02-02 02:04 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2023-01-31 16:58 pgsql: Remove over-optimistic Assert. Tom Lane <tgl@sss.pgh.pa.us> 2023-02-02 01:51 ` Richard Guo <guofenglinux@gmail.com> 2023-02-02 02:01 ` Richard Guo <guofenglinux@gmail.com> 2023-02-02 02:04 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox