Skip to content

Commit 2b0c86b

Browse files
committed
Ensure that the result of evaluating a function during constant-expression
simplification gets detoasted before it is incorporated into a Const node. Otherwise, if an immutable function were to return a TOAST pointer (an unlikely case, but it can be made to happen), we would end up with a plan that depends on the continued existence of the out-of-line toast datum.
1 parent 05c609b commit 2b0c86b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.249 2007/09/06 17:31:58 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.250 2007/10/11 21:27:49 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHOR DATE MAJOR EVENT
@@ -3265,9 +3265,20 @@ evaluate_expr(Expr *expr, Oid result_type, int32 result_typmod)
32653265
/* Get back to outer memory context */
32663266
MemoryContextSwitchTo(oldcontext);
32673267

3268-
/* Must copy result out of sub-context used by expression eval */
3268+
/*
3269+
* Must copy result out of sub-context used by expression eval.
3270+
*
3271+
* Also, if it's varlena, forcibly detoast it. This protects us against
3272+
* storing TOAST pointers into plans that might outlive the referenced
3273+
* data.
3274+
*/
32693275
if (!const_is_null)
3270-
const_val = datumCopy(const_val, resultTypByVal, resultTypLen);
3276+
{
3277+
if (resultTypLen == -1)
3278+
const_val = PointerGetDatum(PG_DETOAST_DATUM_COPY(const_val));
3279+
else
3280+
const_val = datumCopy(const_val, resultTypByVal, resultTypLen);
3281+
}
32713282

32723283
/* Release all the junk we just created */
32733284
FreeExecutorState(estate);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy