forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit8cad5ad
committed
Avoid postgres_fdw crash for a targetlist entry that's just a Param.
foreign_grouping_ok() is willing to put fairly arbitrary expressions intothe targetlist of a remote SELECT that's doing grouping or aggregation onthe remote side, including expressions that have no foreign component tothem at all. This is possibly a bit dubious from an efficiency standpoint;but it rises to the level of a crash-causing bug if the expression is justa Param or non-foreign Var. In that case, the expression will necessarilyalso appear in the fdw_exprs list of values we need to send to the remoteserver, and then setrefs.c's set_foreignscan_references will mistakenlyreplace the fdw_exprs entry with a Var referencing the targetlist result.The root cause of this problem is bad design in commite7cb7ee: it putlogic into set_foreignscan_references that IMV is postgres_fdw-specific,and yet this bug shows that it isn't postgres_fdw-specific enough. Thetransformation being done on fdw_exprs assumes that fdw_exprs is to beevaluated with the fdw_scan_tlist as input, which is not how postgres_fdwuses it; yet it could be the right thing for some other FDW. (In thebigger picture, setrefs.c has no business assuming this for the otherexpression fields of a ForeignScan either.)The right fix therefore would be to expand the FDW API so that theFDW could inform setrefs.c how it intends to evaluate these variousexpressions. We can't change that in the back branches though, and wealso can't just summarily change setrefs.c's behavior there, or we'relikely to break external FDWs.As a stopgap, therefore, hack up postgres_fdw so that it won't attemptto send targetlist entries that look exactly like the fdw_exprs entriesthey'd produce. In most cases this actually produces a superior plan,IMO, with less data needing to be transmitted and returned; so we probablyought to think harder about whether we should ship tlist expressions atall when they don't contain any foreign Vars or Aggs. But that's anoptimization not a bug fix so I left it for later. One case where thisproduces an inferior plan is where the expression in question is actuallya GROUP BY expression: then the restriction prevents us from using remotegrouping. It might be possible to work around that (since that wouldreduce to group-by-a-constant on the remote side); but it seems like apretty unlikely corner case, so I'm not sure it's worth expending effortsolely to improve that. In any case the right long-term answer is to fixthe API as sketched above, and then revert this hack.Per bug #15781 from Sean Johnston. Back-patch to v10 where the problemwas introduced.Discussion:https://postgr.es/m/15781-2601b1002bad087c@postgresql.org1 parent29046c4 commit8cad5ad
File tree
5 files changed
+129
-5
lines changed- contrib/postgres_fdw
- expected
- sql
5 files changed
+129
-5
lines changedLines changed: 49 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
841 | 841 |
| |
842 | 842 |
| |
843 | 843 |
| |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 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 | + | |
844 | 893 |
| |
845 | 894 |
| |
846 | 895 |
| |
|
Lines changed: 40 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2707 | 2707 |
| |
2708 | 2708 |
| |
2709 | 2709 |
| |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
2710 | 2750 |
| |
2711 | 2751 |
| |
2712 | 2752 |
| |
|
Lines changed: 27 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5486 | 5486 |
| |
5487 | 5487 |
| |
5488 | 5488 |
| |
5489 |
| - | |
5490 | 5489 |
| |
5491 | 5490 |
| |
5492 | 5491 |
| |
| |||
5512 | 5511 |
| |
5513 | 5512 |
| |
5514 | 5513 |
| |
| 5514 | + | |
| 5515 | + | |
| 5516 | + | |
| 5517 | + | |
| 5518 | + | |
| 5519 | + | |
| 5520 | + | |
| 5521 | + | |
| 5522 | + | |
5515 | 5523 |
| |
5516 | 5524 |
| |
5517 | 5525 |
| |
| |||
5532 | 5540 |
| |
5533 | 5541 |
| |
5534 | 5542 |
| |
| 5543 | + | |
| 5544 | + | |
| 5545 | + | |
| 5546 | + | |
| 5547 | + | |
| 5548 | + | |
| 5549 | + | |
5535 | 5550 |
| |
5536 | 5551 |
| |
5537 | 5552 |
| |
| |||
5547 | 5562 |
| |
5548 | 5563 |
| |
5549 | 5564 |
| |
5550 |
| - | |
| 5565 | + | |
| 5566 | + | |
5551 | 5567 |
| |
5552 |
| - | |
| 5568 | + | |
| 5569 | + | |
5553 | 5570 |
| |
5554 | 5571 |
| |
5555 | 5572 |
| |
5556 | 5573 |
| |
5557 | 5574 |
| |
5558 | 5575 |
| |
5559 | 5576 |
| |
| 5577 | + | |
| 5578 | + | |
5560 | 5579 |
| |
5561 | 5580 |
| |
5562 | 5581 |
| |
5563 | 5582 |
| |
5564 | 5583 |
| |
5565 |
| - | |
| 5584 | + | |
| 5585 | + | |
| 5586 | + | |
5566 | 5587 |
| |
5567 | 5588 |
| |
5568 | 5589 |
| |
| |||
5649 | 5670 |
| |
5650 | 5671 |
| |
5651 | 5672 |
| |
5652 |
| - | |
| 5673 | + | |
| 5674 | + | |
5653 | 5675 |
| |
5654 | 5676 |
| |
5655 | 5677 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
146 | 146 |
| |
147 | 147 |
| |
148 | 148 |
| |
| 149 | + | |
| 150 | + | |
| 151 | + | |
149 | 152 |
| |
150 | 153 |
| |
151 | 154 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
685 | 685 |
| |
686 | 686 |
| |
687 | 687 |
| |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
688 | 698 |
| |
689 | 699 |
| |
690 | 700 |
| |
|
0 commit comments
Comments
(0)