forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita45adc7
committed
Fix WITH CHECK OPTION on views referencing postgres_fdw tables.
If a view references a foreign table, and the foreign table has aBEFORE INSERT trigger, then it's possible for a tuple inserted orupdated through the view to be changed such that it violates theview's WITH CHECK OPTION constraint.Before this commit, postgres_fdw handled this case inconsistently. ARETURNING clause on the INSERT or UPDATE statement targeting the viewwould cause the finally-inserted tuple to be read back, and the WITHCHECK OPTION violation would throw an error. But without a RETURNINGclause, postgres_fdw would not read the final tuple back, and WITHCHECK OPTION would not throw an error for the violation (or may throwan error when there is no real violation). AFTER ROW triggers on theforeign table had a similar effect as a RETURNING clause on the INSERTor UPDATE statement.To fix, this commit retrieves the attributes needed to enforce theWITH CHECK OPTION constraint along with the attributes needed for theRETURNING clause (if any) from the remote side. Thus, the WITH CHECKOPTION constraint is always evaluated against the final tuple afterany triggers on the remote side.This fix may be considered inconsistent with CHECK constraintsdeclared on foreign tables, which are not enforced locally at all(because the constraint is on a remote object). The discussionconcluded that this difference is reasonable, because the WITH CHECKOPTION is a constraint on the local view (not any remote object);therefore it only makes sense to enforce its WITH CHECK OPTIONconstraint locally.Author: Etsuro FujitaReviewed-by: Arthur Zakirov, Stephen FrostDiscussion:https://www.postgresql.org/message-id/7eb58fab-fd3b-781b-ac33-f7cfec96021f%40lab.ntt.co.jp1 parente915fed commita45adc7
File tree
6 files changed
+261
-58
lines changed- contrib/postgres_fdw
- expected
- sql
- doc/src/sgml
6 files changed
+261
-58
lines changedLines changed: 30 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
140 | 140 |
| |
141 | 141 |
| |
142 | 142 |
| |
| 143 | + | |
143 | 144 |
| |
144 | 145 |
| |
145 | 146 |
| |
| |||
1645 | 1646 |
| |
1646 | 1647 |
| |
1647 | 1648 |
| |
1648 |
| - | |
1649 |
| - | |
| 1649 | + | |
| 1650 | + | |
1650 | 1651 |
| |
1651 | 1652 |
| |
1652 | 1653 |
| |
1653 | 1654 |
| |
1654 | 1655 |
| |
1655 |
| - | |
| 1656 | + | |
| 1657 | + | |
1656 | 1658 |
| |
1657 | 1659 |
| |
1658 | 1660 |
| |
| |||
1701 | 1703 |
| |
1702 | 1704 |
| |
1703 | 1705 |
| |
1704 |
| - | |
| 1706 | + | |
1705 | 1707 |
| |
1706 | 1708 |
| |
1707 | 1709 |
| |
1708 | 1710 |
| |
1709 | 1711 |
| |
1710 | 1712 |
| |
1711 |
| - | |
1712 |
| - | |
| 1713 | + | |
| 1714 | + | |
1713 | 1715 |
| |
1714 | 1716 |
| |
1715 | 1717 |
| |
1716 | 1718 |
| |
1717 |
| - | |
| 1719 | + | |
| 1720 | + | |
1718 | 1721 |
| |
1719 | 1722 |
| |
1720 | 1723 |
| |
| |||
1743 | 1746 |
| |
1744 | 1747 |
| |
1745 | 1748 |
| |
1746 |
| - | |
| 1749 | + | |
1747 | 1750 |
| |
1748 | 1751 |
| |
1749 | 1752 |
| |
| |||
1837 | 1840 |
| |
1838 | 1841 |
| |
1839 | 1842 |
| |
1840 |
| - | |
| 1843 | + | |
1841 | 1844 |
| |
1842 | 1845 |
| |
1843 | 1846 |
| |
| |||
1859 | 1862 |
| |
1860 | 1863 |
| |
1861 | 1864 |
| |
1862 |
| - | |
| 1865 | + | |
1863 | 1866 |
| |
1864 | 1867 |
| |
1865 | 1868 |
| |
| |||
1921 | 1924 |
| |
1922 | 1925 |
| |
1923 | 1926 |
| |
1924 |
| - | |
| 1927 | + | |
1925 | 1928 |
| |
1926 | 1929 |
| |
1927 | 1930 |
| |
| |||
1931 | 1934 |
| |
1932 | 1935 |
| |
1933 | 1936 |
| |
| 1937 | + | |
1934 | 1938 |
| |
1935 | 1939 |
| |
1936 | 1940 |
| |
| |||
1943 | 1947 |
| |
1944 | 1948 |
| |
1945 | 1949 |
| |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
1946 | 1965 |
| |
1947 | 1966 |
| |
1948 | 1967 |
| |
|
Lines changed: 142 additions & 23 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
6173 | 6173 |
| |
6174 | 6174 |
| |
6175 | 6175 |
| |
| 6176 | + | |
6176 | 6177 |
| |
6177 | 6178 |
| |
| 6179 | + | |
6178 | 6180 |
| |
6179 |
| - | |
| 6181 | + | |
6180 | 6182 |
| |
6181 | 6183 |
| |
6182 | 6184 |
| |
| |||
6192 | 6194 |
| |
6193 | 6195 |
| |
6194 | 6196 |
| |
6195 |
| - | |
6196 |
| - | |
| 6197 | + | |
| 6198 | + | |
| 6199 | + | |
| 6200 | + | |
| 6201 | + | |
| 6202 | + | |
| 6203 | + | |
| 6204 | + | |
| 6205 | + | |
| 6206 | + | |
| 6207 | + | |
6197 | 6208 |
| |
6198 |
| - | |
| 6209 | + | |
6199 | 6210 |
| |
6200 |
| - | |
6201 |
| - | |
6202 |
| - | |
| 6211 | + | |
| 6212 | + | |
| 6213 | + | |
| 6214 | + | |
| 6215 | + | |
| 6216 | + | |
| 6217 | + | |
| 6218 | + | |
| 6219 | + | |
| 6220 | + | |
| 6221 | + | |
| 6222 | + | |
| 6223 | + | |
| 6224 | + | |
| 6225 | + | |
| 6226 | + | |
| 6227 | + | |
| 6228 | + | |
| 6229 | + | |
| 6230 | + | |
6203 | 6231 |
| |
6204 |
| - | |
| 6232 | + | |
6205 | 6233 |
| |
6206 |
| - | |
6207 |
| - | |
| 6234 | + | |
| 6235 | + | |
6208 | 6236 |
| |
6209 | 6237 |
| |
6210 |
| - | |
| 6238 | + | |
| 6239 | + | |
| 6240 | + | |
6211 | 6241 |
| |
6212 |
| - | |
6213 |
| - | |
6214 |
| - | |
| 6242 | + | |
| 6243 | + | |
| 6244 | + | |
6215 | 6245 |
| |
6216 |
| - | |
| 6246 | + | |
6217 | 6247 |
| |
6218 |
| - | |
6219 |
| - | |
| 6248 | + | |
| 6249 | + | |
6220 | 6250 |
| |
6221 | 6251 |
| |
6222 |
| - | |
6223 |
| - | |
6224 |
| - | |
| 6252 | + | |
6225 | 6253 |
| |
6226 |
| - | |
6227 |
| - | |
6228 |
| - | |
| 6254 | + | |
| 6255 | + | |
| 6256 | + | |
6229 | 6257 |
| |
6230 | 6258 |
| |
6231 | 6259 |
| |
6232 | 6260 |
| |
| 6261 | + | |
6233 | 6262 |
| |
| 6263 | + | |
| 6264 | + | |
| 6265 | + | |
| 6266 | + | |
| 6267 | + | |
| 6268 | + | |
| 6269 | + | |
| 6270 | + | |
| 6271 | + | |
| 6272 | + | |
| 6273 | + | |
| 6274 | + | |
| 6275 | + | |
| 6276 | + | |
| 6277 | + | |
| 6278 | + | |
| 6279 | + | |
| 6280 | + | |
| 6281 | + | |
| 6282 | + | |
| 6283 | + | |
| 6284 | + | |
| 6285 | + | |
| 6286 | + | |
| 6287 | + | |
| 6288 | + | |
| 6289 | + | |
| 6290 | + | |
| 6291 | + | |
| 6292 | + | |
| 6293 | + | |
| 6294 | + | |
| 6295 | + | |
| 6296 | + | |
| 6297 | + | |
| 6298 | + | |
| 6299 | + | |
| 6300 | + | |
| 6301 | + | |
| 6302 | + | |
| 6303 | + | |
| 6304 | + | |
| 6305 | + | |
| 6306 | + | |
| 6307 | + | |
| 6308 | + | |
| 6309 | + | |
| 6310 | + | |
| 6311 | + | |
| 6312 | + | |
| 6313 | + | |
| 6314 | + | |
| 6315 | + | |
| 6316 | + | |
| 6317 | + | |
| 6318 | + | |
| 6319 | + | |
| 6320 | + | |
| 6321 | + | |
| 6322 | + | |
| 6323 | + | |
| 6324 | + | |
| 6325 | + | |
| 6326 | + | |
| 6327 | + | |
| 6328 | + | |
| 6329 | + | |
| 6330 | + | |
| 6331 | + | |
| 6332 | + | |
| 6333 | + | |
| 6334 | + | |
| 6335 | + | |
| 6336 | + | |
| 6337 | + | |
| 6338 | + | |
| 6339 | + | |
| 6340 | + | |
| 6341 | + | |
| 6342 | + | |
| 6343 | + | |
| 6344 | + | |
| 6345 | + | |
| 6346 | + | |
| 6347 | + | |
| 6348 | + | |
| 6349 | + | |
| 6350 | + | |
| 6351 | + | |
| 6352 | + | |
6234 | 6353 |
| |
6235 | 6354 |
| |
6236 | 6355 |
| |
|
Lines changed: 15 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1582 | 1582 |
| |
1583 | 1583 |
| |
1584 | 1584 |
| |
| 1585 | + | |
1585 | 1586 |
| |
1586 | 1587 |
| |
1587 | 1588 |
| |
| |||
1630 | 1631 |
| |
1631 | 1632 |
| |
1632 | 1633 |
| |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
1633 | 1641 |
| |
1634 | 1642 |
| |
1635 | 1643 |
| |
| |||
1655 | 1663 |
| |
1656 | 1664 |
| |
1657 | 1665 |
| |
1658 |
| - | |
| 1666 | + | |
| 1667 | + | |
1659 | 1668 |
| |
1660 | 1669 |
| |
1661 | 1670 |
| |
1662 | 1671 |
| |
1663 |
| - | |
| 1672 | + | |
| 1673 | + | |
1664 | 1674 |
| |
1665 | 1675 |
| |
1666 | 1676 |
| |
| |||
2046 | 2056 |
| |
2047 | 2057 |
| |
2048 | 2058 |
| |
2049 |
| - | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
2050 | 2062 |
| |
2051 | 2063 |
| |
2052 | 2064 |
| |
|
Lines changed: 4 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
142 | 142 |
| |
143 | 143 |
| |
144 | 144 |
| |
145 |
| - | |
| 145 | + | |
| 146 | + | |
146 | 147 |
| |
147 | 148 |
| |
148 | 149 |
| |
149 |
| - | |
| 150 | + | |
| 151 | + | |
150 | 152 |
| |
151 | 153 |
| |
152 | 154 |
| |
|
0 commit comments
Comments
(0)