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

Commitb7f1fe6

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 parent245dd2b commitb7f1fe6

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-
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.109.2.1 2005/04/14 21:44:46 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.109.2.2 2007/10/11 21:28:39 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -1702,9 +1702,20 @@ simplify_op_or_func(Expr *expr, List *args)
17021702
const_val=ExecEvalExprSwitchContext((Node*)newexpr,econtext,
17031703
&const_is_null,NULL);
17041704

1705-
/* Must copy result out of sub-context used by expression eval */
1705+
/*
1706+
* Must copy result out of sub-context used by expression eval.
1707+
*
1708+
* Also, if it's varlena, forcibly detoast it. This protects us against
1709+
* storing TOAST pointers into plans that might outlive the referenced
1710+
* data.
1711+
*/
17061712
if (!const_is_null)
1707-
const_val=datumCopy(const_val,resultTypByVal,resultTypLen);
1713+
{
1714+
if (resultTypLen==-1)
1715+
const_val=PointerGetDatum(PG_DETOAST_DATUM_COPY(const_val));
1716+
else
1717+
const_val=datumCopy(const_val,resultTypByVal,resultTypLen);
1718+
}
17081719

17091720
FreeExprContext(econtext);
17101721
pfree(newexpr);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp