Skip to content

Commit 8e72239

Browse files
committed
Fix no-longer-valid shortcuts in expression_returns_set().
expression_returns_set() used to short-circuit its recursion upon seeing certain node types, such as DistinctExpr, that it knew the executor did not support set-valued arguments for. That was never inherent, though, just a reflection of laziness in execQual.c. With the new implementation of SRFs there is no reason to think that any scalar-valued expression node could not have a set-valued subexpression, except for AggRefs and WindowFuncs where we know there is a parser check rejecting it. And indeed, the shortcut causes unexpected failures for cases such as a SRF underneath DistinctExpr, because the planner stops looking for SRFs too soon. Discussion: https://postgr.es/m/5259.1497044025@sss.pgh.pa.us
1 parent a571c7f commit 8e72239

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

src/backend/nodes/nodeFuncs.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -694,39 +694,11 @@ expression_returns_set_walker(Node *node, void *context)
694694
/* else fall through to check args */
695695
}
696696

697-
/* Avoid recursion for some cases that can't return a set */
697+
/* Avoid recursion for some cases that parser checks not to return a set */
698698
if (IsA(node, Aggref))
699699
return false;
700700
if (IsA(node, WindowFunc))
701701
return false;
702-
if (IsA(node, DistinctExpr))
703-
return false;
704-
if (IsA(node, NullIfExpr))
705-
return false;
706-
if (IsA(node, ScalarArrayOpExpr))
707-
return false;
708-
if (IsA(node, BoolExpr))
709-
return false;
710-
if (IsA(node, SubLink))
711-
return false;
712-
if (IsA(node, SubPlan))
713-
return false;
714-
if (IsA(node, AlternativeSubPlan))
715-
return false;
716-
if (IsA(node, ArrayExpr))
717-
return false;
718-
if (IsA(node, RowExpr))
719-
return false;
720-
if (IsA(node, RowCompareExpr))
721-
return false;
722-
if (IsA(node, CoalesceExpr))
723-
return false;
724-
if (IsA(node, MinMaxExpr))
725-
return false;
726-
if (IsA(node, SQLValueFunction))
727-
return false;
728-
if (IsA(node, XmlExpr))
729-
return false;
730702

731703
return expression_tree_walker(node, expression_returns_set_walker,
732704
context);

src/test/regress/expected/tsrf.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ SELECT int4mul(generate_series(1,2), 10);
443443
20
444444
(2 rows)
445445

446+
SELECT generate_series(1,3) IS DISTINCT FROM 2;
447+
?column?
448+
----------
449+
t
450+
f
451+
t
452+
(3 rows)
453+
446454
-- but SRFs in function RTEs must be at top level (annoying restriction)
447455
SELECT * FROM int4mul(generate_series(1,2), 10);
448456
ERROR: set-returning functions must appear at top level of FROM

src/test/regress/sql/tsrf.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ VALUES(1, generate_series(1,2));
9898

9999
-- We allow tSRFs that are not at top level
100100
SELECT int4mul(generate_series(1,2), 10);
101+
SELECT generate_series(1,3) IS DISTINCT FROM 2;
101102

102103
-- but SRFs in function RTEs must be at top level (annoying restriction)
103104
SELECT * FROM int4mul(generate_series(1,2), 10);

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