diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-02-21 17:10:49 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-02-21 17:10:49 -0500 |
commit | e8655a77f327bd3fca0f4aaf14b86b540c64ecdf (patch) | |
tree | ba1908a325a4e45b445d5d9f9dc68770b8432fc1 /src/backend/utils/adt/array_selfuncs.c | |
parent | 5a7e75849cb595943fc605c4532716e9dd69f8a0 (diff) | |
download | postgresql-e8655a77f327bd3fca0f4aaf14b86b540c64ecdf.tar.gz postgresql-e8655a77f327bd3fca0f4aaf14b86b540c64ecdf.zip |
Do ScalarArrayOp estimation correctly when array is a stable expression.
Most estimation functions apply estimate_expression_value to see if they
can reduce an expression to a constant; the key difference is that it
allows evaluation of stable as well as immutable functions in hopes of
ending up with a simple Const node. scalararraysel didn't get the memo
though, and neither did gincost_opexpr/gincost_scalararrayopexpr. Fix
that, and remove a now-unnecessary estimate_expression_value step in the
subsidiary function scalararraysel_containment.
Per complaint from Alexey Klyukin. Back-patch to 9.3. The problem
goes back further, but I'm hesitant to change estimation behavior in
long-stable release branches.
Diffstat (limited to 'src/backend/utils/adt/array_selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/array_selfuncs.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/backend/utils/adt/array_selfuncs.c b/src/backend/utils/adt/array_selfuncs.c index 2ee9548ff4a..a66bbe32802 100644 --- a/src/backend/utils/adt/array_selfuncs.c +++ b/src/backend/utils/adt/array_selfuncs.c @@ -68,11 +68,13 @@ static int float_compare_desc(const void *key1, const void *key2); * scalararraysel_containment * Estimate selectivity of ScalarArrayOpExpr via array containment. * - * scalararraysel() has already verified that the operator of a - * ScalarArrayOpExpr is the array element type's default equality or - * inequality operator. If we have const =/<> ANY/ALL (array_var) - * then we can estimate the selectivity as though this were an array - * containment operator, array_var op ARRAY[const]. + * If we have const =/<> ANY/ALL (array_var) then we can estimate the + * selectivity as though this were an array containment operator, + * array_var op ARRAY[const]. + * + * scalararraysel() has already verified that the ScalarArrayOpExpr's operator + * is the array element type's default equality or inequality operator, and + * has aggressively simplified both inputs to constants. * * Returns selectivity (0..1), or -1 if we fail to estimate selectivity. */ @@ -99,9 +101,8 @@ scalararraysel_containment(PlannerInfo *root, } /* - * Aggressively reduce leftop to a constant, if possible. + * leftop must be a constant, else punt. */ - leftop = estimate_expression_value(root, leftop); if (!IsA(leftop, Const)) { ReleaseVariableStats(vardata); |