mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +03:00
Fix interaction of CASE and ArrayCoerceExpr.
An array-type coercion appearing within a CASE that has a constant
(after const-folding) test expression was mangled by the planner, causing
all the elements of the resulting array to be equal to the coerced value
of the CASE's test expression. This is my oversight in commit c12d570fa
:
that changed ArrayCoerceExpr to use a subexpression involving a
CaseTestExpr, and I didn't notice that eval_const_expressions needed an
adjustment to keep from folding such a CaseTestExpr to a constant when
it's inside a suitable CASE.
This is another in what's getting to be a depressingly long line of bugs
associated with misidentification of the referent of a CaseTestExpr.
We're overdue to redesign that mechanism; but any such fix is unlikely
to be back-patchable into v11. As a stopgap, fix eval_const_expressions
to do what it must here. Also add a bunch of comments pointing out the
restrictions and assumptions that are needed to make this work at all.
Also fix a related oversight: contain_context_dependent_node() was not
aware of the relationship of ArrayCoerceExpr to CaseTestExpr. That was
somewhat fail-soft, in that the outcome of a wrong answer would be to
prevent optimizations that could have been made, but let's fix it while
we're at it.
Per bug #15471 from Matt Williams. Back-patch to v11 where the faulty
logic came in.
Discussion: https://postgr.es/m/15471-1117f49271989bad@postgresql.org
This commit is contained in:
@@ -934,8 +934,20 @@ typedef struct CaseWhen
|
||||
* This is effectively like a Param, but can be implemented more simply
|
||||
* since we need only one replacement value at a time.
|
||||
*
|
||||
* We also use this in nested UPDATE expressions.
|
||||
* See transformAssignmentIndirection().
|
||||
* We also abuse this node type for some other purposes, including:
|
||||
* * Placeholder for the current array element value in ArrayCoerceExpr;
|
||||
* see build_coercion_expression().
|
||||
* * Nested FieldStore/ArrayRef assignment expressions in INSERT/UPDATE;
|
||||
* see transformAssignmentIndirection().
|
||||
*
|
||||
* The uses in CaseExpr and ArrayCoerceExpr are safe only to the extent that
|
||||
* there is not any other CaseExpr or ArrayCoerceExpr between the value source
|
||||
* node and its child CaseTestExpr(s). This is true in the parse analysis
|
||||
* output, but the planner's function-inlining logic has to be careful not to
|
||||
* break it.
|
||||
*
|
||||
* The nested-assignment-expression case is safe because the only node types
|
||||
* that can be above such CaseTestExprs are FieldStore and ArrayRef.
|
||||
*/
|
||||
typedef struct CaseTestExpr
|
||||
{
|
||||
|
Reference in New Issue
Block a user