Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2b0c86b

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 (anunlikely case, but it can be made to happen), we would end up with a planthat depends on the continued existence of the out-of-line toast datum.
1 parent05c609b commit2b0c86b

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
* AUTHORDATEMAJOR 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)

[8]ページ先頭

©2009-2025 Movatter.jp