forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7266d09
committed
Allow functions-in-FROM to be pulled up if they reduce to constants.
This allows simplification of the plan tree in some common usagepatterns: we can get rid of a join to the function RTE.In principle we could pull up any immutable expression, but restrictingit to Consts avoids the risk that multiple evaluations of the expressionmight cost more than we can save. (Possibly this could be improved infuture --- but we've more or less promised people that putting a functionin FROM guarantees single evaluation, so we'd have to tread carefully.)To do this, we need to rearrange when eval_const_expressions()happens for expressions in function RTEs. I moved it toinline_set_returning_functions(), which already has to iterate overevery function RTE, and in consequence renamed that function topreprocess_function_rtes(). A useful consequence is thatinline_set_returning_function() no longer has to do this for itself,simplifying that code.In passing, break out pull_up_simple_subquery's code that knows whereeverything that needs pullup_replace_vars() processing is, so thatthe new pull_up_constant_function() routine can share it. We'dgotten away with one-and-a-half copies of that code so far, sincepull_up_simple_values() could assume that a lot of cases didn't applyto it --- but I don't think pull_up_constant_function() can make anysimplifying assumptions. Might as well make pull_up_simple_values()use it too.(Possibly this refactoring should go further: maybe we could sharesome of the code to fill in the pullup_replace_vars_context struct?For now, I left it that the callers fill that completely.)Note: the one existing test case that this patch changes has to bechanged because inlining its function RTEs would destroy the pointof the test, namely to check join order.Alexander Kuzmenkov and Aleksandr Parfenov, reviewed byAntonin Houska and Anastasia Lubennikova, and whacked aroundsome more by meDiscussion:https://postgr.es/m/402356c32eeb93d4fed01f66d6c7fe2d@postgrespro.ru1 parenta8d6a95 commit7266d09
File tree
8 files changed
+499
-156
lines changed- src
- backend/optimizer
- plan
- prep
- util
- include/optimizer
- test/regress
- expected
- sql
8 files changed
+499
-156
lines changedLines changed: 11 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
659 | 659 |
| |
660 | 660 |
| |
661 | 661 |
| |
662 |
| - | |
663 |
| - | |
664 |
| - | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
665 | 666 |
| |
666 |
| - | |
| 667 | + | |
667 | 668 |
| |
668 | 669 |
| |
669 | 670 |
| |
| |||
1071 | 1072 |
| |
1072 | 1073 |
| |
1073 | 1074 |
| |
1074 |
| - | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
1075 | 1078 |
| |
1076 | 1079 |
| |
1077 | 1080 |
| |
| |||
1085 | 1088 |
| |
1086 | 1089 |
| |
1087 | 1090 |
| |
1088 |
| - | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
1089 | 1094 |
| |
1090 | 1095 |
| |
1091 | 1096 |
| |
|
0 commit comments
Comments
(0)