aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-12-30 13:42:04 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2018-12-30 13:42:04 -0500
commit6f19a8c41f976236310a272bb646d3411759e18d (patch)
tree092758c479f96c39dee58b0f355e7c5fe2c931a5 /src
parente0ef136d5235f39f5652c209c08a5d4322560e9c (diff)
downloadpostgresql-6f19a8c41f976236310a272bb646d3411759e18d.tar.gz
postgresql-6f19a8c41f976236310a272bb646d3411759e18d.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/util/clauses.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index f4446169f5e..8f958236f83 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -3378,11 +3378,16 @@ eval_const_expressions_mutator(Node *node,
case T_ArrayRef:
case T_ArrayExpr:
case T_RowExpr:
+ case T_MinMaxExpr:
{
/*
* Generic handling for node types whose own processing is
* known to be immutable, and for which we need no smarts
* beyond "simplify if all inputs are constants".
+ *
+ * Treating MinMaxExpr this way amounts to assuming that the
+ * btree comparison function it calls is immutable; see the
+ * reasoning in contain_mutable_functions_walker.
*/
/* Copy the node and const-simplify its arguments */
@@ -3783,7 +3788,7 @@ eval_const_expressions_mutator(Node *node,
case T_ConvertRowtypeExpr:
{
ConvertRowtypeExpr *cre = castNode(ConvertRowtypeExpr, node);
- Node *arg;
+ Node *arg;
ConvertRowtypeExpr *newcre;
arg = eval_const_expressions_mutator((Node *) cre->arg,