ERROR: no relation entry for relid 3 - Mailing list pgsql-hackers

From Richard Guo
Subject ERROR: no relation entry for relid 3
Date
Msg-id CAMbWs4834TwOtyyycyvja3MuOBkfpXy3dFAL0zt_vcM1KtqV-Q@mail.gmail.com
Whole thread
Responses Re: ERROR: no relation entry for relid 3
Re: ERROR: no relation entry for relid 3
List pgsql-hackers
While fuzzing around the join alias expansion code, I ran into this:

create table t (a int);

select count(*)
from (t t1 full join t t2 using (a)) j,
     lateral (select * from t tablesample system (50) repeatable (j.a)) ss;
ERROR:  no relation entry for relid 3

This fails all the way back to v14 at least, dates back to the
introduction of TABLESAMPLE.

What happens is that the lateral subquery gets pulled up, and the
sampled relation becomes a lateral RTE of the outer level, with the
join alias Var j.a now in its TABLESAMPLE clause.  But
preprocess_expression skips flatten_join_alias_vars for
EXPRKIND_TABLESAMPLE, on the assumption that such clauses can't
contain Vars of the current query level.  The alias Var thus never
gets expanded, and results in that error at last.

Apparently that assumption does not always hold.  I think we can fix
it the same way lateral function and VALUES RTEs are handled, by
adding an EXPRKIND_TABLESAMPLE_LATERAL and using it for the
TABLESAMPLE clause of a lateral relation RTE, so that only the
non-lateral kind skips the alias expansion.  Please see attached.

- Richard

Attachment

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: [PATCH] Release replication slot on error in SQL-callable slot functions
Next
From: Nisha Moond
Date:
Subject: Re: Distinguish publication exclusions in object addresses