- Notifications
You must be signed in to change notification settings - Fork28
Commit25378db
committed
Fix list-munging bug that broke SQL function result coercions.
Since commit913bbd8, check_sql_fn_retval() can either insert typecoercion steps in-line in the Query that produces the SQL function'sresults, or generate a new top-level Query to perform the coercions,if modifying the Query's output in-place wouldn't be safe. However,it appears that the latter case has never actually worked, becausethe code tried to inject the new Query back into the query list it waspassed ... which is not the list that will be used for later processingwhen we execute the SQL function "normally" (without inlining it).So we ended up with no coercion happening at run-time, leading towrong results or crashes depending on the datatypes involved.While the regression tests look like they cover this area well enough,through a huge bit of bad luck all the test cases that exercise theseparate-Query path were checking either inline-able cases (whichaccidentally didn't have the bug) or cases that are no-ops at runtime(e.g., varchar to text), so that the failure to perform the coercionwasn't obvious. The fact that the cases that don't work weren'tallowed at all before v13 probably contributed to not noticing theproblem sooner, too.To fix, get rid of the separate "flat" list of Query nodes and insteadpass the real two-level list that is going to be used later. I choseto make the same change in check_sql_fn_statements(), although that hasno actual bug, just so that we don't need that data structure at all.This is an API change, as evidenced by the adjustments needed tocallers outside functions.c. That's a bit scary to be doing in areleased branch, but so far as I can tell from a quick search,there are no outside callers of these functions (and they aresufficiently specific to our semantics for SQL-language functions thatit's not apparent why any extension would need to call them). In anycase, v13 already changed the API of check_sql_fn_retval() compared toprior branches.Per report from pinker. Back-patch to v13 where this code came in.Discussion:https://postgr.es/m/1603050466566-0.post@n3.nabble.com1 parent33acc6b commit25378db
File tree
6 files changed
+132
-60
lines changed- src
- backend
- catalog
- executor
- optimizer/util
- include/executor
- test/regress
- expected
- sql
6 files changed
+132
-60
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
918 | 918 |
| |
919 | 919 |
| |
920 | 920 |
| |
921 |
| - | |
922 |
| - | |
| 921 | + | |
| 922 | + | |
923 | 923 |
| |
924 | 924 |
| |
925 | 925 |
| |
|
Lines changed: 69 additions & 53 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
608 | 608 |
| |
609 | 609 |
| |
610 | 610 |
| |
611 |
| - | |
612 | 611 |
| |
613 | 612 |
| |
614 | 613 |
| |
| |||
688 | 687 |
| |
689 | 688 |
| |
690 | 689 |
| |
691 |
| - | |
692 |
| - | |
693 |
| - | |
694 |
| - | |
695 |
| - | |
696 |
| - | |
697 |
| - | |
| 690 | + | |
698 | 691 |
| |
699 | 692 |
| |
700 | 693 |
| |
| |||
704 | 697 |
| |
705 | 698 |
| |
706 | 699 |
| |
707 |
| - | |
708 | 700 |
| |
709 | 701 |
| |
710 | 702 |
| |
| |||
716 | 708 |
| |
717 | 709 |
| |
718 | 710 |
| |
719 |
| - | |
720 | 711 |
| |
721 | 712 |
| |
722 |
| - | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
723 | 717 |
| |
724 | 718 |
| |
725 | 719 |
| |
| |||
739 | 733 |
| |
740 | 734 |
| |
741 | 735 |
| |
742 |
| - | |
| 736 | + | |
743 | 737 |
| |
744 | 738 |
| |
745 | 739 |
| |
| |||
1509 | 1503 |
| |
1510 | 1504 |
| |
1511 | 1505 |
| |
1512 |
| - | |
| 1506 | + | |
1513 | 1507 |
| |
1514 | 1508 |
| |
1515 | 1509 |
| |
1516 |
| - | |
| 1510 | + | |
| 1511 | + | |
1517 | 1512 |
| |
1518 |
| - | |
| 1513 | + | |
| 1514 | + | |
1519 | 1515 |
| |
1520 |
| - | |
1521 |
| - | |
1522 |
| - | |
1523 |
| - | |
1524 |
| - | |
1525 |
| - | |
1526 |
| - | |
1527 |
| - | |
1528 |
| - | |
| 1516 | + | |
1529 | 1517 |
| |
1530 |
| - | |
1531 |
| - | |
1532 |
| - | |
1533 |
| - | |
1534 |
| - | |
1535 |
| - | |
1536 |
| - | |
1537 |
| - | |
1538 |
| - | |
1539 |
| - | |
1540 |
| - | |
1541 |
| - | |
1542 |
| - | |
1543 |
| - | |
1544 |
| - | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
1545 | 1529 |
| |
1546 |
| - | |
1547 |
| - | |
1548 |
| - | |
1549 |
| - | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
1550 | 1555 |
| |
1551 | 1556 |
| |
1552 | 1557 |
| |
1553 | 1558 |
| |
1554 | 1559 |
| |
1555 | 1560 |
| |
1556 |
| - | |
| 1561 | + | |
| 1562 | + | |
1557 | 1563 |
| |
1558 | 1564 |
| |
1559 | 1565 |
| |
| |||
1591 | 1597 |
| |
1592 | 1598 |
| |
1593 | 1599 |
| |
1594 |
| - | |
| 1600 | + | |
1595 | 1601 |
| |
1596 | 1602 |
| |
1597 | 1603 |
| |
| |||
1618 | 1624 |
| |
1619 | 1625 |
| |
1620 | 1626 |
| |
1621 |
| - | |
1622 |
| - | |
1623 |
| - | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
1624 | 1634 |
| |
1625 | 1635 |
| |
1626 | 1636 |
| |
1627 |
| - | |
| 1637 | + | |
1628 | 1638 |
| |
1629 |
| - | |
| 1639 | + | |
| 1640 | + | |
1630 | 1641 |
| |
1631 |
| - | |
| 1642 | + | |
1632 | 1643 |
| |
1633 |
| - | |
1634 |
| - | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
1635 | 1651 |
| |
1636 | 1652 |
| |
1637 | 1653 |
| |
|
Lines changed: 4 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4522 | 4522 |
| |
4523 | 4523 |
| |
4524 | 4524 |
| |
4525 |
| - | |
| 4525 | + | |
| 4526 | + | |
4526 | 4527 |
| |
4527 | 4528 |
| |
4528 | 4529 |
| |
| |||
5040 | 5041 |
| |
5041 | 5042 |
| |
5042 | 5043 |
| |
5043 |
| - | |
| 5044 | + | |
5044 | 5045 |
| |
5045 | 5046 |
| |
5046 | 5047 |
| |
| |||
5052 | 5053 |
| |
5053 | 5054 |
| |
5054 | 5055 |
| |
5055 |
| - | |
| 5056 | + | |
5056 | 5057 |
| |
5057 | 5058 |
| |
5058 | 5059 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
32 |
| - | |
| 32 | + | |
33 | 33 |
| |
34 |
| - | |
| 34 | + | |
35 | 35 |
| |
36 | 36 |
| |
37 | 37 |
| |
|
Lines changed: 44 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2109 | 2109 |
| |
2110 | 2110 |
| |
2111 | 2111 |
| |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
2112 | 2156 |
| |
2113 | 2157 |
| |
2114 | 2158 |
| |
|
Lines changed: 11 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 | + | |
632 | 643 |
| |
633 | 644 |
| |
634 | 645 |
| |
|
0 commit comments
Comments
(0)