forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitad22783
committed
Fix several bugs related to ON CONFLICT's EXCLUDED pseudo relation.
Four related issues:1) attnos/varnos/resnos for EXCLUDED were out of sync when a column after one dropped in the underlying relation was referenced.2) References to whole-row variables (i.e. EXCLUDED.*) lead to errors.3) It was possible to reference system columns in the EXCLUDED pseudo relations, even though they would not have valid contents.4) References to EXCLUDED were rewritten by the RLS machinery, as EXCLUDED was treated as if it were the underlying relation.To fix the first two issues, generate the excluded targetlist withdropped columns in mind and add an entry for whole rowvariables. Instead of unconditionally adding a wholerow entry we couldpull up the expression if needed, but doing it unconditionally seemssimpler. The wholerow entry is only really needed for ruleutils/EXPLAINsupport anyway.The remaining two issues are addressed by changing the EXCLUDED RTE tohave relkind = composite. That fits with EXCLUDED not actually being areal relation, and allows to treat it differently in the relevantplaces. scanRTEForColumn now skips looking up system columns when theRTE has a composite relkind; fireRIRrules() already had a correspondingcheck, thereby preventing RLS expansion on EXCLUDED.Also add tests for these issues, and improve a few comments aroundexcluded handling in setrefs.c.Reported-By: Peter Geoghegan, Geoff WinklessAuthor: Andres Freund, Amit Langote, Peter GeogheganDiscussion: CAEzk6fdzJ3xYQZGbcuYM2rBd2BuDkUksmK=mY9UYYDugg_GgZg@mail.gmail.com, CAM3SWZS+CauzbiCEcg-GdE6K6ycHE_Bz6Ksszy8AoixcMHOmsA@mail.gmail.comBackpatch: 9.5, where ON CONFLICT was introduced1 parent1023194 commitad22783
File tree
7 files changed
+283
-38
lines changed- src
- backend
- optimizer/plan
- parser
- test/regress
- expected
- sql
7 files changed
+283
-38
lines changedLines changed: 17 additions & 12 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1935 | 1935 |
| |
1936 | 1936 |
| |
1937 | 1937 |
| |
1938 |
| - | |
1939 |
| - | |
1940 |
| - | |
1941 |
| - | |
1942 |
| - | |
1943 |
| - | |
1944 |
| - | |
1945 |
| - | |
1946 |
| - | |
1947 |
| - | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
1948 | 1953 |
| |
1949 | 1954 |
| |
1950 | 1955 |
| |
| |||
1987 | 1992 |
| |
1988 | 1993 |
| |
1989 | 1994 |
| |
1990 |
| - | |
| 1995 | + | |
1991 | 1996 |
| |
1992 | 1997 |
| |
1993 | 1998 |
| |
| |||
1998 | 2003 |
| |
1999 | 2004 |
| |
2000 | 2005 |
| |
2001 |
| - | |
| 2006 | + | |
2002 | 2007 |
| |
2003 | 2008 |
| |
2004 | 2009 |
| |
|
Lines changed: 62 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
891 | 891 |
| |
892 | 892 |
| |
893 | 893 |
| |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
894 | 899 |
| |
895 | 900 |
| |
896 | 901 |
| |
897 | 902 |
| |
898 | 903 |
| |
899 | 904 |
| |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
900 | 910 |
| |
901 |
| - | |
| 911 | + | |
902 | 912 |
| |
903 | 913 |
| |
| 914 | + | |
904 | 915 |
| |
905 | 916 |
| |
906 | 917 |
| |
907 |
| - | |
908 |
| - | |
909 |
| - | |
910 |
| - | |
911 |
| - | |
912 |
| - | |
913 |
| - | |
914 |
| - | |
915 |
| - | |
| 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 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
916 | 963 |
| |
917 |
| - | |
918 |
| - | |
919 |
| - | |
920 |
| - | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
921 | 969 |
| |
922 | 970 |
| |
923 | 971 |
| |
|
Lines changed: 5 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
686 | 686 |
| |
687 | 687 |
| |
688 | 688 |
| |
689 |
| - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
690 | 692 |
| |
691 |
| - | |
| 693 | + | |
| 694 | + | |
692 | 695 |
| |
693 | 696 |
| |
694 | 697 |
| |
|
Lines changed: 121 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
380 | 380 |
| |
381 | 381 |
| |
382 | 382 |
| |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
383 | 439 |
| |
384 | 440 |
| |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
385 | 457 |
| |
386 | 458 |
| |
387 | 459 |
| |
| |||
566 | 638 |
| |
567 | 639 |
| |
568 | 640 |
| |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + |
Lines changed: 9 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2900 | 2900 |
| |
2901 | 2901 |
| |
2902 | 2902 |
| |
2903 |
| - | |
| 2903 | + | |
2904 | 2904 |
| |
2905 | 2905 |
| |
2906 | 2906 |
| |
2907 | 2907 |
| |
2908 | 2908 |
| |
2909 | 2909 |
| |
2910 | 2910 |
| |
2911 |
| - | |
| 2911 | + | |
2912 | 2912 |
| |
2913 | 2913 |
| |
2914 | 2914 |
| |
| |||
2956 | 2956 |
| |
2957 | 2957 |
| |
2958 | 2958 |
| |
2959 |
| - | |
| 2959 | + | |
2960 | 2960 |
| |
2961 | 2961 |
| |
2962 | 2962 |
| |
2963 | 2963 |
| |
2964 | 2964 |
| |
2965 | 2965 |
| |
2966 |
| - | |
2967 |
| - | |
| 2966 | + | |
| 2967 | + | |
2968 | 2968 |
| |
2969 | 2969 |
| |
2970 | 2970 |
| |
2971 |
| - | |
| 2971 | + | |
2972 | 2972 |
| |
2973 | 2973 |
| |
2974 | 2974 |
| |
| |||
2995 | 2995 |
| |
2996 | 2996 |
| |
2997 | 2997 |
| |
2998 |
| - | |
2999 |
| - | |
| 2998 | + | |
| 2999 | + | |
3000 | 3000 |
| |
3001 | 3001 |
| |
3002 | 3002 |
| |
3003 |
| - | |
| 3003 | + | |
3004 | 3004 |
| |
3005 | 3005 |
| |
3006 | 3006 |
| |
|
0 commit comments
Comments
(0)