forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit66c0185
committed
Allow planner to use Merge Append to efficiently implement UNION
Until now, UNION queries have often been suboptimal as the planner hasonly ever considered using an Append node and making the results uniqueby either using a Hash Aggregate, or by Sorting the entire Append resultand running it through the Unique operator. Both of these methodsalways require reading all rows from the union subqueries.Here we adjust the union planner so that it can request that each subqueryproduce results in target list order so that these can be Merge Appendedtogether and made unique with a Unique node. This can improve performancesignificantly as the union child can make use of the likes of btreeindexes and/or Merge Joins to provide the top-level UNION with presortedinput. This is especially good if the top-level UNION contains a LIMITnode that limits the output rows to a small subset of the unioned rows ascheap startup plans can be used.Author: David RowleyReviewed-by: Richard Guo, Andy FanDiscussion:https://postgr.es/m/CAApHDvpb_63XQodmxKUF8vb9M7CxyUyT4sWvEgqeQU-GB7QFoQ@mail.gmail.com1 parent47f99a4 commit66c0185
File tree
15 files changed
+707
-253
lines changed- contrib/postgres_fdw
- expected
- sql
- src
- backend
- optimizer
- path
- plan
- prep
- parser
- include
- nodes
- optimizer
- test/regress
- expected
- sql
15 files changed
+707
-253
lines changedLines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11495 | 11495 |
| |
11496 | 11496 |
| |
11497 | 11497 |
| |
| 11498 | + | |
| 11499 | + | |
| 11500 | + | |
| 11501 | + | |
11498 | 11502 |
| |
11499 | 11503 |
| |
11500 | 11504 |
| |
| |||
11576 | 11580 |
| |
11577 | 11581 |
| |
11578 | 11582 |
| |
| 11583 | + | |
| 11584 | + | |
| 11585 | + | |
11579 | 11586 |
| |
11580 | 11587 |
| |
11581 | 11588 |
| |
|
Lines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3877 | 3877 |
| |
3878 | 3878 |
| |
3879 | 3879 |
| |
| 3880 | + | |
| 3881 | + | |
| 3882 | + | |
| 3883 | + | |
| 3884 | + | |
3880 | 3885 |
| |
3881 | 3886 |
| |
3882 | 3887 |
| |
| |||
3903 | 3908 |
| |
3904 | 3909 |
| |
3905 | 3910 |
| |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
3906 | 3915 |
| |
3907 | 3916 |
| |
3908 | 3917 |
| |
|
Lines changed: 61 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2867 | 2867 |
| |
2868 | 2868 |
| |
2869 | 2869 |
| |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
| 2916 | + | |
| 2917 | + | |
| 2918 | + | |
| 2919 | + | |
| 2920 | + | |
| 2921 | + | |
| 2922 | + | |
| 2923 | + | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
| 2930 | + | |
2870 | 2931 |
| |
2871 | 2932 |
| |
2872 | 2933 |
| |
|
Lines changed: 19 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2191 | 2191 |
| |
2192 | 2192 |
| |
2193 | 2193 |
| |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
2194 | 2210 |
| |
2195 | 2211 |
| |
2196 | 2212 |
| |
| |||
2208 | 2224 |
| |
2209 | 2225 |
| |
2210 | 2226 |
| |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
2211 | 2230 |
| |
2212 | 2231 |
| |
2213 | 2232 |
| |
|
Lines changed: 84 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
54 | 54 |
| |
55 | 55 |
| |
56 | 56 |
| |
| 57 | + | |
57 | 58 |
| |
58 | 59 |
| |
59 | 60 |
| |
| |||
119 | 120 |
| |
120 | 121 |
| |
121 | 122 |
| |
| 123 | + | |
| 124 | + | |
122 | 125 |
| |
123 | 126 |
| |
124 | 127 |
| |
| |||
249 | 252 |
| |
250 | 253 |
| |
251 | 254 |
| |
| 255 | + | |
| 256 | + | |
252 | 257 |
| |
253 | 258 |
| |
254 | 259 |
| |
| |||
1500 | 1505 |
| |
1501 | 1506 |
| |
1502 | 1507 |
| |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
1503 | 1520 |
| |
1504 | 1521 |
| |
1505 | 1522 |
| |
| |||
3433 | 3450 |
| |
3434 | 3451 |
| |
3435 | 3452 |
| |
| 3453 | + | |
| 3454 | + | |
| 3455 | + | |
| 3456 | + | |
| 3457 | + | |
| 3458 | + | |
| 3459 | + | |
| 3460 | + | |
| 3461 | + | |
| 3462 | + | |
| 3463 | + | |
| 3464 | + | |
| 3465 | + | |
| 3466 | + | |
| 3467 | + | |
| 3468 | + | |
| 3469 | + | |
| 3470 | + | |
| 3471 | + | |
| 3472 | + | |
| 3473 | + | |
3436 | 3474 |
| |
3437 | 3475 |
| |
3438 | 3476 |
| |
| |||
3442 | 3480 |
| |
3443 | 3481 |
| |
3444 | 3482 |
| |
3445 |
| - | |
| 3483 | + | |
| 3484 | + | |
| 3485 | + | |
3446 | 3486 |
| |
3447 | 3487 |
| |
3448 | 3488 |
| |
| |||
3460 | 3500 |
| |
3461 | 3501 |
| |
3462 | 3502 |
| |
| 3503 | + | |
| 3504 | + | |
3463 | 3505 |
| |
3464 | 3506 |
| |
3465 | 3507 |
| |
| |||
7866 | 7908 |
| |
7867 | 7909 |
| |
7868 | 7910 |
| |
| 7911 | + | |
| 7912 | + | |
| 7913 | + | |
| 7914 | + | |
| 7915 | + | |
| 7916 | + | |
| 7917 | + | |
| 7918 | + | |
| 7919 | + | |
| 7920 | + | |
| 7921 | + | |
| 7922 | + | |
| 7923 | + | |
| 7924 | + | |
| 7925 | + | |
| 7926 | + | |
| 7927 | + | |
| 7928 | + | |
| 7929 | + | |
| 7930 | + | |
| 7931 | + | |
| 7932 | + | |
| 7933 | + | |
| 7934 | + | |
| 7935 | + | |
| 7936 | + | |
| 7937 | + | |
| 7938 | + | |
| 7939 | + | |
| 7940 | + | |
| 7941 | + | |
| 7942 | + | |
| 7943 | + | |
| 7944 | + | |
| 7945 | + | |
| 7946 | + | |
| 7947 | + | |
| 7948 | + | |
| 7949 | + | |
| 7950 | + | |
| 7951 | + |
0 commit comments
Comments
(0)