- Notifications
You must be signed in to change notification settings - Fork28
Commit4be058f
committed
In the planner, replace an empty FROM clause with a dummy RTE.
The fact that "SELECT expression" has no base relations has long been athorn in the side of the planner. It makes it hard to flatten a sub-querythat looks like that, or is a trivial VALUES() item, because the plannergenerally uses relid sets to identify sub-relations, and such a sub-querywould have an empty relid set if we flattened it. prepjointree.c containssome baroque logic that works around this in certain special cases --- butthere is a much better answer. We can replace an empty FROM clause with adummy RTE that acts like a table of one row and no columns, and then thereare no such corner cases to worry about. Instead we need some logic toget rid of useless dummy RTEs, but that's simpler and covers more casesthan what was there before.For really trivial cases, where the query is just "SELECT expression" andnothing else, there's a hazard that adding the extra RTE makes for anoticeable slowdown; even though it's not much processing, there's notthat much for the planner to do overall. However testing says that thepenalty is very small, close to the noise level. In more complex queries,this is able to find optimizations that we could not find before.The new RTE type is called RTE_RESULT, since the "scan" plan type itgives rise to is a Result node (the same plan we produced for a "SELECTexpression" query before). To avoid confusion, rename the old ResultPathpath type to GroupResultPath, reflecting that it's only used in degenerategrouping cases where we know the query produces just one grouped row.(It wouldn't work to unify the two cases, because there are differentrules about where the associated quals live during query_planner.)Note: although this touches readfuncs.c, I don't think a catversionbump is required, because the added case can't occur in stored rules,only plans.Patch by me, reviewed by David Rowley and Mark DilgerDiscussion:https://postgr.es/m/15944.1521127664@sss.pgh.pa.us1 parent5c11867 commit4be058f
File tree
35 files changed
+1171
-446
lines changed- contrib
- pg_stat_statements
- postgres_fdw/expected
- src
- backend
- executor
- nodes
- optimizer
- path
- plan
- prep
- util
- parser
- utils/adt
- include
- nodes
- optimizer
- test
- isolation
- expected
- specs
- regress
- expected
- sql
35 files changed
+1171
-446
lines changedLines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2476 | 2476 |
| |
2477 | 2477 |
| |
2478 | 2478 |
| |
| 2479 | + | |
| 2480 | + | |
2479 | 2481 |
| |
2480 | 2482 |
| |
2481 | 2483 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5361 | 5361 |
| |
5362 | 5362 |
| |
5363 | 5363 |
| |
5364 |
| - | |
| 5364 | + | |
5365 | 5365 |
| |
5366 | 5366 |
| |
5367 | 5367 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
437 | 437 |
| |
438 | 438 |
| |
439 | 439 |
| |
| 440 | + | |
| 441 | + | |
440 | 442 |
| |
441 | 443 |
| |
442 |
| - | |
| 444 | + | |
| 445 | + | |
443 | 446 |
| |
444 | 447 |
| |
445 | 448 |
| |
|
Lines changed: 10 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2329 | 2329 |
| |
2330 | 2330 |
| |
2331 | 2331 |
| |
2332 |
| - | |
2333 |
| - | |
2334 |
| - | |
2335 |
| - | |
2336 | 2332 |
| |
2337 | 2333 |
| |
2338 | 2334 |
| |
| |||
2355 | 2351 |
| |
2356 | 2352 |
| |
2357 | 2353 |
| |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
2358 | 2359 |
| |
2359 | 2360 |
| |
2360 | 2361 |
| |
| |||
3164 | 3165 |
| |
3165 | 3166 |
| |
3166 | 3167 |
| |
3167 |
| - | |
3168 |
| - | |
3169 |
| - | |
3170 |
| - | |
3171 | 3168 |
| |
3172 | 3169 |
| |
3173 | 3170 |
| |
| |||
3198 | 3195 |
| |
3199 | 3196 |
| |
3200 | 3197 |
| |
| 3198 | + | |
| 3199 | + | |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
3201 | 3203 |
| |
3202 | 3204 |
| |
3203 | 3205 |
| |
|
Lines changed: 7 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1855 | 1855 |
| |
1856 | 1856 |
| |
1857 | 1857 |
| |
1858 |
| - | |
| 1858 | + | |
1859 | 1859 |
| |
1860 |
| - | |
| 1860 | + | |
1861 | 1861 |
| |
1862 | 1862 |
| |
1863 | 1863 |
| |
| |||
2213 | 2213 |
| |
2214 | 2214 |
| |
2215 | 2215 |
| |
2216 |
| - | |
2217 | 2216 |
| |
2218 | 2217 |
| |
2219 | 2218 |
| |
| |||
3060 | 3059 |
| |
3061 | 3060 |
| |
3062 | 3061 |
| |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
3063 | 3065 |
| |
3064 | 3066 |
| |
3065 | 3067 |
| |
| |||
3943 | 3945 |
| |
3944 | 3946 |
| |
3945 | 3947 |
| |
3946 |
| - | |
3947 |
| - | |
| 3948 | + | |
| 3949 | + | |
3948 | 3950 |
| |
3949 | 3951 |
| |
3950 | 3952 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
295 | 295 |
| |
296 | 296 |
| |
297 | 297 |
| |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
298 | 302 |
| |
299 | 303 |
| |
300 | 304 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1411 | 1411 |
| |
1412 | 1412 |
| |
1413 | 1413 |
| |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
1414 | 1417 |
| |
1415 | 1418 |
| |
1416 | 1419 |
| |
|
Lines changed: 11 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
361 | 361 |
| |
362 | 362 |
| |
363 | 363 |
| |
364 |
| - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
365 | 374 |
| |
366 | 375 |
| |
367 | 376 |
| |
| |||
370 | 379 |
| |
371 | 380 |
| |
372 | 381 |
| |
373 |
| - | |
| 382 | + | |
374 | 383 |
| |
375 | 384 |
| |
376 | 385 |
| |
|
Lines changed: 53 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
117 | 117 |
| |
118 | 118 |
| |
119 | 119 |
| |
| 120 | + | |
| 121 | + | |
120 | 122 |
| |
121 | 123 |
| |
122 | 124 |
| |
| |||
437 | 439 |
| |
438 | 440 |
| |
439 | 441 |
| |
| 442 | + | |
440 | 443 |
| |
441 | 444 |
| |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
442 | 449 |
| |
443 | 450 |
| |
444 | 451 |
| |
| |||
510 | 517 |
| |
511 | 518 |
| |
512 | 519 |
| |
| 520 | + | |
| 521 | + | |
| 522 | + | |
513 | 523 |
| |
514 | 524 |
| |
515 | 525 |
| |
| |||
712 | 722 |
| |
713 | 723 |
| |
714 | 724 |
| |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
715 | 729 |
| |
716 | 730 |
| |
717 | 731 |
| |
| |||
2509 | 2523 |
| |
2510 | 2524 |
| |
2511 | 2525 |
| |
| 2526 | + | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
2512 | 2556 |
| |
2513 | 2557 |
| |
2514 | 2558 |
| |
| |||
3677 | 3721 |
| |
3678 | 3722 |
| |
3679 | 3723 |
| |
3680 |
| - | |
3681 |
| - | |
3682 |
| - | |
3683 | 3724 |
| |
3684 | 3725 |
| |
3685 | 3726 |
| |
| |||
3692 | 3733 |
| |
3693 | 3734 |
| |
3694 | 3735 |
| |
| 3736 | + | |
| 3737 | + | |
| 3738 | + | |
| 3739 | + | |
| 3740 | + | |
| 3741 | + | |
3695 | 3742 |
| |
3696 | 3743 |
| |
3697 | 3744 |
| |
| |||
3716 | 3763 |
| |
3717 | 3764 |
| |
3718 | 3765 |
| |
3719 |
| - | |
| 3766 | + | |
3720 | 3767 |
| |
3721 | 3768 |
| |
3722 | 3769 |
| |
| |||
3742 | 3789 |
| |
3743 | 3790 |
| |
3744 | 3791 |
| |
3745 |
| - | |
3746 |
| - | |
| 3792 | + | |
| 3793 | + | |
3747 | 3794 |
| |
3748 | 3795 |
| |
3749 | 3796 |
| |
|
Lines changed: 57 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1570 | 1570 |
| |
1571 | 1571 |
| |
1572 | 1572 |
| |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
1573 | 1607 |
| |
1574 | 1608 |
| |
1575 | 1609 |
| |
| |||
5044 | 5078 |
| |
5045 | 5079 |
| |
5046 | 5080 |
| |
| 5081 | + | |
| 5082 | + | |
| 5083 | + | |
| 5084 | + | |
| 5085 | + | |
| 5086 | + | |
| 5087 | + | |
| 5088 | + | |
| 5089 | + | |
| 5090 | + | |
| 5091 | + | |
| 5092 | + | |
| 5093 | + | |
| 5094 | + | |
| 5095 | + | |
| 5096 | + | |
| 5097 | + | |
| 5098 | + | |
| 5099 | + | |
| 5100 | + | |
| 5101 | + | |
| 5102 | + | |
| 5103 | + | |
5047 | 5104 |
| |
5048 | 5105 |
| |
5049 | 5106 |
| |
|
0 commit comments
Comments
(0)