- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit69f4b9c
committed
Move targetlist SRF handling from expression evaluation to new executor node.
Evaluation of set returning functions (SRFs_ in the targetlist (like SELECTgenerate_series(1,5)) so far was done in the expression evaluation (i.e.ExecEvalExpr()) and projection (i.e. ExecProject/ExecTargetList) code.This meant that most executor nodes performing projection, and mostexpression evaluation functions, had to deal with the possibility that anevaluated expression could return a set of return values.That's bad because it leads to repeated code in a lot of places. It also,and that's my (Andres's) motivation, made it a lot harder to implement amore efficient way of doing expression evaluation.To fix this, introduce a new executor node (ProjectSet) that can evaluatetargetlists containing one or more SRFs. To avoid the complexity of the oldway of handling nested expressions returning sets (e.g. having to pass upExprDoneCond, and dealing with arguments to functions returning sets etc.),those SRFs can only be at the top level of the node's targetlist. Theplanner makes sure (via split_pathtarget_at_srfs()) that SRF evaluation isonly necessary in ProjectSet nodes and that SRFs are only present at thetop level of the node's targetlist. If there are nested SRFs the plannercreates multiple stacked ProjectSet nodes. The ProjectSet nodes always getinput from an underlying node.We also discussed and prototyped evaluating targetlist SRFs using ROWSFROM(), but that turned out to be more complicated than we'd hoped.While moving SRF evaluation to ProjectSet would allow to retain the old"least common multiple" behavior when multiple SRFs are present in onetargetlist (i.e. continue returning rows until all SRFs are at the end oftheir input at the same time), we decided to instead only return rows tillall SRFs are exhausted, returning NULL for already exhausted ones. Wedeemed the previous behavior to be too confusing, unexpected and actuallynot particularly useful.As a side effect, the previously prohibited case of multiple set returningarguments to a function, is now allowed. Not because it's particularlydesirable, but because it ends up working and there seems to be no argumentfor adding code to prohibit it.Currently the behavior for COALESCE and CASE containing SRFs has changed,returning multiple rows from the expression, even when the SRF containing"arm" of the expression is not evaluated. That's because the SRFs areevaluated in a separate ProjectSet node. As that's quite confusing, we'relikely to instead prohibit SRFs in those places. But that's still beingdiscussed, and the code would reside in places not touched here, so that'sa task for later.There's a lot of, now superfluous, code dealing with set return expressionsaround. But as the changes to get rid of those are verbose largely boring,it seems better for readability to keep the cleanup as a separate commit.Author: Tom Lane and Andres FreundDiscussion:https://postgr.es/m/20160822214023.aaxz5l4igypowyri@alap3.anarazel.de1 parente37360d commit69f4b9c
File tree
35 files changed
+1186
-274
lines changed- doc/src/sgml
- src
- backend
- commands
- executor
- nodes
- optimizer
- path
- plan
- util
- include
- executor
- nodes
- optimizer
- test/regress/expected
35 files changed
+1186
-274
lines changedLines changed: 39 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
962 | 962 |
| |
963 | 963 |
| |
964 | 964 |
| |
965 |
| - | |
| 965 | + | |
966 | 966 |
| |
967 |
| - | |
968 |
| - | |
969 |
| - | |
970 |
| - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
971 | 970 |
| |
972 | 971 |
| |
973 | 972 |
| |
| |||
998 | 997 |
| |
999 | 998 |
| |
1000 | 999 |
| |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
1001 | 1027 |
| |
1002 | 1028 |
| |
1003 | 1029 |
| |
| |||
1012 | 1038 |
| |
1013 | 1039 |
| |
1014 | 1040 |
| |
1015 |
| - | |
1016 |
| - | |
1017 |
| - | |
1018 |
| - | |
1019 |
| - | |
1020 |
| - | |
1021 |
| - | |
1022 |
| - | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1023 | 1049 |
| |
1024 | 1050 |
| |
1025 | 1051 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
852 | 852 |
| |
853 | 853 |
| |
854 | 854 |
| |
| 855 | + | |
| 856 | + | |
| 857 | + | |
855 | 858 |
| |
856 | 859 |
| |
857 | 860 |
| |
|
Lines changed: 3 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
20 |
| - | |
| 20 | + | |
| 21 | + | |
21 | 22 |
| |
22 | 23 |
| |
23 | 24 |
| |
24 |
| - | |
| 25 | + | |
25 | 26 |
| |
26 | 27 |
| |
27 | 28 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
39 | 39 |
| |
40 | 40 |
| |
41 | 41 |
| |
| 42 | + | |
42 | 43 |
| |
43 | 44 |
| |
44 | 45 |
| |
| |||
130 | 131 |
| |
131 | 132 |
| |
132 | 133 |
| |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
133 | 138 |
| |
134 | 139 |
| |
135 | 140 |
| |
|
Lines changed: 15 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
88 | 88 |
| |
89 | 89 |
| |
90 | 90 |
| |
| 91 | + | |
91 | 92 |
| |
92 | 93 |
| |
93 | 94 |
| |
| |||
100 | 101 |
| |
101 | 102 |
| |
102 | 103 |
| |
103 |
| - | |
| 104 | + | |
104 | 105 |
| |
105 | 106 |
| |
106 | 107 |
| |
| |||
155 | 156 |
| |
156 | 157 |
| |
157 | 158 |
| |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
158 | 164 |
| |
159 | 165 |
| |
160 | 166 |
| |
| |||
392 | 398 |
| |
393 | 399 |
| |
394 | 400 |
| |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
395 | 405 |
| |
396 | 406 |
| |
397 | 407 |
| |
| |||
634 | 644 |
| |
635 | 645 |
| |
636 | 646 |
| |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
637 | 651 |
| |
638 | 652 |
| |
639 | 653 |
| |
|
0 commit comments
Comments
(0)