- Notifications
You must be signed in to change notification settings - Fork5.3k
Commit3881561
committed
Avoid rewriting data-modifying CTEs more than once.
Formerly, when updating an auto-updatable view, or a relation withrules, if the original query had any data-modifying CTEs, the rewriterwould rewrite those CTEs multiple times as RewriteQuery() recursedinto the product queries. In most cases that was harmless, becauseRewriteQuery() is mostly idempotent. However, if the CTE involvedupdating an always-generated column, it would trigger an error becauseany subsequent rewrite would appear to be attempting to assign anon-default value to the always-generated column.This could perhaps be fixed by attempting to make RewriteQuery() fullyidempotent, but that looks quite tricky to achieve, and would probablybe quite fragile, given that more generated-column-type features mightbe added in the future.Instead, fix by arranging for RewriteQuery() to rewrite each CTEexactly once (by tracking the number of CTEs already rewritten as itrecurses). This has the advantage of being simpler and more efficient,but it does make RewriteQuery() dependent on the order in whichrewriteRuleAction() joins the CTE lists from the original query andthe rule action, so care must be taken if that is ever changed.Reported-by: Bernice Southey <bernice.southey@gmail.com>Author: Bernice Southey <bernice.southey@gmail.com>Author: Dean Rasheed <dean.a.rasheed@gmail.com>Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>Discussion:https://postgr.es/m/CAEDh4nyD6MSH9bROhsOsuTqGAv_QceU_GDvN9WcHLtZTCYM1kA@mail.gmail.comBackpatch-through: 141 parent87c6f8b commit3881561
File tree
3 files changed
+90
-5
lines changed- src
- backend/rewrite
- test/regress
- expected
- sql
3 files changed
+90
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
596 | 599 | | |
597 | 600 | | |
598 | 601 | | |
| |||
3872 | 3875 | | |
3873 | 3876 | | |
3874 | 3877 | | |
| 3878 | + | |
| 3879 | + | |
| 3880 | + | |
3875 | 3881 | | |
3876 | 3882 | | |
3877 | | - | |
| 3883 | + | |
| 3884 | + | |
3878 | 3885 | | |
3879 | 3886 | | |
3880 | 3887 | | |
| |||
3888 | 3895 | | |
3889 | 3896 | | |
3890 | 3897 | | |
| 3898 | + | |
| 3899 | + | |
| 3900 | + | |
| 3901 | + | |
| 3902 | + | |
| 3903 | + | |
| 3904 | + | |
3891 | 3905 | | |
3892 | 3906 | | |
3893 | 3907 | | |
3894 | 3908 | | |
3895 | 3909 | | |
| 3910 | + | |
3896 | 3911 | | |
3897 | 3912 | | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
3898 | 3917 | | |
3899 | 3918 | | |
3900 | 3919 | | |
3901 | | - | |
| 3920 | + | |
3902 | 3921 | | |
3903 | 3922 | | |
3904 | 3923 | | |
| |||
3958 | 3977 | | |
3959 | 3978 | | |
3960 | 3979 | | |
| 3980 | + | |
3961 | 3981 | | |
3962 | 3982 | | |
3963 | 3983 | | |
| |||
4289 | 4309 | | |
4290 | 4310 | | |
4291 | 4311 | | |
4292 | | - | |
| 4312 | + | |
| 4313 | + | |
4293 | 4314 | | |
4294 | 4315 | | |
4295 | 4316 | | |
| |||
4564 | 4585 | | |
4565 | 4586 | | |
4566 | 4587 | | |
4567 | | - | |
| 4588 | + | |
4568 | 4589 | | |
4569 | 4590 | | |
4570 | 4591 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2872 | 2872 | | |
2873 | 2873 | | |
2874 | 2874 | | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
| 2915 | + | |
2875 | 2916 | | |
2876 | 2917 | | |
2877 | 2918 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1360 | 1360 | | |
1361 | 1361 | | |
1362 | 1362 | | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
1363 | 1386 | | |
1364 | 1387 | | |
1365 | 1388 | | |
| |||
0 commit comments
Comments
(0)