The const expression evaluation routine should always return a copy - Mailing list pgsql-hackers

From Andrei Lepikhov
Subject The const expression evaluation routine should always return a copy
Date
Msg-id 2fcdf4d0-5190-42b8-9e7c-ad950354234c@postgrespro.ru
Whole thread Raw
Responses Re: The const expression evaluation routine should always return a copy
List pgsql-hackers
IMO, the routine eval_const_expressions_mutator contains some stale code:

case T_SubPlan:
case T_AlternativeSubPlan:
   /*
    * Return a SubPlan unchanged --- too late to do anything with it.
    *
    * XXX should we ereport() here instead?  Probably this routine
    * should never be invoked after SubPlan creation.
    */
    return node;

At least, this code could be achieved with estimate_expression_value(). 
So, we should fix the comment. But maybe we need to do a bit more. 
According to the mutator idea, only the Query node is returned 
unchanged. If the Subplan node is on top of the expression, the call 
above returns the same node, which may be unconventional.
I'm not totally sure about the impossibility of constantifying SubPlan: 
we already have InitPlans for uncorrelated subplans. Maybe something 
about parameters that can be estimated as constants at this level and, 
as a result, allow to return a Const instead of SubPlan?
But at least we can return a flat copy of the SubPplan node just for the 
convention — the same thing for the AlternativeSubPlan. See the patch in 
the attachment.

-- 
regards,
Andrei Lepikhov
Postgres Professional
Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Streaming I/O, vectored I/O (WIP)
Next
From: Nathan Bossart
Date:
Subject: Re: cleanup patches for dshash