Tender Wang <tndrwang@gmail.com> 于2026年3月17日周二 20:59写道:
>
> The error was reported in rebuild_joinclause_attr_needed() when
> processing Relid = 1(rtindex =1),
> When processing its joininfo" ON tom1.col_bool IS NOT NULL",
> (gdb) pgprint rinfo->clause
> Var [varno=2 varattno=2 vartype=16
> varreturningtype=VAR_RETURNING_DEFAULT varnosyn=2 varattnosyn=2]
>
> The varno=2, rtindex=2(tom1) has been removed. In
> add_vars_to_attr_needed(), to find the base_rel, but the
> root->simple_rel_array[2] is NULL.
> So the error is reporting.
> It seems the joininfo should be replaced by rtindex = 3, because the
> rtindex=2 would be removed.
> --
(gdb) pgprint rinfo
RestrictInfo [is_pushed_down=false can_join=false pseudoconstant=false
has_clone=true is_clone=false leakproof=false
has_volatile=VOLATILITY_UNKNOWN security_level=0
num_base_rels=1 rinfo_serial=4 eval_cost={startup = -1,
per_tuple = 0} norm_selec=-1 outer_selec=-1 outer_is_left=false
hashjoinoperator=0 left_bucketsize=-1
right_bucketsize=-1 left_mcvfreq=-1 right_mcvfreq=-1
left_hasheqoperator=0 right_hasheqoperator=0]
[clause] Var [varno=2 varattno=2 vartype=16
varreturningtype=VAR_RETURNING_DEFAULT varnosyn=2 varattnosyn=2]
[clause_relids] Bitmapset [3]
[required_relids] Bitmapset [3 1]
[incompatible_relids] Bitmapset [7 6]
[outer_relids] Bitmapset [6 5 3]
The above is the joininfo of the rtindex=1(tom0), we can see that the
required_relids is changed to [3 1], but the clause is still
rtindex=2(varno=2).
I guess the current logic in remove_self_join_rel() may forget to
process the rinfo->clause.
--
Thanks,
Tender Wang