forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1281a5c
committed
Restructure ALTER TABLE execution to fix assorted bugs.
We've had numerous bug reports about how (1) IF NOT EXISTS clauses inALTER TABLE don't behave as-expected, and (2) combining certain actionsinto one ALTER TABLE doesn't work, though executing the same actions asseparate statements does. This patch cleans up all of the cases so farreported from the field, though there are still some oddities associatedwith identity columns.The core problem behind all of these bugs is that we do parse analysisof ALTER TABLE subcommands too soon, before starting execution of thestatement. The root of the bugs in group (1) is that parse analysisschedules derived commands (such as a CREATE SEQUENCE for a serialcolumn) before it's known whether the IF NOT EXISTS clause should causea subcommand to be skipped. The root of the bugs in group (2) is thatearlier subcommands may change the catalog state that later subcommandsneed to be parsed against.Hence, postpone parse analysis of ALTER TABLE's subcommands, and dothat one subcommand at a time, during "phase 2" of ALTER TABLE whichis the phase that does catalog rewrites. Thus the catalog effectsof earlier subcommands are already visible when we analyze later ones.(The sole exception is that we do parse analysis for ALTER COLUMN TYPEsubcommands during phase 1, so that their USING expressions can beparsed against the table's original state, which is what we need.Arguably, these bugs stem from falsely concluding that because ALTERCOLUMN TYPE must do early parse analysis, every other command subtypecan too.)This means that ALTER TABLE itself must deal with execution of anynon-ALTER-TABLE derived statements that are generated by parse analysis.Add a suitable entry point to utility.c to accept those recursivecalls, and create a struct to pass through the information needed bythe recursive call, rather than making the argument lists ofAlterTable() and friends even longer.Getting this to work correctly required a little bit of fiddlingwith the subcommand pass structure, in particular breaking upAT_PASS_ADD_CONSTR into multiple passes. But otherwise it's mostlya pretty straightforward application of the above ideas.Fixing the residual issues for identity columns requires refactoring ofwhere the dependency link from an identity column to its sequence getsset up. So that seems like suitable material for a separate patch,especially since this one is pretty big already.Discussion:https://postgr.es/m/10365.1558909428@sss.pgh.pa.us1 parenta166d40 commit1281a5c
File tree
13 files changed
+827
-267
lines changed- src
- backend
- commands
- parser
- tcop
- include
- commands
- nodes
- parser
- tcop
- test
- modules/test_ddl_deparse
- regress
- expected
- sql
13 files changed
+827
-267
lines changedLines changed: 387 additions & 107 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
145 | 145 |
| |
146 | 146 |
| |
147 | 147 |
| |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
148 | 152 |
| |
149 | 153 |
| |
150 | 154 |
| |
|
Lines changed: 77 additions & 65 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
347 | 347 |
| |
348 | 348 |
| |
349 | 349 |
| |
350 |
| - | |
| 350 | + | |
| 351 | + | |
351 | 352 |
| |
352 | 353 |
| |
353 | 354 |
| |
| |||
472 | 473 |
| |
473 | 474 |
| |
474 | 475 |
| |
475 |
| - | |
476 |
| - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
477 | 482 |
| |
478 | 483 |
| |
479 | 484 |
| |
| |||
484 | 489 |
| |
485 | 490 |
| |
486 | 491 |
| |
487 |
| - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
488 | 496 |
| |
489 | 497 |
| |
490 | 498 |
| |
| |||
568 | 576 |
| |
569 | 577 |
| |
570 | 578 |
| |
571 |
| - | |
| 579 | + | |
| 580 | + | |
572 | 581 |
| |
573 | 582 |
| |
574 | 583 |
| |
| |||
684 | 693 |
| |
685 | 694 |
| |
686 | 695 |
| |
687 |
| - | |
| 696 | + | |
| 697 | + | |
688 | 698 |
| |
689 | 699 |
| |
690 | 700 |
| |
| |||
1086 | 1096 |
| |
1087 | 1097 |
| |
1088 | 1098 |
| |
1089 |
| - | |
| 1099 | + | |
| 1100 | + | |
1090 | 1101 |
| |
1091 | 1102 |
| |
1092 | 1103 |
| |
| |||
2572 | 2583 |
| |
2573 | 2584 |
| |
2574 | 2585 |
| |
2575 |
| - | |
| 2586 | + | |
2576 | 2587 |
| |
2577 | 2588 |
| |
2578 | 2589 |
| |
| |||
3004 | 3015 |
| |
3005 | 3016 |
| |
3006 | 3017 |
| |
3007 |
| - | |
3008 |
| - | |
3009 |
| - | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
3010 | 3021 |
| |
3011 | 3022 |
| |
3012 | 3023 |
| |
3013 | 3024 |
| |
3014 | 3025 |
| |
3015 |
| - | |
| 3026 | + | |
3016 | 3027 |
| |
3017 |
| - | |
| 3028 | + | |
| 3029 | + | |
3018 | 3030 |
| |
3019 | 3031 |
| |
3020 | 3032 |
| |
3021 | 3033 |
| |
3022 | 3034 |
| |
3023 |
| - | |
3024 | 3035 |
| |
3025 | 3036 |
| |
3026 | 3037 |
| |
| |||
3052 | 3063 |
| |
3053 | 3064 |
| |
3054 | 3065 |
| |
3055 |
| - | |
| 3066 | + | |
3056 | 3067 |
| |
3057 | 3068 |
| |
3058 | 3069 |
| |
| |||
3080 | 3091 |
| |
3081 | 3092 |
| |
3082 | 3093 |
| |
3083 |
| - | |
3084 |
| - | |
3085 |
| - | |
| 3094 | + | |
| 3095 | + | |
3086 | 3096 |
| |
3087 | 3097 |
| |
3088 | 3098 |
| |
| |||
3091 | 3101 |
| |
3092 | 3102 |
| |
3093 | 3103 |
| |
3094 |
| - | |
| 3104 | + | |
3095 | 3105 |
| |
3096 | 3106 |
| |
3097 | 3107 |
| |
| |||
3115 | 3125 |
| |
3116 | 3126 |
| |
3117 | 3127 |
| |
| 3128 | + | |
3118 | 3129 |
| |
3119 | 3130 |
| |
3120 | 3131 |
| |
| |||
3130 | 3141 |
| |
3131 | 3142 |
| |
3132 | 3143 |
| |
3133 |
| - | |
3134 |
| - | |
3135 |
| - | |
3136 |
| - | |
3137 |
| - | |
3138 |
| - | |
3139 |
| - | |
3140 |
| - | |
3141 |
| - | |
3142 |
| - | |
3143 | 3144 |
| |
3144 | 3145 |
| |
3145 |
| - | |
| 3146 | + | |
3146 | 3147 |
| |
3147 | 3148 |
| |
3148 | 3149 |
| |
| |||
3161 | 3162 |
| |
3162 | 3163 |
| |
3163 | 3164 |
| |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
3164 | 3170 |
| |
3165 |
| - | |
3166 |
| - | |
3167 |
| - | |
3168 |
| - | |
3169 |
| - | |
3170 |
| - | |
| 3171 | + | |
3171 | 3172 |
| |
3172 | 3173 |
| |
3173 | 3174 |
| |
| |||
3196 | 3197 |
| |
3197 | 3198 |
| |
3198 | 3199 |
| |
| 3200 | + | |
| 3201 | + | |
| 3202 | + | |
| 3203 | + | |
| 3204 | + | |
3199 | 3205 |
| |
3200 |
| - | |
3201 |
| - | |
3202 |
| - | |
3203 |
| - | |
3204 |
| - | |
3205 |
| - | |
3206 |
| - | |
3207 |
| - | |
3208 |
| - | |
| 3206 | + | |
| 3207 | + | |
| 3208 | + | |
| 3209 | + | |
3209 | 3210 |
| |
3210 | 3211 |
| |
3211 | 3212 |
| |
| |||
3221 | 3222 |
| |
3222 | 3223 |
| |
3223 | 3224 |
| |
| 3225 | + | |
3224 | 3226 |
| |
3225 | 3227 |
| |
3226 | 3228 |
| |
| |||
3237 | 3239 |
| |
3238 | 3240 |
| |
3239 | 3241 |
| |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
3240 | 3247 |
| |
3241 |
| - | |
3242 |
| - | |
3243 |
| - | |
| 3248 | + | |
3244 | 3249 |
| |
3245 |
| - | |
3246 |
| - | |
3247 |
| - | |
| 3250 | + | |
| 3251 | + | |
| 3252 | + | |
3248 | 3253 |
| |
3249 |
| - | |
3250 |
| - | |
3251 |
| - | |
3252 |
| - | |
3253 |
| - | |
3254 |
| - | |
| 3254 | + | |
| 3255 | + | |
| 3256 | + | |
| 3257 | + | |
| 3258 | + | |
| 3259 | + | |
3255 | 3260 |
| |
3256 |
| - | |
3257 |
| - | |
| 3261 | + | |
3258 | 3262 |
| |
3259 | 3263 |
| |
3260 | 3264 |
| |
3261 |
| - | |
3262 |
| - | |
| 3265 | + | |
| 3266 | + | |
| 3267 | + | |
| 3268 | + | |
| 3269 | + | |
3263 | 3270 |
| |
3264 | 3271 |
| |
3265 | 3272 |
| |
| |||
3281 | 3288 |
| |
3282 | 3289 |
| |
3283 | 3290 |
| |
| 3291 | + | |
| 3292 | + | |
| 3293 | + | |
| 3294 | + | |
| 3295 | + | |
| 3296 | + | |
3284 | 3297 |
| |
3285 | 3298 |
| |
3286 | 3299 |
| |
| |||
3361 | 3374 |
| |
3362 | 3375 |
| |
3363 | 3376 |
| |
3364 |
| - | |
3365 |
| - | |
3366 |
| - | |
| 3377 | + | |
| 3378 | + | |
3367 | 3379 |
| |
3368 |
| - | |
| 3380 | + | |
3369 | 3381 |
| |
3370 | 3382 |
| |
3371 | 3383 |
| |
|
0 commit comments
Comments
(0)