pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17832: ERROR:  failed to apply nullingrels to a non-Var in HEAD
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2023-03-12 767c598954  Work around implementation restriction in adjust_appendrel_attrs.
* BUG #17832: ERROR:  failed to apply nullingrels to a non-Var in HEAD
@ 2023-03-11 18:05 PG Bug reporting form <noreply@postgresql.org>
  2023-03-12 17:02 ` Re: BUG #17832: ERROR: failed to apply nullingrels to a non-Var in HEAD Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2023-03-11 18:05 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: marko@joh.to

The following bug has been logged on the website:

Bug reference:      17832
Logged by:          Marko Tiikkaja
Email address:      marko@joh.to
PostgreSQL version: Unsupported/Unknown
Operating system:   Linux
Description:        

Running the following query in HEAD fails with the error in $SUBJECT:

SELECT 1
FROM
(
    SELECT NULL::text AS AccountName
) Actual FULL JOIN (
    SELECT text 'foo'
    UNION ALL
    SELECT text 'bar'
) Expected (AccountName)
ON TRUE
WHERE Expected.AccountName IS NULL;

I tried PGv15 online and it seemed to work there, so I'm guessing this only
applies to HEAD.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17832: ERROR: failed to apply nullingrels to a non-Var in HEAD
  2023-03-11 18:05 BUG #17832: ERROR:  failed to apply nullingrels to a non-Var in HEAD PG Bug reporting form <noreply@postgresql.org>
@ 2023-03-12 17:02 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2023-03-12 17:02 UTC (permalink / raw)
  To: marko@joh.to; +Cc: pgsql-bugs@lists.postgresql.org

PG Bug reporting form <noreply@postgresql.org> writes:
> Running the following query in HEAD fails with the error in $SUBJECT:
> SELECT 1
> FROM
> (
>     SELECT NULL::text AS AccountName
> ) Actual FULL JOIN (
>     SELECT text 'foo'
>     UNION ALL
>     SELECT text 'bar'
> ) Expected (AccountName)
> ON TRUE
> WHERE Expected.AccountName IS NULL;

Thanks for the report!  This example is breaking an assumption I made
in adjust_appendrel_attrs:

         * If var->varnullingrels isn't empty, and the translation wouldn't be
         * a Var, we have to fail.  One could imagine wrapping the translated
         * expression in a PlaceHolderVar, but that won't work because this is
         * typically used after freezing placeholders.  Fortunately, the case
         * appears unreachable at the moment.

Not so much :-(.  That comment goes on to speculate about
pre-emptively wrapping translations in PlaceHolderVars, which is
doable but seems inefficient (mainly because we'd have to do it
well in advance of knowing whether it's needed).

The reason we have a problem is that the planner is (in effect) trying
to push down the "Expected.AccountName IS NULL" clause to the UNION
ALL children.  I'm pretty sure that when I wrote this code, I expected
that that would not happen, because it's useless: we will not be able
to apply that clause at the scan level, because it can't be applied
until after the outer join is formed.  So maybe the right thing to do
is not push down the clause, which I think could be implemented by
having set_append_rel_size not forcibly translate the parent's entire
joininfo list, but only those clauses not mentioning any of the rel's
nulling_relids.

I'm slightly worried that after we do this, we might find that some
other example still forces us to remove the implementation restriction
in adjust_appendrel_attrs.  However, it seems like trimming child
joininfo lists like this might be a net win anyway, just by reducing
the amount of effort we spend examining those lists later.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-03-12 17:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11 18:05 BUG #17832: ERROR:  failed to apply nullingrels to a non-Var in HEAD PG Bug reporting form <noreply@postgresql.org>
2023-03-12 17:02 ` Re: BUG #17832: ERROR: failed to apply nullingrels to a non-Var in HEAD 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