- Notifications
You must be signed in to change notification settings - Fork5
Commit9fa82c9
committed
Fix planner's handling of RETURNING lists in writable CTEs.
setrefs.c failed to do "rtoffset" adjustment of Vars in RETURNING lists,which meant they were left with the wrong varnos when the RETURNING listwas in a subquery. That was never possible before writable CTEs, ofcourse, but now it's broken. The executor fails to notice any problembecause ExecEvalVar just references the ecxt_scantuple for any normalvarno; but EXPLAIN breaks when the varno is wrong, as illustrated in arecent complaint from Bartosz Dmytrak.Since the eventual rtoffset of the subquery is not known at the timewe are preparing its plan node, the previous scheme of executingset_returning_clause_references() at that time cannot handle thisadjustment. Fortunately, it turns out that we don't really need to do itthat way, because all the needed information is available during normalsetrefs.c execution; we just have to dig it out of the ModifyTable node.So, do that, and get rid of the kluge of early setrefs processing ofRETURNING lists. (This is a little bit of a cheat in the case of inheritedUPDATE/DELETE, because we are not passing a "root" struct that correspondsexactly to what the subplan was built with. But that doesn't matter, andanyway this is less ugly than early setrefs processing was.)Back-patch to 9.1, where the problem became possible to hit.1 parentc62b8ea commit9fa82c9
File tree
6 files changed
+116
-50
lines changed- src
- backend/optimizer/plan
- include/optimizer
- test/regress
- expected
- sql
6 files changed
+116
-50
lines changedLines changed: 2 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4587 | 4587 |
| |
4588 | 4588 |
| |
4589 | 4589 |
| |
4590 |
| - | |
4591 |
| - | |
4592 |
| - | |
4593 |
| - | |
4594 |
| - | |
4595 |
| - | |
4596 |
| - | |
4597 |
| - | |
4598 |
| - | |
4599 |
| - | |
| 4590 | + | |
| 4591 | + | |
4600 | 4592 |
| |
4601 | 4593 |
| |
4602 | 4594 |
| |
|
Lines changed: 4 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
529 | 529 |
| |
530 | 530 |
| |
531 | 531 |
| |
532 |
| - | |
533 |
| - | |
534 |
| - | |
535 |
| - | |
| 532 | + | |
536 | 533 |
| |
537 | 534 |
| |
538 |
| - | |
539 |
| - | |
540 |
| - | |
541 |
| - | |
542 |
| - | |
543 |
| - | |
544 |
| - | |
545 |
| - | |
546 |
| - | |
547 |
| - | |
| 535 | + | |
548 | 536 |
| |
549 | 537 |
| |
550 | 538 |
| |
| |||
889 | 877 |
| |
890 | 878 |
| |
891 | 879 |
| |
892 |
| - | |
893 |
| - | |
894 |
| - | |
895 |
| - | |
896 |
| - | |
897 |
| - | |
898 |
| - | |
899 |
| - | |
900 |
| - | |
| 880 | + | |
| 881 | + | |
901 | 882 |
| |
902 | 883 |
| |
903 | 884 |
| |
|
Lines changed: 62 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
121 | 121 |
| |
122 | 122 |
| |
123 | 123 |
| |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
124 | 129 |
| |
125 | 130 |
| |
126 | 131 |
| |
| |||
548 | 553 |
| |
549 | 554 |
| |
550 | 555 |
| |
551 |
| - | |
552 |
| - | |
553 |
| - | |
554 |
| - | |
555 |
| - | |
| 556 | + | |
556 | 557 |
| |
557 | 558 |
| |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
558 | 600 |
| |
559 | 601 |
| |
560 | 602 |
| |
| |||
1532 | 1574 |
| |
1533 | 1575 |
| |
1534 | 1576 |
| |
| 1577 | + | |
1535 | 1578 |
| |
1536 | 1579 |
| |
1537 | 1580 |
| |
| |||
1691 | 1734 |
| |
1692 | 1735 |
| |
1693 | 1736 |
| |
1694 |
| - | |
1695 |
| - | |
| 1737 | + | |
| 1738 | + | |
1696 | 1739 |
| |
1697 | 1740 |
| |
1698 | 1741 |
| |
1699 | 1742 |
| |
1700 | 1743 |
| |
1701 | 1744 |
| |
1702 |
| - | |
| 1745 | + | |
1703 | 1746 |
| |
| 1747 | + | |
1704 | 1748 |
| |
1705 |
| - | |
1706 |
| - | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
1707 | 1755 |
| |
1708 |
| - | |
| 1756 | + | |
1709 | 1757 |
| |
1710 | 1758 |
| |
1711 | 1759 |
| |
1712 |
| - | |
| 1760 | + | |
| 1761 | + | |
1713 | 1762 |
| |
1714 | 1763 |
| |
1715 | 1764 |
| |
| |||
1734 | 1783 |
| |
1735 | 1784 |
| |
1736 | 1785 |
| |
1737 |
| - | |
| 1786 | + | |
1738 | 1787 |
| |
1739 | 1788 |
| |
1740 | 1789 |
| |
|
Lines changed: 0 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
120 | 120 |
| |
121 | 121 |
| |
122 | 122 |
| |
123 |
| - | |
124 |
| - | |
125 |
| - | |
126 |
| - | |
127 | 123 |
| |
128 | 124 |
| |
129 | 125 |
| |
|
Lines changed: 42 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1857 | 1857 |
| |
1858 | 1858 |
| |
1859 | 1859 |
| |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
1860 | 1902 |
| |
1861 | 1903 |
| |
1862 | 1904 |
| |
|
Lines changed: 6 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
791 | 791 |
| |
792 | 792 |
| |
793 | 793 |
| |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
794 | 800 |
| |
795 | 801 |
| |
796 | 802 |
| |
|
0 commit comments
Comments
(0)