forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit3f7323c
committed
Repair rare failure of MULTIEXPR_SUBLINK subplans in inherited updates.
Prior to v14, if we have a MULTIEXPR SubPlan (that is, use of the syntaxUPDATE ... SET (c1, ...) = (SELECT ...)) in an UPDATE with an inheritedor partitioned target table, inheritance_planner() will clone thetargetlist and therefore also the MULTIEXPR SubPlan and the Param nodesreferencing it for each child target table. Up to now, we've allowedall the clones to share the underlying subplan as well as the outputparameter IDs -- that is, the runtime ParamExecData slots. Thattechnique is borrowed from the far older code that supports initplans,and it works okay in that case because the cloned SubPlan nodes areessentially identical. So it doesn't matter which one of the clonesthe shared ParamExecData.execPlan field might point to.However, this fails to hold for MULTIEXPR SubPlans, because they canhave nonempty "args" lists (values to be passed into the subplan), andthose lists could get mutated to different states in the various clones.In the submitted reproducer, as well as the test case added here, oneclone contains Vars with varno OUTER_VAR where another has INNER_VAR,because the child tables are respectively on the outer or inner side ofthe join. Sharing the execPlan pointer can result in trying to evaluatean args list that doesn't match the local execution state, with mayhemensuing. The result often is to trigger consistency checks in theexecutor, but I believe this could end in a crash or incorrect updates.To fix, assign new Param IDs to each of the cloned SubPlans, so thatthey don't share ParamExecData slots at runtime. It still seems finefor the clones to share the underlying subplan, and extra ParamExecDataslots are cheap enough that this fix shouldn't cost much.This has been busted since we invented MULTIEXPR SubPlans in 9.5.Probably the lack of previous reports is because query plans in whichthe different clones of a MULTIEXPR mutate to effectively-differentstates are pretty rare. There's no issue in v14 and later, becausewithout inheritance_planner() there's never a reason to cloneMULTIEXPR SubPlans.Per bug #17596 from Andre Lin. Patch v10-v13 only.Discussion:https://postgr.es/m/17596-c5357f61427a81dc@postgresql.org1 parent7d50165 commit3f7323c
File tree
6 files changed
+184
-0
lines changed- src
- backend
- executor
- optimizer/plan
- include/optimizer
- test/regress
- expected
- sql
6 files changed
+184
-0
lines changedLines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
245 | 245 |
| |
246 | 246 |
| |
247 | 247 |
| |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
248 | 263 |
| |
249 | 264 |
| |
250 | 265 |
| |
|
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1606 | 1606 |
| |
1607 | 1607 |
| |
1608 | 1608 |
| |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
1609 | 1613 |
| |
1610 | 1614 |
| |
1611 | 1615 |
| |
|
Lines changed: 95 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
851 | 851 |
| |
852 | 852 |
| |
853 | 853 |
| |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
854 | 949 |
| |
855 | 950 |
| |
856 | 951 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
16 | 16 |
| |
17 | 17 |
| |
18 | 18 |
| |
| 19 | + | |
19 | 20 |
| |
20 | 21 |
| |
21 | 22 |
| |
|
Lines changed: 49 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1715 | 1715 |
| |
1716 | 1716 |
| |
1717 | 1717 |
| |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
1718 | 1767 |
| |
1719 | 1768 |
| |
1720 | 1769 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
629 | 629 |
| |
630 | 630 |
| |
631 | 631 |
| |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
632 | 652 |
| |
633 | 653 |
| |
634 | 654 |
| |
|
0 commit comments
Comments
(0)