mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Fix computation of varnullingrels when const-folding field selection.
We can simplify FieldSelect on a whole-row Var into a plain Var for the selected field. However, we should copy the whole-row Var's varnullingrels when we do so, because the new Var is clearly nullable by exactly the same rels as the original. Failure to do this led to errors like "wrong varnullingrels (b) (expected (b 3)) for Var 2/2". Richard Guo, per bug #18184 from Marian Krucina. Back-patch to v16 where varnullingrels was introduced. Discussion: https://postgr.es/m/18184-5868dd258782058e@postgresql.org
This commit is contained in:
@@ -3296,12 +3296,19 @@ eval_const_expressions_mutator(Node *node,
|
||||
fselect->resulttype,
|
||||
fselect->resulttypmod,
|
||||
fselect->resultcollid))
|
||||
return (Node *) makeVar(((Var *) arg)->varno,
|
||||
fselect->fieldnum,
|
||||
fselect->resulttype,
|
||||
fselect->resulttypmod,
|
||||
fselect->resultcollid,
|
||||
((Var *) arg)->varlevelsup);
|
||||
{
|
||||
Var *newvar;
|
||||
|
||||
newvar = makeVar(((Var *) arg)->varno,
|
||||
fselect->fieldnum,
|
||||
fselect->resulttype,
|
||||
fselect->resulttypmod,
|
||||
fselect->resultcollid,
|
||||
((Var *) arg)->varlevelsup);
|
||||
/* New Var is nullable by same rels as the old one */
|
||||
newvar->varnullingrels = ((Var *) arg)->varnullingrels;
|
||||
return (Node *) newvar;
|
||||
}
|
||||
}
|
||||
if (arg && IsA(arg, RowExpr))
|
||||
{
|
||||
|
Reference in New Issue
Block a user