forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9a8aa25
committed
Fix misidentification of SQL statement type in plpgsql's exec_stmt_execsql.
To distinguish SQL statements that are INSERT/UPDATE/DELETE from otherones, exec_stmt_execsql looked at the post-rewrite form of the statementrather than the original. This is problematic because it did that onlyduring first execution of the statement (in a session), but the correctanswer could change later due to addition or removal of DO INSTEAD rulesduring the session. That could lead to an Assert failure, as reportedby Tushar Ahuja and Robert Haas. In non-assert builds, there's a hazardthat we would fail to enforce STRICT behavior when we'd be expected to.That would happen if an initially present DO INSTEAD, that replaced theoriginal statement with one of a different type, were removed; after thatthe statement should act "normally", including strictness enforcement, butit didn't. (The converse case of enforcing strictness when we shouldn'tdoesn't seem to be a hazard, as addition of a DO INSTEAD that changes thestatement type would always lead to acting as though the statement returnedzero rows, so that the strictness error could not fire.)To fix, inspect the original form of the statement not the post-rewriteform, making it valid to assume the answer can't change intra-session.This should lead to the same answer in every case except when there is aDO INSTEAD that changes the statement type; we will now set mod_stmt=trueanyway, while we would not have done so before. That breaks the Assertin the SPI_OK_REWRITTEN code path, which expected the latter behavior.It might be all right to assert mod_stmt rather than !mod_stmt there,but I'm not entirely convinced that that'd always hold, so just removethe assertion altogether.This has been broken for a long time, so back-patch to all supportedbranches.Discussion:https://postgr.es/m/CA+TgmoZUrRN4xvZe_BbBn_Xp0BDwuMEue-0OyF0fJpfvU2Yc7Q@mail.gmail.com1 parent7019c21 commit9a8aa25
1 file changed
+14
-13
lines changedLines changed: 14 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4031 | 4031 |
| |
4032 | 4032 |
| |
4033 | 4033 |
| |
4034 |
| - | |
4035 | 4034 |
| |
4036 |
| - | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
4037 | 4045 |
| |
4038 |
| - | |
4039 |
| - | |
4040 |
| - | |
4041 |
| - | |
4042 |
| - | |
4043 |
| - | |
4044 |
| - | |
4045 |
| - | |
4046 |
| - | |
| 4046 | + | |
| 4047 | + | |
4047 | 4048 |
| |
4048 | 4049 |
| |
4049 | 4050 |
| |
| |||
4108 | 4109 |
| |
4109 | 4110 |
| |
4110 | 4111 |
| |
4111 |
| - | |
4112 | 4112 |
| |
4113 | 4113 |
| |
4114 | 4114 |
| |
4115 | 4115 |
| |
4116 |
| - | |
| 4116 | + | |
| 4117 | + | |
4117 | 4118 |
| |
4118 | 4119 |
| |
4119 | 4120 |
| |
|
0 commit comments
Comments
(0)