Skip to content

Commit 6f19a8c

Browse files
committed
Teach eval_const_expressions to constant-fold LEAST/GREATEST expressions.
Doing this requires an assumption that the invoked btree comparison function is immutable. We could check that explicitly, but in other places such as contain_mutable_functions we just assume that it's true, so we may as well do likewise here. (If the comparison function's behavior isn't immutable, the sort order in indexes built with it would be unstable, so it seems certainly wrong for it not to be so.) Vik Fearing Discussion: https://postgr.es/m/c6e8504c-4c43-35fa-6c8f-3c0b80a912cc@2ndquadrant.com
1 parent e0ef136 commit 6f19a8c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3378,11 +3378,16 @@ eval_const_expressions_mutator(Node *node,
33783378
case T_ArrayRef:
33793379
case T_ArrayExpr:
33803380
case T_RowExpr:
3381+
case T_MinMaxExpr:
33813382
{
33823383
/*
33833384
* Generic handling for node types whose own processing is
33843385
* known to be immutable, and for which we need no smarts
33853386
* beyond "simplify if all inputs are constants".
3387+
*
3388+
* Treating MinMaxExpr this way amounts to assuming that the
3389+
* btree comparison function it calls is immutable; see the
3390+
* reasoning in contain_mutable_functions_walker.
33863391
*/
33873392

33883393
/* Copy the node and const-simplify its arguments */
@@ -3783,7 +3788,7 @@ eval_const_expressions_mutator(Node *node,
37833788
case T_ConvertRowtypeExpr:
37843789
{
37853790
ConvertRowtypeExpr *cre = castNode(ConvertRowtypeExpr, node);
3786-
Node *arg;
3791+
Node *arg;
37873792
ConvertRowtypeExpr *newcre;
37883793

37893794
arg = eval_const_expressions_mutator((Node *) cre->arg,

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